#pragma once #ifndef DS2482_HAL_H #define DS2482_HAL_H #include "stm32f3xx_hal.h" #define DS2482_I2C_ADDR 0x30 // TODO: change to actual address #define DS2482_CMD_RESET 0xF0 #define DS2482_CMD_SET_READ_PTR 0xE1 #define DS2482_CMD_WRITE_CONFIG 0xD2 #define DS2482_CMD_1W_RESET 0xB4 #define DS2482_CMD_1W_SINGLE_BIT 0x87 #define DS2482_CMD_1W_WRITE_BYTE 0xA5 #define DS2482_CMD_1W_READ_BYTE 0x96 #define DS2482_CMD_1W_TRIPLET 0x78 #define DS2482_STATUS 0xF0 #define DS2482_READ_DATA 0xE1 #define DS2482_CONFIG 0xC3 #define DS2482_CONFIG_APU 1 << 0 #define DS2482_CONFIG_SPU 1 << 2 #define DS2482_CONFIG_1WS 1 << 3 #define DS2482_TIMEOUT_1W 100 #define DS2482_TIMEOUT_I2C 100 typedef struct { uint8_t BUSY : 1; uint8_t PPD : 1; uint8_t SHORT : 1; uint8_t LL : 1; uint8_t RST : 1; uint8_t SBR : 1; uint8_t TSB : 1; uint8_t DIR : 1; } DS2482_Status; HAL_StatusTypeDef ds2482_init(I2C_HandleTypeDef* handle); HAL_StatusTypeDef ds2482_reset(); HAL_StatusTypeDef ds2482_write_config(uint8_t config); HAL_StatusTypeDef ds2482_set_read_ptr(uint8_t read_ptr); HAL_StatusTypeDef ds2482_1w_reset(bool* presence); HAL_StatusTypeDef ds2482_1w_write_byte(uint8_t byte); HAL_StatusTypeDef ds2482_1w_read_byte(uint8_t* byte); HAL_StatusTypeDef ds2482_1w_triplet(uint8_t dir); HAL_StatusTypeDef ds2482_1w_search(uint16_t max_devices, uint64_t devices[static max_devices]); HAL_StatusTypeDef ds2482_1w_verify_device(uint64_t device, bool* present); #endif // DS2482_HAL_H