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!!
Diff: MPR121.cpp
- Revision:
- 1:cee45334b36a
- Parent:
- 0:42add775212a
- Child:
- 2:4c0d4b90a3ed
--- 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;