use mbed os

Dependents:   Seeed_Grove_I2C_Touch_Example

Fork of MPR121 by Sam Grove

Committer:
tulanthoar
Date:
Sun Jul 02 17:34:58 2017 +0000
Revision:
18:8c7054b112f0
Parent:
16:94e77e14a859
Parent:
17:2d6b050ad8b8
Child:
19:eaa64138290b
merge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:42add775212a 1 /**
sam_grove 0:42add775212a 2 * @file MPR121.h
sam_grove 0:42add775212a 3 * @brief Device driver - MPR121 capactiive touch IC
sam_grove 0:42add775212a 4 * @author sam grove
sam_grove 0:42add775212a 5 * @version 1.0
sam_grove 0:42add775212a 6 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf
sam_grove 0:42add775212a 7 *
sam_grove 0:42add775212a 8 * Copyright (c) 2013
sam_grove 0:42add775212a 9 *
sam_grove 0:42add775212a 10 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:42add775212a 11 * you may not use this file except in compliance with the License.
sam_grove 0:42add775212a 12 * You may obtain a copy of the License at
sam_grove 0:42add775212a 13 *
sam_grove 0:42add775212a 14 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:42add775212a 15 *
sam_grove 0:42add775212a 16 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:42add775212a 17 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:42add775212a 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:42add775212a 19 * See the License for the specific language governing permissions and
sam_grove 0:42add775212a 20 * limitations under the License.
sam_grove 0:42add775212a 21 */
sam_grove 0:42add775212a 22
sam_grove 0:42add775212a 23 #ifndef MPR121_H
sam_grove 0:42add775212a 24 #define MPR121_H
sam_grove 0:42add775212a 25
sam_grove 0:42add775212a 26 #include "mbed.h"
sam_grove 0:42add775212a 27
sam_grove 3:828260f21de6 28 /** Using the Sparkfun SEN-10250 BoB
sam_grove 0:42add775212a 29 *
sam_grove 0:42add775212a 30 * Example:
sam_grove 0:42add775212a 31 * @code
sam_grove 3:828260f21de6 32 * #include "mbed.h"
sam_grove 3:828260f21de6 33 * #include "MPR121.h"
sam_grove 3:828260f21de6 34 *
sam_grove 3:828260f21de6 35 * Serial pc(USBTX, USBRX);
sam_grove 3:828260f21de6 36 * DigitalOut myled(LED1);
sam_grove 3:828260f21de6 37 *
sam_grove 3:828260f21de6 38 * #if defined TARGET_LPC1768 || TARGET_LPC11U24
sam_grove 3:828260f21de6 39 * I2C i2c(p28, p27);
sam_grove 3:828260f21de6 40 * InterruptIn irq(p26);
sam_grove 3:828260f21de6 41 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
sam_grove 3:828260f21de6 42 *
sam_grove 3:828260f21de6 43 * #elif defined TARGET_KL25Z
sam_grove 3:828260f21de6 44 * I2C i2c(PTC9, PTC8);
sam_grove 3:828260f21de6 45 * InterruptIn irq(PTA5);
sam_grove 3:828260f21de6 46 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
sam_grove 3:828260f21de6 47 *
sam_grove 3:828260f21de6 48 * #else
sam_grove 3:828260f21de6 49 * #error TARGET NOT TESTED
sam_grove 3:828260f21de6 50 * #endif
sam_grove 3:828260f21de6 51 *
sam_grove 3:828260f21de6 52 * int main()
sam_grove 3:828260f21de6 53 * {
sam_grove 3:828260f21de6 54 * touch_pad.init();
sam_grove 3:828260f21de6 55 * touch_pad.enable();
sam_grove 3:828260f21de6 56 *
sam_grove 3:828260f21de6 57 * while(1)
sam_grove 3:828260f21de6 58 * {
sam_grove 3:828260f21de6 59 * if(touch_pad.isPressed())
sam_grove 3:828260f21de6 60 * {
sam_grove 3:828260f21de6 61 * uint16_t button_val = touch_pad.buttonPressed();
sam_grove 3:828260f21de6 62 * printf("button = 0x%04x\n", button_val);
sam_grove 3:828260f21de6 63 * myled = (button_val>0) ? 1 : 0;
sam_grove 3:828260f21de6 64 * }
sam_grove 3:828260f21de6 65 * }
sam_grove 3:828260f21de6 66 * }
sam_grove 0:42add775212a 67 * @endcode
sam_grove 0:42add775212a 68 */
sam_grove 0:42add775212a 69
sam_grove 0:42add775212a 70 /**
sam_grove 0:42add775212a 71 * @class MPR121
sam_grove 3:828260f21de6 72 * @brief API for the MPR121 capacitive touch IC
sam_grove 0:42add775212a 73 */
sam_grove 0:42add775212a 74 class MPR121
sam_grove 0:42add775212a 75 {
sam_grove 0:42add775212a 76 private:
sam_grove 0:42add775212a 77
sam_grove 0:42add775212a 78 I2C *_i2c;
sam_grove 0:42add775212a 79 InterruptIn *_irq;
sam_grove 0:42add775212a 80 uint8_t _i2c_addr;
sam_grove 0:42add775212a 81 volatile uint16_t _button;
sam_grove 0:42add775212a 82 volatile uint32_t _button_has_changed;
sam_grove 0:42add775212a 83
sam_grove 0:42add775212a 84 /** The interrupt handler for the IRQ pin
sam_grove 0:42add775212a 85 */
sam_grove 0:42add775212a 86 void handler(void);
sam_grove 0:42add775212a 87
sam_grove 0:42add775212a 88 public:
sam_grove 0:42add775212a 89
sam_grove 0:42add775212a 90 /**
sam_grove 0:42add775212a 91 * @enum MPR121_ADDR
sam_grove 0:42add775212a 92 * @brief Possible terminations for the ADDR pin
sam_grove 0:42add775212a 93 */
sam_grove 0:42add775212a 94 enum MPR121_ADDR
sam_grove 0:42add775212a 95 {
tulanthoar 17:2d6b050ad8b8 96 <<<<<<< local
Nathan Yonkee 10:fb2d2454fea4 97 ADDR_VSS = 0x1B, /*!< ADDR connected to VSS */
tulanthoar 17:2d6b050ad8b8 98 =======
sam_grove 0:42add775212a 99 ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */
tulanthoar 17:2d6b050ad8b8 100 >>>>>>> other
sam_grove 0:42add775212a 101 ADDR_VDD, /*!< ADDR connected to VDD */
sam_grove 0:42add775212a 102 ADDR_SCL, /*!< ADDR connected to SDA */
sam_grove 0:42add775212a 103 ADDR_SDA /*!< ADDR connected to SCL */
sam_grove 0:42add775212a 104 };
sam_grove 0:42add775212a 105
sam_grove 0:42add775212a 106 /**
sam_grove 0:42add775212a 107 * @enum MPR121_REGISTER
sam_grove 0:42add775212a 108 * @brief The device register map
sam_grove 0:42add775212a 109 */
sam_grove 0:42add775212a 110 enum MPR121_REGISTER
sam_grove 0:42add775212a 111 {
sam_grove 0:42add775212a 112 ELE0_7_STAT = 0x00,
sam_grove 0:42add775212a 113 ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB,
sam_grove 0:42add775212a 114 EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB,
sam_grove 0:42add775212a 115
sam_grove 0:42add775212a 116 EFD6LB = 0x10,
sam_grove 0:42add775212a 117 EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB,
sam_grove 0:42add775212a 118 EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV,
sam_grove 0:42add775212a 119
sam_grove 0:42add775212a 120 E2BV = 0x20,
sam_grove 0:42add775212a 121 E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV,
sam_grove 0:42add775212a 122 MHDR, NHDR, NCLR, FDLR, MHDF,
sam_grove 0:42add775212a 123
sam_grove 0:42add775212a 124 NHDF = 0x30,
sam_grove 0:42add775212a 125 NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR,
sam_grove 0:42add775212a 126 FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT,
sam_grove 0:42add775212a 127
sam_grove 0:42add775212a 128 FDLPROXT = 0x40,
sam_grove 0:42add775212a 129 E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH,
sam_grove 0:42add775212a 130 E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH,
sam_grove 0:42add775212a 131
sam_grove 0:42add775212a 132 E7RTH = 0x50,
sam_grove 0:42add775212a 133 E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH,
sam_grove 0:42add775212a 134 EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0,
sam_grove 0:42add775212a 135
sam_grove 0:42add775212a 136 CDC1 = 0x60,
sam_grove 0:42add775212a 137 CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1,
sam_grove 0:42add775212a 138 CDT2_CDT3, CDT4_CDT5, CDT6_CDT7,
sam_grove 0:42add775212a 139
sam_grove 0:42add775212a 140 CDT8_CDT9 = 0x70,
sam_grove 0:42add775212a 141 CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET,
sam_grove 0:42add775212a 142 GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL,
sam_grove 0:42add775212a 143
sam_grove 0:42add775212a 144 SRST = 0x80
sam_grove 0:42add775212a 145 };
sam_grove 0:42add775212a 146
sam_grove 0:42add775212a 147 /** Create the MPR121 object
sam_grove 1:cee45334b36a 148 * @param i2c - A defined I2C object
sam_grove 1:cee45334b36a 149 * @param pin - A defined InterruptIn object
sam_grove 1:cee45334b36a 150 * @param i2c_addr - Connection of the address line
sam_grove 0:42add775212a 151 */
sam_grove 0:42add775212a 152 MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
sam_grove 0:42add775212a 153
sam_grove 5:3934358ec2b7 154 /** Create the MPR121 object
sam_grove 5:3934358ec2b7 155 * @param i2c - A defined I2C object
sam_grove 5:3934358ec2b7 156 * @param i2c_addr - Connection of the address line
sam_grove 5:3934358ec2b7 157 */
tulanthoar 17:2d6b050ad8b8 158 <<<<<<< local
Nathan Yonkee 10:fb2d2454fea4 159 MPR121(I2C &i2c, MPR121_ADDR fake);
sam_grove 5:3934358ec2b7 160
tulanthoar 17:2d6b050ad8b8 161 =======
sam_grove 5:3934358ec2b7 162 MPR121(I2C &i2c, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 163 /**
tulanthoar 14:6bcd2f6a4fee 164 * @file MPR121.h
tulanthoar 14:6bcd2f6a4fee 165 * @brief Device driver - MPR121 capactiive touch IC
tulanthoar 14:6bcd2f6a4fee 166 * @author sam grove
tulanthoar 14:6bcd2f6a4fee 167 * @version 1.0
tulanthoar 14:6bcd2f6a4fee 168 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf
tulanthoar 14:6bcd2f6a4fee 169 *
tulanthoar 14:6bcd2f6a4fee 170 * Copyright (c) 2013
tulanthoar 14:6bcd2f6a4fee 171 *
tulanthoar 14:6bcd2f6a4fee 172 * Licensed under the Apache License, Version 2.0 (the "License");
tulanthoar 14:6bcd2f6a4fee 173 * you may not use this file except in compliance with the License.
tulanthoar 14:6bcd2f6a4fee 174 * You may obtain a copy of the License at
tulanthoar 14:6bcd2f6a4fee 175 *
tulanthoar 14:6bcd2f6a4fee 176 * http://www.apache.org/licenses/LICENSE-2.0
tulanthoar 14:6bcd2f6a4fee 177 *
tulanthoar 14:6bcd2f6a4fee 178 * Unless required by applicable law or agreed to in writing, software
tulanthoar 14:6bcd2f6a4fee 179 * distributed under the License is distributed on an "AS IS" BASIS,
tulanthoar 14:6bcd2f6a4fee 180 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tulanthoar 14:6bcd2f6a4fee 181 * See the License for the specific language governing permissions and
tulanthoar 14:6bcd2f6a4fee 182 * limitations under the License.
tulanthoar 14:6bcd2f6a4fee 183 */
tulanthoar 14:6bcd2f6a4fee 184
tulanthoar 14:6bcd2f6a4fee 185 #ifndef MPR121_H
tulanthoar 14:6bcd2f6a4fee 186 #define MPR121_H
tulanthoar 14:6bcd2f6a4fee 187
tulanthoar 14:6bcd2f6a4fee 188 #include "mbed.h"
tulanthoar 14:6bcd2f6a4fee 189 #include "rtos.h"
tulanthoar 14:6bcd2f6a4fee 190
tulanthoar 14:6bcd2f6a4fee 191 /** Using the Sparkfun SEN-10250 BoB
tulanthoar 14:6bcd2f6a4fee 192 *
tulanthoar 14:6bcd2f6a4fee 193 * Example:
tulanthoar 14:6bcd2f6a4fee 194 * @code
tulanthoar 14:6bcd2f6a4fee 195 * #include "mbed.h"
tulanthoar 14:6bcd2f6a4fee 196 * #include "MPR121.h"
tulanthoar 14:6bcd2f6a4fee 197 *
tulanthoar 14:6bcd2f6a4fee 198 * Serial pc(USBTX, USBRX);
tulanthoar 14:6bcd2f6a4fee 199 * DigitalOut myled(LED1);
tulanthoar 14:6bcd2f6a4fee 200 *
tulanthoar 14:6bcd2f6a4fee 201 * #if defined TARGET_LPC1768 || TARGET_LPC11U24
tulanthoar 14:6bcd2f6a4fee 202 * I2C i2c(p28, p27);
tulanthoar 14:6bcd2f6a4fee 203 * InterruptIn irq(p26);
tulanthoar 14:6bcd2f6a4fee 204 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
tulanthoar 14:6bcd2f6a4fee 205 *
tulanthoar 14:6bcd2f6a4fee 206 * #elif defined TARGET_KL25Z
tulanthoar 14:6bcd2f6a4fee 207 * I2C i2c(PTC9, PTC8);
tulanthoar 14:6bcd2f6a4fee 208 * InterruptIn irq(PTA5);
tulanthoar 14:6bcd2f6a4fee 209 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
tulanthoar 14:6bcd2f6a4fee 210 *
tulanthoar 14:6bcd2f6a4fee 211 * #else
tulanthoar 14:6bcd2f6a4fee 212 * #error TARGET NOT TESTED
tulanthoar 14:6bcd2f6a4fee 213 * #endif
tulanthoar 14:6bcd2f6a4fee 214 *
tulanthoar 14:6bcd2f6a4fee 215 * int main()
tulanthoar 14:6bcd2f6a4fee 216 * {
tulanthoar 14:6bcd2f6a4fee 217 * touch_pad.init();
tulanthoar 14:6bcd2f6a4fee 218 * touch_pad.enable();
tulanthoar 14:6bcd2f6a4fee 219 *
tulanthoar 14:6bcd2f6a4fee 220 * while(1)
tulanthoar 14:6bcd2f6a4fee 221 * {
tulanthoar 14:6bcd2f6a4fee 222 * if(touch_pad.isPressed())
tulanthoar 14:6bcd2f6a4fee 223 * {
tulanthoar 14:6bcd2f6a4fee 224 * uint16_t button_val = touch_pad.buttonPressed();
tulanthoar 14:6bcd2f6a4fee 225 * printf("button = 0x%04x\n", button_val);
tulanthoar 14:6bcd2f6a4fee 226 * myled = (button_val>0) ? 1 : 0;
tulanthoar 14:6bcd2f6a4fee 227 * }
tulanthoar 14:6bcd2f6a4fee 228 * }
tulanthoar 14:6bcd2f6a4fee 229 * }
tulanthoar 14:6bcd2f6a4fee 230 * @endcode
tulanthoar 14:6bcd2f6a4fee 231 */
tulanthoar 14:6bcd2f6a4fee 232
tulanthoar 14:6bcd2f6a4fee 233 /**
tulanthoar 14:6bcd2f6a4fee 234 * @class MPR121
tulanthoar 14:6bcd2f6a4fee 235 * @brief API for the MPR121 capacitive touch IC
tulanthoar 14:6bcd2f6a4fee 236 */
tulanthoar 14:6bcd2f6a4fee 237 class MPR121
tulanthoar 14:6bcd2f6a4fee 238 {
tulanthoar 14:6bcd2f6a4fee 239 private:
tulanthoar 14:6bcd2f6a4fee 240
tulanthoar 14:6bcd2f6a4fee 241 I2C *_i2c;
tulanthoar 14:6bcd2f6a4fee 242 InterruptIn *_irq;
tulanthoar 14:6bcd2f6a4fee 243 uint8_t _i2c_addr;
tulanthoar 14:6bcd2f6a4fee 244 volatile uint16_t _button;
tulanthoar 14:6bcd2f6a4fee 245 volatile uint32_t _button_has_changed;
tulanthoar 14:6bcd2f6a4fee 246
tulanthoar 14:6bcd2f6a4fee 247 /** The interrupt handler for the IRQ pin
tulanthoar 14:6bcd2f6a4fee 248 */
tulanthoar 14:6bcd2f6a4fee 249 void handler(void);
tulanthoar 14:6bcd2f6a4fee 250
tulanthoar 14:6bcd2f6a4fee 251 public:
tulanthoar 14:6bcd2f6a4fee 252
tulanthoar 14:6bcd2f6a4fee 253 /**
tulanthoar 14:6bcd2f6a4fee 254 * @enum MPR121_ADDR
tulanthoar 14:6bcd2f6a4fee 255 * @brief Possible terminations for the ADDR pin
tulanthoar 14:6bcd2f6a4fee 256 */
tulanthoar 14:6bcd2f6a4fee 257 enum MPR121_ADDR
tulanthoar 14:6bcd2f6a4fee 258 {
tulanthoar 14:6bcd2f6a4fee 259 ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */
tulanthoar 14:6bcd2f6a4fee 260 ADDR_VDD, /*!< ADDR connected to VDD */
tulanthoar 14:6bcd2f6a4fee 261 ADDR_SCL, /*!< ADDR connected to SDA */
tulanthoar 14:6bcd2f6a4fee 262 ADDR_SDA /*!< ADDR connected to SCL */
tulanthoar 14:6bcd2f6a4fee 263 };
tulanthoar 14:6bcd2f6a4fee 264
tulanthoar 14:6bcd2f6a4fee 265 /**
tulanthoar 14:6bcd2f6a4fee 266 * @enum MPR121_REGISTER
tulanthoar 14:6bcd2f6a4fee 267 * @brief The device register map
tulanthoar 14:6bcd2f6a4fee 268 */
tulanthoar 14:6bcd2f6a4fee 269 enum MPR121_REGISTER
tulanthoar 14:6bcd2f6a4fee 270 {
tulanthoar 14:6bcd2f6a4fee 271 ELE0_7_STAT = 0x00,
tulanthoar 14:6bcd2f6a4fee 272 ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB,
tulanthoar 14:6bcd2f6a4fee 273 EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB,
tulanthoar 14:6bcd2f6a4fee 274
tulanthoar 14:6bcd2f6a4fee 275 EFD6LB = 0x10,
tulanthoar 14:6bcd2f6a4fee 276 EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB,
tulanthoar 14:6bcd2f6a4fee 277 EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV,
tulanthoar 14:6bcd2f6a4fee 278
tulanthoar 14:6bcd2f6a4fee 279 E2BV = 0x20,
tulanthoar 14:6bcd2f6a4fee 280 E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV,
tulanthoar 14:6bcd2f6a4fee 281 MHDR, NHDR, NCLR, FDLR, MHDF,
tulanthoar 14:6bcd2f6a4fee 282
tulanthoar 14:6bcd2f6a4fee 283 NHDF = 0x30,
tulanthoar 14:6bcd2f6a4fee 284 NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR,
tulanthoar 14:6bcd2f6a4fee 285 FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT,
tulanthoar 14:6bcd2f6a4fee 286
tulanthoar 14:6bcd2f6a4fee 287 FDLPROXT = 0x40,
tulanthoar 14:6bcd2f6a4fee 288 E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH,
tulanthoar 14:6bcd2f6a4fee 289 E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH,
tulanthoar 14:6bcd2f6a4fee 290
tulanthoar 14:6bcd2f6a4fee 291 E7RTH = 0x50,
tulanthoar 14:6bcd2f6a4fee 292 E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH,
tulanthoar 14:6bcd2f6a4fee 293 EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0,
tulanthoar 14:6bcd2f6a4fee 294
tulanthoar 14:6bcd2f6a4fee 295 CDC1 = 0x60,
tulanthoar 14:6bcd2f6a4fee 296 CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1,
tulanthoar 14:6bcd2f6a4fee 297 CDT2_CDT3, CDT4_CDT5, CDT6_CDT7,
tulanthoar 14:6bcd2f6a4fee 298
tulanthoar 14:6bcd2f6a4fee 299 CDT8_CDT9 = 0x70,
tulanthoar 14:6bcd2f6a4fee 300 CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET,
tulanthoar 14:6bcd2f6a4fee 301 GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL,
tulanthoar 14:6bcd2f6a4fee 302
tulanthoar 14:6bcd2f6a4fee 303 SRST = 0x80
tulanthoar 14:6bcd2f6a4fee 304 };
tulanthoar 14:6bcd2f6a4fee 305
tulanthoar 14:6bcd2f6a4fee 306 /** Create the MPR121 object
tulanthoar 14:6bcd2f6a4fee 307 * @param i2c - A defined I2C object
tulanthoar 14:6bcd2f6a4fee 308 * @param pin - A defined InterruptIn object
tulanthoar 14:6bcd2f6a4fee 309 * @param i2c_addr - Connection of the address line
tulanthoar 14:6bcd2f6a4fee 310 */
tulanthoar 14:6bcd2f6a4fee 311 MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 312
tulanthoar 14:6bcd2f6a4fee 313 /** Create the MPR121 object
tulanthoar 14:6bcd2f6a4fee 314 * @param i2c - A defined I2C object
tulanthoar 14:6bcd2f6a4fee 315 * @param i2c_addr - Connection of the address line
tulanthoar 14:6bcd2f6a4fee 316 */
tulanthoar 14:6bcd2f6a4fee 317 MPR121(I2C &i2c, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 318
tulanthoar 17:2d6b050ad8b8 319 >>>>>>> other
sam_grove 3:828260f21de6 320 /** Clear state variables and initilize the dependant objects
sam_grove 0:42add775212a 321 */
sam_grove 0:42add775212a 322 void init(void);
tulanthoar 17:2d6b050ad8b8 323 <<<<<<< local
sam_grove 0:42add775212a 324
tulanthoar 17:2d6b050ad8b8 325 =======
tulanthoar 14:6bcd2f6a4fee 326
tulanthoar 17:2d6b050ad8b8 327 >>>>>>> other
sam_grove 0:42add775212a 328 /** Allow the IC to run and collect user input
sam_grove 0:42add775212a 329 */
sam_grove 0:42add775212a 330 void enable(void);
tulanthoar 17:2d6b050ad8b8 331 <<<<<<< local
sam_grove 0:42add775212a 332
tulanthoar 17:2d6b050ad8b8 333 =======
tulanthoar 14:6bcd2f6a4fee 334
tulanthoar 17:2d6b050ad8b8 335 >>>>>>> other
sam_grove 0:42add775212a 336 /** Stop the IC and put into low power mode
sam_grove 0:42add775212a 337 */
sam_grove 0:42add775212a 338 void disable(void);
tulanthoar 17:2d6b050ad8b8 339 <<<<<<< local
sam_grove 0:42add775212a 340
tulanthoar 17:2d6b050ad8b8 341 =======
tulanthoar 14:6bcd2f6a4fee 342
tulanthoar 17:2d6b050ad8b8 343 >>>>>>> other
sam_grove 0:42add775212a 344 /** Determine if a new button press event occured
sam_grove 0:42add775212a 345 * Upon calling the state is cleared until another press is detected
sam_grove 0:42add775212a 346 * @return 1 if a press has been detected since the last call, 0 otherwise
sam_grove 0:42add775212a 347 */
sam_grove 0:42add775212a 348 uint32_t isPressed(void);
tulanthoar 17:2d6b050ad8b8 349 <<<<<<< local
sam_grove 0:42add775212a 350
tulanthoar 17:2d6b050ad8b8 351 =======
tulanthoar 14:6bcd2f6a4fee 352
tulanthoar 17:2d6b050ad8b8 353 >>>>>>> other
sam_grove 0:42add775212a 354 /** Get the electrode status (ELE12 ... ELE0 -> b15 xxx b11 ... b0
sam_grove 0:42add775212a 355 * The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined
sam_grove 0:42add775212a 356 * @return The state of all buttons
sam_grove 0:42add775212a 357 */
sam_grove 0:42add775212a 358 uint16_t buttonPressed(void);
tulanthoar 17:2d6b050ad8b8 359 <<<<<<< local
sam_grove 0:42add775212a 360
tulanthoar 17:2d6b050ad8b8 361 =======
tulanthoar 14:6bcd2f6a4fee 362
tulanthoar 17:2d6b050ad8b8 363 >>>>>>> other
sam_grove 0:42add775212a 364 /** print the register map and values to the console
sam_grove 3:828260f21de6 365 * @param obj - a Serial object that prints to a console
sam_grove 0:42add775212a 366 */
sam_grove 3:828260f21de6 367 void registerDump(Serial &obj) const;
tulanthoar 17:2d6b050ad8b8 368 <<<<<<< local
sam_grove 0:42add775212a 369
tulanthoar 17:2d6b050ad8b8 370 =======
tulanthoar 14:6bcd2f6a4fee 371
tulanthoar 17:2d6b050ad8b8 372 >>>>>>> other
sam_grove 5:3934358ec2b7 373 /** print the register map and values to the console
sam_grove 5:3934358ec2b7 374 */
sam_grove 5:3934358ec2b7 375 void registerDump(void) const;
tulanthoar 17:2d6b050ad8b8 376 <<<<<<< local
sam_grove 5:3934358ec2b7 377
tulanthoar 17:2d6b050ad8b8 378 =======
tulanthoar 14:6bcd2f6a4fee 379
tulanthoar 17:2d6b050ad8b8 380 >>>>>>> other
sam_grove 0:42add775212a 381 /** Write to a register (exposed for debugging reasons)
sam_grove 0:42add775212a 382 * Note: most writes are only valid in stop mode
sam_grove 1:cee45334b36a 383 * @param reg - The register to be written
sam_grove 1:cee45334b36a 384 * @param data - The data to be written
sam_grove 0:42add775212a 385 */
sam_grove 3:828260f21de6 386 void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const;
tulanthoar 17:2d6b050ad8b8 387 <<<<<<< local
sam_grove 0:42add775212a 388
tulanthoar 17:2d6b050ad8b8 389 =======
tulanthoar 14:6bcd2f6a4fee 390
tulanthoar 17:2d6b050ad8b8 391 >>>>>>> other
sam_grove 0:42add775212a 392 /** Read from a register (exposed for debugging reasons)
sam_grove 1:cee45334b36a 393 * @param reg - The register to read from
sam_grove 0:42add775212a 394 * @return The register contents
sam_grove 0:42add775212a 395 */
sam_grove 3:828260f21de6 396 uint8_t readRegister(MPR121_REGISTER const reg) const;
tulanthoar 17:2d6b050ad8b8 397 <<<<<<< local
sam_grove 0:42add775212a 398
tulanthoar 17:2d6b050ad8b8 399 =======
tulanthoar 14:6bcd2f6a4fee 400
tulanthoar 17:2d6b050ad8b8 401 >>>>>>> other
sam_grove 0:42add775212a 402 };
sam_grove 0:42add775212a 403
sam_grove 0:42add775212a 404 #endif
tulanthoar 17:2d6b050ad8b8 405 <<<<<<< local
Nathan Yonkee 11:ad26c0810f02 406 =======
tulanthoar 18:8c7054b112f0 407 >>>>>>> other
tulanthoar 18:8c7054b112f0 408 /**
tulanthoar 18:8c7054b112f0 409 * @file MPR121.h
tulanthoar 18:8c7054b112f0 410 * @brief Device driver - MPR121 capactiive touch IC
tulanthoar 18:8c7054b112f0 411 * @author sam grove
tulanthoar 18:8c7054b112f0 412 * @version 1.0
tulanthoar 18:8c7054b112f0 413 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf
tulanthoar 18:8c7054b112f0 414 *
tulanthoar 18:8c7054b112f0 415 * Copyright (c) 2013
tulanthoar 18:8c7054b112f0 416 *
tulanthoar 18:8c7054b112f0 417 * Licensed under the Apache License, Version 2.0 (the "License");
tulanthoar 18:8c7054b112f0 418 * you may not use this file except in compliance with the License.
tulanthoar 18:8c7054b112f0 419 * You may obtain a copy of the License at
tulanthoar 18:8c7054b112f0 420 *
tulanthoar 18:8c7054b112f0 421 * http://www.apache.org/licenses/LICENSE-2.0
tulanthoar 18:8c7054b112f0 422 *
tulanthoar 18:8c7054b112f0 423 * Unless required by applicable law or agreed to in writing, software
tulanthoar 18:8c7054b112f0 424 * distributed under the License is distributed on an "AS IS" BASIS,
tulanthoar 18:8c7054b112f0 425 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tulanthoar 18:8c7054b112f0 426 * See the License for the specific language governing permissions and
tulanthoar 18:8c7054b112f0 427 * limitations under the License.
tulanthoar 18:8c7054b112f0 428 */
tulanthoar 18:8c7054b112f0 429
tulanthoar 18:8c7054b112f0 430 #ifndef MPR121_H
tulanthoar 18:8c7054b112f0 431 #define MPR121_H
tulanthoar 18:8c7054b112f0 432
tulanthoar 18:8c7054b112f0 433 #include "mbed.h"
tulanthoar 18:8c7054b112f0 434 #include "rtos.h"
tulanthoar 18:8c7054b112f0 435
tulanthoar 18:8c7054b112f0 436 /** Using the Sparkfun SEN-10250 BoB
tulanthoar 18:8c7054b112f0 437 *
tulanthoar 18:8c7054b112f0 438 * Example:
tulanthoar 18:8c7054b112f0 439 * @code
tulanthoar 18:8c7054b112f0 440 * #include "mbed.h"
tulanthoar 18:8c7054b112f0 441 * #include "MPR121.h"
tulanthoar 18:8c7054b112f0 442 *
tulanthoar 18:8c7054b112f0 443 * Serial pc(USBTX, USBRX);
tulanthoar 18:8c7054b112f0 444 * DigitalOut myled(LED1);
tulanthoar 18:8c7054b112f0 445 *
tulanthoar 18:8c7054b112f0 446 * #if defined TARGET_LPC1768 || TARGET_LPC11U24
tulanthoar 18:8c7054b112f0 447 * I2C i2c(p28, p27);
tulanthoar 18:8c7054b112f0 448 * InterruptIn irq(p26);
tulanthoar 18:8c7054b112f0 449 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
tulanthoar 18:8c7054b112f0 450 *
tulanthoar 18:8c7054b112f0 451 * #elif defined TARGET_KL25Z
tulanthoar 18:8c7054b112f0 452 * I2C i2c(PTC9, PTC8);
tulanthoar 18:8c7054b112f0 453 * InterruptIn irq(PTA5);
tulanthoar 18:8c7054b112f0 454 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
tulanthoar 18:8c7054b112f0 455 *
tulanthoar 18:8c7054b112f0 456 * #else
tulanthoar 18:8c7054b112f0 457 * #error TARGET NOT TESTED
tulanthoar 18:8c7054b112f0 458 * #endif
tulanthoar 18:8c7054b112f0 459 *
tulanthoar 18:8c7054b112f0 460 * int main()
tulanthoar 18:8c7054b112f0 461 * {
tulanthoar 18:8c7054b112f0 462 * touch_pad.init();
tulanthoar 18:8c7054b112f0 463 * touch_pad.enable();
tulanthoar 18:8c7054b112f0 464 *
tulanthoar 18:8c7054b112f0 465 * while(1)
tulanthoar 18:8c7054b112f0 466 * {
tulanthoar 18:8c7054b112f0 467 * if(touch_pad.isPressed())
tulanthoar 18:8c7054b112f0 468 * {
tulanthoar 18:8c7054b112f0 469 * uint16_t button_val = touch_pad.buttonPressed();
tulanthoar 18:8c7054b112f0 470 * printf("button = 0x%04x\n", button_val);
tulanthoar 18:8c7054b112f0 471 * myled = (button_val>0) ? 1 : 0;
tulanthoar 18:8c7054b112f0 472 * }
tulanthoar 18:8c7054b112f0 473 * }
tulanthoar 18:8c7054b112f0 474 * }
tulanthoar 18:8c7054b112f0 475 * @endcode
tulanthoar 18:8c7054b112f0 476 */
tulanthoar 18:8c7054b112f0 477
tulanthoar 18:8c7054b112f0 478 /**
tulanthoar 18:8c7054b112f0 479 * @class MPR121
tulanthoar 18:8c7054b112f0 480 * @brief API for the MPR121 capacitive touch IC
tulanthoar 18:8c7054b112f0 481 */
tulanthoar 18:8c7054b112f0 482 class MPR121
tulanthoar 18:8c7054b112f0 483 {
tulanthoar 18:8c7054b112f0 484 private:
tulanthoar 18:8c7054b112f0 485
tulanthoar 18:8c7054b112f0 486 I2C *_i2c;
tulanthoar 18:8c7054b112f0 487 InterruptIn *_irq;
tulanthoar 18:8c7054b112f0 488 uint8_t _i2c_addr;
tulanthoar 18:8c7054b112f0 489 volatile uint16_t _button;
tulanthoar 18:8c7054b112f0 490 volatile uint32_t _button_has_changed;
tulanthoar 18:8c7054b112f0 491
tulanthoar 18:8c7054b112f0 492 /** The interrupt handler for the IRQ pin
tulanthoar 18:8c7054b112f0 493 */
tulanthoar 18:8c7054b112f0 494 void handler(void);
tulanthoar 18:8c7054b112f0 495
tulanthoar 18:8c7054b112f0 496 public:
tulanthoar 18:8c7054b112f0 497
tulanthoar 18:8c7054b112f0 498 /**
tulanthoar 18:8c7054b112f0 499 * @enum MPR121_ADDR
tulanthoar 18:8c7054b112f0 500 * @brief Possible terminations for the ADDR pin
tulanthoar 18:8c7054b112f0 501 */
tulanthoar 18:8c7054b112f0 502 enum MPR121_ADDR
tulanthoar 18:8c7054b112f0 503 {
tulanthoar 18:8c7054b112f0 504 ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */
tulanthoar 18:8c7054b112f0 505 ADDR_VDD, /*!< ADDR connected to VDD */
tulanthoar 18:8c7054b112f0 506 ADDR_SCL, /*!< ADDR connected to SDA */
tulanthoar 18:8c7054b112f0 507 ADDR_SDA /*!< ADDR connected to SCL */
tulanthoar 18:8c7054b112f0 508 };
tulanthoar 18:8c7054b112f0 509
tulanthoar 18:8c7054b112f0 510 /**
tulanthoar 18:8c7054b112f0 511 * @enum MPR121_REGISTER
tulanthoar 18:8c7054b112f0 512 * @brief The device register map
tulanthoar 18:8c7054b112f0 513 */
tulanthoar 18:8c7054b112f0 514 enum MPR121_REGISTER
tulanthoar 18:8c7054b112f0 515 {
tulanthoar 18:8c7054b112f0 516 ELE0_7_STAT = 0x00,
tulanthoar 18:8c7054b112f0 517 ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB,
tulanthoar 18:8c7054b112f0 518 EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB,
tulanthoar 18:8c7054b112f0 519
tulanthoar 18:8c7054b112f0 520 EFD6LB = 0x10,
tulanthoar 18:8c7054b112f0 521 EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB,
tulanthoar 18:8c7054b112f0 522 EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV,
tulanthoar 18:8c7054b112f0 523
tulanthoar 18:8c7054b112f0 524 E2BV = 0x20,
tulanthoar 18:8c7054b112f0 525 E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV,
tulanthoar 18:8c7054b112f0 526 MHDR, NHDR, NCLR, FDLR, MHDF,
tulanthoar 18:8c7054b112f0 527
tulanthoar 18:8c7054b112f0 528 NHDF = 0x30,
tulanthoar 18:8c7054b112f0 529 NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR,
tulanthoar 18:8c7054b112f0 530 FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT,
tulanthoar 18:8c7054b112f0 531
tulanthoar 18:8c7054b112f0 532 FDLPROXT = 0x40,
tulanthoar 18:8c7054b112f0 533 E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH,
tulanthoar 18:8c7054b112f0 534 E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH,
tulanthoar 18:8c7054b112f0 535
tulanthoar 18:8c7054b112f0 536 E7RTH = 0x50,
tulanthoar 18:8c7054b112f0 537 E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH,
tulanthoar 18:8c7054b112f0 538 EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0,
tulanthoar 18:8c7054b112f0 539
tulanthoar 18:8c7054b112f0 540 CDC1 = 0x60,
tulanthoar 18:8c7054b112f0 541 CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1,
tulanthoar 18:8c7054b112f0 542 CDT2_CDT3, CDT4_CDT5, CDT6_CDT7,
tulanthoar 18:8c7054b112f0 543
tulanthoar 18:8c7054b112f0 544 CDT8_CDT9 = 0x70,
tulanthoar 18:8c7054b112f0 545 CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET,
tulanthoar 18:8c7054b112f0 546 GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL,
tulanthoar 18:8c7054b112f0 547
tulanthoar 18:8c7054b112f0 548 SRST = 0x80
tulanthoar 18:8c7054b112f0 549 };
tulanthoar 18:8c7054b112f0 550
tulanthoar 18:8c7054b112f0 551 /** Create the MPR121 object
tulanthoar 18:8c7054b112f0 552 * @param i2c - A defined I2C object
tulanthoar 18:8c7054b112f0 553 * @param pin - A defined InterruptIn object
tulanthoar 18:8c7054b112f0 554 * @param i2c_addr - Connection of the address line
tulanthoar 18:8c7054b112f0 555 */
tulanthoar 18:8c7054b112f0 556 MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
tulanthoar 18:8c7054b112f0 557
tulanthoar 18:8c7054b112f0 558 /** Create the MPR121 object
tulanthoar 18:8c7054b112f0 559 * @param i2c - A defined I2C object
tulanthoar 18:8c7054b112f0 560 * @param i2c_addr - Connection of the address line
tulanthoar 18:8c7054b112f0 561 */
tulanthoar 18:8c7054b112f0 562 MPR121(I2C &i2c, MPR121_ADDR i2c_addr);
tulanthoar 18:8c7054b112f0 563
tulanthoar 18:8c7054b112f0 564 /** Clear state variables and initilize the dependant objects
tulanthoar 18:8c7054b112f0 565 */
tulanthoar 18:8c7054b112f0 566 void init(void);
tulanthoar 18:8c7054b112f0 567
tulanthoar 18:8c7054b112f0 568 /** Allow the IC to run and collect user input
tulanthoar 18:8c7054b112f0 569 */
tulanthoar 18:8c7054b112f0 570 void enable(void);
tulanthoar 18:8c7054b112f0 571
tulanthoar 18:8c7054b112f0 572 /** Stop the IC and put into low power mode
tulanthoar 18:8c7054b112f0 573 */
tulanthoar 18:8c7054b112f0 574 void disable(void);
tulanthoar 18:8c7054b112f0 575
tulanthoar 18:8c7054b112f0 576 /** Determine if a new button press event occured
tulanthoar 18:8c7054b112f0 577 * Upon calling the state is cleared until another press is detected
tulanthoar 18:8c7054b112f0 578 * @return 1 if a press has been detected since the last call, 0 otherwise
tulanthoar 18:8c7054b112f0 579 */
tulanthoar 18:8c7054b112f0 580 uint32_t isPressed(void);
tulanthoar 18:8c7054b112f0 581
tulanthoar 18:8c7054b112f0 582 /** Get the electrode status (ELE12 ... ELE0 -> b15 xxx b11 ... b0
tulanthoar 18:8c7054b112f0 583 * The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined
tulanthoar 18:8c7054b112f0 584 * @return The state of all buttons
tulanthoar 18:8c7054b112f0 585 */
tulanthoar 18:8c7054b112f0 586 uint16_t buttonPressed(void);
tulanthoar 18:8c7054b112f0 587
tulanthoar 18:8c7054b112f0 588 /** print the register map and values to the console
tulanthoar 18:8c7054b112f0 589 * @param obj - a Serial object that prints to a console
tulanthoar 18:8c7054b112f0 590 */
tulanthoar 18:8c7054b112f0 591 void registerDump(Serial &obj) const;
tulanthoar 18:8c7054b112f0 592
tulanthoar 18:8c7054b112f0 593 /** print the register map and values to the console
tulanthoar 18:8c7054b112f0 594 */
tulanthoar 18:8c7054b112f0 595 void registerDump(void) const;
tulanthoar 18:8c7054b112f0 596
tulanthoar 18:8c7054b112f0 597 /** Write to a register (exposed for debugging reasons)
tulanthoar 18:8c7054b112f0 598 * Note: most writes are only valid in stop mode
tulanthoar 18:8c7054b112f0 599 * @param reg - The register to be written
tulanthoar 18:8c7054b112f0 600 * @param data - The data to be written
tulanthoar 18:8c7054b112f0 601 */
tulanthoar 18:8c7054b112f0 602 void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const;
tulanthoar 18:8c7054b112f0 603
tulanthoar 18:8c7054b112f0 604 /** Read from a register (exposed for debugging reasons)
tulanthoar 18:8c7054b112f0 605 * @param reg - The register to read from
tulanthoar 18:8c7054b112f0 606 * @return The register contents
tulanthoar 18:8c7054b112f0 607 */
tulanthoar 18:8c7054b112f0 608 uint8_t readRegister(MPR121_REGISTER const reg) const;
tulanthoar 18:8c7054b112f0 609
tulanthoar 18:8c7054b112f0 610 };
tulanthoar 18:8c7054b112f0 611
tulanthoar 18:8c7054b112f0 612 #endif
Nathan Yonkee 11:ad26c0810f02 613 >>>>>>> merge rev
tulanthoar 18:8c7054b112f0 614 <<<<<<< local
tulanthoar 18:8c7054b112f0 615 =======
tulanthoar 14:6bcd2f6a4fee 616 <<<<<<< local
sam_grove 0:42add775212a 617 /**
sam_grove 0:42add775212a 618 * @file MPR121.h
sam_grove 0:42add775212a 619 * @brief Device driver - MPR121 capactiive touch IC
sam_grove 0:42add775212a 620 * @author sam grove
sam_grove 0:42add775212a 621 * @version 1.0
sam_grove 0:42add775212a 622 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf
sam_grove 0:42add775212a 623 *
sam_grove 0:42add775212a 624 * Copyright (c) 2013
sam_grove 0:42add775212a 625 *
sam_grove 0:42add775212a 626 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:42add775212a 627 * you may not use this file except in compliance with the License.
sam_grove 0:42add775212a 628 * You may obtain a copy of the License at
sam_grove 0:42add775212a 629 *
sam_grove 0:42add775212a 630 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:42add775212a 631 *
sam_grove 0:42add775212a 632 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:42add775212a 633 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:42add775212a 634 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:42add775212a 635 * See the License for the specific language governing permissions and
sam_grove 0:42add775212a 636 * limitations under the License.
sam_grove 0:42add775212a 637 */
sam_grove 0:42add775212a 638
sam_grove 0:42add775212a 639 #ifndef MPR121_H
sam_grove 0:42add775212a 640 #define MPR121_H
sam_grove 0:42add775212a 641
sam_grove 0:42add775212a 642 #include "mbed.h"
tulanthoar 13:185ada085785 643 //#include "rtos.h"
sam_grove 0:42add775212a 644
sam_grove 3:828260f21de6 645 /** Using the Sparkfun SEN-10250 BoB
sam_grove 0:42add775212a 646 *
sam_grove 0:42add775212a 647 * Example:
sam_grove 0:42add775212a 648 * @code
sam_grove 3:828260f21de6 649 * #include "mbed.h"
sam_grove 3:828260f21de6 650 * #include "MPR121.h"
sam_grove 3:828260f21de6 651 *
sam_grove 3:828260f21de6 652 * Serial pc(USBTX, USBRX);
sam_grove 3:828260f21de6 653 * DigitalOut myled(LED1);
sam_grove 3:828260f21de6 654 *
sam_grove 3:828260f21de6 655 * #if defined TARGET_LPC1768 || TARGET_LPC11U24
sam_grove 3:828260f21de6 656 * I2C i2c(p28, p27);
sam_grove 3:828260f21de6 657 * InterruptIn irq(p26);
sam_grove 3:828260f21de6 658 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
sam_grove 3:828260f21de6 659 *
sam_grove 3:828260f21de6 660 * #elif defined TARGET_KL25Z
sam_grove 3:828260f21de6 661 * I2C i2c(PTC9, PTC8);
sam_grove 3:828260f21de6 662 * InterruptIn irq(PTA5);
sam_grove 3:828260f21de6 663 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
sam_grove 3:828260f21de6 664 *
sam_grove 3:828260f21de6 665 * #else
sam_grove 3:828260f21de6 666 * #error TARGET NOT TESTED
sam_grove 3:828260f21de6 667 * #endif
sam_grove 3:828260f21de6 668 *
sam_grove 3:828260f21de6 669 * int main()
sam_grove 3:828260f21de6 670 * {
sam_grove 3:828260f21de6 671 * touch_pad.init();
sam_grove 3:828260f21de6 672 * touch_pad.enable();
sam_grove 3:828260f21de6 673 *
sam_grove 3:828260f21de6 674 * while(1)
sam_grove 3:828260f21de6 675 * {
sam_grove 3:828260f21de6 676 * if(touch_pad.isPressed())
sam_grove 3:828260f21de6 677 * {
sam_grove 3:828260f21de6 678 * uint16_t button_val = touch_pad.buttonPressed();
sam_grove 3:828260f21de6 679 * printf("button = 0x%04x\n", button_val);
sam_grove 3:828260f21de6 680 * myled = (button_val>0) ? 1 : 0;
sam_grove 3:828260f21de6 681 * }
sam_grove 3:828260f21de6 682 * }
sam_grove 3:828260f21de6 683 * }
sam_grove 0:42add775212a 684 * @endcode
sam_grove 0:42add775212a 685 */
sam_grove 0:42add775212a 686
sam_grove 0:42add775212a 687 /**
sam_grove 0:42add775212a 688 * @class MPR121
sam_grove 3:828260f21de6 689 * @brief API for the MPR121 capacitive touch IC
sam_grove 0:42add775212a 690 */
sam_grove 0:42add775212a 691 class MPR121
sam_grove 0:42add775212a 692 {
sam_grove 0:42add775212a 693 private:
sam_grove 0:42add775212a 694
sam_grove 0:42add775212a 695 I2C *_i2c;
sam_grove 0:42add775212a 696 InterruptIn *_irq;
sam_grove 0:42add775212a 697 uint8_t _i2c_addr;
sam_grove 0:42add775212a 698 volatile uint16_t _button;
sam_grove 0:42add775212a 699 volatile uint32_t _button_has_changed;
sam_grove 0:42add775212a 700
sam_grove 0:42add775212a 701 /** The interrupt handler for the IRQ pin
sam_grove 0:42add775212a 702 */
sam_grove 0:42add775212a 703 void handler(void);
sam_grove 0:42add775212a 704
sam_grove 0:42add775212a 705 public:
sam_grove 0:42add775212a 706
sam_grove 0:42add775212a 707 /**
sam_grove 0:42add775212a 708 * @enum MPR121_ADDR
sam_grove 0:42add775212a 709 * @brief Possible terminations for the ADDR pin
sam_grove 0:42add775212a 710 */
sam_grove 0:42add775212a 711 enum MPR121_ADDR
sam_grove 0:42add775212a 712 {
sam_grove 0:42add775212a 713 ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */
sam_grove 0:42add775212a 714 ADDR_VDD, /*!< ADDR connected to VDD */
sam_grove 0:42add775212a 715 ADDR_SCL, /*!< ADDR connected to SDA */
sam_grove 0:42add775212a 716 ADDR_SDA /*!< ADDR connected to SCL */
sam_grove 0:42add775212a 717 };
sam_grove 0:42add775212a 718
sam_grove 0:42add775212a 719 /**
sam_grove 0:42add775212a 720 * @enum MPR121_REGISTER
sam_grove 0:42add775212a 721 * @brief The device register map
sam_grove 0:42add775212a 722 */
sam_grove 0:42add775212a 723 enum MPR121_REGISTER
sam_grove 0:42add775212a 724 {
sam_grove 0:42add775212a 725 ELE0_7_STAT = 0x00,
sam_grove 0:42add775212a 726 ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB,
sam_grove 0:42add775212a 727 EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB,
sam_grove 0:42add775212a 728
sam_grove 0:42add775212a 729 EFD6LB = 0x10,
sam_grove 0:42add775212a 730 EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB,
sam_grove 0:42add775212a 731 EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV,
sam_grove 0:42add775212a 732
sam_grove 0:42add775212a 733 E2BV = 0x20,
sam_grove 0:42add775212a 734 E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV,
sam_grove 0:42add775212a 735 MHDR, NHDR, NCLR, FDLR, MHDF,
sam_grove 0:42add775212a 736
sam_grove 0:42add775212a 737 NHDF = 0x30,
sam_grove 0:42add775212a 738 NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR,
sam_grove 0:42add775212a 739 FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT,
sam_grove 0:42add775212a 740
sam_grove 0:42add775212a 741 FDLPROXT = 0x40,
sam_grove 0:42add775212a 742 E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH,
sam_grove 0:42add775212a 743 E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH,
sam_grove 0:42add775212a 744
sam_grove 0:42add775212a 745 E7RTH = 0x50,
sam_grove 0:42add775212a 746 E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH,
sam_grove 0:42add775212a 747 EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0,
sam_grove 0:42add775212a 748
sam_grove 0:42add775212a 749 CDC1 = 0x60,
sam_grove 0:42add775212a 750 CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1,
sam_grove 0:42add775212a 751 CDT2_CDT3, CDT4_CDT5, CDT6_CDT7,
sam_grove 0:42add775212a 752
sam_grove 0:42add775212a 753 CDT8_CDT9 = 0x70,
sam_grove 0:42add775212a 754 CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET,
sam_grove 0:42add775212a 755 GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL,
sam_grove 0:42add775212a 756
sam_grove 0:42add775212a 757 SRST = 0x80
sam_grove 0:42add775212a 758 };
sam_grove 0:42add775212a 759
sam_grove 0:42add775212a 760 /** Create the MPR121 object
sam_grove 1:cee45334b36a 761 * @param i2c - A defined I2C object
sam_grove 1:cee45334b36a 762 * @param pin - A defined InterruptIn object
sam_grove 1:cee45334b36a 763 * @param i2c_addr - Connection of the address line
sam_grove 0:42add775212a 764 */
sam_grove 0:42add775212a 765 MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
sam_grove 0:42add775212a 766
sam_grove 5:3934358ec2b7 767 /** Create the MPR121 object
sam_grove 5:3934358ec2b7 768 * @param i2c - A defined I2C object
sam_grove 5:3934358ec2b7 769 * @param i2c_addr - Connection of the address line
sam_grove 5:3934358ec2b7 770 */
sam_grove 5:3934358ec2b7 771 MPR121(I2C &i2c, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 772 /**
tulanthoar 14:6bcd2f6a4fee 773 * @file MPR121.h
tulanthoar 14:6bcd2f6a4fee 774 * @brief Device driver - MPR121 capactiive touch IC
tulanthoar 14:6bcd2f6a4fee 775 * @author sam grove
tulanthoar 14:6bcd2f6a4fee 776 * @version 1.0
tulanthoar 14:6bcd2f6a4fee 777 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf
tulanthoar 14:6bcd2f6a4fee 778 *
tulanthoar 14:6bcd2f6a4fee 779 * Copyright (c) 2013
tulanthoar 14:6bcd2f6a4fee 780 *
tulanthoar 14:6bcd2f6a4fee 781 * Licensed under the Apache License, Version 2.0 (the "License");
tulanthoar 14:6bcd2f6a4fee 782 * you may not use this file except in compliance with the License.
tulanthoar 14:6bcd2f6a4fee 783 * You may obtain a copy of the License at
tulanthoar 14:6bcd2f6a4fee 784 *
tulanthoar 14:6bcd2f6a4fee 785 * http://www.apache.org/licenses/LICENSE-2.0
tulanthoar 14:6bcd2f6a4fee 786 *
tulanthoar 14:6bcd2f6a4fee 787 * Unless required by applicable law or agreed to in writing, software
tulanthoar 14:6bcd2f6a4fee 788 * distributed under the License is distributed on an "AS IS" BASIS,
tulanthoar 14:6bcd2f6a4fee 789 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tulanthoar 14:6bcd2f6a4fee 790 * See the License for the specific language governing permissions and
tulanthoar 14:6bcd2f6a4fee 791 * limitations under the License.
tulanthoar 14:6bcd2f6a4fee 792 */
tulanthoar 14:6bcd2f6a4fee 793
tulanthoar 14:6bcd2f6a4fee 794 #ifndef MPR121_H
tulanthoar 14:6bcd2f6a4fee 795 #define MPR121_H
tulanthoar 14:6bcd2f6a4fee 796
tulanthoar 14:6bcd2f6a4fee 797 #include "mbed.h"
tulanthoar 14:6bcd2f6a4fee 798 #include "rtos.h"
tulanthoar 14:6bcd2f6a4fee 799
tulanthoar 14:6bcd2f6a4fee 800 /** Using the Sparkfun SEN-10250 BoB
tulanthoar 14:6bcd2f6a4fee 801 *
tulanthoar 14:6bcd2f6a4fee 802 * Example:
tulanthoar 14:6bcd2f6a4fee 803 * @code
tulanthoar 14:6bcd2f6a4fee 804 * #include "mbed.h"
tulanthoar 14:6bcd2f6a4fee 805 * #include "MPR121.h"
tulanthoar 14:6bcd2f6a4fee 806 *
tulanthoar 14:6bcd2f6a4fee 807 * Serial pc(USBTX, USBRX);
tulanthoar 14:6bcd2f6a4fee 808 * DigitalOut myled(LED1);
tulanthoar 14:6bcd2f6a4fee 809 *
tulanthoar 14:6bcd2f6a4fee 810 * #if defined TARGET_LPC1768 || TARGET_LPC11U24
tulanthoar 14:6bcd2f6a4fee 811 * I2C i2c(p28, p27);
tulanthoar 14:6bcd2f6a4fee 812 * InterruptIn irq(p26);
tulanthoar 14:6bcd2f6a4fee 813 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
tulanthoar 14:6bcd2f6a4fee 814 *
tulanthoar 14:6bcd2f6a4fee 815 * #elif defined TARGET_KL25Z
tulanthoar 14:6bcd2f6a4fee 816 * I2C i2c(PTC9, PTC8);
tulanthoar 14:6bcd2f6a4fee 817 * InterruptIn irq(PTA5);
tulanthoar 14:6bcd2f6a4fee 818 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
tulanthoar 14:6bcd2f6a4fee 819 *
tulanthoar 14:6bcd2f6a4fee 820 * #else
tulanthoar 14:6bcd2f6a4fee 821 * #error TARGET NOT TESTED
tulanthoar 14:6bcd2f6a4fee 822 * #endif
tulanthoar 14:6bcd2f6a4fee 823 *
tulanthoar 14:6bcd2f6a4fee 824 * int main()
tulanthoar 14:6bcd2f6a4fee 825 * {
tulanthoar 14:6bcd2f6a4fee 826 * touch_pad.init();
tulanthoar 14:6bcd2f6a4fee 827 * touch_pad.enable();
tulanthoar 14:6bcd2f6a4fee 828 *
tulanthoar 14:6bcd2f6a4fee 829 * while(1)
tulanthoar 14:6bcd2f6a4fee 830 * {
tulanthoar 14:6bcd2f6a4fee 831 * if(touch_pad.isPressed())
tulanthoar 14:6bcd2f6a4fee 832 * {
tulanthoar 14:6bcd2f6a4fee 833 * uint16_t button_val = touch_pad.buttonPressed();
tulanthoar 14:6bcd2f6a4fee 834 * printf("button = 0x%04x\n", button_val);
tulanthoar 14:6bcd2f6a4fee 835 * myled = (button_val>0) ? 1 : 0;
tulanthoar 14:6bcd2f6a4fee 836 * }
tulanthoar 14:6bcd2f6a4fee 837 * }
tulanthoar 14:6bcd2f6a4fee 838 * }
tulanthoar 14:6bcd2f6a4fee 839 * @endcode
tulanthoar 14:6bcd2f6a4fee 840 */
tulanthoar 14:6bcd2f6a4fee 841
tulanthoar 14:6bcd2f6a4fee 842 /**
tulanthoar 14:6bcd2f6a4fee 843 * @class MPR121
tulanthoar 14:6bcd2f6a4fee 844 * @brief API for the MPR121 capacitive touch IC
tulanthoar 14:6bcd2f6a4fee 845 */
tulanthoar 14:6bcd2f6a4fee 846 class MPR121
tulanthoar 14:6bcd2f6a4fee 847 {
tulanthoar 14:6bcd2f6a4fee 848 private:
tulanthoar 14:6bcd2f6a4fee 849
tulanthoar 14:6bcd2f6a4fee 850 I2C *_i2c;
tulanthoar 14:6bcd2f6a4fee 851 InterruptIn *_irq;
tulanthoar 14:6bcd2f6a4fee 852 uint8_t _i2c_addr;
tulanthoar 14:6bcd2f6a4fee 853 volatile uint16_t _button;
tulanthoar 14:6bcd2f6a4fee 854 volatile uint32_t _button_has_changed;
tulanthoar 14:6bcd2f6a4fee 855
tulanthoar 14:6bcd2f6a4fee 856 /** The interrupt handler for the IRQ pin
tulanthoar 14:6bcd2f6a4fee 857 */
tulanthoar 14:6bcd2f6a4fee 858 void handler(void);
tulanthoar 14:6bcd2f6a4fee 859
tulanthoar 14:6bcd2f6a4fee 860 public:
tulanthoar 14:6bcd2f6a4fee 861
tulanthoar 14:6bcd2f6a4fee 862 /**
tulanthoar 14:6bcd2f6a4fee 863 * @enum MPR121_ADDR
tulanthoar 14:6bcd2f6a4fee 864 * @brief Possible terminations for the ADDR pin
tulanthoar 14:6bcd2f6a4fee 865 */
tulanthoar 14:6bcd2f6a4fee 866 enum MPR121_ADDR
tulanthoar 14:6bcd2f6a4fee 867 {
tulanthoar 14:6bcd2f6a4fee 868 ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */
tulanthoar 14:6bcd2f6a4fee 869 ADDR_VDD, /*!< ADDR connected to VDD */
tulanthoar 14:6bcd2f6a4fee 870 ADDR_SCL, /*!< ADDR connected to SDA */
tulanthoar 14:6bcd2f6a4fee 871 ADDR_SDA /*!< ADDR connected to SCL */
tulanthoar 14:6bcd2f6a4fee 872 };
tulanthoar 14:6bcd2f6a4fee 873
tulanthoar 14:6bcd2f6a4fee 874 /**
tulanthoar 14:6bcd2f6a4fee 875 * @enum MPR121_REGISTER
tulanthoar 14:6bcd2f6a4fee 876 * @brief The device register map
tulanthoar 14:6bcd2f6a4fee 877 */
tulanthoar 14:6bcd2f6a4fee 878 enum MPR121_REGISTER
tulanthoar 14:6bcd2f6a4fee 879 {
tulanthoar 14:6bcd2f6a4fee 880 ELE0_7_STAT = 0x00,
tulanthoar 14:6bcd2f6a4fee 881 ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB,
tulanthoar 14:6bcd2f6a4fee 882 EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB,
tulanthoar 14:6bcd2f6a4fee 883
tulanthoar 14:6bcd2f6a4fee 884 EFD6LB = 0x10,
tulanthoar 14:6bcd2f6a4fee 885 EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB,
tulanthoar 14:6bcd2f6a4fee 886 EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV,
tulanthoar 14:6bcd2f6a4fee 887
tulanthoar 14:6bcd2f6a4fee 888 E2BV = 0x20,
tulanthoar 14:6bcd2f6a4fee 889 E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV,
tulanthoar 14:6bcd2f6a4fee 890 MHDR, NHDR, NCLR, FDLR, MHDF,
tulanthoar 14:6bcd2f6a4fee 891
tulanthoar 14:6bcd2f6a4fee 892 NHDF = 0x30,
tulanthoar 14:6bcd2f6a4fee 893 NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR,
tulanthoar 14:6bcd2f6a4fee 894 FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT,
tulanthoar 14:6bcd2f6a4fee 895
tulanthoar 14:6bcd2f6a4fee 896 FDLPROXT = 0x40,
tulanthoar 14:6bcd2f6a4fee 897 E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH,
tulanthoar 14:6bcd2f6a4fee 898 E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH,
tulanthoar 14:6bcd2f6a4fee 899
tulanthoar 14:6bcd2f6a4fee 900 E7RTH = 0x50,
tulanthoar 14:6bcd2f6a4fee 901 E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH,
tulanthoar 14:6bcd2f6a4fee 902 EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0,
tulanthoar 14:6bcd2f6a4fee 903
tulanthoar 14:6bcd2f6a4fee 904 CDC1 = 0x60,
tulanthoar 14:6bcd2f6a4fee 905 CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1,
tulanthoar 14:6bcd2f6a4fee 906 CDT2_CDT3, CDT4_CDT5, CDT6_CDT7,
tulanthoar 14:6bcd2f6a4fee 907
tulanthoar 14:6bcd2f6a4fee 908 CDT8_CDT9 = 0x70,
tulanthoar 14:6bcd2f6a4fee 909 CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET,
tulanthoar 14:6bcd2f6a4fee 910 GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL,
tulanthoar 14:6bcd2f6a4fee 911
tulanthoar 14:6bcd2f6a4fee 912 SRST = 0x80
tulanthoar 14:6bcd2f6a4fee 913 };
tulanthoar 14:6bcd2f6a4fee 914
tulanthoar 14:6bcd2f6a4fee 915 /** Create the MPR121 object
tulanthoar 14:6bcd2f6a4fee 916 * @param i2c - A defined I2C object
tulanthoar 14:6bcd2f6a4fee 917 * @param pin - A defined InterruptIn object
tulanthoar 14:6bcd2f6a4fee 918 * @param i2c_addr - Connection of the address line
tulanthoar 14:6bcd2f6a4fee 919 */
tulanthoar 14:6bcd2f6a4fee 920 MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 921
tulanthoar 14:6bcd2f6a4fee 922 /** Create the MPR121 object
tulanthoar 14:6bcd2f6a4fee 923 * @param i2c - A defined I2C object
tulanthoar 14:6bcd2f6a4fee 924 * @param i2c_addr - Connection of the address line
tulanthoar 14:6bcd2f6a4fee 925 */
tulanthoar 14:6bcd2f6a4fee 926 MPR121(I2C &i2c, MPR121_ADDR i2c_addr);
tulanthoar 14:6bcd2f6a4fee 927
sam_grove 3:828260f21de6 928 /** Clear state variables and initilize the dependant objects
sam_grove 0:42add775212a 929 */
sam_grove 0:42add775212a 930 void init(void);
tulanthoar 14:6bcd2f6a4fee 931
sam_grove 0:42add775212a 932 /** Allow the IC to run and collect user input
sam_grove 0:42add775212a 933 */
sam_grove 0:42add775212a 934 void enable(void);
tulanthoar 14:6bcd2f6a4fee 935
sam_grove 0:42add775212a 936 /** Stop the IC and put into low power mode
sam_grove 0:42add775212a 937 */
sam_grove 0:42add775212a 938 void disable(void);
tulanthoar 14:6bcd2f6a4fee 939
sam_grove 0:42add775212a 940 /** Determine if a new button press event occured
sam_grove 0:42add775212a 941 * Upon calling the state is cleared until another press is detected
sam_grove 0:42add775212a 942 * @return 1 if a press has been detected since the last call, 0 otherwise
sam_grove 0:42add775212a 943 */
sam_grove 0:42add775212a 944 uint32_t isPressed(void);
tulanthoar 14:6bcd2f6a4fee 945
sam_grove 0:42add775212a 946 /** Get the electrode status (ELE12 ... ELE0 -> b15 xxx b11 ... b0
sam_grove 0:42add775212a 947 * The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined
sam_grove 0:42add775212a 948 * @return The state of all buttons
sam_grove 0:42add775212a 949 */
sam_grove 0:42add775212a 950 uint16_t buttonPressed(void);
tulanthoar 14:6bcd2f6a4fee 951
sam_grove 0:42add775212a 952 /** print the register map and values to the console
sam_grove 3:828260f21de6 953 * @param obj - a Serial object that prints to a console
sam_grove 0:42add775212a 954 */
sam_grove 3:828260f21de6 955 void registerDump(Serial &obj) const;
tulanthoar 14:6bcd2f6a4fee 956
sam_grove 5:3934358ec2b7 957 /** print the register map and values to the console
sam_grove 5:3934358ec2b7 958 */
sam_grove 5:3934358ec2b7 959 void registerDump(void) const;
tulanthoar 14:6bcd2f6a4fee 960
sam_grove 0:42add775212a 961 /** Write to a register (exposed for debugging reasons)
sam_grove 0:42add775212a 962 * Note: most writes are only valid in stop mode
sam_grove 1:cee45334b36a 963 * @param reg - The register to be written
sam_grove 1:cee45334b36a 964 * @param data - The data to be written
sam_grove 0:42add775212a 965 */
sam_grove 3:828260f21de6 966 void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const;
tulanthoar 14:6bcd2f6a4fee 967
sam_grove 0:42add775212a 968 /** Read from a register (exposed for debugging reasons)
sam_grove 1:cee45334b36a 969 * @param reg - The register to read from
sam_grove 0:42add775212a 970 * @return The register contents
sam_grove 0:42add775212a 971 */
sam_grove 3:828260f21de6 972 uint8_t readRegister(MPR121_REGISTER const reg) const;
tulanthoar 14:6bcd2f6a4fee 973
sam_grove 0:42add775212a 974 };
sam_grove 0:42add775212a 975
sam_grove 0:42add775212a 976 #endif
Nathan Yonkee 11:ad26c0810f02 977 >>>>>>> merge rev
tulanthoar 17:2d6b050ad8b8 978 =======
tulanthoar 18:8c7054b112f0 979 =======
tulanthoar 17:2d6b050ad8b8 980 >>>>>>> other
tulanthoar 18:8c7054b112f0 981 >>>>>>> other