minor refactor

This commit is contained in:
Kilian Bracher 2024-06-27 16:09:55 +02:00
parent a41cc7e9de
commit 64545e5ebd
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
2 changed files with 28 additions and 30 deletions

View File

@ -1,6 +1,34 @@
#include "DS2482_HAL.h"
#include <stdint.h>
#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
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;
static I2C_HandleTypeDef* hi2c;
HAL_StatusTypeDef ds2482_init(I2C_HandleTypeDef* handle) {

View File

@ -13,40 +13,10 @@
#error "No target defined"
#endif
#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);