Capacitive touch sensor (8 probes) by Microchip

http://www.microchip.com/_images/ics/medium-CAP1298-QFN-16.png

"The CAP1298 is a turnkey capacitive touch controller providing a wide variety of button and proximity functionality, and making it easy for designers to add aesthetically pleasing, low-cost and robust touch interfaces. It also offers improved proximity detection with its Signal Guard option." (from Microchip website)

http://www.microchip.com/wwwproducts/en/CAP1298

Committer:
fskorup
Date:
Tue Jan 31 15:59:36 2017 +0000
Revision:
1:8b152c72eded
Parent:
0:3480c5e1f395
updated descriptors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fskorup 0:3480c5e1f395 1 /*
fskorup 0:3480c5e1f395 2 ___ ___ ___
fskorup 0:3480c5e1f395 3 /\ \ /\ \ /\ \
fskorup 0:3480c5e1f395 4 /::\ \ /::\ \ /::\ \
fskorup 0:3480c5e1f395 5 /:/\:\__\ /::\:\__\ /::\:\__\
fskorup 0:3480c5e1f395 6 \:\ \/__/ \/\::/ / \/\::/ /
fskorup 0:3480c5e1f395 7 \:\__\ /:/ / \/__/
fskorup 0:3480c5e1f395 8 \/__/ \/__/
fskorup 0:3480c5e1f395 9
fskorup 1:8b152c72eded 10 2016 Flow design labs, Project LEAF
fskorup 0:3480c5e1f395 11
fskorup 0:3480c5e1f395 12 //////////////////////////////////////////////////////
fskorup 0:3480c5e1f395 13 // CAP12xx_SEN - Sensitivity values - 1x minimum //
fskorup 0:3480c5e1f395 14 // 0x0F //128x sensitivity //
fskorup 0:3480c5e1f395 15 // 0x1F //64x sensitivity //
fskorup 0:3480c5e1f395 16 // 0x2F //32x sensitivity //
fskorup 0:3480c5e1f395 17 // 0x3F //16x sensitivity //
fskorup 0:3480c5e1f395 18 // 0x4F //8x sensitivity //
fskorup 0:3480c5e1f395 19 // 0x5F //4x sensitivity //
fskorup 0:3480c5e1f395 20 // 0x6F //2x sensitivity //
fskorup 0:3480c5e1f395 21 // 0x7F //1x sensitivity //
fskorup 0:3480c5e1f395 22 //////////////////////////////////////////////////////
fskorup 0:3480c5e1f395 23
fskorup 0:3480c5e1f395 24 * Example:
fskorup 0:3480c5e1f395 25 * @code
fskorup 0:3480c5e1f395 26 * //I2C i2c(p1, p2); //SDA, SCL lines
fskorup 0:3480c5e1f395 27 * //InterruptIn interrupt(p24);
fskorup 0:3480c5e1f395 28 * CAP12xx touch_pad(i2c, interrupt);
fskorup 0:3480c5e1f395 29 * CAP12xx touch_pad(p1, p2, p3);
fskorup 0:3480c5e1f395 30 * uint8_t probe = 0;
fskorup 0:3480c5e1f395 31 *
fskorup 0:3480c5e1f395 32 * int main(){
fskorup 0:3480c5e1f395 33 *
fskorup 0:3480c5e1f395 34 * printf("\n\rInitializing CAP12xx\n\r");
fskorup 0:3480c5e1f395 35 *
fskorup 0:3480c5e1f395 36 * if (touch_pad.init()) {
fskorup 0:3480c5e1f395 37 * printf("OK - CAP12xx detected\n\r");
fskorup 0:3480c5e1f395 38 * } else {
fskorup 0:3480c5e1f395 39 * printf("ERROR - CAP12xx not found, check connection\n\r"); //Based on chip revision this can happen. Library uses 0x01 chip revision for identification
fskorup 0:3480c5e1f395 40 * }
fskorup 0:3480c5e1f395 41 * touch_pad.enable();
fskorup 0:3480c5e1f395 42 *
fskorup 0:3480c5e1f395 43 * while(1) {
fskorup 0:3480c5e1f395 44 * if (touch_pad.touched()){
fskorup 0:3480c5e1f395 45 * printf("Touched - %u\n\r", touch_pad.identify_probe_touched());
fskorup 0:3480c5e1f395 46 * }
fskorup 0:3480c5e1f395 47 * }
fskorup 0:3480c5e1f395 48 * }
fskorup 0:3480c5e1f395 49 * @endcode
fskorup 0:3480c5e1f395 50 */
fskorup 0:3480c5e1f395 51
fskorup 0:3480c5e1f395 52 #ifndef CAP12xx_H
fskorup 0:3480c5e1f395 53 #define CAP12xx_H
fskorup 0:3480c5e1f395 54
fskorup 0:3480c5e1f395 55 #include "mbed.h"
fskorup 0:3480c5e1f395 56
fskorup 0:3480c5e1f395 57 #define CAP12xx_MAIN 0x00 //Controls power states and indicates an interrupt
fskorup 0:3480c5e1f395 58 #define CAP12xx_MINT 0x1 //Clears interrupts on touch
fskorup 0:3480c5e1f395 59 #define CAP12xx_SEN 0x1F //Controls the sensitivity of the threshold and delta counts and datascaling of the base counts
fskorup 0:3480c5e1f395 60 #define CAP12xx_MTC 0x2A //Determines the number of simultaneous touches to flag a multiple touch condition
fskorup 0:3480c5e1f395 61 #define CAP12xx_SIS 0x03 //Returns the state of the sampled capacitive touch sensor inputs
fskorup 0:3480c5e1f395 62 #define CAP12xx_PID 0xFD //Stores a fixed value that identifies the CAP12xx
fskorup 0:3480c5e1f395 63 #define CAP12xx_MID 0xFE //Stores a fixed value that identifies Microchip
fskorup 0:3480c5e1f395 64 #define CAP12xx_REV 0xFF //Stores a fixed value that represents the revision number
fskorup 0:3480c5e1f395 65 #define CAP12xx_ACT 0x24 //Controls averaging and sampling window for Active
fskorup 0:3480c5e1f395 66 #define CAP12xx_CAL 0x26 //Forces calibration for capacitive touch sensor inputs and indicates calibration failure
fskorup 0:3480c5e1f395 67 #define CAP12xx_ENA 0x27 //Determines which capacitive sensor inputs can generate interrupts
fskorup 0:3480c5e1f395 68 #define CAP12xx_IRP 0x28 //Turn off interrupt repeat on button hold
fskorup 0:3480c5e1f395 69 #define CAP12xx_GRD 0x29 //Enables the signal guard for specific sensor inputs
fskorup 0:3480c5e1f395 70 #define CAP12xx_STB 0x41 //Controls averaging and sensing cycle time for Standby
fskorup 0:3480c5e1f395 71 #define CAP12xx_IRR 0x44 //Set interrupt on press but not release - default 0x41
fskorup 0:3480c5e1f395 72
fskorup 0:3480c5e1f395 73 class CAP12xx
fskorup 0:3480c5e1f395 74 {
fskorup 0:3480c5e1f395 75 private:
fskorup 0:3480c5e1f395 76 I2C communication;
fskorup 0:3480c5e1f395 77 InterruptIn interrupt;
fskorup 0:3480c5e1f395 78 uint8_t core_address;
fskorup 0:3480c5e1f395 79 uint8_t probe;
fskorup 0:3480c5e1f395 80 uint8_t probe_touched;
fskorup 0:3480c5e1f395 81 void handler(void);
fskorup 0:3480c5e1f395 82
fskorup 0:3480c5e1f395 83 public:
fskorup 0:3480c5e1f395 84 CAP12xx(PinName SDA, PinName SCL, PinName interrupt_pin);
fskorup 0:3480c5e1f395 85 bool init();
fskorup 0:3480c5e1f395 86 void enable(void);
fskorup 0:3480c5e1f395 87 void disable(void);
fskorup 0:3480c5e1f395 88 uint8_t touched(void);
fskorup 0:3480c5e1f395 89 uint8_t identifyProbeTouched(void);
fskorup 0:3480c5e1f395 90 void setSensitivity(char level);
fskorup 0:3480c5e1f395 91 void writeRegister(char address, char data);
fskorup 0:3480c5e1f395 92 uint8_t readRegister(char address);
fskorup 0:3480c5e1f395 93 uint8_t inspect(void);
fskorup 0:3480c5e1f395 94 };
fskorup 0:3480c5e1f395 95
fskorup 0:3480c5e1f395 96 #endif