use mbed os
Dependents: Seeed_Grove_I2C_Touch_Example
Fork of MPR121 by
MPR121.h@16:94e77e14a859, 2017-07-02 (annotated)
- Committer:
- Nathan Yonkee
- Date:
- Sun Jul 02 11:27:59 2017 -0600
- Revision:
- 16:94e77e14a859
- Parent:
- 15:8c7fba79a28e
- Parent:
- 14:6bcd2f6a4fee
- Child:
- 18:8c7054b112f0
merge
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nathan Yonkee |
16:94e77e14a859 | 1 | <<<<<<< working copy |
Nate Yonkee |
9:8cb5ce483be3 | 2 | /** |
Nate Yonkee |
9:8cb5ce483be3 | 3 | * @file MPR121.h |
Nate Yonkee |
9:8cb5ce483be3 | 4 | * @brief Device driver - MPR121 capactiive touch IC |
Nate Yonkee |
9:8cb5ce483be3 | 5 | * @author sam grove |
Nate Yonkee |
9:8cb5ce483be3 | 6 | * @version 1.0 |
Nate Yonkee |
9:8cb5ce483be3 | 7 | * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf |
Nate Yonkee |
9:8cb5ce483be3 | 8 | * |
Nate Yonkee |
9:8cb5ce483be3 | 9 | * Copyright (c) 2013 |
Nate Yonkee |
9:8cb5ce483be3 | 10 | * |
Nate Yonkee |
9:8cb5ce483be3 | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Nate Yonkee |
9:8cb5ce483be3 | 12 | * you may not use this file except in compliance with the License. |
Nate Yonkee |
9:8cb5ce483be3 | 13 | * You may obtain a copy of the License at |
Nate Yonkee |
9:8cb5ce483be3 | 14 | * |
Nate Yonkee |
9:8cb5ce483be3 | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nate Yonkee |
9:8cb5ce483be3 | 16 | * |
Nate Yonkee |
9:8cb5ce483be3 | 17 | * Unless required by applicable law or agreed to in writing, software |
Nate Yonkee |
9:8cb5ce483be3 | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
Nate Yonkee |
9:8cb5ce483be3 | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Nate Yonkee |
9:8cb5ce483be3 | 20 | * See the License for the specific language governing permissions and |
Nate Yonkee |
9:8cb5ce483be3 | 21 | * limitations under the License. |
Nate Yonkee |
9:8cb5ce483be3 | 22 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 23 | |
Nate Yonkee |
9:8cb5ce483be3 | 24 | #ifndef MPR121_H |
Nate Yonkee |
9:8cb5ce483be3 | 25 | #define MPR121_H |
Nate Yonkee |
9:8cb5ce483be3 | 26 | |
Nate Yonkee |
9:8cb5ce483be3 | 27 | #include "mbed.h" |
Nate Yonkee |
9:8cb5ce483be3 | 28 | #include "rtos.h" |
Nate Yonkee |
9:8cb5ce483be3 | 29 | |
Nate Yonkee |
9:8cb5ce483be3 | 30 | /** Using the Sparkfun SEN-10250 BoB |
Nate Yonkee |
9:8cb5ce483be3 | 31 | * |
Nate Yonkee |
9:8cb5ce483be3 | 32 | * Example: |
Nate Yonkee |
9:8cb5ce483be3 | 33 | * @code |
Nate Yonkee |
9:8cb5ce483be3 | 34 | * #include "mbed.h" |
Nate Yonkee |
9:8cb5ce483be3 | 35 | * #include "MPR121.h" |
Nate Yonkee |
9:8cb5ce483be3 | 36 | * |
Nate Yonkee |
9:8cb5ce483be3 | 37 | * Serial pc(USBTX, USBRX); |
Nate Yonkee |
9:8cb5ce483be3 | 38 | * DigitalOut myled(LED1); |
Nate Yonkee |
9:8cb5ce483be3 | 39 | * |
Nate Yonkee |
9:8cb5ce483be3 | 40 | * #if defined TARGET_LPC1768 || TARGET_LPC11U24 |
Nate Yonkee |
9:8cb5ce483be3 | 41 | * I2C i2c(p28, p27); |
Nate Yonkee |
9:8cb5ce483be3 | 42 | * InterruptIn irq(p26); |
Nate Yonkee |
9:8cb5ce483be3 | 43 | * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS); |
Nate Yonkee |
9:8cb5ce483be3 | 44 | * |
Nate Yonkee |
9:8cb5ce483be3 | 45 | * #elif defined TARGET_KL25Z |
Nate Yonkee |
9:8cb5ce483be3 | 46 | * I2C i2c(PTC9, PTC8); |
Nate Yonkee |
9:8cb5ce483be3 | 47 | * InterruptIn irq(PTA5); |
Nate Yonkee |
9:8cb5ce483be3 | 48 | * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS); |
Nate Yonkee |
9:8cb5ce483be3 | 49 | * |
Nate Yonkee |
9:8cb5ce483be3 | 50 | * #else |
Nate Yonkee |
9:8cb5ce483be3 | 51 | * #error TARGET NOT TESTED |
Nate Yonkee |
9:8cb5ce483be3 | 52 | * #endif |
Nate Yonkee |
9:8cb5ce483be3 | 53 | * |
Nate Yonkee |
9:8cb5ce483be3 | 54 | * int main() |
Nate Yonkee |
9:8cb5ce483be3 | 55 | * { |
Nate Yonkee |
9:8cb5ce483be3 | 56 | * touch_pad.init(); |
Nate Yonkee |
9:8cb5ce483be3 | 57 | * touch_pad.enable(); |
Nate Yonkee |
9:8cb5ce483be3 | 58 | * |
Nate Yonkee |
9:8cb5ce483be3 | 59 | * while(1) |
Nate Yonkee |
9:8cb5ce483be3 | 60 | * { |
Nate Yonkee |
9:8cb5ce483be3 | 61 | * if(touch_pad.isPressed()) |
Nate Yonkee |
9:8cb5ce483be3 | 62 | * { |
Nate Yonkee |
9:8cb5ce483be3 | 63 | * uint16_t button_val = touch_pad.buttonPressed(); |
Nate Yonkee |
9:8cb5ce483be3 | 64 | * printf("button = 0x%04x\n", button_val); |
Nate Yonkee |
9:8cb5ce483be3 | 65 | * myled = (button_val>0) ? 1 : 0; |
Nate Yonkee |
9:8cb5ce483be3 | 66 | * } |
Nate Yonkee |
9:8cb5ce483be3 | 67 | * } |
Nate Yonkee |
9:8cb5ce483be3 | 68 | * } |
Nate Yonkee |
9:8cb5ce483be3 | 69 | * @endcode |
Nate Yonkee |
9:8cb5ce483be3 | 70 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 71 | |
Nate Yonkee |
9:8cb5ce483be3 | 72 | /** |
Nate Yonkee |
9:8cb5ce483be3 | 73 | * @class MPR121 |
Nate Yonkee |
9:8cb5ce483be3 | 74 | * @brief API for the MPR121 capacitive touch IC |
Nate Yonkee |
9:8cb5ce483be3 | 75 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 76 | class MPR121 |
Nate Yonkee |
9:8cb5ce483be3 | 77 | { |
Nate Yonkee |
9:8cb5ce483be3 | 78 | private: |
Nate Yonkee |
9:8cb5ce483be3 | 79 | |
Nate Yonkee |
9:8cb5ce483be3 | 80 | I2C *_i2c; |
Nate Yonkee |
9:8cb5ce483be3 | 81 | InterruptIn *_irq; |
Nate Yonkee |
9:8cb5ce483be3 | 82 | uint8_t _i2c_addr; |
Nate Yonkee |
9:8cb5ce483be3 | 83 | volatile uint16_t _button; |
Nate Yonkee |
9:8cb5ce483be3 | 84 | volatile uint32_t _button_has_changed; |
Nate Yonkee |
9:8cb5ce483be3 | 85 | |
Nate Yonkee |
9:8cb5ce483be3 | 86 | /** The interrupt handler for the IRQ pin |
Nate Yonkee |
9:8cb5ce483be3 | 87 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 88 | void handler(void); |
Nate Yonkee |
9:8cb5ce483be3 | 89 | |
Nate Yonkee |
9:8cb5ce483be3 | 90 | public: |
Nate Yonkee |
9:8cb5ce483be3 | 91 | |
Nate Yonkee |
9:8cb5ce483be3 | 92 | /** |
Nate Yonkee |
9:8cb5ce483be3 | 93 | * @enum MPR121_ADDR |
Nate Yonkee |
9:8cb5ce483be3 | 94 | * @brief Possible terminations for the ADDR pin |
Nate Yonkee |
9:8cb5ce483be3 | 95 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 96 | enum MPR121_ADDR |
Nate Yonkee |
9:8cb5ce483be3 | 97 | { |
Nate Yonkee |
9:8cb5ce483be3 | 98 | ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */ |
Nate Yonkee |
9:8cb5ce483be3 | 99 | ADDR_VDD, /*!< ADDR connected to VDD */ |
Nate Yonkee |
9:8cb5ce483be3 | 100 | ADDR_SCL, /*!< ADDR connected to SDA */ |
Nate Yonkee |
9:8cb5ce483be3 | 101 | ADDR_SDA /*!< ADDR connected to SCL */ |
Nate Yonkee |
9:8cb5ce483be3 | 102 | }; |
Nate Yonkee |
9:8cb5ce483be3 | 103 | |
Nate Yonkee |
9:8cb5ce483be3 | 104 | /** |
Nate Yonkee |
9:8cb5ce483be3 | 105 | * @enum MPR121_REGISTER |
Nate Yonkee |
9:8cb5ce483be3 | 106 | * @brief The device register map |
Nate Yonkee |
9:8cb5ce483be3 | 107 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 108 | enum MPR121_REGISTER |
Nate Yonkee |
9:8cb5ce483be3 | 109 | { |
Nate Yonkee |
9:8cb5ce483be3 | 110 | ELE0_7_STAT = 0x00, |
Nate Yonkee |
9:8cb5ce483be3 | 111 | ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB, |
Nate Yonkee |
9:8cb5ce483be3 | 112 | EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB, |
Nate Yonkee |
9:8cb5ce483be3 | 113 | |
Nate Yonkee |
9:8cb5ce483be3 | 114 | EFD6LB = 0x10, |
Nate Yonkee |
9:8cb5ce483be3 | 115 | EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB, |
Nate Yonkee |
9:8cb5ce483be3 | 116 | EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV, |
Nate Yonkee |
9:8cb5ce483be3 | 117 | |
Nate Yonkee |
9:8cb5ce483be3 | 118 | E2BV = 0x20, |
Nate Yonkee |
9:8cb5ce483be3 | 119 | E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV, |
Nate Yonkee |
9:8cb5ce483be3 | 120 | MHDR, NHDR, NCLR, FDLR, MHDF, |
Nate Yonkee |
9:8cb5ce483be3 | 121 | |
Nate Yonkee |
9:8cb5ce483be3 | 122 | NHDF = 0x30, |
Nate Yonkee |
9:8cb5ce483be3 | 123 | NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR, |
Nate Yonkee |
9:8cb5ce483be3 | 124 | FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT, |
Nate Yonkee |
9:8cb5ce483be3 | 125 | |
Nate Yonkee |
9:8cb5ce483be3 | 126 | FDLPROXT = 0x40, |
Nate Yonkee |
9:8cb5ce483be3 | 127 | E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH, |
Nate Yonkee |
9:8cb5ce483be3 | 128 | E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH, |
Nate Yonkee |
9:8cb5ce483be3 | 129 | |
Nate Yonkee |
9:8cb5ce483be3 | 130 | E7RTH = 0x50, |
Nate Yonkee |
9:8cb5ce483be3 | 131 | E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH, |
Nate Yonkee |
9:8cb5ce483be3 | 132 | EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0, |
Nate Yonkee |
9:8cb5ce483be3 | 133 | |
Nate Yonkee |
9:8cb5ce483be3 | 134 | CDC1 = 0x60, |
Nate Yonkee |
9:8cb5ce483be3 | 135 | CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1, |
Nate Yonkee |
9:8cb5ce483be3 | 136 | CDT2_CDT3, CDT4_CDT5, CDT6_CDT7, |
Nate Yonkee |
9:8cb5ce483be3 | 137 | |
Nate Yonkee |
9:8cb5ce483be3 | 138 | CDT8_CDT9 = 0x70, |
Nate Yonkee |
9:8cb5ce483be3 | 139 | CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET, |
Nate Yonkee |
9:8cb5ce483be3 | 140 | GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL, |
Nate Yonkee |
9:8cb5ce483be3 | 141 | |
Nate Yonkee |
9:8cb5ce483be3 | 142 | SRST = 0x80 |
Nate Yonkee |
9:8cb5ce483be3 | 143 | }; |
Nate Yonkee |
9:8cb5ce483be3 | 144 | |
Nate Yonkee |
9:8cb5ce483be3 | 145 | /** Create the MPR121 object |
Nate Yonkee |
9:8cb5ce483be3 | 146 | * @param i2c - A defined I2C object |
Nate Yonkee |
9:8cb5ce483be3 | 147 | * @param pin - A defined InterruptIn object |
Nate Yonkee |
9:8cb5ce483be3 | 148 | * @param i2c_addr - Connection of the address line |
Nate Yonkee |
9:8cb5ce483be3 | 149 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 150 | MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr); |
Nate Yonkee |
9:8cb5ce483be3 | 151 | |
Nate Yonkee |
9:8cb5ce483be3 | 152 | /** Create the MPR121 object |
Nate Yonkee |
9:8cb5ce483be3 | 153 | * @param i2c - A defined I2C object |
Nate Yonkee |
9:8cb5ce483be3 | 154 | * @param i2c_addr - Connection of the address line |
Nate Yonkee |
9:8cb5ce483be3 | 155 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 156 | MPR121(I2C &i2c, MPR121_ADDR i2c_addr); |
Nate Yonkee |
9:8cb5ce483be3 | 157 | |
Nate Yonkee |
9:8cb5ce483be3 | 158 | /** Clear state variables and initilize the dependant objects |
Nate Yonkee |
9:8cb5ce483be3 | 159 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 160 | void init(void); |
Nate Yonkee |
9:8cb5ce483be3 | 161 | |
Nate Yonkee |
9:8cb5ce483be3 | 162 | /** Allow the IC to run and collect user input |
Nate Yonkee |
9:8cb5ce483be3 | 163 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 164 | void enable(void); |
Nate Yonkee |
9:8cb5ce483be3 | 165 | |
Nate Yonkee |
9:8cb5ce483be3 | 166 | /** Stop the IC and put into low power mode |
Nate Yonkee |
9:8cb5ce483be3 | 167 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 168 | void disable(void); |
Nate Yonkee |
9:8cb5ce483be3 | 169 | |
Nate Yonkee |
9:8cb5ce483be3 | 170 | /** Determine if a new button press event occured |
Nate Yonkee |
9:8cb5ce483be3 | 171 | * Upon calling the state is cleared until another press is detected |
Nate Yonkee |
9:8cb5ce483be3 | 172 | * @return 1 if a press has been detected since the last call, 0 otherwise |
Nate Yonkee |
9:8cb5ce483be3 | 173 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 174 | uint32_t isPressed(void); |
Nate Yonkee |
9:8cb5ce483be3 | 175 | |
Nate Yonkee |
9:8cb5ce483be3 | 176 | /** Get the electrode status (ELE12 ... ELE0 -> b15 xxx b11 ... b0 |
Nate Yonkee |
9:8cb5ce483be3 | 177 | * The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined |
Nate Yonkee |
9:8cb5ce483be3 | 178 | * @return The state of all buttons |
Nate Yonkee |
9:8cb5ce483be3 | 179 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 180 | uint16_t buttonPressed(void); |
Nate Yonkee |
9:8cb5ce483be3 | 181 | |
Nate Yonkee |
9:8cb5ce483be3 | 182 | /** print the register map and values to the console |
Nate Yonkee |
9:8cb5ce483be3 | 183 | * @param obj - a Serial object that prints to a console |
Nate Yonkee |
9:8cb5ce483be3 | 184 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 185 | void registerDump(Serial &obj) const; |
Nate Yonkee |
9:8cb5ce483be3 | 186 | |
Nate Yonkee |
9:8cb5ce483be3 | 187 | /** print the register map and values to the console |
Nate Yonkee |
9:8cb5ce483be3 | 188 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 189 | void registerDump(void) const; |
Nate Yonkee |
9:8cb5ce483be3 | 190 | |
Nate Yonkee |
9:8cb5ce483be3 | 191 | /** Write to a register (exposed for debugging reasons) |
Nate Yonkee |
9:8cb5ce483be3 | 192 | * Note: most writes are only valid in stop mode |
Nate Yonkee |
9:8cb5ce483be3 | 193 | * @param reg - The register to be written |
Nate Yonkee |
9:8cb5ce483be3 | 194 | * @param data - The data to be written |
Nate Yonkee |
9:8cb5ce483be3 | 195 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 196 | void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const; |
Nate Yonkee |
9:8cb5ce483be3 | 197 | |
Nate Yonkee |
9:8cb5ce483be3 | 198 | /** Read from a register (exposed for debugging reasons) |
Nate Yonkee |
9:8cb5ce483be3 | 199 | * @param reg - The register to read from |
Nate Yonkee |
9:8cb5ce483be3 | 200 | * @return The register contents |
Nate Yonkee |
9:8cb5ce483be3 | 201 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 202 | uint8_t readRegister(MPR121_REGISTER const reg) const; |
Nate Yonkee |
9:8cb5ce483be3 | 203 | |
Nate Yonkee |
9:8cb5ce483be3 | 204 | }; |
Nate Yonkee |
9:8cb5ce483be3 | 205 | |
Nate Yonkee |
9:8cb5ce483be3 | 206 | #endif |
Nathan Yonkee |
11:ad26c0810f02 | 207 | >>>>>>> merge rev |
Nathan Yonkee |
16:94e77e14a859 | 208 | ======= |
tulanthoar | 14:6bcd2f6a4fee | 209 | <<<<<<< local |
sam_grove | 0:42add775212a | 210 | /** |
sam_grove | 0:42add775212a | 211 | * @file MPR121.h |
sam_grove | 0:42add775212a | 212 | * @brief Device driver - MPR121 capactiive touch IC |
sam_grove | 0:42add775212a | 213 | * @author sam grove |
sam_grove | 0:42add775212a | 214 | * @version 1.0 |
sam_grove | 0:42add775212a | 215 | * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf |
sam_grove | 0:42add775212a | 216 | * |
sam_grove | 0:42add775212a | 217 | * Copyright (c) 2013 |
sam_grove | 0:42add775212a | 218 | * |
sam_grove | 0:42add775212a | 219 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 0:42add775212a | 220 | * you may not use this file except in compliance with the License. |
sam_grove | 0:42add775212a | 221 | * You may obtain a copy of the License at |
sam_grove | 0:42add775212a | 222 | * |
sam_grove | 0:42add775212a | 223 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 0:42add775212a | 224 | * |
sam_grove | 0:42add775212a | 225 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 0:42add775212a | 226 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 0:42add775212a | 227 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 0:42add775212a | 228 | * See the License for the specific language governing permissions and |
sam_grove | 0:42add775212a | 229 | * limitations under the License. |
sam_grove | 0:42add775212a | 230 | */ |
sam_grove | 0:42add775212a | 231 | |
sam_grove | 0:42add775212a | 232 | #ifndef MPR121_H |
sam_grove | 0:42add775212a | 233 | #define MPR121_H |
sam_grove | 0:42add775212a | 234 | |
sam_grove | 0:42add775212a | 235 | #include "mbed.h" |
tulanthoar | 13:185ada085785 | 236 | //#include "rtos.h" |
sam_grove | 0:42add775212a | 237 | |
sam_grove | 3:828260f21de6 | 238 | /** Using the Sparkfun SEN-10250 BoB |
sam_grove | 0:42add775212a | 239 | * |
sam_grove | 0:42add775212a | 240 | * Example: |
sam_grove | 0:42add775212a | 241 | * @code |
sam_grove | 3:828260f21de6 | 242 | * #include "mbed.h" |
sam_grove | 3:828260f21de6 | 243 | * #include "MPR121.h" |
sam_grove | 3:828260f21de6 | 244 | * |
sam_grove | 3:828260f21de6 | 245 | * Serial pc(USBTX, USBRX); |
sam_grove | 3:828260f21de6 | 246 | * DigitalOut myled(LED1); |
sam_grove | 3:828260f21de6 | 247 | * |
sam_grove | 3:828260f21de6 | 248 | * #if defined TARGET_LPC1768 || TARGET_LPC11U24 |
sam_grove | 3:828260f21de6 | 249 | * I2C i2c(p28, p27); |
sam_grove | 3:828260f21de6 | 250 | * InterruptIn irq(p26); |
sam_grove | 3:828260f21de6 | 251 | * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS); |
sam_grove | 3:828260f21de6 | 252 | * |
sam_grove | 3:828260f21de6 | 253 | * #elif defined TARGET_KL25Z |
sam_grove | 3:828260f21de6 | 254 | * I2C i2c(PTC9, PTC8); |
sam_grove | 3:828260f21de6 | 255 | * InterruptIn irq(PTA5); |
sam_grove | 3:828260f21de6 | 256 | * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS); |
sam_grove | 3:828260f21de6 | 257 | * |
sam_grove | 3:828260f21de6 | 258 | * #else |
sam_grove | 3:828260f21de6 | 259 | * #error TARGET NOT TESTED |
sam_grove | 3:828260f21de6 | 260 | * #endif |
sam_grove | 3:828260f21de6 | 261 | * |
sam_grove | 3:828260f21de6 | 262 | * int main() |
sam_grove | 3:828260f21de6 | 263 | * { |
sam_grove | 3:828260f21de6 | 264 | * touch_pad.init(); |
sam_grove | 3:828260f21de6 | 265 | * touch_pad.enable(); |
sam_grove | 3:828260f21de6 | 266 | * |
sam_grove | 3:828260f21de6 | 267 | * while(1) |
sam_grove | 3:828260f21de6 | 268 | * { |
sam_grove | 3:828260f21de6 | 269 | * if(touch_pad.isPressed()) |
sam_grove | 3:828260f21de6 | 270 | * { |
sam_grove | 3:828260f21de6 | 271 | * uint16_t button_val = touch_pad.buttonPressed(); |
sam_grove | 3:828260f21de6 | 272 | * printf("button = 0x%04x\n", button_val); |
sam_grove | 3:828260f21de6 | 273 | * myled = (button_val>0) ? 1 : 0; |
sam_grove | 3:828260f21de6 | 274 | * } |
sam_grove | 3:828260f21de6 | 275 | * } |
sam_grove | 3:828260f21de6 | 276 | * } |
sam_grove | 0:42add775212a | 277 | * @endcode |
sam_grove | 0:42add775212a | 278 | */ |
sam_grove | 0:42add775212a | 279 | |
sam_grove | 0:42add775212a | 280 | /** |
sam_grove | 0:42add775212a | 281 | * @class MPR121 |
sam_grove | 3:828260f21de6 | 282 | * @brief API for the MPR121 capacitive touch IC |
sam_grove | 0:42add775212a | 283 | */ |
sam_grove | 0:42add775212a | 284 | class MPR121 |
sam_grove | 0:42add775212a | 285 | { |
sam_grove | 0:42add775212a | 286 | private: |
sam_grove | 0:42add775212a | 287 | |
sam_grove | 0:42add775212a | 288 | I2C *_i2c; |
sam_grove | 0:42add775212a | 289 | InterruptIn *_irq; |
sam_grove | 0:42add775212a | 290 | uint8_t _i2c_addr; |
sam_grove | 0:42add775212a | 291 | volatile uint16_t _button; |
sam_grove | 0:42add775212a | 292 | volatile uint32_t _button_has_changed; |
sam_grove | 0:42add775212a | 293 | |
sam_grove | 0:42add775212a | 294 | /** The interrupt handler for the IRQ pin |
sam_grove | 0:42add775212a | 295 | */ |
sam_grove | 0:42add775212a | 296 | void handler(void); |
sam_grove | 0:42add775212a | 297 | |
sam_grove | 0:42add775212a | 298 | public: |
sam_grove | 0:42add775212a | 299 | |
sam_grove | 0:42add775212a | 300 | /** |
sam_grove | 0:42add775212a | 301 | * @enum MPR121_ADDR |
sam_grove | 0:42add775212a | 302 | * @brief Possible terminations for the ADDR pin |
sam_grove | 0:42add775212a | 303 | */ |
sam_grove | 0:42add775212a | 304 | enum MPR121_ADDR |
sam_grove | 0:42add775212a | 305 | { |
sam_grove | 0:42add775212a | 306 | ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */ |
sam_grove | 0:42add775212a | 307 | ADDR_VDD, /*!< ADDR connected to VDD */ |
sam_grove | 0:42add775212a | 308 | ADDR_SCL, /*!< ADDR connected to SDA */ |
sam_grove | 0:42add775212a | 309 | ADDR_SDA /*!< ADDR connected to SCL */ |
sam_grove | 0:42add775212a | 310 | }; |
sam_grove | 0:42add775212a | 311 | |
sam_grove | 0:42add775212a | 312 | /** |
sam_grove | 0:42add775212a | 313 | * @enum MPR121_REGISTER |
sam_grove | 0:42add775212a | 314 | * @brief The device register map |
sam_grove | 0:42add775212a | 315 | */ |
sam_grove | 0:42add775212a | 316 | enum MPR121_REGISTER |
sam_grove | 0:42add775212a | 317 | { |
sam_grove | 0:42add775212a | 318 | ELE0_7_STAT = 0x00, |
sam_grove | 0:42add775212a | 319 | ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB, |
sam_grove | 0:42add775212a | 320 | EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB, |
sam_grove | 0:42add775212a | 321 | |
sam_grove | 0:42add775212a | 322 | EFD6LB = 0x10, |
sam_grove | 0:42add775212a | 323 | EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB, |
sam_grove | 0:42add775212a | 324 | EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV, |
sam_grove | 0:42add775212a | 325 | |
sam_grove | 0:42add775212a | 326 | E2BV = 0x20, |
sam_grove | 0:42add775212a | 327 | E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV, |
sam_grove | 0:42add775212a | 328 | MHDR, NHDR, NCLR, FDLR, MHDF, |
sam_grove | 0:42add775212a | 329 | |
sam_grove | 0:42add775212a | 330 | NHDF = 0x30, |
sam_grove | 0:42add775212a | 331 | NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR, |
sam_grove | 0:42add775212a | 332 | FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT, |
sam_grove | 0:42add775212a | 333 | |
sam_grove | 0:42add775212a | 334 | FDLPROXT = 0x40, |
sam_grove | 0:42add775212a | 335 | E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH, |
sam_grove | 0:42add775212a | 336 | E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH, |
sam_grove | 0:42add775212a | 337 | |
sam_grove | 0:42add775212a | 338 | E7RTH = 0x50, |
sam_grove | 0:42add775212a | 339 | E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH, |
sam_grove | 0:42add775212a | 340 | EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0, |
sam_grove | 0:42add775212a | 341 | |
sam_grove | 0:42add775212a | 342 | CDC1 = 0x60, |
sam_grove | 0:42add775212a | 343 | CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1, |
sam_grove | 0:42add775212a | 344 | CDT2_CDT3, CDT4_CDT5, CDT6_CDT7, |
sam_grove | 0:42add775212a | 345 | |
sam_grove | 0:42add775212a | 346 | CDT8_CDT9 = 0x70, |
sam_grove | 0:42add775212a | 347 | CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET, |
sam_grove | 0:42add775212a | 348 | GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL, |
sam_grove | 0:42add775212a | 349 | |
sam_grove | 0:42add775212a | 350 | SRST = 0x80 |
sam_grove | 0:42add775212a | 351 | }; |
sam_grove | 0:42add775212a | 352 | |
sam_grove | 0:42add775212a | 353 | /** Create the MPR121 object |
sam_grove | 1:cee45334b36a | 354 | * @param i2c - A defined I2C object |
sam_grove | 1:cee45334b36a | 355 | * @param pin - A defined InterruptIn object |
sam_grove | 1:cee45334b36a | 356 | * @param i2c_addr - Connection of the address line |
sam_grove | 0:42add775212a | 357 | */ |
sam_grove | 0:42add775212a | 358 | MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr); |
sam_grove | 0:42add775212a | 359 | |
sam_grove | 5:3934358ec2b7 | 360 | /** Create the MPR121 object |
sam_grove | 5:3934358ec2b7 | 361 | * @param i2c - A defined I2C object |
sam_grove | 5:3934358ec2b7 | 362 | * @param i2c_addr - Connection of the address line |
sam_grove | 5:3934358ec2b7 | 363 | */ |
sam_grove | 5:3934358ec2b7 | 364 | MPR121(I2C &i2c, MPR121_ADDR i2c_addr); |
tulanthoar | 14:6bcd2f6a4fee | 365 | /** |
tulanthoar | 14:6bcd2f6a4fee | 366 | * @file MPR121.h |
tulanthoar | 14:6bcd2f6a4fee | 367 | * @brief Device driver - MPR121 capactiive touch IC |
tulanthoar | 14:6bcd2f6a4fee | 368 | * @author sam grove |
tulanthoar | 14:6bcd2f6a4fee | 369 | * @version 1.0 |
tulanthoar | 14:6bcd2f6a4fee | 370 | * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf |
tulanthoar | 14:6bcd2f6a4fee | 371 | * |
tulanthoar | 14:6bcd2f6a4fee | 372 | * Copyright (c) 2013 |
tulanthoar | 14:6bcd2f6a4fee | 373 | * |
tulanthoar | 14:6bcd2f6a4fee | 374 | * Licensed under the Apache License, Version 2.0 (the "License"); |
tulanthoar | 14:6bcd2f6a4fee | 375 | * you may not use this file except in compliance with the License. |
tulanthoar | 14:6bcd2f6a4fee | 376 | * You may obtain a copy of the License at |
tulanthoar | 14:6bcd2f6a4fee | 377 | * |
tulanthoar | 14:6bcd2f6a4fee | 378 | * http://www.apache.org/licenses/LICENSE-2.0 |
tulanthoar | 14:6bcd2f6a4fee | 379 | * |
tulanthoar | 14:6bcd2f6a4fee | 380 | * Unless required by applicable law or agreed to in writing, software |
tulanthoar | 14:6bcd2f6a4fee | 381 | * distributed under the License is distributed on an "AS IS" BASIS, |
tulanthoar | 14:6bcd2f6a4fee | 382 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
tulanthoar | 14:6bcd2f6a4fee | 383 | * See the License for the specific language governing permissions and |
tulanthoar | 14:6bcd2f6a4fee | 384 | * limitations under the License. |
tulanthoar | 14:6bcd2f6a4fee | 385 | */ |
tulanthoar | 14:6bcd2f6a4fee | 386 | |
tulanthoar | 14:6bcd2f6a4fee | 387 | #ifndef MPR121_H |
tulanthoar | 14:6bcd2f6a4fee | 388 | #define MPR121_H |
tulanthoar | 14:6bcd2f6a4fee | 389 | |
tulanthoar | 14:6bcd2f6a4fee | 390 | #include "mbed.h" |
tulanthoar | 14:6bcd2f6a4fee | 391 | #include "rtos.h" |
tulanthoar | 14:6bcd2f6a4fee | 392 | |
tulanthoar | 14:6bcd2f6a4fee | 393 | /** Using the Sparkfun SEN-10250 BoB |
tulanthoar | 14:6bcd2f6a4fee | 394 | * |
tulanthoar | 14:6bcd2f6a4fee | 395 | * Example: |
tulanthoar | 14:6bcd2f6a4fee | 396 | * @code |
tulanthoar | 14:6bcd2f6a4fee | 397 | * #include "mbed.h" |
tulanthoar | 14:6bcd2f6a4fee | 398 | * #include "MPR121.h" |
tulanthoar | 14:6bcd2f6a4fee | 399 | * |
tulanthoar | 14:6bcd2f6a4fee | 400 | * Serial pc(USBTX, USBRX); |
tulanthoar | 14:6bcd2f6a4fee | 401 | * DigitalOut myled(LED1); |
tulanthoar | 14:6bcd2f6a4fee | 402 | * |
tulanthoar | 14:6bcd2f6a4fee | 403 | * #if defined TARGET_LPC1768 || TARGET_LPC11U24 |
tulanthoar | 14:6bcd2f6a4fee | 404 | * I2C i2c(p28, p27); |
tulanthoar | 14:6bcd2f6a4fee | 405 | * InterruptIn irq(p26); |
tulanthoar | 14:6bcd2f6a4fee | 406 | * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS); |
tulanthoar | 14:6bcd2f6a4fee | 407 | * |
tulanthoar | 14:6bcd2f6a4fee | 408 | * #elif defined TARGET_KL25Z |
tulanthoar | 14:6bcd2f6a4fee | 409 | * I2C i2c(PTC9, PTC8); |
tulanthoar | 14:6bcd2f6a4fee | 410 | * InterruptIn irq(PTA5); |
tulanthoar | 14:6bcd2f6a4fee | 411 | * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS); |
tulanthoar | 14:6bcd2f6a4fee | 412 | * |
tulanthoar | 14:6bcd2f6a4fee | 413 | * #else |
tulanthoar | 14:6bcd2f6a4fee | 414 | * #error TARGET NOT TESTED |
tulanthoar | 14:6bcd2f6a4fee | 415 | * #endif |
tulanthoar | 14:6bcd2f6a4fee | 416 | * |
tulanthoar | 14:6bcd2f6a4fee | 417 | * int main() |
tulanthoar | 14:6bcd2f6a4fee | 418 | * { |
tulanthoar | 14:6bcd2f6a4fee | 419 | * touch_pad.init(); |
tulanthoar | 14:6bcd2f6a4fee | 420 | * touch_pad.enable(); |
tulanthoar | 14:6bcd2f6a4fee | 421 | * |
tulanthoar | 14:6bcd2f6a4fee | 422 | * while(1) |
tulanthoar | 14:6bcd2f6a4fee | 423 | * { |
tulanthoar | 14:6bcd2f6a4fee | 424 | * if(touch_pad.isPressed()) |
tulanthoar | 14:6bcd2f6a4fee | 425 | * { |
tulanthoar | 14:6bcd2f6a4fee | 426 | * uint16_t button_val = touch_pad.buttonPressed(); |
tulanthoar | 14:6bcd2f6a4fee | 427 | * printf("button = 0x%04x\n", button_val); |
tulanthoar | 14:6bcd2f6a4fee | 428 | * myled = (button_val>0) ? 1 : 0; |
tulanthoar | 14:6bcd2f6a4fee | 429 | * } |
tulanthoar | 14:6bcd2f6a4fee | 430 | * } |
tulanthoar | 14:6bcd2f6a4fee | 431 | * } |
tulanthoar | 14:6bcd2f6a4fee | 432 | * @endcode |
tulanthoar | 14:6bcd2f6a4fee | 433 | */ |
tulanthoar | 14:6bcd2f6a4fee | 434 | |
tulanthoar | 14:6bcd2f6a4fee | 435 | /** |
tulanthoar | 14:6bcd2f6a4fee | 436 | * @class MPR121 |
tulanthoar | 14:6bcd2f6a4fee | 437 | * @brief API for the MPR121 capacitive touch IC |
tulanthoar | 14:6bcd2f6a4fee | 438 | */ |
tulanthoar | 14:6bcd2f6a4fee | 439 | class MPR121 |
tulanthoar | 14:6bcd2f6a4fee | 440 | { |
tulanthoar | 14:6bcd2f6a4fee | 441 | private: |
tulanthoar | 14:6bcd2f6a4fee | 442 | |
tulanthoar | 14:6bcd2f6a4fee | 443 | I2C *_i2c; |
tulanthoar | 14:6bcd2f6a4fee | 444 | InterruptIn *_irq; |
tulanthoar | 14:6bcd2f6a4fee | 445 | uint8_t _i2c_addr; |
tulanthoar | 14:6bcd2f6a4fee | 446 | volatile uint16_t _button; |
tulanthoar | 14:6bcd2f6a4fee | 447 | volatile uint32_t _button_has_changed; |
tulanthoar | 14:6bcd2f6a4fee | 448 | |
tulanthoar | 14:6bcd2f6a4fee | 449 | /** The interrupt handler for the IRQ pin |
tulanthoar | 14:6bcd2f6a4fee | 450 | */ |
tulanthoar | 14:6bcd2f6a4fee | 451 | void handler(void); |
tulanthoar | 14:6bcd2f6a4fee | 452 | |
tulanthoar | 14:6bcd2f6a4fee | 453 | public: |
tulanthoar | 14:6bcd2f6a4fee | 454 | |
tulanthoar | 14:6bcd2f6a4fee | 455 | /** |
tulanthoar | 14:6bcd2f6a4fee | 456 | * @enum MPR121_ADDR |
tulanthoar | 14:6bcd2f6a4fee | 457 | * @brief Possible terminations for the ADDR pin |
tulanthoar | 14:6bcd2f6a4fee | 458 | */ |
tulanthoar | 14:6bcd2f6a4fee | 459 | enum MPR121_ADDR |
tulanthoar | 14:6bcd2f6a4fee | 460 | { |
tulanthoar | 14:6bcd2f6a4fee | 461 | ADDR_VSS = 0x5A, /*!< ADDR connected to VSS */ |
tulanthoar | 14:6bcd2f6a4fee | 462 | ADDR_VDD, /*!< ADDR connected to VDD */ |
tulanthoar | 14:6bcd2f6a4fee | 463 | ADDR_SCL, /*!< ADDR connected to SDA */ |
tulanthoar | 14:6bcd2f6a4fee | 464 | ADDR_SDA /*!< ADDR connected to SCL */ |
tulanthoar | 14:6bcd2f6a4fee | 465 | }; |
tulanthoar | 14:6bcd2f6a4fee | 466 | |
tulanthoar | 14:6bcd2f6a4fee | 467 | /** |
tulanthoar | 14:6bcd2f6a4fee | 468 | * @enum MPR121_REGISTER |
tulanthoar | 14:6bcd2f6a4fee | 469 | * @brief The device register map |
tulanthoar | 14:6bcd2f6a4fee | 470 | */ |
tulanthoar | 14:6bcd2f6a4fee | 471 | enum MPR121_REGISTER |
tulanthoar | 14:6bcd2f6a4fee | 472 | { |
tulanthoar | 14:6bcd2f6a4fee | 473 | ELE0_7_STAT = 0x00, |
tulanthoar | 14:6bcd2f6a4fee | 474 | ELE8_11_STAT, ELE0_7_OOR_STAT, ELE8_11_OOR_STAT, EFD0LB, EFD0HB, |
tulanthoar | 14:6bcd2f6a4fee | 475 | EFD1LB, EFD1HB, EFD2LB, EFD2HB, EFD3LB, EFD3HB, EFD4LB, EFD4HB, EFD5LB, EFD5HB, |
tulanthoar | 14:6bcd2f6a4fee | 476 | |
tulanthoar | 14:6bcd2f6a4fee | 477 | EFD6LB = 0x10, |
tulanthoar | 14:6bcd2f6a4fee | 478 | EFD6HB, EFD7LB, EFD7HB, EFD8LB, EFD8HB, EFD9LB, EFD9HB, EFD10LB, |
tulanthoar | 14:6bcd2f6a4fee | 479 | EFD10HB, EFD11LB, EFD11HB, EFDPROXLB, EFDPROXHB, E0BV, E1BV, |
tulanthoar | 14:6bcd2f6a4fee | 480 | |
tulanthoar | 14:6bcd2f6a4fee | 481 | E2BV = 0x20, |
tulanthoar | 14:6bcd2f6a4fee | 482 | E3BV, E4BV, E5BV, E6BV, E7BV, E8BV, E9BV, E10BV, E11BV, EPROXBV, |
tulanthoar | 14:6bcd2f6a4fee | 483 | MHDR, NHDR, NCLR, FDLR, MHDF, |
tulanthoar | 14:6bcd2f6a4fee | 484 | |
tulanthoar | 14:6bcd2f6a4fee | 485 | NHDF = 0x30, |
tulanthoar | 14:6bcd2f6a4fee | 486 | NCLF, FDLF, NHDT, NCLT, FDLT, MHDPROXR, NHDPROXR, NCLPROXR, |
tulanthoar | 14:6bcd2f6a4fee | 487 | FDLPROXR, MHDPROXF, NHDPROXF, NCLPROXF, FDLPROXF, NHDPROXT, NCLPROXT, |
tulanthoar | 14:6bcd2f6a4fee | 488 | |
tulanthoar | 14:6bcd2f6a4fee | 489 | FDLPROXT = 0x40, |
tulanthoar | 14:6bcd2f6a4fee | 490 | E0TTH, E0RTH, E1TTH, E1RTH, E2TTH, E2RTH, E3TTH, E3RTH, |
tulanthoar | 14:6bcd2f6a4fee | 491 | E4TTH, E4RTH, E5TTH, E5RTH, E6TTH, E6RTH, E7TTH, |
tulanthoar | 14:6bcd2f6a4fee | 492 | |
tulanthoar | 14:6bcd2f6a4fee | 493 | E7RTH = 0x50, |
tulanthoar | 14:6bcd2f6a4fee | 494 | E8TTH, E8RTH, E9TTH, E9RTH, E10TTH, E10RTH, E11TTH, E11RTH, |
tulanthoar | 14:6bcd2f6a4fee | 495 | EPROXTTH, EPROXRTH, DT_DR, CDC_CONFIG, CDT_CONFIG, ECR, CDC0, |
tulanthoar | 14:6bcd2f6a4fee | 496 | |
tulanthoar | 14:6bcd2f6a4fee | 497 | CDC1 = 0x60, |
tulanthoar | 14:6bcd2f6a4fee | 498 | CDC2, CDC3, CDC4, CDC5, CDC6, CDC7, CDC8, CDC9, CDC10, CDC11, CDCPROX, CDT0_CDT1, |
tulanthoar | 14:6bcd2f6a4fee | 499 | CDT2_CDT3, CDT4_CDT5, CDT6_CDT7, |
tulanthoar | 14:6bcd2f6a4fee | 500 | |
tulanthoar | 14:6bcd2f6a4fee | 501 | CDT8_CDT9 = 0x70, |
tulanthoar | 14:6bcd2f6a4fee | 502 | CDT10_CDT11, CDTPROX, GPIO_CTRL0, GPIO_CTRL1, GPIO_DATA, GPIO_DIR, GPIO_EN, GPIO_SET, |
tulanthoar | 14:6bcd2f6a4fee | 503 | GPIO_CLR, GPIO_TOGGLE, AUTO_CFG0, AUTO_CFG1, USL, LSL, TL, |
tulanthoar | 14:6bcd2f6a4fee | 504 | |
tulanthoar | 14:6bcd2f6a4fee | 505 | SRST = 0x80 |
tulanthoar | 14:6bcd2f6a4fee | 506 | }; |
tulanthoar | 14:6bcd2f6a4fee | 507 | |
tulanthoar | 14:6bcd2f6a4fee | 508 | /** Create the MPR121 object |
tulanthoar | 14:6bcd2f6a4fee | 509 | * @param i2c - A defined I2C object |
tulanthoar | 14:6bcd2f6a4fee | 510 | * @param pin - A defined InterruptIn object |
tulanthoar | 14:6bcd2f6a4fee | 511 | * @param i2c_addr - Connection of the address line |
tulanthoar | 14:6bcd2f6a4fee | 512 | */ |
tulanthoar | 14:6bcd2f6a4fee | 513 | MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr); |
tulanthoar | 14:6bcd2f6a4fee | 514 | |
tulanthoar | 14:6bcd2f6a4fee | 515 | /** Create the MPR121 object |
tulanthoar | 14:6bcd2f6a4fee | 516 | * @param i2c - A defined I2C object |
tulanthoar | 14:6bcd2f6a4fee | 517 | * @param i2c_addr - Connection of the address line |
tulanthoar | 14:6bcd2f6a4fee | 518 | */ |
tulanthoar | 14:6bcd2f6a4fee | 519 | MPR121(I2C &i2c, MPR121_ADDR i2c_addr); |
tulanthoar | 14:6bcd2f6a4fee | 520 | |
sam_grove | 3:828260f21de6 | 521 | /** Clear state variables and initilize the dependant objects |
sam_grove | 0:42add775212a | 522 | */ |
sam_grove | 0:42add775212a | 523 | void init(void); |
tulanthoar | 14:6bcd2f6a4fee | 524 | |
sam_grove | 0:42add775212a | 525 | /** Allow the IC to run and collect user input |
sam_grove | 0:42add775212a | 526 | */ |
sam_grove | 0:42add775212a | 527 | void enable(void); |
tulanthoar | 14:6bcd2f6a4fee | 528 | |
sam_grove | 0:42add775212a | 529 | /** Stop the IC and put into low power mode |
sam_grove | 0:42add775212a | 530 | */ |
sam_grove | 0:42add775212a | 531 | void disable(void); |
tulanthoar | 14:6bcd2f6a4fee | 532 | |
sam_grove | 0:42add775212a | 533 | /** Determine if a new button press event occured |
sam_grove | 0:42add775212a | 534 | * Upon calling the state is cleared until another press is detected |
sam_grove | 0:42add775212a | 535 | * @return 1 if a press has been detected since the last call, 0 otherwise |
sam_grove | 0:42add775212a | 536 | */ |
sam_grove | 0:42add775212a | 537 | uint32_t isPressed(void); |
tulanthoar | 14:6bcd2f6a4fee | 538 | |
sam_grove | 0:42add775212a | 539 | /** Get the electrode status (ELE12 ... ELE0 -> b15 xxx b11 ... b0 |
sam_grove | 0:42add775212a | 540 | * The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined |
sam_grove | 0:42add775212a | 541 | * @return The state of all buttons |
sam_grove | 0:42add775212a | 542 | */ |
sam_grove | 0:42add775212a | 543 | uint16_t buttonPressed(void); |
tulanthoar | 14:6bcd2f6a4fee | 544 | |
sam_grove | 0:42add775212a | 545 | /** print the register map and values to the console |
sam_grove | 3:828260f21de6 | 546 | * @param obj - a Serial object that prints to a console |
sam_grove | 0:42add775212a | 547 | */ |
sam_grove | 3:828260f21de6 | 548 | void registerDump(Serial &obj) const; |
tulanthoar | 14:6bcd2f6a4fee | 549 | |
sam_grove | 5:3934358ec2b7 | 550 | /** print the register map and values to the console |
sam_grove | 5:3934358ec2b7 | 551 | */ |
sam_grove | 5:3934358ec2b7 | 552 | void registerDump(void) const; |
tulanthoar | 14:6bcd2f6a4fee | 553 | |
sam_grove | 0:42add775212a | 554 | /** Write to a register (exposed for debugging reasons) |
sam_grove | 0:42add775212a | 555 | * Note: most writes are only valid in stop mode |
sam_grove | 1:cee45334b36a | 556 | * @param reg - The register to be written |
sam_grove | 1:cee45334b36a | 557 | * @param data - The data to be written |
sam_grove | 0:42add775212a | 558 | */ |
sam_grove | 3:828260f21de6 | 559 | void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const; |
tulanthoar | 14:6bcd2f6a4fee | 560 | |
sam_grove | 0:42add775212a | 561 | /** Read from a register (exposed for debugging reasons) |
sam_grove | 1:cee45334b36a | 562 | * @param reg - The register to read from |
sam_grove | 0:42add775212a | 563 | * @return The register contents |
sam_grove | 0:42add775212a | 564 | */ |
sam_grove | 3:828260f21de6 | 565 | uint8_t readRegister(MPR121_REGISTER const reg) const; |
tulanthoar | 14:6bcd2f6a4fee | 566 | |
sam_grove | 0:42add775212a | 567 | }; |
sam_grove | 0:42add775212a | 568 | |
sam_grove | 0:42add775212a | 569 | #endif |
Nathan Yonkee |
16:94e77e14a859 | 570 | >>>>>>> merge rev |