A device driver for the Freescale MPR121 capactive touch IC. Not optimized for any particular system, just a starting point to get the chip up in running in no time. Changes to registers init() method will tailor the library for end system use.

Dependents:   Seeed_Grove_I2C_Touch_Example MPR121_HelloWorld mbed_petbottle_holder_shikake test_DEV-10508 ... more

Datasheet:

http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf

Information

Must add pull-ups to the I2C bus!!

Files at this revision

API Documentation at this revision

Comitter:
sam_grove
Date:
Thu Mar 07 23:57:27 2013 +0000
Parent:
0:42add775212a
Child:
2:4c0d4b90a3ed
Commit message:
Updated enable and disable members to put the device in a lower power mode when not in use.

Changed in this revision

MPR121.cpp Show annotated file Show diff for this revision Revisions of this file
MPR121.h Show annotated file Show diff for this revision Revisions of this file
--- a/MPR121.cpp	Thu Mar 07 19:25:08 2013 +0000
+++ b/MPR121.cpp	Thu Mar 07 23:57:27 2013 +0000
@@ -109,6 +109,10 @@
 {
     _button = 0;
     _button_has_changed = 0;
+    // enable the 12 electrodes - allow disable to put device into
+    //  lower current consumption mode
+    MPR121::writeRegister(ECR, 0x8f);
+    // and attach the interrupt handler
     _irq->fall(this, &MPR121::handler);
     
     return;
@@ -116,9 +120,14 @@
 
 void MPR121::disable(void)
 {
+    // detach the interrupt handler
     _irq->fall(NULL);
     _button = 0;
     _button_has_changed = 0;
+    //  put the device in low current consumption mode - dont re-init registers
+    MPR121::writeRegister(ECR, 0x0);
+    MPR121::writeRegister(AUTO_CFG0, 0x0); // REG 0x7B
+    MPR121::writeRegister(AUTO_CFG1, 0x0); // REG 0x7C
     
     return;
 }
@@ -134,7 +143,7 @@
     return _button;
 }
 
-void MPR121::registerDump(void)
+void MPR121::registerDump(void) const
 {
     uint8_t reg_val = 0;
     
@@ -168,7 +177,7 @@
     return;
 }
 
-void MPR121::writeRegister(uint8_t reg, uint8_t data)
+void MPR121::writeRegister(uint8_t const reg, uint8_t const data) const
 {
     char buf[2] = {reg, data};
     uint8_t result = 0;
@@ -185,7 +194,7 @@
     return;
 }
 
-uint8_t MPR121::readRegister(uint8_t reg)
+uint8_t MPR121::readRegister(uint8_t const reg) const
 {
     uint8_t result = 1, data = 0;
     
--- a/MPR121.h	Thu Mar 07 19:25:08 2013 +0000
+++ b/MPR121.h	Thu Mar 07 23:57:27 2013 +0000
@@ -137,9 +137,9 @@
     };
     
     /** Create the MPR121 object
-     *  @param i2c A defined I2C object
-     *  @param pin A defined InterruptIn object
-     *  @param i2c_addr Connection of the address line
+     *  @param i2c - A defined I2C object
+     *  @param pin - A defined InterruptIn object
+     *  @param i2c_addr - Connection of the address line
      */    
     MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
     
@@ -169,20 +169,20 @@
     
     /** print the register map and values to the console
      */
-    void registerDump(void);
+    void registerDump(void) const;
     
     /** Write to a register (exposed for debugging reasons)
      *  Note: most writes are only valid in stop mode
-     *  @param reg The register to be written
-     *  @param data The data to be written
+     *  @param reg - The register to be written
+     *  @param data - The data to be written
      */
-    void writeRegister(uint8_t reg, uint8_t data);
+    void writeRegister(uint8_t const reg, uint8_t const data) const;
     
     /** Read from a register (exposed for debugging reasons)
-     *  @param reg The register to read from
+     *  @param reg - The register to read from
      *  @return The register contents
      */
-    uint8_t readRegister(uint8_t reg);
+    uint8_t readRegister(uint8_t const reg) const;
     
 };