42#define CHIP_NAME "ASAIR AGS10"
43#define MANUFACTURER_NAME "ASAIR"
44#define SUPPLY_VOLTAGE_MIN 2.9f
45#define SUPPLY_VOLTAGE_MAX 3.1f
46#define MAX_CURRENT 25.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define AGS10_ADDRESS (0x1A << 1)
59#define AGS10_REG_DATA 0x00
60#define AGS10_REG_CALIBRATION 0x01
61#define AGS10_REG_VERSION 0x11
62#define AGS10_REG_RESISTANCE 0x20
63#define AGS10_REG_SLAVE_ADDR 0x21
76static uint8_t a_ags10_iic_read(
ags10_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
102static uint8_t a_ags10_iic_write(
ags10_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
119static uint8_t a_ags10_calc_crc(uint8_t *data, uint8_t len)
125 for (
byte = 0;
byte < len;
byte++)
128 for (i = 0; i < 8; i++)
130 if ((crc & 0x80) != 0)
132 crc = (crc << 1) ^ 0x31;
172 handle->
debug_print(
"ags10: iic_deinit is null.\n");
178 handle->
debug_print(
"ags10: iic_read_cmd is null.\n");
184 handle->
debug_print(
"ags10: iic_write_cmd is null.\n");
190 handle->
debug_print(
"ags10: iic_write is null.\n");
236 handle->
debug_print(
"ags10: iic deinit failed.\n");
332 if (a_ags10_calc_crc(buf, 4) != buf[4])
338 if ((buf[0] & 0x01) != 0)
344 *raw = (uint32_t)(buf[1]) << 16 |
345 (uint32_t)(buf[2]) << 8 |
346 (uint32_t)(buf[3]) << 0;
379 buf[2] = (raw >> 8) & 0xFF;
380 buf[3] = (raw >> 0) & 0xFF;
381 buf[4] = a_ags10_calc_crc(buf, 4);
385 handle->
debug_print(
"ags10: write calibration failed.\n");
422 buf[4] = a_ags10_calc_crc(buf, 4);
426 handle->
debug_print(
"ags10: write calibration failed.\n");
463 buf[4] = a_ags10_calc_crc(buf, 4);
467 handle->
debug_print(
"ags10: write calibration failed.\n");
506 handle->
debug_print(
"ags10: read resistance failed.\n");
510 if (a_ags10_calc_crc(buf, 4) != buf[4])
516 *raw = (uint32_t)(buf[0]) << 24 |
517 (uint32_t)(buf[1]) << 16 |
518 (uint32_t)(buf[2]) << 8 |
519 (uint32_t)(buf[3]) << 0;
520 *ohm = (double)(*raw) * 100.0;
554 handle->
debug_print(
"ags10: read version failed.\n");
558 if (a_ags10_calc_crc(buf, 4) != buf[4])
599 buf[4] = a_ags10_calc_crc(buf, 4);
603 handle->
debug_print(
"ags10: modify slave address failed.\n");
637 if (a_ags10_iic_write(handle, reg, buf, len) != 0)
669 if (a_ags10_iic_read(handle, reg, buf, len) != 0)
#define AGS10_REG_DATA
chip register definition
#define SUPPLY_VOLTAGE_MAX
#define AGS10_REG_VERSION
#define AGS10_REG_RESISTANCE
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define AGS10_ADDRESS
chip address definition
#define AGS10_REG_SLAVE_ADDR
#define CHIP_NAME
chip information definition
#define AGS10_REG_CALIBRATION
uint8_t ags10_deinit(ags10_handle_t *handle)
close the chip
uint8_t ags10_info(ags10_info_t *info)
get chip's information
uint8_t ags10_current_resistance_zero_point_calibration(ags10_handle_t *handle)
zero point calibration using current resistance
uint8_t ags10_zero_point_calibration(ags10_handle_t *handle, uint16_t raw)
zero point calibration
struct ags10_info_s ags10_info_t
ags10 information structure definition
uint8_t ags10_get_resistance(ags10_handle_t *handle, uint32_t *raw, double *ohm)
get resistance
uint8_t ags10_get_slave_address(ags10_handle_t *handle, uint8_t *addr)
get slave address
uint8_t ags10_read_tvoc(ags10_handle_t *handle, uint32_t *raw, uint32_t *ppb)
read tvoc
uint8_t ags10_modify_slave_address(ags10_handle_t *handle, uint8_t addr_7bit)
modify slave address
uint8_t ags10_get_version(ags10_handle_t *handle, uint8_t *version)
get version
uint8_t ags10_reset_zero_point_calibration(ags10_handle_t *handle)
reset zero point calibration
struct ags10_handle_s ags10_handle_t
ags10 handle structure definition
uint8_t ags10_set_slave_address(ags10_handle_t *handle, uint8_t addr)
set slave address
uint8_t ags10_init(ags10_handle_t *handle)
initialize the chip
uint8_t ags10_set_reg(ags10_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t ags10_get_reg(ags10_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register