Firmware SDK
twr_mpl3115a2.h
1 #ifndef _TWR_MPL3115A2_H
2 #define _TWR_MPL3115A2_H
3 
4 #include <twr_i2c.h>
5 #include <twr_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
26 
28 
29 typedef enum
30 {
31  TWR_MPL3115A2_STATE_ERROR = -1,
32  TWR_MPL3115A2_STATE_INITIALIZE = 0,
33  TWR_MPL3115A2_STATE_MEASURE_ALTITUDE = 1,
34  TWR_MPL3115A2_STATE_READ_ALTITUDE = 2,
35  TWR_MPL3115A2_STATE_MEASURE_PRESSURE = 3,
36  TWR_MPL3115A2_STATE_READ_PRESSURE = 4,
37  TWR_MPL3115A2_STATE_UPDATE = 5
38 
39 } twr_mpl3115a2_state_t;
40 
41 struct twr_mpl3115a2_t
42 {
43  twr_i2c_channel_t _i2c_channel;
44  uint8_t _i2c_address;
45  twr_scheduler_task_id_t _task_id_interval;
46  twr_scheduler_task_id_t _task_id_measure;
47  void (*_event_handler)(twr_mpl3115a2_t *, twr_mpl3115a2_event_t, void *);
48  void *_event_param;
49  bool _measurement_active;
50  twr_tick_t _update_interval;
51  twr_mpl3115a2_state_t _state;
52  twr_tick_t _tick_ready;
53  bool _altitude_valid;
54  bool _pressure_valid;
55  uint8_t _reg_out_p_msb_altitude;
56  uint8_t _reg_out_p_csb_altitude;
57  uint8_t _reg_out_p_lsb_altitude;
58  uint8_t _reg_out_t_msb_altitude;
59  uint8_t _reg_out_t_lsb_altitude;
60  uint8_t _reg_out_p_msb_pressure;
61  uint8_t _reg_out_p_csb_pressure;
62  uint8_t _reg_out_p_lsb_pressure;
63  uint8_t _reg_out_t_msb_pressure;
64  uint8_t _reg_out_t_lsb_pressure;
65 };
66 
68 
73 
74 void twr_mpl3115a2_init(twr_mpl3115a2_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
75 
78 
80 
85 
86 void twr_mpl3115a2_set_event_handler(twr_mpl3115a2_t *self, void (*event_handler)(twr_mpl3115a2_t *, twr_mpl3115a2_event_t, void *), void *event_param);
87 
91 
93 
98 
100 
106 
107 bool twr_mpl3115a2_get_altitude_meter(twr_mpl3115a2_t *self, float *meter);
108 
114 
115 bool twr_mpl3115a2_get_pressure_pascal(twr_mpl3115a2_t *self, float *pascal);
116 
118 
119 #endif // _TWR_MPL3115A2_H
struct twr_mpl3115a2_t twr_mpl3115a2_t
MPL3115A2 instance.
Definition: twr_mpl3115a2.h:25
void twr_mpl3115a2_deinit(twr_mpl3115a2_t *self)
Deinitialize MPL3115A2.
Definition: twr_mpl3115a2.c:26
void twr_mpl3115a2_init(twr_mpl3115a2_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize MPL3115A2.
Definition: twr_mpl3115a2.c:11
void twr_mpl3115a2_set_update_interval(twr_mpl3115a2_t *self, twr_tick_t interval)
Set measurement interval.
Definition: twr_mpl3115a2.c:41
twr_mpl3115a2_event_t
Callback events.
Definition: twr_mpl3115a2.h:13
bool twr_mpl3115a2_get_pressure_pascal(twr_mpl3115a2_t *self, float *pascal)
Get measured pressured in Pascal.
Definition: twr_mpl3115a2.c:85
bool twr_mpl3115a2_measure(twr_mpl3115a2_t *self)
Start measurement manually.
Definition: twr_mpl3115a2.c:57
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16
twr_i2c_channel_t
I2C channels.
Definition: twr_i2c.h:15
bool twr_mpl3115a2_get_altitude_meter(twr_mpl3115a2_t *self, float *meter)
Get measured altitude in meters.
Definition: twr_mpl3115a2.c:71
void twr_mpl3115a2_set_event_handler(twr_mpl3115a2_t *self, void(*event_handler)(twr_mpl3115a2_t *, twr_mpl3115a2_event_t, void *), void *event_param)
Set callback function.
Definition: twr_mpl3115a2.c:35