-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIQS263.c
174 lines (121 loc) · 4.98 KB
/
IQS263.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
******************************************************************************
* File Name : IQS263.c
* Description : This file contains the common defines of the application
******************************************************************************
*
* COPYRIGHT(c) 2017 Akash kapashia
* Created by Akash kapashia
******************************************************************************
*/
#include "IQS263.h"
#include "stm32l0xx_hal.h"
static int PROX_THRESHOLD = 0x10; //0x10
static int TOUCH_THRESHOLD = 0x20;
static int TOUCH_THRESHOLD_CH1 = 0x20; //0x20
static int TOUCH_THRESHOLD_CH2 = 0x20; //0x20
static int TOUCH_THRESHOLD_CH3 = 0x20; //0x20
static int MOVEMENT_THRESHOLD = 0x03;
static int RESEED_BLOCK = 0x00;
static int HALT_TIME = 0x00;
static int I2C_TIMEOUT = 0x04;
uint8_t CH1_Event=0;
uint8_t CH2_Event=0;
uint8_t CH3_Event=0;
uint8_t IQS263_Threshold[8];
extern I2C_HandleTypeDef hi2cxt;
/**
*
* @param NONE
* @return NONE
*/
void Init_IQS263( )
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin : SD_CS_Pin */
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
uint8_t data_buffer[8]={0};
HAL_Delay(10);
/*....................READING SYSTEM FLAGS..........................*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
HAL_I2C_Mem_Read( &hi2cxt, IQS263_ADD, (uint8_t)SYS_FLAGS, I2C_MEMADD_SIZE_8BIT, data_buffer, 2,50);
while (HAL_I2C_GetState(&hi2cxt) != HAL_I2C_STATE_READY)
{
}
/*....................READING DEVICE INFO..........................*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
HAL_I2C_Mem_Read(&hi2cxt, IQS263_ADD,( uint8_t ) DEVICE_INFO, I2C_MEMADD_SIZE_8BIT, &data_buffer[0],2, 70);
while (HAL_I2C_GetState(&hi2cxt) != HAL_I2C_STATE_READY)
{
}
/*....................READING ACTIVE CHANNELS..........................*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
HAL_I2C_Mem_Read( &hi2cxt, IQS263_ADD, ACTIVE_CHANNELS, I2C_MEMADD_SIZE_8BIT, data_buffer, 1,60);
while (HAL_I2C_GetState(&hi2cxt) != HAL_I2C_STATE_READY)
{
}
/*....................READING THRESHOLDS..........................*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
HAL_I2C_Mem_Read( &hi2cxt, IQS263_ADD, THRESHOLDS, I2C_MEMADD_SIZE_8BIT, IQS263_Threshold, 8,60);
while (HAL_I2C_GetState(&hi2cxt) != HAL_I2C_STATE_READY)
{
}
/*....................WRITING THRESHOLDS..........................*/
IQS263_Threshold[0]= PROX_THRESHOLD ; //0x10
IQS263_Threshold[1]= TOUCH_THRESHOLD ;
IQS263_Threshold[2]= TOUCH_THRESHOLD_CH1 ; //0x20
IQS263_Threshold[3]= TOUCH_THRESHOLD_CH2 ; //0x20
IQS263_Threshold[4]= TOUCH_THRESHOLD_CH3 ; //
IQS263_Threshold[5]= 14 ; //
IQS263_Threshold[6]= HALT_TIME ;
IQS263_Threshold[7]=250;
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
HAL_I2C_Mem_Write( &hi2cxt, IQS263_ADD, THRESHOLDS, I2C_MEMADD_SIZE_8BIT, IQS263_Threshold, 8,60);
while (HAL_I2C_GetState(&hi2cxt) != HAL_I2C_STATE_READY)
{
}
while (HAL_I2C_IsDeviceReady(&hi2cxt, IQS263_ADD, 10, 300) == HAL_TIMEOUT);
/*....................READING THRESHOLDS..........................*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
HAL_I2C_Mem_Read( &hi2cxt, IQS263_ADD, THRESHOLDS, I2C_MEMADD_SIZE_8BIT, IQS263_Threshold, 8,60);
while (HAL_I2C_GetState(&hi2cxt) != HAL_I2C_STATE_READY)
{
}
while (HAL_I2C_IsDeviceReady(&hi2cxt, IQS263_ADD, 10, 300) == HAL_TIMEOUT);
/*....................READING PROXI SETTING..........................*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
HAL_I2C_Mem_Read( &hi2cxt, IQS263_ADD, PROX_SETTINGS, I2C_MEMADD_SIZE_8BIT, data_buffer, 5,60);
while (HAL_I2C_GetState(&hi2cxt) != HAL_I2C_STATE_READY)
{
}
while (HAL_I2C_IsDeviceReady(&hi2cxt, IQS263_ADD, 10, 300) == HAL_TIMEOUT);
/*....................WRITING PROXI SETTING..........................*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
data_buffer[0]=0;
data_buffer[2]=8;
HAL_I2C_Mem_Write( &hi2cxt, IQS263_ADD, PROX_SETTINGS, I2C_MEMADD_SIZE_8BIT, data_buffer, 5, 60);
while (HAL_I2C_GetState(&hi2cxt) != HAL_I2C_STATE_READY)
{
}
while (HAL_I2C_IsDeviceReady(&hi2cxt, IQS263_ADD, 10, 300) == HAL_TIMEOUT);
}
/**
*
* @param NONE
* @return NONE
*/
void IQS263_READ_TOUCH_Events(){
uint8_t data[2]={0};
/*....................READING TOUCH EVENTS..........................*/
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==1);
HAL_I2C_Mem_Read(&hi2cxt, IQS263_ADD, TOUCH_BYTES, I2C_MEMADD_SIZE_8BIT,data,1,70);
CH1_Event=data[0]&0x02;
CH2_Event=data[0]&0x04;
CH3_Event=data[0]&0x08;
}