LibDriver HMC5883L
Loading...
Searching...
No Matches
driver_hmc5883l_basic.c
Go to the documentation of this file.
1
37
39
40static hmc5883l_handle_t gs_handle;
41
50{
51 uint8_t res;
52
53 /* link interface function */
61
62 /* hmc5883l init */
63 res = hmc5883l_init(&gs_handle);
64 if (res != 0)
65 {
66 hmc5883l_interface_debug_print("hmc5883l: init failed.\n");
67
68 return 1;
69 }
70
71 /* set average sample */
73 if (res != 0)
74 {
75 hmc5883l_interface_debug_print("hmc5883l: set average sample failed.\n");
76 (void)hmc5883l_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* set data output rate */
83 if (res != 0)
84 {
85 hmc5883l_interface_debug_print("hmc5883l: set data output rate failed.\n");
86 (void)hmc5883l_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set mode */
93 if (res != 0)
94 {
95 hmc5883l_interface_debug_print("hmc5883l: set mode failed.\n");
96 (void)hmc5883l_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set gain */
103 if (res != 0)
104 {
105 hmc5883l_interface_debug_print("hmc5883l: set gain failed.\n");
106 (void)hmc5883l_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set enable high speed iic */
112 res = hmc5883l_enable_high_speed_iic(&gs_handle);
113 if (res != 0)
114 {
115 hmc5883l_interface_debug_print("hmc5883l: enable high speed iic failed.\n");
116 (void)hmc5883l_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* start continuous read */
122 res = hmc5883l_start_continuous_read(&gs_handle);
123 if (res != 0)
124 {
125 hmc5883l_interface_debug_print("hmc5883l: start continuous read failed.\n");
126 (void)hmc5883l_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 return 0;
132}
133
142uint8_t hmc5883l_basic_read(float m_gauss[3])
143{
144 int16_t raw[3];
145
146 /* read x,y,z data */
147 if (hmc5883l_continuous_read(&gs_handle, (int16_t *)raw, m_gauss) != 0)
148 {
149 return 1;
150 }
151 else
152 {
153 return 0;
154 }
155}
156
165{
166 uint8_t res;
167
168 /* stop continuous read*/
169 res = hmc5883l_stop_continuous_read(&gs_handle);
170 if (res != 0)
171 {
172 return 1;
173 }
174
175 /* close hmc5883l */
176 if (hmc5883l_deinit(&gs_handle) != 0)
177 {
178 return 1;
179 }
180 else
181 {
182 return 0;
183 }
184}
driver hmc5883l basic header file
uint8_t hmc5883l_set_mode(hmc5883l_handle_t *handle, hmc5883l_mode_t mode)
set the chip mode
uint8_t hmc5883l_set_gain(hmc5883l_handle_t *handle, hmc5883l_gain_t gain)
set the chip gain
uint8_t hmc5883l_set_average_sample(hmc5883l_handle_t *handle, hmc5883l_average_sample_t average_sample)
set the average sample rate
uint8_t hmc5883l_init(hmc5883l_handle_t *handle)
initialize the chip
uint8_t hmc5883l_continuous_read(hmc5883l_handle_t *handle, int16_t raw[3], float m_gauss[3])
read data continuously
uint8_t hmc5883l_set_data_output_rate(hmc5883l_handle_t *handle, hmc5883l_data_output_rate_t data_rate)
set the data output rate
uint8_t hmc5883l_deinit(hmc5883l_handle_t *handle)
close the chip
struct hmc5883l_handle_s hmc5883l_handle_t
hmc5883l handle structure definition
uint8_t hmc5883l_start_continuous_read(hmc5883l_handle_t *handle)
start reading data
uint8_t hmc5883l_enable_high_speed_iic(hmc5883l_handle_t *handle)
enable the high speed iic
uint8_t hmc5883l_stop_continuous_read(hmc5883l_handle_t *handle)
stop reading data
#define HMC5883L_BASIC_DEFAULT_AVERAGE_SAMPLE
hmc5883l basic example default definition
#define HMC5883L_BASIC_DEFAULT_DATA_OUTPUT_RATE
#define HMC5883L_BASIC_DEFAULT_GAIN
uint8_t hmc5883l_basic_init(void)
basic example init
uint8_t hmc5883l_basic_deinit(void)
basic example deinit
#define HMC5883L_BASIC_DEFAULT_MODE
uint8_t hmc5883l_basic_read(float m_gauss[3])
basic example read
uint8_t hmc5883l_interface_iic_deinit(void)
interface iic bus deinit
uint8_t hmc5883l_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void hmc5883l_interface_debug_print(const char *const fmt,...)
interface print format data
void hmc5883l_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hmc5883l_interface_iic_init(void)
interface iic bus init
uint8_t hmc5883l_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write