LibDriver MAG3110
Loading...
Searching...
No Matches
driver_mag3110_basic.c
Go to the documentation of this file.
1
36
38
39static mag3110_handle_t gs_handle;
40
48uint8_t mag3110_basic_init(void)
49{
50 uint8_t res;
51 uint16_t offset;
52
53 /* link interface function */
61
62 /* mag3110 init */
63 res = mag3110_init(&gs_handle);
64 if (res != 0)
65 {
66 mag3110_interface_debug_print("mag3110: init failed.\n");
67
68 return 1;
69 }
70
71 /* convert offset */
73 if (res != 0)
74 {
75 mag3110_interface_debug_print("mag3110: offset convert to register failed.\n");
76 (void)mag3110_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* set default offset x */
82 res = mag3110_set_offset_x(&gs_handle, offset);
83 if (res != 0)
84 {
85 mag3110_interface_debug_print("mag3110: set offset x failed.\n");
86 (void)mag3110_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set default offset y */
92 res = mag3110_set_offset_y(&gs_handle, offset);
93 if (res != 0)
94 {
95 mag3110_interface_debug_print("mag3110: set offset y failed.\n");
96 (void)mag3110_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set default offset z */
102 res = mag3110_set_offset_z(&gs_handle, offset);
103 if (res != 0)
104 {
105 mag3110_interface_debug_print("mag3110: set offset z failed.\n");
106 (void)mag3110_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set default disable offset correction */
113 if (res != 0)
114 {
115 mag3110_interface_debug_print("mag3110: set disable offset correction failed.\n");
116 (void)mag3110_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* set default rate over sample */
123 if (res != 0)
124 {
125 mag3110_interface_debug_print("mag3110: set rate over sample failed.\n");
126 (void)mag3110_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* set the default fast read mode */
133 if (res != 0)
134 {
135 mag3110_interface_debug_print("mag3110: set fast read mode failed.\n");
136 (void)mag3110_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 /* set default trigger mode */
143 if (res != 0)
144 {
145 mag3110_interface_debug_print("mag3110: set trigger mode failed.\n");
146 (void)mag3110_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 /* set default automatic magnetic sensor reset */
153 if (res != 0)
154 {
155 mag3110_interface_debug_print("mag3110: set automatic magnetic sensor reset failed.\n");
156 (void)mag3110_deinit(&gs_handle);
157
158 return 1;
159 }
160
161 /* active mode */
162 res = mag3110_set_mode(&gs_handle, MAG3110_MODE_ACTIVE);
163 if (res != 0)
164 {
165 mag3110_interface_debug_print("mag3110: set mode failed.\n");
166 (void)mag3110_deinit(&gs_handle);
167
168 return 1;
169 }
170
171 return 0;
172}
173
182uint8_t mag3110_basic_read(float ut[3])
183{
184 int16_t raw[3];
185
186 /* read x,y,z data */
187 if (mag3110_read(&gs_handle, (int16_t *)raw, ut) != 0)
188 {
189 return 1;
190 }
191
192 return 0;
193}
194
203{
204 /* close mag3110 */
205 if (mag3110_deinit(&gs_handle) != 0)
206 {
207 return 1;
208 }
209
210 return 0;
211}
driver mag3110 basic 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_set_trigger_mode(mag3110_handle_t *handle, mag3110_bool_t enable)
enable or disable trigger mode
struct mag3110_handle_s mag3110_handle_t
mag3110 handle structure definition
uint8_t mag3110_set_mode(mag3110_handle_t *handle, mag3110_mode_t mode)
set mode
uint8_t mag3110_set_disable_offset_correction(mag3110_handle_t *handle, mag3110_bool_t enable)
enable or disable offset correction
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
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_set_offset_z(mag3110_handle_t *handle, uint16_t offset)
set offset z
@ MAG3110_MODE_ACTIVE
uint8_t mag3110_basic_init(void)
basic example init
uint8_t mag3110_basic_deinit(void)
basic example deinit
#define MAG3110_BASIC_DEFAULT_TRIGGER_MODE
#define MAG3110_BASIC_DEFAULT_FAST_READ
#define MAG3110_BASIC_DEFAULT_OFFSET
mag3110 basic example default definition
uint8_t mag3110_basic_read(float ut[3])
basic example read
#define MAG3110_BASIC_DEFAULT_AUTO_RESET
#define MAG3110_BASIC_DEFAULT_DISABLE_OFFSET_CORRECTION
#define MAG3110_BASIC_DEFAULT_RATE_OVER_SAMPLE
uint8_t mag3110_interface_iic_deinit(void)
interface iic bus deinit
void mag3110_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t mag3110_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t mag3110_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t mag3110_interface_iic_init(void)
interface iic bus init
void mag3110_interface_debug_print(const char *const fmt,...)
interface print format data