use mbed os

Dependents:   Seeed_Grove_I2C_Touch_Example

Fork of MPR121 by Sam Grove

Committer:
Nathan Yonkee
Date:
Sun Jul 02 11:10:26 2017 -0600
Revision:
11:ad26c0810f02
Parent:
10:fb2d2454fea4
Parent:
9:8cb5ce483be3
Child:
15:8c7fba79a28e
Child:
17:2d6b050ad8b8
merge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nathan Yonkee 11:ad26c0810f02 1 <<<<<<< working copy
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"
Nathan Yonkee 10:fb2d2454fea4 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 {
Nathan Yonkee 10:fb2d2454fea4 98 ADDR_VSS = 0x1B, /*!< 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 */
Nathan Yonkee 10:fb2d2454fea4 156 MPR121(I2C &i2c, MPR121_ADDR fake);
sam_grove 5:3934358ec2b7 157
sam_grove 3:828260f21de6 158 /** Clear state variables and initilize the dependant objects
sam_grove 0:42add775212a 159 */
sam_grove 0:42add775212a 160 void init(void);
sam_grove 0:42add775212a 161
sam_grove 0:42add775212a 162 /** Allow the IC to run and collect user input
sam_grove 0:42add775212a 163 */
sam_grove 0:42add775212a 164 void enable(void);
sam_grove 0:42add775212a 165
sam_grove 0:42add775212a 166 /** Stop the IC and put into low power mode
sam_grove 0:42add775212a 167 */
sam_grove 0:42add775212a 168 void disable(void);
sam_grove 0:42add775212a 169
sam_grove 0:42add775212a 170 /** Determine if a new button press event occured
sam_grove 0:42add775212a 171 * Upon calling the state is cleared until another press is detected
sam_grove 0:42add775212a 172 * @return 1 if a press has been detected since the last call, 0 otherwise
sam_grove 0:42add775212a 173 */
sam_grove 0:42add775212a 174 uint32_t isPressed(void);
sam_grove 0:42add775212a 175
sam_grove 0:42add775212a 176 /** Get the electrode status (ELE12 ... ELE0 -> b15 xxx b11 ... b0
sam_grove 0:42add775212a 177 * The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined
sam_grove 0:42add775212a 178 * @return The state of all buttons
sam_grove 0:42add775212a 179 */
sam_grove 0:42add775212a 180 uint16_t buttonPressed(void);
sam_grove 0:42add775212a 181
sam_grove 0:42add775212a 182 /** print the register map and values to the console
sam_grove 3:828260f21de6 183 * @param obj - a Serial object that prints to a console
sam_grove 0:42add775212a 184 */
sam_grove 3:828260f21de6 185 void registerDump(Serial &obj) const;
sam_grove 0:42add775212a 186
sam_grove 5:3934358ec2b7 187 /** print the register map and values to the console
sam_grove 5:3934358ec2b7 188 */
sam_grove 5:3934358ec2b7 189 void registerDump(void) const;
sam_grove 5:3934358ec2b7 190
sam_grove 0:42add775212a 191 /** Write to a register (exposed for debugging reasons)
sam_grove 0:42add775212a 192 * Note: most writes are only valid in stop mode
sam_grove 1:cee45334b36a 193 * @param reg - The register to be written
sam_grove 1:cee45334b36a 194 * @param data - The data to be written
sam_grove 0:42add775212a 195 */
sam_grove 3:828260f21de6 196 void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const;
sam_grove 0:42add775212a 197
sam_grove 0:42add775212a 198 /** Read from a register (exposed for debugging reasons)
sam_grove 1:cee45334b36a 199 * @param reg - The register to read from
sam_grove 0:42add775212a 200 * @return The register contents
sam_grove 0:42add775212a 201 */
sam_grove 3:828260f21de6 202 uint8_t readRegister(MPR121_REGISTER const reg) const;
sam_grove 0:42add775212a 203
sam_grove 0:42add775212a 204 };
sam_grove 0:42add775212a 205
sam_grove 0:42add775212a 206 #endif
Nathan Yonkee 11:ad26c0810f02 207 =======
Nate Yonkee 9:8cb5ce483be3 208 /**
Nate Yonkee 9:8cb5ce483be3 209 * @file MPR121.h
Nate Yonkee 9:8cb5ce483be3 210 * @brief Device driver - MPR121 capactiive touch IC
Nate Yonkee 9:8cb5ce483be3 211 * @author sam grove
Nate Yonkee 9:8cb5ce483be3 212 * @version 1.0
Nate Yonkee 9:8cb5ce483be3 213 * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf
Nate Yonkee 9:8cb5ce483be3 214 *
Nate Yonkee 9:8cb5ce483be3 215 * Copyright (c) 2013
Nate Yonkee 9:8cb5ce483be3 216 *
Nate Yonkee 9:8cb5ce483be3 217 * Licensed under the Apache License, Version 2.0 (the "License");
Nate Yonkee 9:8cb5ce483be3 218 * you may not use this file except in compliance with the License.
Nate Yonkee 9:8cb5ce483be3 219 * You may obtain a copy of the License at
Nate Yonkee 9:8cb5ce483be3 220 *
Nate Yonkee 9:8cb5ce483be3 221 * http://www.apache.org/licenses/LICENSE-2.0
Nate Yonkee 9:8cb5ce483be3 222 *
Nate Yonkee 9:8cb5ce483be3 223 * Unless required by applicable law or agreed to in writing, software
Nate Yonkee 9:8cb5ce483be3 224 * distributed under the License is distributed on an "AS IS" BASIS,
Nate Yonkee 9:8cb5ce483be3 225 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Nate Yonkee 9:8cb5ce483be3 226 * See the License for the specific language governing permissions and
Nate Yonkee 9:8cb5ce483be3 227 * limitations under the License.
Nate Yonkee 9:8cb5ce483be3 228 */
Nate Yonkee 9:8cb5ce483be3 229
Nate Yonkee 9:8cb5ce483be3 230 #ifndef MPR121_H
Nate Yonkee 9:8cb5ce483be3 231 #define MPR121_H
Nate Yonkee 9:8cb5ce483be3 232
Nate Yonkee 9:8cb5ce483be3 233 #include "mbed.h"
Nate Yonkee 9:8cb5ce483be3 234 #include "rtos.h"
Nate Yonkee 9:8cb5ce483be3 235
Nate Yonkee 9:8cb5ce483be3 236 /** Using the Sparkfun SEN-10250 BoB
Nate Yonkee 9:8cb5ce483be3 237 *
Nate Yonkee 9:8cb5ce483be3 238 * Example:
Nate Yonkee 9:8cb5ce483be3 239 * @code
Nate Yonkee 9:8cb5ce483be3 240 * #include "mbed.h"
Nate Yonkee 9:8cb5ce483be3 241 * #include "MPR121.h"
Nate Yonkee 9:8cb5ce483be3 242 *
Nate Yonkee 9:8cb5ce483be3 243 * Serial pc(USBTX, USBRX);
Nate Yonkee 9:8cb5ce483be3 244 * DigitalOut myled(LED1);
Nate Yonkee 9:8cb5ce483be3 245 *
Nate Yonkee 9:8cb5ce483be3 246 * #if defined TARGET_LPC1768 || TARGET_LPC11U24
Nate Yonkee 9:8cb5ce483be3 247 * I2C i2c(p28, p27);
Nate Yonkee 9:8cb5ce483be3 248 * InterruptIn irq(p26);
Nate Yonkee 9:8cb5ce483be3 249 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
Nate Yonkee 9:8cb5ce483be3 250 *
Nate Yonkee 9:8cb5ce483be3 251 * #elif defined TARGET_KL25Z
Nate Yonkee 9:8cb5ce483be3 252 * I2C i2c(PTC9, PTC8);
Nate Yonkee 9:8cb5ce483be3 253 * InterruptIn irq(PTA5);
Nate Yonkee 9:8cb5ce483be3 254 * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
Nate Yonkee 9:8cb5ce483be3 255 *
Nate Yonkee 9:8cb5ce483be3 256 * #else
Nate Yonkee 9:8cb5ce483be3 257 * #error TARGET NOT TESTED
Nate Yonkee 9:8cb5ce483be3 258 * #endif
Nate Yonkee 9:8cb5ce483be3 259 *
Nate Yonkee 9:8cb5ce483be3 260 * int main()
Nate Yonkee 9:8cb5ce483be3 261 * {
Nate Yonkee 9:8cb5ce483be3 262 * touch_pad.init();
Nate Yonkee 9:8cb5ce483be3 263 * touch_pad.enable();
Nate Yonkee 9:8cb5ce483be3 264 *
Nate Yonkee 9:8cb5ce483be3 265 * while(1)
Nate Yonkee 9:8cb5ce483be3 266 * {
Nate Yonkee 9:8cb5ce483be3 267 * if(touch_pad.isPressed())
Nate Yonkee 9:8cb5ce483be3 268 * {
Nate Yonkee 9:8cb5ce483be3 269 * uint16_t button_val = touch_pad.buttonPressed();
Nate Yonkee 9:8cb5ce483be3 270 * printf("button = 0x%04x\n", button_val);
Nate Yonkee 9:8cb5ce483be3 271 * myled = (button_val>0) ? 1 : 0;
Nate Yonkee 9:8cb5ce483be3 272 * }
Nate Yonkee 9:8cb5ce483be3 273 * }
Nate Yonkee 9:8cb5ce483be3 274 * }
Nate Yonkee 9:8cb5ce483be3 275 * @endcode
Nate Yonkee 9:8cb5ce483be3 276 */
Nate Yonkee 9:8cb5ce483be3 277
Nate Yonkee 9:8cb5ce483be3 278 /**
Nate Yonkee 9:8cb5ce483be3 279 * @class MPR121
Nate Yonkee 9:8cb5ce483be3 280 * @brief API for the MPR121 capacitive touch IC
Nate Yonkee 9:8cb5ce483be3 281 */
Nate Yonkee 9:8cb5ce483be3 282 class MPR121
Nate Yonkee 9:8cb5ce483be3 283 {
Nate Yonkee 9:8cb5ce483be3 284 private:
Nate Yonkee 9:8cb5ce483be3 285
Nate Yonkee 9:8cb5ce483be3 286 I2C *_i2c;
Nate Yonkee 9:8cb5ce483be3 287 InterruptIn *_irq;
Nate Yonkee 9:8cb5ce483be3 288 uint8_t _i2c_addr;
Nate Yonkee 9:8cb5ce483be3 289 volatile uint16_t _button;
Nate Yonkee 9:8cb5ce483be3 290 volatile uint32_t _button_has_changed;
Nate Yonkee 9:8cb5ce483be3 291
Nate Yonkee 9:8cb5ce483be3 292 /** The interrupt handler for the IRQ pin
Nate Yonkee 9:8cb5ce483be3 293 */
Nate Yonkee 9:8cb5ce483be3 294 void handler(void);
Nate Yonkee 9:8cb5ce483be3 295
Nate Yonkee 9:8cb5ce483be3 296 public:
Nate Yonkee 9:8cb5ce483be3 297
Nate Yonkee 9:8cb5ce483be3 298 /**
Nate Yonkee 9:8cb5ce483be3 299 * @enum MPR121_ADDR
Nate Yonkee 9:8cb5ce483be3 300 * @brief Possible terminations for the ADDR pin
Nate Yonkee 9:8cb5ce483be3 301 */
Nate Yonkee 9:8cb5ce483be3 302 enum MPR121_ADDR
Nate Yonkee 9:8cb5ce483be3 303 {
Nate Yonkee 9:8cb5ce483be3 304 ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */
Nate Yonkee 9:8cb5ce483be3 305 ADDR_VDD, /*!< ADDR connected to VDD */
Nate Yonkee 9:8cb5ce483be3 306 ADDR_SCL, /*!< ADDR connected to SDA */
Nate Yonkee 9:8cb5ce483be3 307 ADDR_SDA /*!< ADDR connected to SCL */
Nate Yonkee 9:8cb5ce483be3 308 };
Nate Yonkee 9:8cb5ce483be3 309
Nate Yonkee 9:8cb5ce483be3 310 /**
Nate Yonkee 9:8cb5ce483be3 311 * @enum MPR121_REGISTER
Nate Yonkee 9:8cb5ce483be3 312 * @brief The device register map
Nate Yonkee 9:8cb5ce483be3 313 */
Nate Yonkee 9:8cb5ce483be3 314 enum MPR121_REGISTER
Nate Yonkee 9:8cb5ce483be3 315 {
Nate Yonkee 9:8cb5ce483be3 316 ELE0_7_STAT = 0x00,
Nate Yonkee 9:8cb5ce483be3 317 ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB,
Nate Yonkee 9:8cb5ce483be3 318 EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB,
Nate Yonkee 9:8cb5ce483be3 319
Nate Yonkee 9:8cb5ce483be3 320 EFD6LB = 0x10,
Nate Yonkee 9:8cb5ce483be3 321 EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB,
Nate Yonkee 9:8cb5ce483be3 322 EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV,
Nate Yonkee 9:8cb5ce483be3 323
Nate Yonkee 9:8cb5ce483be3 324 E2BV = 0x20,
Nate Yonkee 9:8cb5ce483be3 325 E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV,
Nate Yonkee 9:8cb5ce483be3 326 MHDR, NHDR, NCLR, FDLR, MHDF,
Nate Yonkee 9:8cb5ce483be3 327
Nate Yonkee 9:8cb5ce483be3 328 NHDF = 0x30,
Nate Yonkee 9:8cb5ce483be3 329 NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR,
Nate Yonkee 9:8cb5ce483be3 330 FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT,
Nate Yonkee 9:8cb5ce483be3 331
Nate Yonkee 9:8cb5ce483be3 332 FDLPROXT = 0x40,
Nate Yonkee 9:8cb5ce483be3 333 E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH,
Nate Yonkee 9:8cb5ce483be3 334 E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH,
Nate Yonkee 9:8cb5ce483be3 335
Nate Yonkee 9:8cb5ce483be3 336 E7RTH = 0x50,
Nate Yonkee 9:8cb5ce483be3 337 E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH,
Nate Yonkee 9:8cb5ce483be3 338 EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0,
Nate Yonkee 9:8cb5ce483be3 339
Nate Yonkee 9:8cb5ce483be3 340 CDC1 = 0x60,
Nate Yonkee 9:8cb5ce483be3 341 CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1,
Nate Yonkee 9:8cb5ce483be3 342 CDT2_CDT3, CDT4_CDT5, CDT6_CDT7,
Nate Yonkee 9:8cb5ce483be3 343
Nate Yonkee 9:8cb5ce483be3 344 CDT8_CDT9 = 0x70,
Nate Yonkee 9:8cb5ce483be3 345 CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET,
Nate Yonkee 9:8cb5ce483be3 346 GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL,
Nate Yonkee 9:8cb5ce483be3 347
Nate Yonkee 9:8cb5ce483be3 348 SRST = 0x80
Nate Yonkee 9:8cb5ce483be3 349 };
Nate Yonkee 9:8cb5ce483be3 350
Nate Yonkee 9:8cb5ce483be3 351 /** Create the MPR121 object
Nate Yonkee 9:8cb5ce483be3 352 * @param i2c - A defined I2C object
Nate Yonkee 9:8cb5ce483be3 353 * @param pin - A defined InterruptIn object
Nate Yonkee 9:8cb5ce483be3 354 * @param i2c_addr - Connection of the address line
Nate Yonkee 9:8cb5ce483be3 355 */
Nate Yonkee 9:8cb5ce483be3 356 MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
Nate Yonkee 9:8cb5ce483be3 357
Nate Yonkee 9:8cb5ce483be3 358 /** Create the MPR121 object
Nate Yonkee 9:8cb5ce483be3 359 * @param i2c - A defined I2C object
Nate Yonkee 9:8cb5ce483be3 360 * @param i2c_addr - Connection of the address line
Nate Yonkee 9:8cb5ce483be3 361 */
Nate Yonkee 9:8cb5ce483be3 362 MPR121(I2C &i2c, MPR121_ADDR i2c_addr);
Nate Yonkee 9:8cb5ce483be3 363
Nate Yonkee 9:8cb5ce483be3 364 /** Clear state variables and initilize the dependant objects
Nate Yonkee 9:8cb5ce483be3 365 */
Nate Yonkee 9:8cb5ce483be3 366 void init(void);
Nate Yonkee 9:8cb5ce483be3 367
Nate Yonkee 9:8cb5ce483be3 368 /** Allow the IC to run and collect user input
Nate Yonkee 9:8cb5ce483be3 369 */
Nate Yonkee 9:8cb5ce483be3 370 void enable(void);
Nate Yonkee 9:8cb5ce483be3 371
Nate Yonkee 9:8cb5ce483be3 372 /** Stop the IC and put into low power mode
Nate Yonkee 9:8cb5ce483be3 373 */
Nate Yonkee 9:8cb5ce483be3 374 void disable(void);
Nate Yonkee 9:8cb5ce483be3 375
Nate Yonkee 9:8cb5ce483be3 376 /** Determine if a new button press event occured
Nate Yonkee 9:8cb5ce483be3 377 * Upon calling the state is cleared until another press is detected
Nate Yonkee 9:8cb5ce483be3 378 * @return 1 if a press has been detected since the last call, 0 otherwise
Nate Yonkee 9:8cb5ce483be3 379 */
Nate Yonkee 9:8cb5ce483be3 380 uint32_t isPressed(void);
Nate Yonkee 9:8cb5ce483be3 381
Nate Yonkee 9:8cb5ce483be3 382 /** Get the electrode status (ELE12 ... ELE0 -> b15 xxx b11 ... b0
Nate Yonkee 9:8cb5ce483be3 383 * The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined
Nate Yonkee 9:8cb5ce483be3 384 * @return The state of all buttons
Nate Yonkee 9:8cb5ce483be3 385 */
Nate Yonkee 9:8cb5ce483be3 386 uint16_t buttonPressed(void);
Nate Yonkee 9:8cb5ce483be3 387
Nate Yonkee 9:8cb5ce483be3 388 /** print the register map and values to the console
Nate Yonkee 9:8cb5ce483be3 389 * @param obj - a Serial object that prints to a console
Nate Yonkee 9:8cb5ce483be3 390 */
Nate Yonkee 9:8cb5ce483be3 391 void registerDump(Serial &obj) const;
Nate Yonkee 9:8cb5ce483be3 392
Nate Yonkee 9:8cb5ce483be3 393 /** print the register map and values to the console
Nate Yonkee 9:8cb5ce483be3 394 */
Nate Yonkee 9:8cb5ce483be3 395 void registerDump(void) const;
Nate Yonkee 9:8cb5ce483be3 396
Nate Yonkee 9:8cb5ce483be3 397 /** Write to a register (exposed for debugging reasons)
Nate Yonkee 9:8cb5ce483be3 398 * Note: most writes are only valid in stop mode
Nate Yonkee 9:8cb5ce483be3 399 * @param reg - The register to be written
Nate Yonkee 9:8cb5ce483be3 400 * @param data - The data to be written
Nate Yonkee 9:8cb5ce483be3 401 */
Nate Yonkee 9:8cb5ce483be3 402 void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const;
Nate Yonkee 9:8cb5ce483be3 403
Nate Yonkee 9:8cb5ce483be3 404 /** Read from a register (exposed for debugging reasons)
Nate Yonkee 9:8cb5ce483be3 405 * @param reg - The register to read from
Nate Yonkee 9:8cb5ce483be3 406 * @return The register contents
Nate Yonkee 9:8cb5ce483be3 407 */
Nate Yonkee 9:8cb5ce483be3 408 uint8_t readRegister(MPR121_REGISTER const reg) const;
Nate Yonkee 9:8cb5ce483be3 409
Nate Yonkee 9:8cb5ce483be3 410 };
Nate Yonkee 9:8cb5ce483be3 411
Nate Yonkee 9:8cb5ce483be3 412 #endif
Nathan Yonkee 11:ad26c0810f02 413 >>>>>>> merge rev