42#define CHIP_NAME "NXP MAG3110"
43#define MANUFACTURER_NAME "NXP"
44#define SUPPLY_VOLTAGE_MIN 1.95f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 0.9f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define MAG3110_ADDRESS (0x0E << 1)
59#define MAG3110_REG_DR_STATUS 0x00
60#define MAG3110_REG_OUT_X_MSB 0x01
61#define MAG3110_REG_OUT_X_LSB 0x02
62#define MAG3110_REG_OUT_Y_MSB 0x03
63#define MAG3110_REG_OUT_Y_LSB 0x04
64#define MAG3110_REG_OUT_Z_MSB 0x05
65#define MAG3110_REG_OUT_Z_LSB 0x06
66#define MAG3110_REG_WHO_AM_I 0x07
67#define MAG3110_REG_SYSMOD 0x08
68#define MAG3110_REG_OFF_X_MSB 0x09
69#define MAG3110_REG_OFF_X_LSB 0x0A
70#define MAG3110_REG_OFF_Y_MSB 0x0B
71#define MAG3110_REG_OFF_Y_LSB 0x0C
72#define MAG3110_REG_OFF_Z_MSB 0x0D
73#define MAG3110_REG_OFF_Z_LSB 0x0E
74#define MAG3110_REG_DIE_TEMP 0x0F
75#define MAG3110_REG_CTRL_REG1 0x10
76#define MAG3110_REG_CTRL_REG2 0x11
89static uint8_t a_mag3110_iic_read(
mag3110_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
110static uint8_t a_mag3110_iic_write(
mag3110_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
147 handle->
debug_print(
"mag3110: read status failed.\n");
183 handle->
debug_print(
"mag3110: read mode failed.\n");
216 r = (int16_t)(ut / 0.1f);
218 *reg = (uint16_t)(r);
248 if ((r & (1 << 14)) != 0)
252 *ut = (float)(r) * 0.1f;
283 if (offset > 0x8000U)
285 handle->
debug_print(
"mag3110: offset > 0x8000.\n");
291 buf[0] = (prev >> 8) & 0xFF;
292 buf[1] = (prev >> 0) & 0xFF;
296 handle->
debug_print(
"mag3110: write offset failed.\n");
333 handle->
debug_print(
"mag3110: read offset failed.\n");
337 prev = ((uint16_t)buf[0] << 8) | buf[1];
369 if (offset > 0x8000U)
371 handle->
debug_print(
"mag3110: offset > 0x8000.\n");
377 buf[0] = (prev >> 8) & 0xFF;
378 buf[1] = (prev >> 0) & 0xFF;
382 handle->
debug_print(
"mag3110: write offset failed.\n");
419 handle->
debug_print(
"mag3110: read offset failed.\n");
423 prev = ((uint16_t)buf[0] << 8) | buf[1];
455 if (offset > 0x8000U)
457 handle->
debug_print(
"mag3110: offset > 0x8000.\n");
463 buf[0] = (prev >> 8) & 0xFF;
464 buf[1] = (prev >> 0) & 0xFF;
468 handle->
debug_print(
"mag3110: write offset failed.\n");
505 handle->
debug_print(
"mag3110: read offset failed.\n");
509 prev = ((uint16_t)buf[0] << 8) | buf[1];
544 handle->
debug_print(
"mag3110: read die temp failed.\n");
549 *degree = (float)(*raw);
582 handle->
debug_print(
"mag3110: read ctrl failed.\n");
586 prev &= ~(0x1F << 3);
587 prev |= (rate_over_sample << 3);
591 handle->
debug_print(
"mag3110: write ctrl failed.\n");
627 handle->
debug_print(
"mag3110: read ctrl failed.\n");
664 handle->
debug_print(
"mag3110: read ctrl failed.\n");
669 prev |= (enable << 2);
673 handle->
debug_print(
"mag3110: write ctrl failed.\n");
709 handle->
debug_print(
"mag3110: read ctrl failed.\n");
746 handle->
debug_print(
"mag3110: read ctrl failed.\n");
751 prev |= (enable << 1);
755 handle->
debug_print(
"mag3110: write ctrl failed.\n");
791 handle->
debug_print(
"mag3110: read ctrl failed.\n");
828 handle->
debug_print(
"mag3110: read ctrl failed.\n");
837 handle->
debug_print(
"mag3110: write ctrl failed.\n");
873 handle->
debug_print(
"mag3110: read ctrl failed.\n");
910 handle->
debug_print(
"mag3110: read ctrl failed.\n");
915 prev |= (enable << 7);
919 handle->
debug_print(
"mag3110: write ctrl failed.\n");
955 handle->
debug_print(
"mag3110: read ctrl failed.\n");
960 prev |= (enable << 5);
964 handle->
debug_print(
"mag3110: write ctrl failed.\n");
1000 handle->
debug_print(
"mag3110: read ctrl failed.\n");
1024 uint16_t timeout = 1000;
1038 handle->
debug_print(
"mag3110: read ctrl failed.\n");
1047 handle->
debug_print(
"mag3110: write ctrl failed.\n");
1051 while (timeout != 0)
1057 handle->
debug_print(
"mag3110: read ctrl failed.\n");
1061 if ((prev & (1 << 4)) == 0)
1090 uint16_t timeout = 1000;
1102 handle->
debug_print(
"mag3110: iic_init is null.\n");
1108 handle->
debug_print(
"mag3110: iic_deinit is null.\n");
1114 handle->
debug_print(
"mag3110: iic_read is null.\n");
1120 handle->
debug_print(
"mag3110: iic_write is null.\n");
1126 handle->
debug_print(
"mag3110: delay_ms is null.\n");
1133 handle->
debug_print(
"mag3110: iic init failed.\n");
1138 (uint8_t *)&
id, 1) != 0)
1140 handle->
debug_print(
"mag3110: read id failed.\n");
1156 handle->
debug_print(
"mag3110: read ctrl failed.\n");
1165 handle->
debug_print(
"mag3110: write ctrl failed.\n");
1171 while (timeout != 0)
1177 handle->
debug_print(
"mag3110: read ctrl failed.\n");
1182 if ((prev & (1 << 4)) == 0)
1230 handle->
debug_print(
"mag3110: read ctrl failed.\n");
1238 handle->
debug_print(
"mag3110: write ctrl failed.\n");
1244 handle->
debug_print(
"mag3110: iic deinit failed.\n");
1272 uint16_t timeout = 1000;
1286 handle->
debug_print(
"mag3110: read ctrl failed.\n");
1290 if ((prev & (1 << 1)) != 0)
1292 while (timeout != 0)
1299 handle->
debug_print(
"mag3110: read status failed.\n");
1303 if ((status & (1 << 3)) != 0)
1315 if ((prev & (1 << 2)) != 0)
1320 handle->
debug_print(
"mag3110: read data failed.\n");
1324 raw[0] = (int16_t)(((uint16_t)buf[0] << 8) | 0x00);
1325 raw[1] = (int16_t)(((uint16_t)buf[1] << 8) | 0x00);
1326 raw[2] = (int16_t)(((uint16_t)buf[2] << 8) | 0x00);
1327 ut[0] = (float)(raw[0]) * 0.1f;
1328 ut[1] = (float)(raw[1]) * 0.1f;
1329 ut[2] = (float)(raw[2]) * 0.1f;
1336 handle->
debug_print(
"mag3110: read data failed.\n");
1340 raw[0] = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]);
1341 raw[1] = (int16_t)(((uint16_t)buf[2] << 8) | buf[3]);
1342 raw[2] = (int16_t)(((uint16_t)buf[4] << 8) | buf[5]);
1343 ut[0] = (float)(raw[0]) * 0.1f;
1344 ut[1] = (float)(raw[1]) * 0.1f;
1345 ut[2] = (float)(raw[2]) * 0.1f;
1375 return a_mag3110_iic_write(handle, reg, buf, len);
1402 return a_mag3110_iic_read(handle, reg, buf, len);
#define MAG3110_REG_OFF_X_MSB
#define MAG3110_REG_SYSMOD
#define MAG3110_REG_CTRL_REG2
#define MAG3110_REG_WHO_AM_I
#define MAG3110_REG_DR_STATUS
chip register definition
#define MAG3110_ADDRESS
iic address definition
#define SUPPLY_VOLTAGE_MAX
#define MAG3110_REG_CTRL_REG1
#define MAG3110_REG_OFF_Y_MSB
#define MAG3110_REG_DIE_TEMP
#define MAG3110_REG_OUT_X_MSB
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
#define MAG3110_REG_OFF_Z_MSB
driver mag3110 header file
uint8_t mag3110_set_rate_over_sample(mag3110_handle_t *handle, mag3110_rate_over_sample_t rate_over_sample)
set rate over sample
uint8_t mag3110_info(mag3110_info_t *info)
get chip's information
uint8_t mag3110_get_data_ready_status(mag3110_handle_t *handle, uint8_t *status)
get data ready status
uint8_t mag3110_set_trigger_mode(mag3110_handle_t *handle, mag3110_bool_t enable)
enable or disable trigger mode
uint8_t mag3110_get_offset_z(mag3110_handle_t *handle, uint16_t *offset)
get offset z
struct mag3110_handle_s mag3110_handle_t
mag3110 handle structure definition
uint8_t mag3110_get_trigger_mode(mag3110_handle_t *handle, mag3110_bool_t *enable)
get trigger mode status
uint8_t mag3110_set_mode(mag3110_handle_t *handle, mag3110_mode_t mode)
set mode
uint8_t mag3110_get_fast_read_mode(mag3110_handle_t *handle, mag3110_bool_t *enable)
get fast read mode status
uint8_t mag3110_set_disable_offset_correction(mag3110_handle_t *handle, mag3110_bool_t enable)
enable or disable offset correction
mag3110_bool_t
mag3110 bool enumeration definition
uint8_t mag3110_deinit(mag3110_handle_t *handle)
close the chip
uint8_t mag3110_init(mag3110_handle_t *handle)
initialize the chip
uint8_t mag3110_set_offset_y(mag3110_handle_t *handle, uint16_t offset)
set offset y
uint8_t mag3110_set_offset_x(mag3110_handle_t *handle, uint16_t offset)
set offset x
struct mag3110_info_s mag3110_info_t
mag3110 information structure definition
uint8_t mag3110_get_offset_y(mag3110_handle_t *handle, uint16_t *offset)
get offset y
uint8_t mag3110_get_rate_over_sample(mag3110_handle_t *handle, mag3110_rate_over_sample_t *rate_over_sample)
get rate over sample
uint8_t mag3110_get_offset_x(mag3110_handle_t *handle, uint16_t *offset)
get offset x
uint8_t mag3110_get_mode_status(mag3110_handle_t *handle, mag3110_mode_status_t *mode)
get mode status
mag3110_rate_over_sample_t
mag3110 rate over sample enumeration definition
uint8_t mag3110_set_automatic_magnetic_sensor_reset(mag3110_handle_t *handle, mag3110_bool_t enable)
enable or disable automatic magnetic sensor reset
uint8_t mag3110_read(mag3110_handle_t *handle, int16_t raw[3], float ut[3])
read data
uint8_t mag3110_set_fast_read_mode(mag3110_handle_t *handle, mag3110_bool_t enable)
enable or disable fast read mode
uint8_t mag3110_offset_convert_to_register(mag3110_handle_t *handle, float ut, uint16_t *reg)
convert the offset to the register raw data
uint8_t mag3110_offset_convert_to_data(mag3110_handle_t *handle, uint16_t reg, float *ut)
convert the register raw data to the offset threshold
uint8_t mag3110_get_mode(mag3110_handle_t *handle, mag3110_mode_t *mode)
get mode
uint8_t mag3110_reset(mag3110_handle_t *handle)
reset
uint8_t mag3110_get_disable_offset_correction(mag3110_handle_t *handle, mag3110_bool_t *enable)
get offset correction status
uint8_t mag3110_read_die_temperature(mag3110_handle_t *handle, int8_t *raw, float *degree)
read die temperature
uint8_t mag3110_set_offset_z(mag3110_handle_t *handle, uint16_t offset)
set offset z
mag3110_mode_status_t
mag3110 mode status enumeration definition
mag3110_mode_t
mag3110 mode enumeration definition
uint8_t mag3110_get_reg(mag3110_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t mag3110_set_reg(mag3110_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v