amiro-os / include / amiro / input / mpr121.hpp @ 181f2892
History | View | Annotate | Download (4.632 KB)
1 |
#ifndef MPR121_HPP_
|
---|---|
2 |
#define MPR121_HPP_
|
3 |
|
4 |
#include <ch.hpp> |
5 |
#include <amiro/bus/i2c/I2CParams.hpp> |
6 |
|
7 |
namespace amiro {
|
8 |
|
9 |
class I2CDriver; |
10 |
|
11 |
class MPR121 : public chibios_rt::BaseStaticThread<256>{ |
12 |
|
13 |
enum { SLA = 0x5Au }; |
14 |
|
15 |
struct thresholds {
|
16 |
|
17 |
uint8_t touch_threshold; |
18 |
uint8_t release_threshold; |
19 |
|
20 |
} __attribute__((packed)); |
21 |
|
22 |
struct charge_time {
|
23 |
|
24 |
uint8_t cdt0 :3;
|
25 |
uint8_t res0 :1;
|
26 |
uint8_t cdt1 :3;
|
27 |
uint8_t res1 :1;
|
28 |
|
29 |
}__attribute__((packed)); |
30 |
|
31 |
struct registers {
|
32 |
|
33 |
uint16_t touch_status; |
34 |
uint16_t oor_status; |
35 |
uint16_t ele_filt_data[13]; /* LE */ |
36 |
uint8_t ele_baseline[13];
|
37 |
uint8_t mhd_rising; |
38 |
uint8_t nhd_amt_rising; |
39 |
uint8_t ncl_rising; |
40 |
uint8_t fdl_rising; |
41 |
uint8_t mhd_falling; |
42 |
uint8_t nhd_amt_falling; |
43 |
uint8_t ncl_falling; |
44 |
uint8_t fdl_falling; |
45 |
uint8_t ndh_amt_touched; |
46 |
uint8_t ncl_touched; |
47 |
uint8_t fdl_touched; |
48 |
uint8_t eleprox_mhd_rising; |
49 |
uint8_t eleprox_nhd_amt_rising; |
50 |
uint8_t eleprox_ncl_rising; |
51 |
uint8_t eleprox_fdl_rising; |
52 |
uint8_t eleprox_mhd_falling; |
53 |
uint8_t eleprox_nhd_amt_falling; |
54 |
uint8_t eleprox_ncl_falling; |
55 |
uint8_t eleprox_fdl_falling; |
56 |
uint8_t eleprox_nhd_amt_touched; |
57 |
uint8_t eleprox_ncl_touched; |
58 |
uint8_t eleprox_fdl_touched; |
59 |
struct thresholds ele_thresholds[13]; |
60 |
uint8_t debounce; |
61 |
uint8_t cdc_config; |
62 |
uint8_t cdt_config; |
63 |
uint8_t ele_config; |
64 |
uint8_t ele_current[13];
|
65 |
struct charge_time ele_charge_time[(13 + 1)/2]; |
66 |
uint16_t gpio_ctrl; |
67 |
uint8_t gpio_data; |
68 |
uint8_t gpio_ddr; |
69 |
uint8_t gpio_en; |
70 |
uint8_t gpio_set; |
71 |
uint8_t gpio_clear; |
72 |
uint8_t gpio_toggle; |
73 |
uint16_t auto_cfg_ctrl; |
74 |
uint8_t auto_cfg_usl; |
75 |
uint8_t auto_cfg_lsl; |
76 |
uint8_t auto_cfg_target; |
77 |
uint8_t soft_reset; |
78 |
|
79 |
} __attribute__((packed)); |
80 |
|
81 |
public:
|
82 |
|
83 |
struct MPR121Config {
|
84 |
|
85 |
uint16_t global_config; |
86 |
uint8_t ele_config; |
87 |
uint16_t auto_config; |
88 |
uint8_t up_side_limit; |
89 |
uint8_t low_side_limit; |
90 |
uint8_t target_level; |
91 |
|
92 |
}; |
93 |
|
94 |
enum {
|
95 |
|
96 |
FFI_6 = 0x0000u,
|
97 |
FFI_10 = 0x0040u,
|
98 |
FFI_18 = 0x0080u,
|
99 |
FFI_34 = 0x00C0u,
|
100 |
|
101 |
CDT_OFF = 0x0000u,
|
102 |
CDT_0_5 = 0x2000u,
|
103 |
CDT_1 = 0x4000u,
|
104 |
CDT_2 = 0x6000u,
|
105 |
CDT_4 = 0x8000u,
|
106 |
CDT_8 = 0xA000u,
|
107 |
CDT_16 = 0xC000u,
|
108 |
CDT_32 = 0xE000u,
|
109 |
SFI_4 = 0x0000u,
|
110 |
SFI_6 = 0x0800u,
|
111 |
SFI_10 = 0x1000u,
|
112 |
SFI_18 = 0x1800u,
|
113 |
ESI_1 = 0x0000u,
|
114 |
ESI_2 = 0x0100u,
|
115 |
ESI_4 = 0x0200u,
|
116 |
ESI_8 = 0x0300u,
|
117 |
ESI_16 = 0x0400u,
|
118 |
ESI_32 = 0x0500u,
|
119 |
ESI_64 = 0x0600u,
|
120 |
ESI_128 = 0x0700u,
|
121 |
}; |
122 |
|
123 |
enum {
|
124 |
|
125 |
CL_ON_CURRENT = 0x00u,
|
126 |
CL_OFF = 0x40u,
|
127 |
CL_ON_HIGH5 = 0x80u,
|
128 |
CL_ON_ALL = 0xC0u,
|
129 |
ELEPROX_0 = 0x00u,
|
130 |
ELEPROX_2 = 0x10u,
|
131 |
ELEPROX_4 = 0x20u,
|
132 |
ELEPROX_12 = 0x30u,
|
133 |
|
134 |
}; |
135 |
|
136 |
enum {
|
137 |
|
138 |
AC_ENABLE = 0x0001u,
|
139 |
AC_RECONF_EN = 0x0002u,
|
140 |
BVA_ON_CURRENT = 0x0000u,
|
141 |
BVA_OFF = 0x0004u,
|
142 |
BVA_ON_HIGH5 = 0x0008u,
|
143 |
BVA_ON_ALL = 0x000Cu,
|
144 |
RETRY_OFF = 0x0000u,
|
145 |
RETRY_2 = 0x0010u,
|
146 |
RETRY_4 = 0x0020u,
|
147 |
RETRY_8 = 0x0030u,
|
148 |
/* skip FFI */
|
149 |
AC_FAIL_INT_EN = 0x0100u,
|
150 |
AC_RECONF_FAIL_INT_EN = 0x0200u,
|
151 |
AC_OUT_OF_RANGE_INT_EN = 0x0400u,
|
152 |
AC_SKIP_CHRG_TIME_SRCH = 0x8000u,
|
153 |
|
154 |
}; |
155 |
|
156 |
enum {
|
157 |
|
158 |
SOFT_RST_MAGIC = 0x63u,
|
159 |
|
160 |
}; |
161 |
|
162 |
public:
|
163 |
|
164 |
MPR121(I2CDriver *driver, const uint8_t master_id);
|
165 |
virtual ~MPR121();
|
166 |
|
167 |
chibios_rt::EvtSource* getEventSource(); |
168 |
uint16_t getButtonStatus(); |
169 |
uint8_t getButtonStatus(uint8_t ix); |
170 |
uint16_t getElectrodeData(uint8_t ix); |
171 |
uint8_t getBaselineData(uint8_t ix); |
172 |
msg_t configure(const MPR121Config *cfg);
|
173 |
|
174 |
protected:
|
175 |
virtual msg_t main(void); |
176 |
|
177 |
private:
|
178 |
|
179 |
inline msg_t softReset();
|
180 |
inline msg_t writeConfig(const MPR121Config *cfg); |
181 |
inline msg_t updateButtonData();
|
182 |
|
183 |
private:
|
184 |
|
185 |
I2CDriver *driver; |
186 |
uint8_t master_id; |
187 |
chibios_rt::EvtSource eventSource; |
188 |
|
189 |
uint16_t button_state; |
190 |
uint16_t electrode_data[13];
|
191 |
uint8_t baseline_data[13];
|
192 |
I2CTxParams tx_params; |
193 |
|
194 |
}; |
195 |
|
196 |
|
197 |
} /* amiro */
|
198 |
|
199 |
#endif /* MPR121_HPP_ */ |