Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / alld_mpr121.h @ cf1f756b

History | View | Annotate | Download (7.508 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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
#ifndef _AMIROLLD_MPR121_H_
20
#define _AMIROLLD_MPR121_H_
21

    
22
#include <amiro-lld.h>
23

    
24
#if defined(AMIROLLD_CFG_USE_MPR121) || defined(__DOXYGEN__)
25

    
26
/**
27
 * @brief Maximum I2C frequency.
28
 */
29
#define MPR121_LLD_I2C_MAXFREQUENCY   400000
30

    
31
/**
32
 * @brief A falling edge indicates an interrupt.
33
 */
34
#define MPR121_LLD_INT_EDGE           APAL_GPIO_EDGE_FALLING
35

    
36
/**
37
 * @brief The MPR121 driver struct
38
 */
39
typedef struct {
40
  apalI2CDriver_t* i2cd;        /**< @brief The I2C Driver */
41
} MPR121Driver;
42

    
43
enum {
44
  MPR121_LLD_I2C_ADDR_FIXED   = 0x5Au,
45
  MPR121_LLD_I2C_ADDR_VSS     = 0x00u,
46
  MPR121_LLD_I2C_ADDR_VDD     = 0x01u,
47
  MPR121_LLD_I2C_ADDR_SDA     = 0x04u,
48
  MPR121_LLD_I2C_SOFTRESET    = 0x63,
49
};
50

    
51
/**
52
 * @brief Registers of the mpr121.
53
 */
54
typedef enum {
55
  MPR121_LLD_REGISTER_TOUCH_STATUS  = 0x00,
56
  MPR121_LLD_REGISTER_OOR_STATUS    = 0x02,
57
  MPR121_LLD_REGISTER_FILTERED_DATA = 0x04,
58
  MPR121_LLD_REGISTER_BASELINE      = 0x1E,
59

    
60
  MPR121_LLD_REGISTER_MHD_RISING    = 0x2B,
61
  MPR121_LLD_REGISTER_NHD_RISING    = 0x2C,
62
  MPR121_LLD_REGISTER_NCL_RISING    = 0x2D,
63
  MPR121_LLD_REGISTER_FDL_RISING    = 0x2E,
64
  MPR121_LLD_REGISTER_MHD_FALLING   = 0x2F,
65
  MPR121_LLD_REGISTER_NHD_FALLING   = 0x30,
66
  MPR121_LLD_REGISTER_NCL_FALLING   = 0x31,
67
  MPR121_LLD_REGISTER_FDL_FALLING   = 0x32,
68
  MPR121_LLD_REGISTER_NHD_TOUCHED   = 0x33,
69
  MPR121_LLD_REGISTER_NCL_TOUCHED   = 0x34,
70
  MPR121_LLD_REGISTER_FDL_TOUCHED   = 0x35,
71

    
72
  MPR121_LLD_REGISTER_ELEPROX_MHD_RISING    = 0x36,
73
  MPR121_LLD_REGISTER_ELEPROX_NHD_RISING    = 0x37,
74
  MPR121_LLD_REGISTER_ELEPROX_NCL_RISING    = 0x38,
75
  MPR121_LLD_REGISTER_ELEPROX_FDL_RISING    = 0x39,
76
  MPR121_LLD_REGISTER_ELEPROX_MHD_FALLING   = 0x3A,
77
  MPR121_LLD_REGISTER_ELEPROX_NHD_FALLING   = 0x3B,
78
  MPR121_LLD_REGISTER_ELEPROX_NCL_FALLING   = 0x3C,
79
  MPR121_LLD_REGISTER_ELEPROX_FDL_FALLING   = 0x3D,
80
  MPR121_LLD_REGISTER_ELEPROX_NHD_TOUCHED   = 0x3E,
81
  MPR121_LLD_REGISTER_ELEPROX_NCL_TOUCHED   = 0x3F,
82
  MPR121_LLD_REGISTER_ELEPROX_FDL_TOUCHED   = 0x40,
83

    
84
  MPR121_LLD_REGISTER_THRESHOLDS  = 0x41,
85
  MPR121_LLD_REGISTER_DEBOUNCE    = 0x5B,
86
  MPR121_LLD_REGISTER_CONFIG_1    = 0x5C,
87
  MPR121_LLD_REGISTER_CONFIG_2    = 0x5D,
88
  MPR121_LLD_REGISTER_CONFIG_ECR  = 0x5E,
89
  MPR121_LLD_REGISTER_ELE_CURRENT = 0x5F,
90
  MPR121_LLD_REGISTER_CHARGE_TIME = 0x6C,
91

    
92
  MPR121_LLD_REGISTER_GPIO_CTRL_0         = 0x73,
93
  MPR121_LLD_REGISTER_GPIO_CTRL_1         = 0x74,
94
  MPR121_LLD_REGISTER_GPIO_DATA           = 0x75,
95
  MPR121_LLD_REGISTER_GPIO_DIRECTION_CTRL = 0x76,
96
  MPR121_LLD_REGISTER_GPIO_ENABLE         = 0x77,
97
  MPR121_LLD_REGISTER_GPIO_DATA_SET       = 0x78,
98
  MPR121_LLD_REGISTER_GPIO_DATA_CLEAR     = 0x79,
99
  MPR121_LLD_REGISTER_GPIO_DATA_TOGGLE    = 0x7A,
100

    
101
  MPR121_LLD_REGISTER_AUTOCFG_CTRL_0       = 0x7B,
102
  MPR121_LLD_REGISTER_AUTOCFG_CTRL_1       = 0x7C,
103
  MPR121_LLD_REGISTER_AUTOCFG_USL          = 0x7D,
104
  MPR121_LLD_REGISTER_AUTOCFG_LSL          = 0x7E,
105
  MPR121_LLD_REGISTER_AUTOCFG_TARGET_LEVEL = 0x7F,
106

    
107
  MPR121_LLD_REGISTER_SOFT_RESET           = 0x80
108
} mpr121_lld_register_t;
109

    
110
/**
111
 * @brief Configuration data type.
112
 */
113
typedef union {
114
  uint8_t values[8];
115
  struct {
116
    uint8_t auto_config_1;
117
    uint8_t auto_config_2;
118
    uint8_t up_side_limit;
119
    uint8_t low_side_limit;
120
    uint8_t target_level;
121
    uint8_t config_1;
122
    uint8_t config_2;
123
    uint8_t ele_config;
124
  } registers;
125
} mpr121_lld_config_t;
126

    
127
/**
128
 * €brief Configutation register 1 masks.
129
 */
130
typedef enum {
131
  MPR121_LLD_FFI_6     = 0x00u,
132
  MPR121_LLD_FFI_10    = 0x40u,
133
  MPR121_LLD_FFI_18    = 0x80u,
134
  MPR121_LLD_FFI_34    = 0xC0u,
135
} mpr121_lld_config1_t;
136

    
137
/**
138
 * @brief Configuration register 2 masks.
139
 */
140
typedef enum {
141
  MPR121_LLD_CDT_OFF   = 0x00u,
142
  MPR121_LLD_CDT_0_5   = 0x20u,
143
  MPR121_LLD_CDT_1     = 0x40u,
144
  MPR121_LLD_CDT_2     = 0x60u,
145
  MPR121_LLD_CDT_4     = 0x80u,
146
  MPR121_LLD_CDT_8     = 0xA0u,
147
  MPR121_LLD_CDT_16    = 0xC0u,
148
  MPR121_LLD_CDT_32    = 0xE0u,
149
  MPR121_LLD_SFI_4     = 0x00u,
150
  MPR121_LLD_SFI_6     = 0x08u,
151
  MPR121_LLD_SFI_10    = 0x10u,
152
  MPR121_LLD_SFI_18    = 0x18u,
153
  MPR121_LLD_ESI_1     = 0x00u,
154
  MPR121_LLD_ESI_2     = 0x01u,
155
  MPR121_LLD_ESI_4     = 0x02u,
156
  MPR121_LLD_ESI_8     = 0x03u,
157
  MPR121_LLD_ESI_16    = 0x04u,
158
  MPR121_LLD_ESI_32    = 0x05u,
159
  MPR121_LLD_ESI_64    = 0x06u,
160
  MPR121_LLD_ESI_128   = 0x07u,
161
} mpr121_lld_config2_t;
162

    
163
/**
164
 * @brief Ele configuration register masks.
165
 */
166
typedef enum {
167
  MPR121_LLD_CL_ON_CURRENT  = 0x00u,
168
  MPR121_LLD_CL_OFF         = 0x40u,
169
  MPR121_LLD_CL_ON_HIGH5    = 0x80u,
170
  MPR121_LLD_CL_ON_ALL      = 0xC0u,
171
  MPR121_LLD_ELEPROX_0      = 0x00u,
172
  MPR121_LLD_ELEPROX_2      = 0x10u,
173
  MPR121_LLD_ELEPROX_4      = 0x20u,
174
  MPR121_LLD_ELEPROX_12     = 0x30u,
175
} mpr121_lld_ele_config_t;
176

    
177
/**
178
 * @brief Auto configuration register 0 masks.
179
 */
180
typedef enum {
181
  MPR121_LLD_AC_ENABLE      = 0x01u,
182
  MPR121_LLD_AC_RECONF_EN   = 0x02u,
183
  MPR121_LLD_BVA_ON_CURRENT = 0x00u,
184
  MPR121_LLD_BVA_OFF        = 0x04u,
185
  MPR121_LLD_BVA_ON_HIGH5   = 0x08u,
186
  MPR121_LLD_BVA_ON_ALL     = 0x0Cu,
187
  MPR121_LLD_RETRY_OFF      = 0x00u,
188
  MPR121_LLD_RETRY_2        = 0x10u,
189
  MPR121_LLD_RETRY_4        = 0x20u,
190
  MPR121_LLD_RETRY_8        = 0x30u,
191
  /* skip FFI */
192
} mpr121_lld_auto_config0_t;
193

    
194
/**
195
 * @brief Auto configuration register 1 masks.
196
 */
197
typedef enum {
198
  MPR121_LLD_AC_FAIL_INT_EN         = 0x01u,
199
  MPR121_LLD_AC_RECONF_FAIL_INT_EN  = 0x02u,
200
  MPR121_LLD_AC_OUT_OF_RANGE_INT_EN = 0x04u,
201
  MPR121_LLD_AC_SKIP_CHRG_TIME_SRCH = 0x80u,
202
} mpr121_lld_auto_config1_t;
203

    
204
#ifdef __cplusplus
205
extern "C" {
206
#endif
207
  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);
208
  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);
209
  apalExitStatus_t mpr121_lld_soft_reset(const MPR121Driver* const mprd, const apalTime_t timeout);
210
  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);
211
  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);
212
  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);
213
  apalExitStatus_t mpr121_lld_write_config(const MPR121Driver* const mprd, const mpr121_lld_config_t cfg, const apalTime_t timeout);
214
  apalExitStatus_t mpr121_lld_read_config(const MPR121Driver* const mprd, mpr121_lld_config_t* const cfg, const apalTime_t timeout);
215
#ifdef __cplusplus
216
}
217
#endif
218

    
219
#endif /* defined(AMIROLLD_CFG_USE_MPR121) */
220

    
221
#endif /* _AMIROLLD_MPR121_H_ */