42#define CHIP_NAME "AtomBit BA121"
43#define MANUFACTURER_NAME "AtomBit"
44#define SUPPLY_VOLTAGE_MIN 3.3f
45#define SUPPLY_VOLTAGE_MAX 5.0f
46#define MAX_CURRENT 3.0f
47#define TEMPERATURE_MIN -10.0f
48#define TEMPERATURE_MAX 75.0f
49#define DRIVER_VERSION 1000
54#define BA121_COMMAND_READ 0xA0
55#define BA121_COMMAND_BASELINE 0xA6
56#define BA121_COMMAND_NTC_RES 0xA3
57#define BA121_COMMAND_NTC_B 0xA5
69static uint8_t a_ba121_make_frame(uint8_t command, uint32_t data, uint8_t output[6])
75 output[1] = (data >> 24) & 0xFF;
76 output[2] = (data >> 16) & 0xFF;
77 output[3] = (data >> 8) & 0xFF;
78 output[4] = (data >> 0) & 0xFF;
81 for (i = 0; i < 5; i++)
85 output[5] = sum & 0xFF;
101static uint8_t a_ba121_parse_frame(
ba121_handle_t *handle, uint8_t is_data, uint8_t input[6], uint32_t *data)
107 for (i = 0; i < 5; i++)
111 if ((sum & 0xFF) != input[5])
119 if (input[0] != 0xAA)
121 handle->
debug_print(
"ba121: frame header invalid.\n");
125 *data = ((uint32_t)input[1] << 24) | ((uint32_t)input[2] << 16) |
126 ((uint32_t)input[3] << 8) | ((uint32_t)input[4] << 0);
130 if (input[0] != 0xAC)
132 handle->
debug_print(
"ba121: frame header invalid.\n");
136 *data = ((uint32_t)input[1] << 24) | ((uint32_t)input[2] << 26) |
137 ((uint32_t)input[3] << 8) | ((uint32_t)input[4] << 0);
165 handle->
debug_print(
"ba121: uart_init is null.\n");
171 handle->
debug_print(
"ba121: uart_deinit is null.\n");
177 handle->
debug_print(
"ba121: uart_read is null.\n");
183 handle->
debug_print(
"ba121: uart_flush is null.\n");
189 handle->
debug_print(
"ba121: uart_write is null.\n");
235 handle->
debug_print(
"ba121: uart deinit failed.\n");
260 uint16_t *temperature_raw,
float *temperature)
281 handle->
debug_print(
"ba121: uart flush failed.\n");
288 handle->
debug_print(
"ba121: uart write failed.\n");
300 res = a_ba121_parse_frame(handle, 1, input, &data);
307 *conductivity_raw = (data >> 16) & 0xFFFFU;
308 *conductivity_us_cm = *conductivity_raw;
309 *temperature_raw = (data >> 0) & 0xFFFFU;
310 *temperature = (float)(*temperature_raw) / 100.0f;
348 handle->
debug_print(
"ba121: uart flush failed.\n");
355 handle->
debug_print(
"ba121: uart write failed.\n");
367 res = a_ba121_parse_frame(handle, 0, input, &data);
419 handle->
debug_print(
"ba121: uart flush failed.\n");
426 handle->
debug_print(
"ba121: uart write failed.\n");
438 res = a_ba121_parse_frame(handle, 0, input, &data);
490 handle->
debug_print(
"ba121: uart flush failed.\n");
497 handle->
debug_print(
"ba121: uart write failed.\n");
509 res = a_ba121_parse_frame(handle, 0, input, &data);
580 handle->
debug_print(
"ba121: uart flush failed.\n");
587 handle->
debug_print(
"ba121: uart write failed.\n");
620 l = handle->
uart_read((uint8_t *)buf, len);
#define BA121_COMMAND_NTC_RES
#define BA121_COMMAND_NTC_B
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BA121_COMMAND_READ
chip command definition
#define BA121_COMMAND_BASELINE
#define CHIP_NAME
chip information definition
struct ba121_handle_s ba121_handle_t
ba121 handle structure definition
uint8_t ba121_baseline_calibration(ba121_handle_t *handle)
baseline calibration
uint8_t ba121_read(ba121_handle_t *handle, uint16_t *conductivity_raw, uint16_t *conductivity_us_cm, uint16_t *temperature_raw, float *temperature)
read the data
uint8_t ba121_get_last_status(ba121_handle_t *handle, ba121_status_t *status)
get last status
uint8_t ba121_init(ba121_handle_t *handle)
initialize the chip
struct ba121_info_s ba121_info_t
ba121 information structure definition
uint8_t ba121_info(ba121_info_t *info)
get chip's information
ba121_status_t
ba121 status enumeration definition
uint8_t ba121_set_ntc_resistance(ba121_handle_t *handle, uint32_t ohm)
set ntc resistance
uint8_t ba121_set_ntc_b(ba121_handle_t *handle, uint16_t value)
set ntc b
uint8_t ba121_deinit(ba121_handle_t *handle)
close the chip
uint8_t ba121_get_buffer(ba121_handle_t *handle, uint8_t *buf, uint16_t len)
get buffer
uint8_t ba121_set_buffer(ba121_handle_t *handle, uint8_t *buf, uint16_t len)
set buffer
uint8_t(* uart_flush)(void)
uint8_t(* uart_write)(uint8_t *buf, uint16_t len)
void(* delay_ms)(uint32_t ms)
uint8_t(* uart_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint8_t(* uart_init)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v