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 
29 #include "CAP1203.h"
30 
34 
42 {
43  CAP1203_ActiveMode(); //All three sensors are monitored in Active mode
44  CAP1203_Write(SENSINPUTEN,CS1|CS2|CS3); //Set active inputs
45  CAP1203_Write(AVERAGE_SAMP_CONF, AVG|SAMP_TIME|CYCLE_TIME); //Setup averaging and sampling time
46 }
47 
52 unsigned char CAP1203_ActiveMode(void)
53 {
54  unsigned char status = CAP1203_Read(MAIN_CTRL_REG);
55  status &= ~STBY;
58 }
59 
64 unsigned char CAP1203_StandbyMode(void)
65 {
66  CAP1203_Write(STANDBY_SENS,0x07); //Set sensitivity in standby mode
67  unsigned char status = CAP1203_Read(MAIN_CTRL_REG);
68  status |= STBY;
71 }
72 
77 unsigned char CAP1203_DeepSleep(void)
78 {
79  unsigned char status = CAP1203_Read(MAIN_CTRL_REG);
80  status |= SLEEP; //Set Sleep bit
81  CAP1203_Write(MAIN_CTRL_REG,status); //Update register
83 }
84 
89 unsigned char CAP1203_ResumeFromDeepSleep(void)
90 {
91  unsigned char status = CAP1203_Read(MAIN_CTRL_REG);
92  status &= ~SLEEP;
95 }
96 
103 void CAP1203_ConfigureMultiTouch(touch_type number,unsigned char mulchan )
104 {
105  CAP1203_Write(MULTITOUCH,((unsigned char)number)|MULTBLK_EN); //Set number of simultaneous touches
107  CAP1203_Write(MULTIPATTERN,mulchan);
108 }
109 
114 unsigned char CAP1203_MultitouchEvent(void)
115 {
116  unsigned char mt = 0;
117  unsigned char multi = CAP1203_Read(GEN_STATUS);
118  if((multi & MULT) == MULT)
119  {
120  mt = 1;
121  }
122  return mt;
123 }
124 
131 {
132  CAP1203_Write(PWR_BUTTON,button);
133  CAP1203_Write(PWR_CONFIG,PWR_EN|TIME1120ms); //Configure as power button in Active mode
134 }
135 
136 
141 unsigned char CAP1203_ReadPowerButton(void)
142 {
143  unsigned char pressed = 0;
144  unsigned char button = CAP1203_Read(GEN_STATUS);
145 
146  if (button & PWR)
147  {
148  pressed = 1;
149  }else{
150  pressed = 0;
151  }
152  return pressed;
153 }
154 
159 unsigned char CAP1203_ReadPressedButton(void)
160 {
161  unsigned char buttonPressed = 0;
162  unsigned char status = CAP1203_GetStatusReg(); //Check if touch bit was registered
163  if (status & TOUCH)
164  {
165  unsigned char button = CAP1203_Read(SENSOR_INPUTS);
166  switch(button)
167  {
168  case CS1:
169  buttonPressed = 3;
170  break;
171  case CS2:
172  buttonPressed = 2;
173  break;
174  case CS3:
175  buttonPressed = 1;
176  break;
177  default:
178  buttonPressed = 0;
179  break;
180  }
181  }
182  CAP1203_Write(MAIN_CTRL_REG,0x00); //Clear interrupt
183  return buttonPressed;
184 }
185 
190 unsigned char CAP1203_GetStatusReg(void)
191 {
192  unsigned char status = CAP1203_Read(GEN_STATUS);
193  return status;
194 }
195 
202 {
203  CAP1203_Write(REPEAT_RATE,pin); //Enable repeat rate for the input pins
204  CAP1203_Write(INT_ENABLE,pin); //2:0 c2:c1:c0 last three bits are the specific channels
205 }
206 
213 {
214  CAP1203_Write(0x00,sensitivity);
215 }
216 
221 unsigned char CAP1203_CheckSensorStatus(void)
222 {
223  unsigned char sensor = 0;
224 
225  return sensor;
226 }
227 
232 unsigned char CAP1203_ClearInterrupt(void)
233 {
234  unsigned char intStatus = 0x00;
236  return intStatus;
237 }
238 
243 unsigned int CAP1203_ReadID(void)
244 {
245  unsigned char id = CAP1203_Read(PRODUCT_ID);
246  unsigned char manu = CAP1203_Read(MAN_ID);
247  return ((manu << 8)|id);
248 }
249 
251 
257 void CAP1203_Write(unsigned char reg, unsigned char data)
258 {
259  I2C_WriteByteRegister(reg,data); //Write data to register reg
260 }
261 
267 unsigned char CAP1203_Read(unsigned char reg)
268 {
269  unsigned char value = I2C_ReadByteRegister(reg);
270 
271  return value;
272 }
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
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
CAP1203 driver header.
#define MTP_ALERT
Definition: CAP1203.h:176