LibDriver MAG3110
Loading...
Searching...
No Matches
driver_mag3110.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_MAG3110_H
38#define DRIVER_MAG3110_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
62typedef enum
63{
67
82
92
96typedef enum
97{
101
105typedef enum
106{
140
144typedef struct mag3110_handle_s
145{
146 uint8_t (*iic_init)(void);
147 uint8_t (*iic_deinit)(void);
148 uint8_t (*iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
149 uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
150 void (*delay_ms)(uint32_t ms);
151 void (*debug_print)(const char *const fmt, ...);
152 uint8_t inited;
154
170
174
181
188#define DRIVER_MAG3110_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
189
196#define DRIVER_MAG3110_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
197
204#define DRIVER_MAG3110_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
205
212#define DRIVER_MAG3110_LINK_IIC_READ(HANDLE, FUC) (HANDLE)->iic_read = FUC
213
220#define DRIVER_MAG3110_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC
221
228#define DRIVER_MAG3110_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
229
236#define DRIVER_MAG3110_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
237
241
248
257uint8_t mag3110_info(mag3110_info_t *info);
258
271uint8_t mag3110_init(mag3110_handle_t *handle);
272
284uint8_t mag3110_deinit(mag3110_handle_t *handle);
285
299uint8_t mag3110_read(mag3110_handle_t *handle, int16_t raw[3], float ut[3]);
300
312uint8_t mag3110_reset(mag3110_handle_t *handle);
313
326uint8_t mag3110_read_die_temperature(mag3110_handle_t *handle, int8_t *raw, float *degree);
327
339uint8_t mag3110_get_data_ready_status(mag3110_handle_t *handle, uint8_t *status);
340
353
366uint8_t mag3110_set_offset_x(mag3110_handle_t *handle, uint16_t offset);
367
379uint8_t mag3110_get_offset_x(mag3110_handle_t *handle, uint16_t *offset);
380
393uint8_t mag3110_set_offset_y(mag3110_handle_t *handle, uint16_t offset);
394
406uint8_t mag3110_get_offset_y(mag3110_handle_t *handle, uint16_t *offset);
407
420uint8_t mag3110_set_offset_z(mag3110_handle_t *handle, uint16_t offset);
421
433uint8_t mag3110_get_offset_z(mag3110_handle_t *handle, uint16_t *offset);
434
447
460
473
486
499
512
525
537uint8_t mag3110_get_mode(mag3110_handle_t *handle, mag3110_mode_t *mode);
538
551
564
577
589uint8_t mag3110_offset_convert_to_register(mag3110_handle_t *handle, float ut, uint16_t *reg);
590
602uint8_t mag3110_offset_convert_to_data(mag3110_handle_t *handle, uint16_t reg, float *ut);
603
607
614
628uint8_t mag3110_set_reg(mag3110_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
629
643uint8_t mag3110_get_reg(mag3110_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
644
648
652
653#ifdef __cplusplus
654}
655#endif
656
657#endif
uint8_t mag3110_set_rate_over_sample(mag3110_handle_t *handle, mag3110_rate_over_sample_t rate_over_sample)
set rate over sample
mag3110_status_t
mag3110 status enumeration definition
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
@ MAG3110_STATUS_Z_OVERWRITE
@ MAG3110_STATUS_X_READY
@ MAG3110_STATUS_ZYX_READY
@ MAG3110_STATUS_ZYX_OVERWRITE
@ MAG3110_STATUS_Y_READY
@ MAG3110_STATUS_X_OVERWRITE
@ MAG3110_STATUS_Z_READY
@ MAG3110_STATUS_Y_OVERWRITE
@ MAG3110_BOOL_TRUE
@ MAG3110_BOOL_FALSE
@ MAG3110_RATE_5HZ_OVER_SAMPLE_16
@ MAG3110_RATE_2P5HZ_OVER_SAMPLE_32
@ MAG3110_RATE_2P5HZ_OVER_SAMPLE_16
@ MAG3110_RATE_10HZ_OVER_SAMPLE_64
@ MAG3110_RATE_20HZ_OVER_SAMPLE_32
@ MAG3110_RATE_1P25HZ_OVER_SAMPLE_16
@ MAG3110_RATE_0P08HZ_OVER_SAMPLE_128
@ MAG3110_RATE_1P25HZ_OVER_SAMPLE_64
@ MAG3110_RATE_0P63HZ_OVER_SAMPLE_128
@ MAG3110_RATE_0P31HZ_OVER_SAMPLE_32
@ MAG3110_RATE_10HZ_OVER_SAMPLE_16
@ MAG3110_RATE_0P16HZ_OVER_SAMPLE_64
@ MAG3110_RATE_2P5HZ_OVER_SAMPLE_128
@ MAG3110_RATE_10HZ_OVER_SAMPLE_32
@ MAG3110_RATE_0P63HZ_OVER_SAMPLE_64
@ MAG3110_RATE_1P25HZ_OVER_SAMPLE_32
@ MAG3110_RATE_20HZ_OVER_SAMPLE_64
@ MAG3110_RATE_2P5HZ_OVER_SAMPLE_64
@ MAG3110_RATE_1P25HZ_OVER_SAMPLE_128
@ MAG3110_RATE_0P31HZ_OVER_SAMPLE_128
@ MAG3110_RATE_20HZ_OVER_SAMPLE_16
@ MAG3110_RATE_0P63HZ_OVER_SAMPLE_32
@ MAG3110_RATE_0P63HZ_OVER_SAMPLE_16
@ MAG3110_RATE_5HZ_OVER_SAMPLE_128
@ MAG3110_RATE_5HZ_OVER_SAMPLE_32
@ MAG3110_RATE_40HZ_OVER_SAMPLE_32
@ MAG3110_RATE_10HZ_OVER_SAMPLE_128
@ MAG3110_RATE_5HZ_OVER_SAMPLE_64
@ MAG3110_RATE_40HZ_OVER_SAMPLE_16
@ MAG3110_RATE_0P16HZ_OVER_SAMPLE_128
@ MAG3110_RATE_0P31HZ_OVER_SAMPLE_64
@ MAG3110_RATE_80HZ_OVER_SAMPLE_16
@ MAG3110_MODE_STATUS_ACTIVE_RAW
@ MAG3110_MODE_STATUS_ACTIVE_NON_RAW
@ MAG3110_MODE_STATUS_STANDBY
@ MAG3110_MODE_ACTIVE
@ MAG3110_MODE_STANDBY
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
mag3110 handle structure definition
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)
mag3110 information structure definition
uint32_t driver_version
char manufacturer_name[32]