42#define CHIP_NAME "AtomBit BA111"
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 BA111_COMMAND_READ 0xA0
55#define BA111_COMMAND_BASELINE 0xA6
56#define BA111_COMMAND_NTC_RES 0xA3
57#define BA111_COMMAND_NTC_B 0xA5
69static uint8_t a_ba111_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_ba111_parse_frame(
ba111_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(
"ba111: 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(
"ba111: 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(
"ba111: uart_init is null.\n");
171 handle->
debug_print(
"ba111: uart_deinit is null.\n");
177 handle->
debug_print(
"ba111: uart_read is null.\n");
183 handle->
debug_print(
"ba111: uart_flush is null.\n");
189 handle->
debug_print(
"ba111: uart_write is null.\n");
235 handle->
debug_print(
"ba111: uart deinit failed.\n");
260 uint16_t *temperature_raw,
float *temperature)
281 handle->
debug_print(
"ba111: uart flush failed.\n");
288 handle->
debug_print(
"ba111: uart write failed.\n");
300 res = a_ba111_parse_frame(handle, 1, input, &data);
307 *tds_raw = (data >> 16) & 0xFFFFU;
308 *tds_ppm = *tds_raw ;
309 *temperature_raw = (data >> 0) & 0xFFFFU;
310 *temperature = (float)(*temperature_raw) / 100.0f;
348 handle->
debug_print(
"ba111: uart flush failed.\n");
355 handle->
debug_print(
"ba111: uart write failed.\n");
367 res = a_ba111_parse_frame(handle, 0, input, &data);
419 handle->
debug_print(
"ba111: uart flush failed.\n");
426 handle->
debug_print(
"ba111: uart write failed.\n");
438 res = a_ba111_parse_frame(handle, 0, input, &data);
490 handle->
debug_print(
"ba111: uart flush failed.\n");
497 handle->
debug_print(
"ba111: uart write failed.\n");
509 res = a_ba111_parse_frame(handle, 0, input, &data);
580 handle->
debug_print(
"ba111: uart flush failed.\n");
587 handle->
debug_print(
"ba111: uart write failed.\n");
620 l = handle->
uart_read((uint8_t *)buf, len);
#define BA111_COMMAND_BASELINE
#define BA111_COMMAND_READ
chip command definition
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BA111_COMMAND_NTC_B
#define CHIP_NAME
chip information definition
#define BA111_COMMAND_NTC_RES
struct ba111_handle_s ba111_handle_t
ba111 handle structure definition
uint8_t ba111_init(ba111_handle_t *handle)
initialize the chip
struct ba111_info_s ba111_info_t
ba111 information structure definition
uint8_t ba111_set_ntc_resistance(ba111_handle_t *handle, uint32_t ohm)
set ntc resistance
uint8_t ba111_info(ba111_info_t *info)
get chip's information
ba111_status_t
ba111 status enumeration definition
uint8_t ba111_baseline_calibration(ba111_handle_t *handle)
baseline calibration
uint8_t ba111_read(ba111_handle_t *handle, uint16_t *tds_raw, uint16_t *tds_ppm, uint16_t *temperature_raw, float *temperature)
read the data
uint8_t ba111_deinit(ba111_handle_t *handle)
close the chip
uint8_t ba111_set_ntc_b(ba111_handle_t *handle, uint16_t value)
set ntc b
uint8_t ba111_get_last_status(ba111_handle_t *handle, ba111_status_t *status)
get last status
uint8_t ba111_set_buffer(ba111_handle_t *handle, uint8_t *buf, uint16_t len)
set buffer
uint8_t ba111_get_buffer(ba111_handle_t *handle, uint8_t *buf, uint16_t len)
get 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