Firmware SDK
twr_lis2dh12.h
1 #ifndef _TWR_LIS2DH12_H
2 #define _TWR_LIS2DH12_H
3 
4 #include <twr_i2c.h>
5 #include <twr_tick.h>
6 #include <twr_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  TWR_LIS2DH12_STATE_ERROR = -1,
113  TWR_LIS2DH12_STATE_INITIALIZE = 0,
114  TWR_LIS2DH12_STATE_MEASURE = 1,
115  TWR_LIS2DH12_STATE_READ = 2,
116  TWR_LIS2DH12_STATE_UPDATE = 3
117 
118 } twr_lis2dh12_state_t;
119 
120 struct twr_lis2dh12_t
121 {
122  twr_i2c_channel_t _i2c_channel;
123  uint8_t _i2c_address;
124  void (*_event_handler)(twr_lis2dh12_t *, twr_lis2dh12_event_t, void *);
125  void *_event_param;
126  twr_tick_t _update_interval;
127  twr_lis2dh12_state_t _state;
128  bool _accelerometer_valid;
130  bool _alarm_active;
131  bool _irq_flag;
132  twr_scheduler_task_id_t _task_id_interval;
133  twr_scheduler_task_id_t _task_id_measure;
134  bool _measurement_active;
135  twr_lis2dh12_resolution_t _resolution;
136  twr_lis2dh12_scale_t _scale;
137 };
138 
140 
145 
146 bool twr_lis2dh12_init(twr_lis2dh12_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
147 
152 
153 void twr_lis2dh12_set_event_handler(twr_lis2dh12_t *self, void (*event_handler)(twr_lis2dh12_t *, twr_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 // _TWR_LIS2DH12_H
void twr_lis2dh12_set_event_handler(twr_lis2dh12_t *self, void(*event_handler)(twr_lis2dh12_t *, twr_lis2dh12_event_t, void *), void *event_param)
Set callback function.
Definition: twr_lis2dh12.c:49
float y_axis
Y-axis.
Definition: twr_lis2dh12.h:81
bool twr_lis2dh12_set_scale(twr_lis2dh12_t *self, twr_lis2dh12_scale_t scale)
Set scale.
Definition: twr_lis2dh12.c:404
twr_lis2dh12_resolution_t
Resolution and mode.
Definition: twr_lis2dh12.h:29
twr_lis2dh12_event_t
Callback events.
Definition: twr_lis2dh12.h:14
float threshold
Alarm threshold in g.
Definition: twr_lis2dh12.h:93
LIS2DH12 result in g.
Definition: twr_lis2dh12.h:75
bool twr_lis2dh12_get_result_g(twr_lis2dh12_t *self, twr_lis2dh12_result_g_t *result_g)
Get measured acceleration in g.
Definition: twr_lis2dh12.c:92
float x_axis
X-axis.
Definition: twr_lis2dh12.h:78
struct twr_lis2dh12_t twr_lis2dh12_t
LIS2DH12 instance.
Definition: twr_lis2dh12.h:106
±2 g (Default)
Definition: twr_lis2dh12.h:45
8-bit data output (Low-power mode)
Definition: twr_lis2dh12.h:38
bool twr_lis2dh12_set_alarm(twr_lis2dh12_t *self, twr_lis2dh12_alarm_t *alarm)
Enable or disable accelerometer threshold alarm.
Definition: twr_lis2dh12.c:300
LIS2DH12 result in raw values.
Definition: twr_lis2dh12.h:60
void twr_lis2dh12_set_update_interval(twr_lis2dh12_t *self, twr_tick_t interval)
Set measurement interval.
Definition: twr_lis2dh12.c:55
int16_t x_axis
X-axis.
Definition: twr_lis2dh12.h:63
12-bit data output (High-resolution mode)
Definition: twr_lis2dh12.h:35
LIS2DH12 alarm set structure.
Definition: twr_lis2dh12.h:90
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
bool twr_lis2dh12_init(twr_lis2dh12_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize LIS2DH12.
Definition: twr_lis2dh12.c:25
int16_t z_axis
Z-axis.
Definition: twr_lis2dh12.h:69
bool twr_lis2dh12_set_resolution(twr_lis2dh12_t *self, twr_lis2dh12_resolution_t resolution)
Set resolution.
Definition: twr_lis2dh12.c:393
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16
10-bit data output (Normal mode) (Default)
Definition: twr_lis2dh12.h:32
twr_i2c_channel_t
I2C channels.
Definition: twr_i2c.h:15
float z_axis
Z-axis.
Definition: twr_lis2dh12.h:84
bool twr_lis2dh12_get_result_raw(twr_lis2dh12_t *self, twr_lis2dh12_result_raw_t *result_raw)
Get measured acceleration as raw value.
Definition: twr_lis2dh12.c:85
twr_lis2dh12_scale_t
Definition: twr_lis2dh12.h:42
bool twr_lis2dh12_measure(twr_lis2dh12_t *self)
Start measurement manually.
Definition: twr_lis2dh12.c:71
int16_t y_axis
Y-axis.
Definition: twr_lis2dh12.h:66