Sensorian  1.0
C API Reference Guide Library
CAP1203.c
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
28 #include "CAP1203.h"
29 
33 
40 void CAP1203_Initialize(void)
41 {
42  CAP1203_ActiveMode(); //All three sensors are monitored in Active mode
43  CAP1203_Write(SENSINPUTEN,CS1|CS2|CS3); //Set active inputs
44  CAP1203_Write(AVERAGE_SAMP_CONF, AVG|SAMP_TIME|CYCLE_TIME); //Setup averaging and sampling time
45 }
46 
51 unsigned char CAP1203_ActiveMode(void)
52 {
53  unsigned char status = CAP1203_Read(MAIN_CTRL_REG);
54  status &= ~STBY;
57 }
58 
63 unsigned char CAP1203_StandbyMode(void)
64 {
65  CAP1203_Write(STANDBY_SENS,0x07); //Set sensitivity in standby mode
66  unsigned char status = CAP1203_Read(MAIN_CTRL_REG);
67  status |= STBY;
70 }
71 
76 unsigned char CAP1203_DeepSleep(void)
77 {
78  unsigned char status = CAP1203_Read(MAIN_CTRL_REG);
79  status |= SLEEP; //Set Sleep bit
80  CAP1203_Write(MAIN_CTRL_REG,status); //Update register
82 }
83 
88 unsigned char CAP1203_ResumeFromDeepSleep(void)
89 {
90  unsigned char status = CAP1203_Read(MAIN_CTRL_REG);
91  status &= ~SLEEP;
94 }
95 
102 void CAP1203_ConfigureMultiTouch(touch_type number,unsigned char mulchan )
103 {
104  CAP1203_Write(MULTITOUCH,((unsigned char)number)|MULTBLK_EN); //Set number of simultaneous touches
106  CAP1203_Write(MULTIPATTERN,mulchan);
107 }
108 
113 unsigned char CAP1203_MultitouchEvent(void)
114 {
115  unsigned char mt = 0;
116  unsigned char multi = CAP1203_Read(GEN_STATUS);
117  if((multi & MULT) == MULT)
118  {
119  mt = 1;
120  }
121  return mt;
122 }
123 
130 {
131  CAP1203_Write(PWR_BUTTON,button);
132  CAP1203_Write(PWR_CONFIG,PWR_EN|TIME1120ms); //Configure as power button in Active mode
133 }
134 
135 
140 unsigned char CAP1203_ReadPowerButton(void)
141 {
142  unsigned char pressed = 0;
143  unsigned char button = CAP1203_Read(GEN_STATUS);
144 
145  if (button & PWR)
146  {
147  pressed = 1;
148  }else{
149  pressed = 0;
150  }
151  return pressed;
152 }
153 
158 unsigned char CAP1203_ReadPressedButton(void)
159 {
160  unsigned char buttonPressed = 0;
161  unsigned char status = CAP1203_GetStatusReg(); //Check if touch bit was registered
162  if (status & TOUCH)
163  {
164  unsigned char button = CAP1203_Read(SENSOR_INPUTS);
165  switch(button)
166  {
167  case CS1:
168  buttonPressed = 3;
169  break;
170  case CS2:
171  buttonPressed = 2;
172  break;
173  case CS3:
174  buttonPressed = 1;
175  break;
176  default:
177  buttonPressed = 0;
178  break;
179  }
180  }
181  CAP1203_Write(MAIN_CTRL_REG,0x00); //Clear interrupt
182  return buttonPressed;
183 }
184 
189 unsigned char CAP1203_GetStatusReg(void)
190 {
191  unsigned char status = CAP1203_Read(GEN_STATUS);
192  return status;
193 }
194 
201 {
202  CAP1203_Write(REPEAT_RATE,pin); //Enable repeat rate for the input pins
203  CAP1203_Write(INT_ENABLE,pin); //2:0 c2:c1:c0 last three bits are the specific channels
204 }
205 
212 {
213  CAP1203_Write(0x00,sensitivity);
214 }
215 
220 unsigned char CAP1203_CheckSensorStatus(void)
221 {
222  unsigned char sensor = 0;
223 
224  return sensor;
225 }
226 
231 unsigned char CAP1203_ClearInterrupt(void)
232 {
233  unsigned char intStatus = 0x00;
235  return intStatus;
236 }
237 
242 unsigned int CAP1203_ReadID(void)
243 {
244  unsigned char id = CAP1203_Read(PRODUCT_ID);
245  unsigned char manu = CAP1203_Read(MAN_ID);
246  return ((manu << 8)|id);
247 }
248 
250 
256 void CAP1203_Write(unsigned char reg, unsigned char data)
257 {
258  I2C_WriteByteRegister(reg,data); //Write data to register reg
259 }
260 
266 unsigned char CAP1203_Read(unsigned char reg)
267 {
268  unsigned char value = I2C_ReadByteRegister(reg);
269 
270  return value;
271 }
unsigned char CAP1203_MultitouchEvent(void)
Return true if a multitouch event was detected.
Definition: CAP1203.c:114
unsigned char CAP1203_StandbyMode(void)
Configures the controller in standby mode.
Definition: CAP1203.c:64
button_type
Definition: CAP1203.h:211
#define REPEAT_RATE
Definition: CAP1203.h:54
#define MAIN_CTRL_REG
Definition: CAP1203.h:39
#define MTP_TH1
Definition: CAP1203.h:173
#define SENSINPUTEN
Definition: CAP1203.h:48
#define CS1
Definition: CAP1203.h:99
#define CS3
Definition: CAP1203.h:97
unsigned char CAP1203_ReadPressedButton(void)
Return id indicating which button was pressed.
Definition: CAP1203.c:159
#define MULT
Definition: CAP1203.h:92
unsigned char CAP1203_ReadPowerButton(void)
Read the status of the power button.
Definition: CAP1203.c:141
void CAP1203_Initialize(void)
Basic configuration for the capacitive touch controller. Configures the sensor inactive mode and acti...
Definition: CAP1203.c:41
#define TOUCH
Definition: CAP1203.h:94
#define INT_ENABLE
Definition: CAP1203.h:53
#define PWR_BUTTON
Definition: CAP1203.h:73
#define PWR_EN
Definition: CAP1203.h:185
#define MULTITOUCH
Definition: CAP1203.h:55
#define MAN_ID
Definition: CAP1203.h:81
unsigned char CAP1203_Read(unsigned char reg)
Reads data from register reg address.
Definition: CAP1203.c:267
#define CYCLE_TIME
Definition: CAP1203.h:164
void I2C_WriteByteRegister(unsigned char reg, unsigned char data)
Writes a byte value to a register address.
Definition: i2c.c:66
void CAP1203_SetSensitivity(sensitivity_type sensitivity)
Sets the sensitivity of each channel.
Definition: CAP1203.c:212
sensitivity_type
Definition: CAP1203.h:229
unsigned char CAP1203_CheckSensorStatus(void)
Checks the sensor status.
Definition: CAP1203.c:221
void CAP1203_EnableInterrupt(button_type pin)
Enable interrupt, the ALERT pin goes high once an interrupt occurs.
Definition: CAP1203.c:201
#define SAMP_TIME
Definition: CAP1203.h:163
touch_type
Definition: CAP1203.h:194
#define MULTIPATCONF
Definition: CAP1203.h:56
#define PRODUCT_ID
Definition: CAP1203.h:80
#define STANDBY_SENS
Definition: CAP1203.h:67
#define AVERAGE_SAMP_CONF
Definition: CAP1203.h:51
#define PWR_CONFIG
Definition: CAP1203.h:74
void CAP1203_SetPowerButton(button_type button)
Configures the button as a power button.
Definition: CAP1203.c:130
void CAP1203_ConfigureMultiTouch(touch_type number, unsigned char mulchan)
Enables the multi-touch capability of the controller.
Definition: CAP1203.c:103
#define GEN_STATUS
Definition: CAP1203.h:40
#define TIME1120ms
Definition: CAP1203.h:188
#define MTP_TH0
Definition: CAP1203.h:174
CAP1203 driver header.
unsigned char CAP1203_ResumeFromDeepSleep(void)
Takes the controller out of deep sleep mode.
Definition: CAP1203.c:89
unsigned char CAP1203_ActiveMode(void)
Configures the controller in active mode.
Definition: CAP1203.c:52
unsigned char CAP1203_GetStatusReg(void)
Reads the status register.
Definition: CAP1203.c:190
#define STBY
Definition: CAP1203.h:85
#define AVG
Definition: CAP1203.h:162
#define PWR
Definition: CAP1203.h:91
#define MULTBLK_EN
Definition: CAP1203.h:167
unsigned char I2C_ReadByteRegister(char reg)
Reads a byte from a register.
Definition: i2c.c:122
unsigned char CAP1203_ClearInterrupt(void)
Clears any impending interrupts.
Definition: CAP1203.c:232
unsigned int CAP1203_ReadID(void)
Returns product chip and manufacturing ID.
Definition: CAP1203.c:243
#define SENSOR_INPUTS
Definition: CAP1203.h:41
void CAP1203_Write(unsigned char reg, unsigned char data)
Write data value to register address.
Definition: CAP1203.c:257
unsigned char CAP1203_DeepSleep(void)
Configures the controller in deep sleep mode.
Definition: CAP1203.c:77
#define MULTIPATTERN
Definition: CAP1203.h:57
#define MTP_EN
Definition: CAP1203.h:172
#define CS2
Definition: CAP1203.h:98
#define SLEEP
Definition: CAP1203.h:86
#define COMP_PTRN
Definition: CAP1203.h:175
#define MTP_ALERT
Definition: CAP1203.h:176