Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_lis2dh12.h
1 #ifndef _BC_LIS2DH12_H
2 #define _BC_LIS2DH12_H
3 
4 #include <bc_i2c.h>
5 #include <bc_tick.h>
6 #include <bc_scheduler.h>
7 
11 
13 
14 typedef enum
15 {
18 
21 
24 
26 
28 
29 typedef enum
30 {
33 
36 
39 
41 
42 typedef enum
43 {
46 
49 
52 
55 
57 
59 
60 typedef struct
61 {
63  int16_t x_axis;
64 
66  int16_t y_axis;
67 
69  int16_t z_axis;
70 
72 
74 
75 typedef struct
76 {
78  float x_axis;
79 
81  float y_axis;
82 
84  float z_axis;
85 
87 
89 
90 typedef struct
91 {
93  float threshold;
94  uint8_t duration;
95  bool x_low;
96  bool x_high;
97  bool y_low;
98  bool y_high;
99  bool z_low;
100  bool z_high;
101 
103 
105 
107 
109 
110 typedef enum
111 {
112  BC_LIS2DH12_STATE_ERROR = -1,
113  BC_LIS2DH12_STATE_INITIALIZE = 0,
114  BC_LIS2DH12_STATE_MEASURE = 1,
115  BC_LIS2DH12_STATE_READ = 2,
116  BC_LIS2DH12_STATE_UPDATE = 3
117 
118 } bc_lis2dh12_state_t;
119 
120 struct bc_lis2dh12_t
121 {
122  bc_i2c_channel_t _i2c_channel;
123  uint8_t _i2c_address;
124  void (*_event_handler)(bc_lis2dh12_t *, bc_lis2dh12_event_t, void *);
125  void *_event_param;
126  bc_tick_t _update_interval;
127  bc_lis2dh12_state_t _state;
128  bool _accelerometer_valid;
130  bool _alarm_active;
131  bool _irq_flag;
132  bc_scheduler_task_id_t _task_id_interval;
133  bc_scheduler_task_id_t _task_id_measure;
134  bool _measurement_active;
135  bc_lis2dh12_resolution_t _resolution;
136  bc_lis2dh12_scale_t _scale;
137 };
138 
140 
145 
146 bool bc_lis2dh12_init(bc_lis2dh12_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address);
147 
152 
153 void bc_lis2dh12_set_event_handler(bc_lis2dh12_t *self, void (*event_handler)(bc_lis2dh12_t *, bc_lis2dh12_event_t, void *), void *event_param);
154 
158 
160 
165 
167 
173 
175 
181 
183 
189 
191 
197 
199 
205 
207 
209 
210 #endif // _BC_LIS2DH12_H
bc_lis2dh12_resolution_t
Resolution and mode.
Definition: bc_lis2dh12.h:29
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
float z_axis
Z-axis.
Definition: bc_lis2dh12.h:84
8-bit data output (Low-power mode)
Definition: bc_lis2dh12.h:38
float y_axis
Y-axis.
Definition: bc_lis2dh12.h:81
bool bc_lis2dh12_measure(bc_lis2dh12_t *self)
Start measurement manually.
Definition: bc_lis2dh12.c:71
bool bc_lis2dh12_init(bc_lis2dh12_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize LIS2DH12.
Definition: bc_lis2dh12.c:25
bc_lis2dh12_event_t
Callback events.
Definition: bc_lis2dh12.h:14
bool bc_lis2dh12_get_result_raw(bc_lis2dh12_t *self, bc_lis2dh12_result_raw_t *result_raw)
Get measured acceleration as raw value.
Definition: bc_lis2dh12.c:85
±2 g (Default)
Definition: bc_lis2dh12.h:45
float threshold
Alarm threshold in g.
Definition: bc_lis2dh12.h:93
int16_t x_axis
X-axis.
Definition: bc_lis2dh12.h:63
struct bc_lis2dh12_t bc_lis2dh12_t
LIS2DH12 instance.
Definition: bc_lis2dh12.h:106
int16_t y_axis
Y-axis.
Definition: bc_lis2dh12.h:66
bool bc_lis2dh12_set_scale(bc_lis2dh12_t *self, bc_lis2dh12_scale_t scale)
Set scale.
Definition: bc_lis2dh12.c:404
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
12-bit data output (High-resolution mode)
Definition: bc_lis2dh12.h:35
LIS2DH12 alarm set structure.
Definition: bc_lis2dh12.h:90
LIS2DH12 result in raw values.
Definition: bc_lis2dh12.h:60
bool bc_lis2dh12_set_alarm(bc_lis2dh12_t *self, bc_lis2dh12_alarm_t *alarm)
Enable or disable accelerometer threshold alarm.
Definition: bc_lis2dh12.c:300
void bc_lis2dh12_set_update_interval(bc_lis2dh12_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_lis2dh12.c:55
int16_t z_axis
Z-axis.
Definition: bc_lis2dh12.h:69
bc_i2c_channel_t
I2C channels.
Definition: bc_i2c.h:15
bc_lis2dh12_scale_t
Definition: bc_lis2dh12.h:42
LIS2DH12 result in g.
Definition: bc_lis2dh12.h:75
bool bc_lis2dh12_set_resolution(bc_lis2dh12_t *self, bc_lis2dh12_resolution_t resolution)
Set resolution.
Definition: bc_lis2dh12.c:393
10-bit data output (Normal mode) (Default)
Definition: bc_lis2dh12.h:32
bool bc_lis2dh12_get_result_g(bc_lis2dh12_t *self, bc_lis2dh12_result_g_t *result_g)
Get measured acceleration in g.
Definition: bc_lis2dh12.c:92
void bc_lis2dh12_set_event_handler(bc_lis2dh12_t *self, void(*event_handler)(bc_lis2dh12_t *, bc_lis2dh12_event_t, void *), void *event_param)
Set callback function.
Definition: bc_lis2dh12.c:49
float x_axis
X-axis.
Definition: bc_lis2dh12.h:78