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!!

Revision:
3:828260f21de6
Parent:
2:4c0d4b90a3ed
Child:
5:3934358ec2b7
Child:
7:eb4012317732
--- a/MPR121.h	Fri Mar 29 21:32:38 2013 +0000
+++ b/MPR121.h	Tue Aug 27 21:39:33 2013 +0000
@@ -24,58 +24,52 @@
 #define MPR121_H
 
 #include "mbed.h"
-#include "LogUtil.h"
 
-/** Using the Sparkfun SEN-10250
+/** Using the Sparkfun SEN-10250 BoB
  *
  * Example:
  * @code
- * #include "mbed.h"
- * #include "MPR121.h"
- * 
- * // TODO: put IC in low power mode when disabled
- * 
- * DigitalOut myled(LED1);
- * DigitalOut off(LED4);
- * Timer t;
- * 
- * LogUtil logger;
- * 
- * I2C i2c(p28, p27);
- * InterruptIn irq(p26);
- * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
- * 
- * int main() 
- * {       
- *     touch_pad.init();
- *     touch_pad.enable();
- *     t.start();
- *     while(1)
- *     {
- *         if(touch_pad.isPressed())
- *         {
- *             uint16_t button_val = touch_pad.buttonPressed();
- *             LOG("button = 0x%04x\n", button_val);
- *             myled = (button_val>0) ? 1 : 0;
- *         }
- *         if(t.read_ms() > 5000)
- *         {
- *             touch_pad.disable();
- *             off = 1;
- *             wait(5.0f);
- *             off = 0;
- *             touch_pad.enable();
- *             t.reset();
- *         }
- *             
- *     }
- * }
+ *  #include "mbed.h"
+ *  #include "MPR121.h"
+ *  
+ *  Serial pc(USBTX, USBRX);
+ *  DigitalOut myled(LED1);
+ *  
+ *  #if defined TARGET_LPC1768 || TARGET_LPC11U24
+ *    I2C i2c(p28, p27);
+ *    InterruptIn irq(p26);
+ *    MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
+ *  
+ *  #elif defined TARGET_KL25Z
+ *    I2C i2c(PTC9, PTC8);
+ *    InterruptIn irq(PTA5);
+ *    MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
+ *  
+ *  #else
+ *    #error TARGET NOT TESTED
+ *  #endif
+ *  
+ *  int main()  
+ *  {       
+ *      touch_pad.init();
+ *      touch_pad.enable();
+ *      
+ *      while(1)
+ *      {
+ *          if(touch_pad.isPressed())
+ *          {
+ *              uint16_t button_val = touch_pad.buttonPressed();
+ *              printf("button = 0x%04x\n", button_val);
+ *              myled = (button_val>0) ? 1 : 0;
+ *          }            
+ *      }
+ *  }
  * @endcode
  */
 
 /**
  *  @class MPR121
- *  @brief API abstraction for the MPR121 capacitive touch IC
+ *  @brief API for the MPR121 capacitive touch IC
  */ 
 class MPR121
 {
@@ -153,7 +147,7 @@
      */    
     MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr);
     
-    /** Clear state vars and initilize the dependant objects
+    /** Clear state variables and initilize the dependant objects
      */
     void init(void);
     
@@ -178,21 +172,22 @@
     uint16_t buttonPressed(void);
     
     /** print the register map and values to the console
+     *  @param obj - a Serial object that prints to a console
      */
-    void registerDump(void) const;
+    void registerDump(Serial &obj) 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
      */
-    void writeRegister(uint8_t const reg, uint8_t const data) const;
+    void writeRegister(MPR121_REGISTER const reg, uint8_t const data) const;
     
     /** Read from a register (exposed for debugging reasons)
      *  @param reg - The register to read from
      *  @return The register contents
      */
-    uint8_t readRegister(uint8_t const reg) const;
+    uint8_t readRegister(MPR121_REGISTER const reg) const;
     
 };