Go to the documentation of this file.
38 #define REG_INVALID_ADDRESS 0xffffU
39 #define REG_ERROR_READ_ADDRESS 0xeeeeee00U
40 #define REG_ERROR_READ_OF_WO_REG 0xeeeeee01U
82 uint16_t register_address = (buffer[0] << 8) | buffer[1];
105 return (reg != NULL) && (reg->
write != NULL);
122 if (reg->
read != NULL)
138 buffer[0] = (data >> 24) & 0xff;
139 buffer[1] = (data >> 16) & 0xff;
140 buffer[2] = (data >> 8) & 0xff;
141 buffer[3] = (data >> 0) & 0xff;
161 (((uint32_t)buffer[0]) << 24) |
162 (((uint32_t)buffer[1]) << 16) |
163 (((uint32_t)buffer[2]) << 8) |
164 (((uint32_t)buffer[3]) << 0);
170 if (reg->
write != NULL)
172 if (!reg->
write(data))
332 return (int32_t)(value*1000.0f);
338 return (uint32_t)(value*1000.0f);
344 float val = (float)value;
353 float val = (float)value;
void acc_reg_protocol_data_out(uint8_t *buffer, size_t data_out_length)
Handle data input from the register protocol.
float acc_reg_protocol_int32_milli_to_float(int32_t value)
Convert int32 / 1000 to float.
#define ACC_REG_PROTOCOL_ADDRESS_LENGTH
#define ACC_REG_ERROR_FLAG_PACKET_LENGTH_ERROR
acc_reg_write_func_t * write
static void read_register(uint8_t *buffer)
Read register at current register address and increase address.
static bool write_register(uint8_t *buffer)
Write register at current register address and increase address.
static uint16_t reg_address
#define ACC_REG_ERROR_FLAG_ADDRESS_ERROR
void acc_reg_protocol_reset(void)
Reset register protocol.
void acc_reg_protocol_data_in(uint8_t *buffer, size_t data_in_length)
Handle data input to the register protocol.
@ REG_STATE_WAIT_FOR_READ
static void set_address(uint8_t *buffer)
Set current register address.
#define REG_ERROR_READ_OF_WO_REG
#define ACC_REG_PROTOCOL_REGDATA_LENGTH
int32_t acc_reg_protocol_float_to_int32_milli(float value)
Convert 1000 * float to int32.
@ REG_STATE_WAIT_FOR_ADDRESS
static uint16_t reg_register_count
float acc_reg_protocol_uint32_milli_to_float(uint32_t value)
Convert uint32 / 1000 to float.
acc_reg_protocol_state_t
Register protocol state.
#define ACC_REG_ERROR_FLAG_WRITE_FAILED
#define REG_ERROR_READ_ADDRESS
void acc_reg_protocol_setup(const acc_reg_protocol_t *protocol_struct, uint16_t register_count)
Setup register protocol.
uint32_t acc_reg_protocol_get_error_flags(void)
Get the error flags for the register protocol.
static const acc_reg_protocol_t * reg_protocol_struct
static bool register_is_writable(void)
Return true if register is writable.
uint32_t acc_reg_protocol_float_to_uint32_milli(float value)
Convert 1000 * float to uint32.
acc_reg_mode_t
Register access mode.
#define ACC_REG_ERROR_FLAG_PROTOCOL_STATE_ERROR
#define ACC_REG_ERROR_FLAG_WRITE_TO_READ_ONLY
Register access mode and functions struct.
@ REG_STATE_NACK_NEXT_WRITE
@ REG_STATE_WAIT_FOR_WRITE
@ REG_STATE_WAIT_FOR_READ_OR_WRITE
static acc_reg_protocol_state_t reg_state
bool acc_reg_protocol_data_nack(void)
Should protocol NACK the next data.
static uint32_t reg_error_flags
acc_reg_read_func_t * read
#define REG_INVALID_ADDRESS
static const acc_reg_protocol_t * get_register_struct(uint16_t register_address)
Get register struct from protocol struct.