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:
2:4c0d4b90a3ed
Parent:
1:cee45334b36a
Child:
3:828260f21de6
--- a/MPR121.cpp	Thu Mar 07 23:57:27 2013 +0000
+++ b/MPR121.cpp	Fri Mar 29 21:32:38 2013 +0000
@@ -150,7 +150,7 @@
     for(int i=0; i<0x80; i++)
     {
         reg_val = MPR121::readRegister(i);
-        printf("Reg 0x%02x: 0x%02x \n", i, reg_val);
+        LOG("Reg 0x%02x: 0x%02x \n", i, reg_val);
     }
     
     return;
@@ -168,7 +168,7 @@
     
     if(0 != oor_val)
     {
-        error("%s %d: MPR121 OOR failure - 0x%04x\n", __FILE__, __LINE__, oor_val);
+        ERROR("MPR121 OOR failure - 0x%04x\n", oor_val);
     }
    
     _button = reg_val;
@@ -188,7 +188,7 @@
     
     if(0 != result)
     {
-        error("%s %d: I2c write failed\n", __FILE__, __LINE__);
+        ERROR("I2c write failed\n");
     }
     
     return;
@@ -196,6 +196,30 @@
 
 uint8_t MPR121::readRegister(uint8_t const reg) const
 {
+    // from https://github.com/mbedmicro/mbed/blob/master/libraries/tests/peripherals/MMA8451Q/MMA8451Q.cpp
+//    char t[1] = {reg};
+//    uint8_t data;
+//    _i2c->write(_i2c_addr, t, 1, true);
+//    _i2c->read(_i2c_addr, (char *)data, 1);
+//    return data;
+
+    // modified and still wont work - need a scope
+//    char buf[1] = {reg};
+//    uint8_t w_result = 0, r_result = 0;
+//    uint8_t data;
+//    
+//    __disable_irq();
+//    w_result = _i2c->write(_i2c_addr, buf, 1, true);
+//    r_result = _i2c->read(_i2c_addr, (char *)&data, 2);
+//    __enable_irq();
+//    
+//    if((0 != w_result) || (0 != r_result))
+//    {
+//        ERROR("I2c read failed: %d, %d\n", w_result, r_result);
+//    }
+//    
+//    return (uint8_t)data;
+    
     uint8_t result = 1, data = 0;
     
     __disable_irq(); // Tickers and other timebase events can jack up the I2C bus
@@ -212,7 +236,7 @@
     
     if(1 != result)
     {
-        error("%s %d: I2C read failed\n", __FILE__, __LINE__);
+        ERROR("I2C read failed\n");
     }
     
     return data;