LibDriver HMC5883L
Loading...
Searching...
No Matches
driver_hmc5883l_shot.c
Go to the documentation of this file.
1
37
39
40static hmc5883l_handle_t gs_handle;
41
49uint8_t hmc5883l_shot_init(void)
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 return 0;
122}
123
132uint8_t hmc5883l_shot_read(float m_gauss[3])
133{
134 int16_t raw[3];
135
136 /* read x,y,z data */
137 if (hmc5883l_single_read(&gs_handle, (int16_t *)raw, m_gauss) != 0)
138 {
139 return 1;
140 }
141 else
142 {
143 return 0;
144 }
145}
146
155{
156 /* close hmc5883l */
157 if (hmc5883l_deinit(&gs_handle) != 0)
158 {
159 return 1;
160 }
161 else
162 {
163 return 0;
164 }
165}
driver hmc5883l shot 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_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_single_read(hmc5883l_handle_t *handle, int16_t raw[3], float m_gauss[3])
read data once
uint8_t hmc5883l_enable_high_speed_iic(hmc5883l_handle_t *handle)
enable the high speed iic
uint8_t hmc5883l_shot_init(void)
shot example init
#define HMC5883L_SHOT_DEFAULT_DATA_OUTPUT_RATE
#define HMC5883L_SHOT_DEFAULT_GAIN
#define HMC5883L_SHOT_DEFAULT_AVERAGE_SAMPLE
hmc5883l shot example default definition
#define HMC5883L_SHOT_DEFAULT_MODE
uint8_t hmc5883l_shot_read(float m_gauss[3])
shot example read
uint8_t hmc5883l_shot_deinit(void)
shot example deinit
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