use mbed os

Dependents:   Seeed_Grove_I2C_Touch_Example

Fork of MPR121 by Sam Grove

Revision:
19:eaa64138290b
Parent:
15:8c7fba79a28e
Child:
22:b1fa74a5123b
--- a/MPR121.cpp	Sun Jul 02 17:34:58 2017 +0000
+++ b/MPR121.cpp	Sun Jul 02 11:55:42 2017 -0600
@@ -1,4 +1,3 @@
-<<<<<<< working copy
 /**
  * @file    MPR121.cpp
  * @brief   Device driver - MPR121 capactiive touch IC
@@ -26,7 +25,8 @@
 
 #define DEBUG 1
 
-MPR121::MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr) {
+MPR121::MPR121(I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr)
+{
     _i2c = &i2c;
     _irq = &pin;
     _i2c_addr = (i2c_addr << 1);
@@ -34,7 +34,8 @@
     return;
 }
 
-MPR121::MPR121(I2C &i2c, MPR121_ADDR fake) {
+MPR121::MPR121(I2C &i2c, MPR121_ADDR fake)
+{
     _i2c = &i2c;
     _irq = NULL;
     _i2c_addr = (0x1b << 1);
@@ -42,17 +43,18 @@
     int result=0;
     char data = 10;
     result = _i2c->write(_i2c_addr, reg, 1, true);
-    if(result == 0 ) debug("result is 0");
-    result = _i2c->read(_i2c_addr, &data, 1);
-    if(result == 0 ) debug("result is 0");
+        if(result == 0 ) debug("result is 0");
+    result = _i2c->read(_i2c_addr, &data, 1); 
+        if(result == 0 ) debug("result is 0");
 
     return;
 }
 
-void MPR121::init(void) {
+void MPR121::init(void)
+{
     // set the i2c speed
     /* _i2c->frequency(400000);
-    */
+ */
     // irq is open-collector and active-low
     if(_irq != NULL) {
         _irq->mode(PullUp);
@@ -103,7 +105,8 @@
     return;
 }
 
-void MPR121::enable(void) {
+void MPR121::enable(void)
+{
     _button = 0;
     _button_has_changed = 0;
     // enable the 12 electrodes - allow disable to put device into
@@ -117,7 +120,8 @@
     return;
 }
 
-void MPR121::disable(void) {
+void MPR121::disable(void)
+{
     // detach the interrupt handler
     _irq->fall(NULL);
     _button = 0;
@@ -130,36 +134,39 @@
     return;
 }
 
-uint32_t MPR121::isPressed(void) {
+uint32_t MPR121::isPressed(void)
+{
 
     char reg[1] = { 0x03 };
     int result=0;
     char data = -1;
     result = _i2c->write(_i2c_addr, reg, 1, true);
-    if(result == 0 ) debug("result is 0");
-    result = _i2c->read(_i2c_addr, &data, 1);
-    if(result == 0 ) debug("result is 0");
+        if(result == 0 ) debug("result is 0");
+    result = _i2c->read(_i2c_addr, &data, 1); 
+        if(result == 0 ) debug("result is 0");
     if(data > 0) data = true;
     return data;
     /* return _button_has_changed;
-    */
+ */
 }
 
-uint16_t MPR121::buttonPressed(void) {
+uint16_t MPR121::buttonPressed(void)
+{
     char reg[1] = { 0x03 };
     int result=0;
     char data = -1;
     result = _i2c->write(_i2c_addr, reg, 1, true);
-    if(result == 0 ) debug("result is 0");
-    result = _i2c->read(_i2c_addr, &data, 1);
-    if(result == 0 ) debug("result is 0");
+        if(result == 0 ) debug("result is 0");
+    result = _i2c->read(_i2c_addr, &data, 1); 
+        if(result == 0 ) debug("result is 0");
     if(data == 4) data = 3;
     if(data == 2) data = 2;
     if(data == 1) data = 1;
     return data;
 }
 
-void MPR121::registerDump(Serial &obj) const {
+void MPR121::registerDump(Serial &obj) const
+{
     uint8_t reg_val = 0;
 
     for(int i=0; i<0x80; i++) {
@@ -170,7 +177,8 @@
     return;
 }
 
-void MPR121::registerDump(void) const {
+void MPR121::registerDump(void) const
+{
     uint8_t reg_val = 0;
 
     for(int i=0; i<0x80; i++) {
@@ -181,7 +189,8 @@
     return;
 }
 
-void MPR121::handler(void) {
+void MPR121::handler(void)
+{
     uint16_t reg_val = 0, oor_val = 0;
     // read register 0 and 1
     reg_val  = MPR121::readRegister(ELE0_7_STAT);
@@ -204,28 +213,33 @@
     return;
 }
 
-void MPR121::writeRegister(MPR121_REGISTER const reg, uint8_t const data) const {
+void MPR121::writeRegister(MPR121_REGISTER const reg, uint8_t const data) const
+{
     char buf[2] = {reg, data};
     uint8_t result = 0;
 
     result = _i2c->write(_i2c_addr, buf, 2);
-    if(result && DEBUG) {
+    if(result && DEBUG)
+    {
         debug("I2C write failed\n");
     }
 
     return;
 }
 
-uint8_t MPR121::readRegister(MPR121_REGISTER const reg) const {
+uint8_t MPR121::readRegister(MPR121_REGISTER const reg) const
+{
     char buf[1] = {reg}, data = 0;
     uint8_t result = 1;
 
     result &= _i2c->write(_i2c_addr, buf, 1, true);
-    result &= _i2c->read(_i2c_addr, &data, 1);
-
-    if(result && DEBUG) {
+    result &= _i2c->read(_i2c_addr, &data, 1); 
+    
+    if(result && DEBUG)
+    {
         debug("I2C read failed\n");
     }
 
     return data;
 }
+