use mbed os

Dependents:   Seeed_Grove_I2C_Touch_Example

Fork of MPR121 by Sam Grove

Committer:
tulanthoar
Date:
Sun Jul 02 17:06:35 2017 +0000
Revision:
14:6bcd2f6a4fee
Parent:
13:185ada085785
Parent:
9:8cb5ce483be3
Child:
16:94e77e14a859
Child:
17:2d6b050ad8b8
merge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tulanthoar 14:6bcd2f6a4fee 1 <<<<<<< local
sam_grove 0:42add775212a 2 /**
sam_grove 0:42add775212a 3 * @file MPR121.h
sam_grove 0:42add775212a 4 * @brief Device driver - MPR121 capactiive touch IC
sam_grove 0:42add775212a 5 * @author sam grove
sam_grove 0:42add775212a 6 * @version 1.0
sam_grove 0:42add775212a 7 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf
sam_grove 0:42add775212a 8 *
sam_grove 0:42add775212a 9 * Copyright (c) 2013
sam_grove 0:42add775212a 10 *
sam_grove 0:42add775212a 11 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:42add775212a 12 * you may not use this file except in compliance with the License.
sam_grove 0:42add775212a 13 * You may obtain a copy of the License at
sam_grove 0:42add775212a 14 *
sam_grove 0:42add775212a 15 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:42add775212a 16 *
sam_grove 0:42add775212a 17 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:42add775212a 18 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:42add775212a 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:42add775212a 20 * See the License for the specific language governing permissions and
sam_grove 0:42add775212a 21 * limitations under the License.
sam_grove 0:42add775212a 22 */
sam_grove 0:42add775212a 23
sam_grove 0:42add775212a 24 #ifndef MPR121_H
sam_grove 0:42add775212a 25 #define MPR121_H
sam_grove 0:42add775212a 26
sam_grove 0:42add775212a 27 #include "mbed.h"
tulanthoar 13:185ada085785 28 //#include "rtos.h"
sam_grove 0:42add775212a 29
sam_grove 3:828260f21de6 30 /** Using the Sparkfun SEN-10250 BoB
sam_grove 0:42add775212a 31 *
sam_grove 0:42add775212a 32 * Example:
sam_grove 0:42add775212a 33 * @code
sam_grove 3:828260f21de6 34 * #include "mbed.h"
sam_grove 3:828260f21de6 35 * #include "MPR121.h"
sam_grove 3:828260f21de6 36 *
sam_grove 3:828260f21de6 37 * Serial pc(USBTX, USBRX);
sam_grove 3:828260f21de6 38 * DigitalOut myled(LED1);
sam_grove 3:828260f21de6 39 *
sam_grove 3:828260f21de6 40 * #if defined TARGET_LPC1768 || TARGET_LPC11U24
sam_grove 3:828260f21de6 41 * I2C i2c(p28, p27);
sam_grove 3:828260f21de6 42 * InterruptIn irq(p26);
sam_grove 3:828260f21de6 43 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
sam_grove 3:828260f21de6 44 *
sam_grove 3:828260f21de6 45 * #elif defined TARGET_KL25Z
sam_grove 3:828260f21de6 46 * I2C i2c(PTC9, PTC8);
sam_grove 3:828260f21de6 47 * InterruptIn irq(PTA5);
sam_grove 3:828260f21de6 48 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
sam_grove 3:828260f21de6 49 *
sam_grove 3:828260f21de6 50 * #else
sam_grove 3:828260f21de6 51 * #error TARGET NOT TESTED
sam_grove 3:828260f21de6 52 * #endif
sam_grove 3:828260f21de6 53 *
sam_grove 3:828260f21de6 54 * int main()
sam_grove 3:828260f21de6 55 * {
sam_grove 3:828260f21de6 56 * touch_pad.init();
sam_grove 3:828260f21de6 57 * touch_pad.enable();
sam_grove 3:828260f21de6 58 *
sam_grove 3:828260f21de6 59 * while(1)
sam_grove 3:828260f21de6 60 * {
sam_grove 3:828260f21de6 61 * if(touch_pad.isPressed())
sam_grove 3:828260f21de6 62 * {
sam_grove 3:828260f21de6 63 * uint16_t button_val = touch_pad.buttonPressed();
sam_grove 3:828260f21de6 64 * printf("button = 0x%04x\n", button_val);
sam_grove 3:828260f21de6 65 * myled = (button_val>0) ? 1 : 0;
sam_grove 3:828260f21de6 66 * }
sam_grove 3:828260f21de6 67 * }
sam_grove 3:828260f21de6 68 * }
sam_grove 0:42add775212a 69 * @endcode
sam_grove 0:42add775212a 70 */
sam_grove 0:42add775212a 71
sam_grove 0:42add775212a 72 /**
sam_grove 0:42add775212a 73 * @class MPR121
sam_grove 3:828260f21de6 74 * @brief API for the MPR121 capacitive touch IC
sam_grove 0:42add775212a 75 */
sam_grove 0:42add775212a 76 class MPR121
sam_grove 0:42add775212a 77 {
sam_grove 0:42add775212a 78 private:
sam_grove 0:42add775212a 79
sam_grove 0:42add775212a 80 I2C *_i2c;
sam_grove 0:42add775212a 81 InterruptIn *_irq;
sam_grove 0:42add775212a 82 uint8_t _i2c_addr;
sam_grove 0:42add775212a 83 volatile uint16_t _button;
sam_grove 0:42add775212a 84 volatile uint32_t _button_has_changed;
sam_grove 0:42add775212a 85
sam_grove 0:42add775212a 86 /** The interrupt handler for the IRQ pin
sam_grove 0:42add775212a 87 */
sam_grove 0:42add775212a 88 void handler(void);
sam_grove 0:42add775212a 89
sam_grove 0:42add775212a 90 public:
sam_grove 0:42add775212a 91
sam_grove 0:42add775212a 92 /**
sam_grove 0:42add775212a 93 * @enum MPR121_ADDR
sam_grove 0:42add775212a 94 * @brief Possible terminations for the ADDR pin
sam_grove 0:42add775212a 95 */
sam_grove 0:42add775212a 96 enum MPR121_ADDR
sam_grove 0:42add775212a 97 {
sam_grove 0:42add775212a 98 ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */
sam_grove 0:42add775212a 99 ADDR_VDD, /*!< ADDR connected to VDD */
sam_grove 0:42add775212a 100 ADDR_SCL, /*!< ADDR connected to SDA */
sam_grove 0:42add775212a 101 ADDR_SDA /*!< ADDR connected to SCL */
sam_grove 0:42add775212a 102 };
sam_grove 0:42add775212a 103
sam_grove 0:42add775212a 104 /**
sam_grove 0:42add775212a 105 * @enum MPR121_REGISTER
sam_grove 0:42add775212a 106 * @brief The device register map
sam_grove 0:42add775212a 107 */
sam_grove 0:42add775212a 108 enum MPR121_REGISTER
sam_grove 0:42add775212a 109 {
sam_grove 0:42add775212a 110 ELE0_7_STAT = 0x00,
sam_grove 0:42add775212a 111 ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB,
sam_grove 0:42add775212a 112 EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB,
sam_grove 0:42add775212a 113
sam_grove 0:42add775212a 114 EFD6LB = 0x10,
sam_grove 0:42add775212a 115 EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB,
sam_grove 0:42add775212a 116 EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV,
sam_grove 0:42add775212a 117
sam_grove 0:42add775212a 118 E2BV = 0x20,
sam_grove 0:42add775212a 119 E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV,
sam_grove 0:42add775212a 120 MHDR, NHDR, NCLR, FDLR, MHDF,
sam_grove 0:42add775212a 121
sam_grove 0:42add775212a 122 NHDF = 0x30,
sam_grove 0:42add775212a 123 NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR,
sam_grove 0:42add775212a 124 FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT,
sam_grove 0:42add775212a 125
sam_grove 0:42add775212a 126 FDLPROXT = 0x40,
sam_grove 0:42add775212a 127 E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH,
sam_grove 0:42add775212a 128 E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH,
sam_grove 0:42add775212a 129
sam_grove 0:42add775212a 130 E7RTH = 0x50,
sam_grove 0:42add775212a 131 E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH,
sam_grove 0:42add775212a 132 EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0,
sam_grove 0:42add775212a 133
sam_grove 0:42add775212a 134 CDC1 = 0x60,
sam_grove 0:42add775212a 135 CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1,
sam_grove 0:42add775212a 136 CDT2_CDT3, CDT4_CDT5, CDT6_CDT7,
sam_grove 0:42add775212a 137
sam_grove 0:42add775212a 138 CDT8_CDT9 = 0x70,
sam_grove 0:42add775212a 139 CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET,
sam_grove 0:42add775212a 140 GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL,
sam_grove 0:42add775212a 141
sam_grove 0:42add775212a 142 SRST = 0x80
sam_grove 0:42add775212a 143 };
sam_grove 0:42add775212a 144
sam_grove 0:42add775212a 145 /** Create the MPR121 object
sam_grove 1:cee45334b36a 146 * @param i2c - A defined I2C object
sam_grove 1:cee45334b36a 147 * @param pin - A defined InterruptIn object
sam_grove 1:cee45334b36a 148 * @param i2c_addr - Connection of the address line
sam_grove 0:42add775212a 149 */
sam_grove 0:42add775212a 150 MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
sam_grove 0:42add775212a 151
sam_grove 5:3934358ec2b7 152 /** Create the MPR121 object
sam_grove 5:3934358ec2b7 153 * @param i2c - A defined I2C object
sam_grove 5:3934358ec2b7 154 * @param i2c_addr - Connection of the address line
sam_grove 5:3934358ec2b7 155 */
sam_grove 5:3934358ec2b7 156 MPR121(I2C &i2c, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 157 /**
tulanthoar 14:6bcd2f6a4fee 158 * @file MPR121.h
tulanthoar 14:6bcd2f6a4fee 159 * @brief Device driver - MPR121 capactiive touch IC
tulanthoar 14:6bcd2f6a4fee 160 * @author sam grove
tulanthoar 14:6bcd2f6a4fee 161 * @version 1.0
tulanthoar 14:6bcd2f6a4fee 162 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf
tulanthoar 14:6bcd2f6a4fee 163 *
tulanthoar 14:6bcd2f6a4fee 164 * Copyright (c) 2013
tulanthoar 14:6bcd2f6a4fee 165 *
tulanthoar 14:6bcd2f6a4fee 166 * Licensed under the Apache License, Version 2.0 (the "License");
tulanthoar 14:6bcd2f6a4fee 167 * you may not use this file except in compliance with the License.
tulanthoar 14:6bcd2f6a4fee 168 * You may obtain a copy of the License at
tulanthoar 14:6bcd2f6a4fee 169 *
tulanthoar 14:6bcd2f6a4fee 170 * http://www.apache.org/licenses/LICENSE-2.0
tulanthoar 14:6bcd2f6a4fee 171 *
tulanthoar 14:6bcd2f6a4fee 172 * Unless required by applicable law or agreed to in writing, software
tulanthoar 14:6bcd2f6a4fee 173 * distributed under the License is distributed on an "AS IS" BASIS,
tulanthoar 14:6bcd2f6a4fee 174 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tulanthoar 14:6bcd2f6a4fee 175 * See the License for the specific language governing permissions and
tulanthoar 14:6bcd2f6a4fee 176 * limitations under the License.
tulanthoar 14:6bcd2f6a4fee 177 */
tulanthoar 14:6bcd2f6a4fee 178
tulanthoar 14:6bcd2f6a4fee 179 #ifndef MPR121_H
tulanthoar 14:6bcd2f6a4fee 180 #define MPR121_H
tulanthoar 14:6bcd2f6a4fee 181
tulanthoar 14:6bcd2f6a4fee 182 #include "mbed.h"
tulanthoar 14:6bcd2f6a4fee 183 #include "rtos.h"
tulanthoar 14:6bcd2f6a4fee 184
tulanthoar 14:6bcd2f6a4fee 185 /** Using the Sparkfun SEN-10250 BoB
tulanthoar 14:6bcd2f6a4fee 186 *
tulanthoar 14:6bcd2f6a4fee 187 * Example:
tulanthoar 14:6bcd2f6a4fee 188 * @code
tulanthoar 14:6bcd2f6a4fee 189 * #include "mbed.h"
tulanthoar 14:6bcd2f6a4fee 190 * #include "MPR121.h"
tulanthoar 14:6bcd2f6a4fee 191 *
tulanthoar 14:6bcd2f6a4fee 192 * Serial pc(USBTX, USBRX);
tulanthoar 14:6bcd2f6a4fee 193 * DigitalOut myled(LED1);
tulanthoar 14:6bcd2f6a4fee 194 *
tulanthoar 14:6bcd2f6a4fee 195 * #if defined TARGET_LPC1768 || TARGET_LPC11U24
tulanthoar 14:6bcd2f6a4fee 196 * I2C i2c(p28, p27);
tulanthoar 14:6bcd2f6a4fee 197 * InterruptIn irq(p26);
tulanthoar 14:6bcd2f6a4fee 198 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
tulanthoar 14:6bcd2f6a4fee 199 *
tulanthoar 14:6bcd2f6a4fee 200 * #elif defined TARGET_KL25Z
tulanthoar 14:6bcd2f6a4fee 201 * I2C i2c(PTC9, PTC8);
tulanthoar 14:6bcd2f6a4fee 202 * InterruptIn irq(PTA5);
tulanthoar 14:6bcd2f6a4fee 203 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
tulanthoar 14:6bcd2f6a4fee 204 *
tulanthoar 14:6bcd2f6a4fee 205 * #else
tulanthoar 14:6bcd2f6a4fee 206 * #error TARGET NOT TESTED
tulanthoar 14:6bcd2f6a4fee 207 * #endif
tulanthoar 14:6bcd2f6a4fee 208 *
tulanthoar 14:6bcd2f6a4fee 209 * int main()
tulanthoar 14:6bcd2f6a4fee 210 * {
tulanthoar 14:6bcd2f6a4fee 211 * touch_pad.init();
tulanthoar 14:6bcd2f6a4fee 212 * touch_pad.enable();
tulanthoar 14:6bcd2f6a4fee 213 *
tulanthoar 14:6bcd2f6a4fee 214 * while(1)
tulanthoar 14:6bcd2f6a4fee 215 * {
tulanthoar 14:6bcd2f6a4fee 216 * if(touch_pad.isPressed())
tulanthoar 14:6bcd2f6a4fee 217 * {
tulanthoar 14:6bcd2f6a4fee 218 * uint16_t button_val = touch_pad.buttonPressed();
tulanthoar 14:6bcd2f6a4fee 219 * printf("button = 0x%04x\n", button_val);
tulanthoar 14:6bcd2f6a4fee 220 * myled = (button_val>0) ? 1 : 0;
tulanthoar 14:6bcd2f6a4fee 221 * }
tulanthoar 14:6bcd2f6a4fee 222 * }
tulanthoar 14:6bcd2f6a4fee 223 * }
tulanthoar 14:6bcd2f6a4fee 224 * @endcode
tulanthoar 14:6bcd2f6a4fee 225 */
tulanthoar 14:6bcd2f6a4fee 226
tulanthoar 14:6bcd2f6a4fee 227 /**
tulanthoar 14:6bcd2f6a4fee 228 * @class MPR121
tulanthoar 14:6bcd2f6a4fee 229 * @brief API for the MPR121 capacitive touch IC
tulanthoar 14:6bcd2f6a4fee 230 */
tulanthoar 14:6bcd2f6a4fee 231 class MPR121
tulanthoar 14:6bcd2f6a4fee 232 {
tulanthoar 14:6bcd2f6a4fee 233 private:
tulanthoar 14:6bcd2f6a4fee 234
tulanthoar 14:6bcd2f6a4fee 235 I2C *_i2c;
tulanthoar 14:6bcd2f6a4fee 236 InterruptIn *_irq;
tulanthoar 14:6bcd2f6a4fee 237 uint8_t _i2c_addr;
tulanthoar 14:6bcd2f6a4fee 238 volatile uint16_t _button;
tulanthoar 14:6bcd2f6a4fee 239 volatile uint32_t _button_has_changed;
tulanthoar 14:6bcd2f6a4fee 240
tulanthoar 14:6bcd2f6a4fee 241 /** The interrupt handler for the IRQ pin
tulanthoar 14:6bcd2f6a4fee 242 */
tulanthoar 14:6bcd2f6a4fee 243 void handler(void);
tulanthoar 14:6bcd2f6a4fee 244
tulanthoar 14:6bcd2f6a4fee 245 public:
tulanthoar 14:6bcd2f6a4fee 246
tulanthoar 14:6bcd2f6a4fee 247 /**
tulanthoar 14:6bcd2f6a4fee 248 * @enum MPR121_ADDR
tulanthoar 14:6bcd2f6a4fee 249 * @brief Possible terminations for the ADDR pin
tulanthoar 14:6bcd2f6a4fee 250 */
tulanthoar 14:6bcd2f6a4fee 251 enum MPR121_ADDR
tulanthoar 14:6bcd2f6a4fee 252 {
tulanthoar 14:6bcd2f6a4fee 253 ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */
tulanthoar 14:6bcd2f6a4fee 254 ADDR_VDD, /*!< ADDR connected to VDD */
tulanthoar 14:6bcd2f6a4fee 255 ADDR_SCL, /*!< ADDR connected to SDA */
tulanthoar 14:6bcd2f6a4fee 256 ADDR_SDA /*!< ADDR connected to SCL */
tulanthoar 14:6bcd2f6a4fee 257 };
tulanthoar 14:6bcd2f6a4fee 258
tulanthoar 14:6bcd2f6a4fee 259 /**
tulanthoar 14:6bcd2f6a4fee 260 * @enum MPR121_REGISTER
tulanthoar 14:6bcd2f6a4fee 261 * @brief The device register map
tulanthoar 14:6bcd2f6a4fee 262 */
tulanthoar 14:6bcd2f6a4fee 263 enum MPR121_REGISTER
tulanthoar 14:6bcd2f6a4fee 264 {
tulanthoar 14:6bcd2f6a4fee 265 ELE0_7_STAT = 0x00,
tulanthoar 14:6bcd2f6a4fee 266 ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB,
tulanthoar 14:6bcd2f6a4fee 267 EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB,
tulanthoar 14:6bcd2f6a4fee 268
tulanthoar 14:6bcd2f6a4fee 269 EFD6LB = 0x10,
tulanthoar 14:6bcd2f6a4fee 270 EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB,
tulanthoar 14:6bcd2f6a4fee 271 EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV,
tulanthoar 14:6bcd2f6a4fee 272
tulanthoar 14:6bcd2f6a4fee 273 E2BV = 0x20,
tulanthoar 14:6bcd2f6a4fee 274 E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV,
tulanthoar 14:6bcd2f6a4fee 275 MHDR, NHDR, NCLR, FDLR, MHDF,
tulanthoar 14:6bcd2f6a4fee 276
tulanthoar 14:6bcd2f6a4fee 277 NHDF = 0x30,
tulanthoar 14:6bcd2f6a4fee 278 NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR,
tulanthoar 14:6bcd2f6a4fee 279 FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT,
tulanthoar 14:6bcd2f6a4fee 280
tulanthoar 14:6bcd2f6a4fee 281 FDLPROXT = 0x40,
tulanthoar 14:6bcd2f6a4fee 282 E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH,
tulanthoar 14:6bcd2f6a4fee 283 E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH,
tulanthoar 14:6bcd2f6a4fee 284
tulanthoar 14:6bcd2f6a4fee 285 E7RTH = 0x50,
tulanthoar 14:6bcd2f6a4fee 286 E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH,
tulanthoar 14:6bcd2f6a4fee 287 EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0,
tulanthoar 14:6bcd2f6a4fee 288
tulanthoar 14:6bcd2f6a4fee 289 CDC1 = 0x60,
tulanthoar 14:6bcd2f6a4fee 290 CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1,
tulanthoar 14:6bcd2f6a4fee 291 CDT2_CDT3, CDT4_CDT5, CDT6_CDT7,
tulanthoar 14:6bcd2f6a4fee 292
tulanthoar 14:6bcd2f6a4fee 293 CDT8_CDT9 = 0x70,
tulanthoar 14:6bcd2f6a4fee 294 CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET,
tulanthoar 14:6bcd2f6a4fee 295 GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL,
tulanthoar 14:6bcd2f6a4fee 296
tulanthoar 14:6bcd2f6a4fee 297 SRST = 0x80
tulanthoar 14:6bcd2f6a4fee 298 };
tulanthoar 14:6bcd2f6a4fee 299
tulanthoar 14:6bcd2f6a4fee 300 /** Create the MPR121 object
tulanthoar 14:6bcd2f6a4fee 301 * @param i2c - A defined I2C object
tulanthoar 14:6bcd2f6a4fee 302 * @param pin - A defined InterruptIn object
tulanthoar 14:6bcd2f6a4fee 303 * @param i2c_addr - Connection of the address line
tulanthoar 14:6bcd2f6a4fee 304 */
tulanthoar 14:6bcd2f6a4fee 305 MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 306
tulanthoar 14:6bcd2f6a4fee 307 /** Create the MPR121 object
tulanthoar 14:6bcd2f6a4fee 308 * @param i2c - A defined I2C object
tulanthoar 14:6bcd2f6a4fee 309 * @param i2c_addr - Connection of the address line
tulanthoar 14:6bcd2f6a4fee 310 */
tulanthoar 14:6bcd2f6a4fee 311 MPR121(I2C &i2c, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 312
sam_grove 3:828260f21de6 313 /** Clear state variables and initilize the dependant objects
sam_grove 0:42add775212a 314 */
sam_grove 0:42add775212a 315 void init(void);
tulanthoar 14:6bcd2f6a4fee 316
sam_grove 0:42add775212a 317 /** Allow the IC to run and collect user input
sam_grove 0:42add775212a 318 */
sam_grove 0:42add775212a 319 void enable(void);
tulanthoar 14:6bcd2f6a4fee 320
sam_grove 0:42add775212a 321 /** Stop the IC and put into low power mode
sam_grove 0:42add775212a 322 */
sam_grove 0:42add775212a 323 void disable(void);
tulanthoar 14:6bcd2f6a4fee 324
sam_grove 0:42add775212a 325 /** Determine if a new button press event occured
sam_grove 0:42add775212a 326 * Upon calling the state is cleared until another press is detected
sam_grove 0:42add775212a 327 * @return 1 if a press has been detected since the last call, 0 otherwise
sam_grove 0:42add775212a 328 */
sam_grove 0:42add775212a 329 uint32_t isPressed(void);
tulanthoar 14:6bcd2f6a4fee 330
sam_grove 0:42add775212a 331 /** Get the electrode status (ELE12 ... ELE0 -> b15 xxx b11 ... b0
sam_grove 0:42add775212a 332 * The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined
sam_grove 0:42add775212a 333 * @return The state of all buttons
sam_grove 0:42add775212a 334 */
sam_grove 0:42add775212a 335 uint16_t buttonPressed(void);
tulanthoar 14:6bcd2f6a4fee 336
sam_grove 0:42add775212a 337 /** print the register map and values to the console
sam_grove 3:828260f21de6 338 * @param obj - a Serial object that prints to a console
sam_grove 0:42add775212a 339 */
sam_grove 3:828260f21de6 340 void registerDump(Serial &obj) const;
tulanthoar 14:6bcd2f6a4fee 341
sam_grove 5:3934358ec2b7 342 /** print the register map and values to the console
sam_grove 5:3934358ec2b7 343 */
sam_grove 5:3934358ec2b7 344 void registerDump(void) const;
tulanthoar 14:6bcd2f6a4fee 345
sam_grove 0:42add775212a 346 /** Write to a register (exposed for debugging reasons)
sam_grove 0:42add775212a 347 * Note: most writes are only valid in stop mode
sam_grove 1:cee45334b36a 348 * @param reg - The register to be written
sam_grove 1:cee45334b36a 349 * @param data - The data to be written
sam_grove 0:42add775212a 350 */
sam_grove 3:828260f21de6 351 void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const;
tulanthoar 14:6bcd2f6a4fee 352
sam_grove 0:42add775212a 353 /** Read from a register (exposed for debugging reasons)
sam_grove 1:cee45334b36a 354 * @param reg - The register to read from
sam_grove 0:42add775212a 355 * @return The register contents
sam_grove 0:42add775212a 356 */
sam_grove 3:828260f21de6 357 uint8_t readRegister(MPR121_REGISTER const reg) const;
tulanthoar 14:6bcd2f6a4fee 358
sam_grove 0:42add775212a 359 };
sam_grove 0:42add775212a 360
sam_grove 0:42add775212a 361 #endif