Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / MPR121 / v1 / alld_MPR121.h @ 9466e34d

History | View | Annotate | Download (9.19 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
/**
20
 * @file    alld_MPR121.h
21
 * @brief   Touch Sensor macros and structures.
22
 *
23
 * @addtogroup lld_touch
24
 * @{
25
 */
26

    
27
#ifndef AMIROLLD_MPR121_H
28
#define AMIROLLD_MPR121_H
29

    
30
#include <amiro-lld.h>
31

    
32
/******************************************************************************/
33
/* CONSTANTS                                                                  */
34
/******************************************************************************/
35

    
36
/**
37
 * @brief Maximum I2C frequency.
38
 */
39
#define MPR121_LLD_I2C_MAXFREQUENCY   400000
40

    
41
/**
42
 * @brief A falling edge indicates an interrupt.
43
 */
44
#define MPR121_LLD_INT_EDGE           APAL_GPIO_EDGE_FALLING
45

    
46
/******************************************************************************/
47
/* SETTINGS                                                                   */
48
/******************************************************************************/
49

    
50
/******************************************************************************/
51
/* CHECKS                                                                     */
52
/******************************************************************************/
53

    
54
/******************************************************************************/
55
/* DATA STRUCTURES AND TYPES                                                  */
56
/******************************************************************************/
57

    
58
/**
59
 * @brief The MPR121 driver struct
60
 */
61
typedef struct {
62
  apalI2CDriver_t* i2cd;        /**< @brief The I2C Driver */
63
} MPR121Driver;
64

    
65
enum {
66
  MPR121_LLD_I2C_ADDR_FIXED   = 0x5Au,
67
  MPR121_LLD_I2C_ADDR_VSS     = 0x00u,
68
  MPR121_LLD_I2C_ADDR_VDD     = 0x01u,
69
  MPR121_LLD_I2C_ADDR_SDA     = 0x04u,
70
  MPR121_LLD_I2C_SOFTRESET    = 0x63,
71
};
72

    
73
/**
74
 * @brief Registers of the mpr121.
75
 */
76
typedef enum {
77
  MPR121_LLD_REGISTER_TOUCH_STATUS  = 0x00,
78
  MPR121_LLD_REGISTER_OOR_STATUS    = 0x02,
79
  MPR121_LLD_REGISTER_FILTERED_DATA = 0x04,
80
  MPR121_LLD_REGISTER_BASELINE      = 0x1E,
81

    
82
  MPR121_LLD_REGISTER_MHD_RISING    = 0x2B,
83
  MPR121_LLD_REGISTER_NHD_RISING    = 0x2C,
84
  MPR121_LLD_REGISTER_NCL_RISING    = 0x2D,
85
  MPR121_LLD_REGISTER_FDL_RISING    = 0x2E,
86
  MPR121_LLD_REGISTER_MHD_FALLING   = 0x2F,
87
  MPR121_LLD_REGISTER_NHD_FALLING   = 0x30,
88
  MPR121_LLD_REGISTER_NCL_FALLING   = 0x31,
89
  MPR121_LLD_REGISTER_FDL_FALLING   = 0x32,
90
  MPR121_LLD_REGISTER_NHD_TOUCHED   = 0x33,
91
  MPR121_LLD_REGISTER_NCL_TOUCHED   = 0x34,
92
  MPR121_LLD_REGISTER_FDL_TOUCHED   = 0x35,
93

    
94
  MPR121_LLD_REGISTER_ELEPROX_MHD_RISING    = 0x36,
95
  MPR121_LLD_REGISTER_ELEPROX_NHD_RISING    = 0x37,
96
  MPR121_LLD_REGISTER_ELEPROX_NCL_RISING    = 0x38,
97
  MPR121_LLD_REGISTER_ELEPROX_FDL_RISING    = 0x39,
98
  MPR121_LLD_REGISTER_ELEPROX_MHD_FALLING   = 0x3A,
99
  MPR121_LLD_REGISTER_ELEPROX_NHD_FALLING   = 0x3B,
100
  MPR121_LLD_REGISTER_ELEPROX_NCL_FALLING   = 0x3C,
101
  MPR121_LLD_REGISTER_ELEPROX_FDL_FALLING   = 0x3D,
102
  MPR121_LLD_REGISTER_ELEPROX_NHD_TOUCHED   = 0x3E,
103
  MPR121_LLD_REGISTER_ELEPROX_NCL_TOUCHED   = 0x3F,
104
  MPR121_LLD_REGISTER_ELEPROX_FDL_TOUCHED   = 0x40,
105

    
106
  MPR121_LLD_REGISTER_THRESHOLDS  = 0x41,
107
  MPR121_LLD_REGISTER_DEBOUNCE    = 0x5B,
108
  MPR121_LLD_REGISTER_CONFIG_1    = 0x5C,
109
  MPR121_LLD_REGISTER_CONFIG_2    = 0x5D,
110
  MPR121_LLD_REGISTER_CONFIG_ECR  = 0x5E,
111
  MPR121_LLD_REGISTER_ELE_CURRENT = 0x5F,
112
  MPR121_LLD_REGISTER_CHARGE_TIME = 0x6C,
113

    
114
  MPR121_LLD_REGISTER_GPIO_CTRL_0         = 0x73,
115
  MPR121_LLD_REGISTER_GPIO_CTRL_1         = 0x74,
116
  MPR121_LLD_REGISTER_GPIO_DATA           = 0x75,
117
  MPR121_LLD_REGISTER_GPIO_DIRECTION_CTRL = 0x76,
118
  MPR121_LLD_REGISTER_GPIO_ENABLE         = 0x77,
119
  MPR121_LLD_REGISTER_GPIO_DATA_SET       = 0x78,
120
  MPR121_LLD_REGISTER_GPIO_DATA_CLEAR     = 0x79,
121
  MPR121_LLD_REGISTER_GPIO_DATA_TOGGLE    = 0x7A,
122

    
123
  MPR121_LLD_REGISTER_AUTOCFG_CTRL_0       = 0x7B,
124
  MPR121_LLD_REGISTER_AUTOCFG_CTRL_1       = 0x7C,
125
  MPR121_LLD_REGISTER_AUTOCFG_USL          = 0x7D,
126
  MPR121_LLD_REGISTER_AUTOCFG_LSL          = 0x7E,
127
  MPR121_LLD_REGISTER_AUTOCFG_TARGET_LEVEL = 0x7F,
128

    
129
  MPR121_LLD_REGISTER_SOFT_RESET           = 0x80
130
} mpr121_lld_register_t;
131

    
132
/**
133
 * @brief Configuration data type.
134
 */
135
typedef union {
136
  uint8_t values[8];
137
  struct {
138
    uint8_t auto_config_1;
139
    uint8_t auto_config_2;
140
    uint8_t up_side_limit;
141
    uint8_t low_side_limit;
142
    uint8_t target_level;
143
    uint8_t config_1;
144
    uint8_t config_2;
145
    uint8_t ele_config;
146
  } registers;
147
} mpr121_lld_config_t;
148

    
149
/**
150
 * €brief Configutation register 1 masks.
151
 */
152
typedef enum {
153
  MPR121_LLD_FFI_6     = 0x00u,
154
  MPR121_LLD_FFI_10    = 0x40u,
155
  MPR121_LLD_FFI_18    = 0x80u,
156
  MPR121_LLD_FFI_34    = 0xC0u,
157
} mpr121_lld_config1_t;
158

    
159
/**
160
 * @brief Configuration register 2 masks.
161
 */
162
typedef enum {
163
  MPR121_LLD_CDT_OFF   = 0x00u,
164
  MPR121_LLD_CDT_0_5   = 0x20u,
165
  MPR121_LLD_CDT_1     = 0x40u,
166
  MPR121_LLD_CDT_2     = 0x60u,
167
  MPR121_LLD_CDT_4     = 0x80u,
168
  MPR121_LLD_CDT_8     = 0xA0u,
169
  MPR121_LLD_CDT_16    = 0xC0u,
170
  MPR121_LLD_CDT_32    = 0xE0u,
171
  MPR121_LLD_SFI_4     = 0x00u,
172
  MPR121_LLD_SFI_6     = 0x08u,
173
  MPR121_LLD_SFI_10    = 0x10u,
174
  MPR121_LLD_SFI_18    = 0x18u,
175
  MPR121_LLD_ESI_1     = 0x00u,
176
  MPR121_LLD_ESI_2     = 0x01u,
177
  MPR121_LLD_ESI_4     = 0x02u,
178
  MPR121_LLD_ESI_8     = 0x03u,
179
  MPR121_LLD_ESI_16    = 0x04u,
180
  MPR121_LLD_ESI_32    = 0x05u,
181
  MPR121_LLD_ESI_64    = 0x06u,
182
  MPR121_LLD_ESI_128   = 0x07u,
183
} mpr121_lld_config2_t;
184

    
185
/**
186
 * @brief Ele configuration register masks.
187
 */
188
typedef enum {
189
  MPR121_LLD_CL_ON_CURRENT  = 0x00u,
190
  MPR121_LLD_CL_OFF         = 0x40u,
191
  MPR121_LLD_CL_ON_HIGH5    = 0x80u,
192
  MPR121_LLD_CL_ON_ALL      = 0xC0u,
193
  MPR121_LLD_ELEPROX_0      = 0x00u,
194
  MPR121_LLD_ELEPROX_2      = 0x10u,
195
  MPR121_LLD_ELEPROX_4      = 0x20u,
196
  MPR121_LLD_ELEPROX_12     = 0x30u,
197
} mpr121_lld_ele_config_t;
198

    
199
/**
200
 * @brief Auto configuration register 0 masks.
201
 */
202
typedef enum {
203
  MPR121_LLD_AC_ENABLE      = 0x01u,
204
  MPR121_LLD_AC_RECONF_EN   = 0x02u,
205
  MPR121_LLD_BVA_ON_CURRENT = 0x00u,
206
  MPR121_LLD_BVA_OFF        = 0x04u,
207
  MPR121_LLD_BVA_ON_HIGH5   = 0x08u,
208
  MPR121_LLD_BVA_ON_ALL     = 0x0Cu,
209
  MPR121_LLD_RETRY_OFF      = 0x00u,
210
  MPR121_LLD_RETRY_2        = 0x10u,
211
  MPR121_LLD_RETRY_4        = 0x20u,
212
  MPR121_LLD_RETRY_8        = 0x30u,
213
  /* skip FFI */
214
} mpr121_lld_auto_config0_t;
215

    
216
/**
217
 * @brief Auto configuration register 1 masks.
218
 */
219
typedef enum {
220
  MPR121_LLD_AC_FAIL_INT_EN         = 0x01u,
221
  MPR121_LLD_AC_RECONF_FAIL_INT_EN  = 0x02u,
222
  MPR121_LLD_AC_OUT_OF_RANGE_INT_EN = 0x04u,
223
  MPR121_LLD_AC_SKIP_CHRG_TIME_SRCH = 0x80u,
224
} mpr121_lld_auto_config1_t;
225

    
226
/******************************************************************************/
227
/* MACROS                                                                     */
228
/******************************************************************************/
229

    
230
/******************************************************************************/
231
/* EXTERN DECLARATIONS                                                        */
232
/******************************************************************************/
233

    
234
#ifdef __cplusplus
235
extern "C" {
236
#endif
237
  apalExitStatus_t mpr121_lld_read_register(const MPR121Driver* const mprd, const mpr121_lld_register_t regaddr, const uint8_t offset, const uint8_t size, uint8_t* const data, const apalTime_t timeout);
238
  apalExitStatus_t mpr121_lld_write_register(const MPR121Driver* const mprd, const mpr121_lld_register_t regaddr, const uint8_t offset, const uint8_t size, const uint8_t* const data, const apalTime_t timeout);
239
  apalExitStatus_t mpr121_lld_soft_reset(const MPR121Driver* const mprd, const apalTime_t timeout);
240
  apalExitStatus_t mpr121_lld_read_filtered_data(const MPR121Driver* const mprd, const uint8_t index, const uint8_t num, uint16_t* const data, const apalTime_t timeout);
241
  apalExitStatus_t mpr121_lld_read_baseline_data(const MPR121Driver* const mprd, const uint8_t index, const uint8_t num, uint8_t* const data, const apalTime_t timeout);
242
  apalExitStatus_t mpr121_lld_read_electrode_data(const MPR121Driver* const mprd, const uint8_t index, const uint8_t num, uint8_t* const data, const apalTime_t timeout);
243
  apalExitStatus_t mpr121_lld_write_config(const MPR121Driver* const mprd, const mpr121_lld_config_t cfg, const apalTime_t timeout);
244
  apalExitStatus_t mpr121_lld_read_config(const MPR121Driver* const mprd, mpr121_lld_config_t* const cfg, const apalTime_t timeout);
245
#ifdef __cplusplus
246
}
247
#endif
248

    
249
/******************************************************************************/
250
/* INLINE FUNCTIONS                                                           */
251
/******************************************************************************/
252

    
253
#endif /* AMIROLLD_MPR121_H */
254

    
255
/** @} */