23 #define UV_TASKLIST 0x80
24 #define GESTURE_TASKLIST 0x7
25 #define HOVER_TASKLIST 0x1
26 #define UV_IRQ_EN IE_ALS_EVRYSAMPLE
27 #define GESTURE_IRQ (IE_ALS_EVRYSAMPLE | IE_PS1_EVRYSAMPLE | IE_PS2_EVRYSAMPLE | IE_PS3_EVRYSAMPLE)
28 #define MEASRATE_FAST 320
29 #define MEASRATE_SLOW 32000
30 #define PS_HOVER_THRESHOLD 295
31 #define PS_THRESHOLD 275
32 #define SI1147_DEVICE_ID 0x47
39 static si114x_i2c_t si114x_i2c;
44 static gesture_t ProcessSi1147Samples(Si114x_Sample_TypeDef *samples);
63 if (data == SI1147_DEVICE_ID)
155 *uvIndex = data + 50;
162 if (data > PS_HOVER_THRESHOLD)
181 static void readPSData(HANDLE
si114x_handle, Si114x_Sample_TypeDef *sample)
210 Si114x_Sample_TypeDef sample;
213 sample.timestamp = timestamp;
219 return ProcessSi1147Samples(&sample);
233 static gesture_t ProcessSi1147Samples(Si114x_Sample_TypeDef *samples)
237 static u32 ps_entry_time[3] = { 0, 0, 0 };
238 static u32 ps_exit_time[3] = { 0, 0, 0 };
240 static u8 ps_state[3] = { 0, 0, 0 };
250 ps[0] = samples->ps1;
251 ps[1] = samples->ps2;
252 ps[2] = samples->ps3;
255 for (array_counter = 0; array_counter < 3; array_counter++)
259 if (ps[array_counter] >= PS_THRESHOLD)
261 if (ps_state[array_counter] == 0)
263 ps_state[array_counter] = 1;
264 ps_entry_time[array_counter] = samples->timestamp;
269 if (ps_state[array_counter] == 1)
271 ps_state[array_counter] = 0;
272 ps_exit_time[array_counter] = samples->timestamp;
278 if ((ps[0] < PS_THRESHOLD) && (ps[1] < PS_THRESHOLD) && (ps[2] < PS_THRESHOLD))
282 if ((ps_entry_time[0] != 0) && (ps_entry_time[1] != 0) && (ps_entry_time[2] != 0)
283 && (ps_exit_time[0] != 0) && (ps_exit_time[1] != 0) && (ps_exit_time[2] != 0))
286 if ((ps_exit_time[0] > 0xFC000000L) || (ps_exit_time[1] > 0xFC000000L) || (ps_exit_time[2] > 0xFC000000L)
287 || (ps_entry_time[0] > 0xFC000000L) || (ps_entry_time[1] > 0xFC000000L) || (ps_entry_time[2] > 0xFC000000L))
289 ps_exit_time[0] += 0x1FFFFFFFL;
290 ps_exit_time[1] += 0x1FFFFFFFL;
291 ps_exit_time[2] += 0x1FFFFFFFL;
293 ps_entry_time[0] += 0x1FFFFFFFL;
294 ps_entry_time[1] += 0x1FFFFFFFL;
295 ps_entry_time[2] += 0x1FFFFFFFL;
300 ps_time[0] = (ps_exit_time[0] - ps_entry_time[0]) / 2;
301 ps_time[0] = ps_time[0] + ps_entry_time[0];
303 ps_time[1] = (ps_exit_time[1] - ps_entry_time[1]) / 2;
304 ps_time[1] = ps_time[1] + ps_entry_time[1];
306 ps_time[2] = (ps_exit_time[2] - ps_entry_time[2]) / 2;
307 ps_time[2] = ps_time[2] + ps_entry_time[2];
311 if (ps_time[1] > ps_time[2])
313 diff_x = ps_time[1] - ps_time[2];
317 diff_x = ps_time[2] - ps_time[1];
319 if( ps_time[0] > ps_time[1] )
321 diff_y1 = ps_time[0] - ps_time[1];
325 diff_y1 = ps_time[1] - ps_time[0];
328 if( ps_time[0] > ps_time[2] )
330 diff_y2 = ps_time[0] - ps_time[2];
334 diff_y2 = ps_time[2] - ps_time[0];
339 ps_avg = (
u32) ps_time[0] + (
u32) ps_time[1] + (
u32) ps_time[2];
342 if ((ps_exit_time[0] - ps_entry_time[0]) > 10 || (ps_exit_time[1] - ps_entry_time[1]) > 10 || (ps_exit_time[2] - ps_entry_time[2]) > 10)
344 if( ( (ps_time[0] < ps_time[1]) && (diff_y1 > diff_x) ) || ( (ps_time[0] <= ps_time[2]) && (diff_y2 > diff_x) ) )
348 else if ( ( (ps_time[0] < ps_time[1]) && (diff_y1 > diff_x) ) || ( (ps_time[0] > ps_time[2]) && (diff_y2 > diff_x) ) )
352 else if((ps_time[0] < ps_time[1]) && (ps_time[2] < ps_time[1]) && (diff_x > ((diff_y1+diff_y2)/2)))
356 else if( (ps_time[0] < ps_time[2]) && (ps_time[1] < ps_time[2]) && (diff_x > ((diff_y1+diff_y2)/2)))
362 for (array_counter = 0; array_counter < 3; array_counter++)
364 ps_exit_time[array_counter] = 0;
365 ps_entry_time[array_counter] = 0;
SI114X_CAL_S Data Structure.
Si114x function prototypes, structure and bit definitions.
int16_t Si114xParamSet(HANDLE si114x_handle, uint8_t address, uint8_t value)
Writes a byte to an Si113x/4x Parameter.
Driver for the Si1147 Proximity sensor.
int Si1147_MeasureUVAndObjectPresent(I2C_TypeDef *i2c, uint8_t addr, uint16_t *uvIndex, int *objectDetect)
Reads the UV measurement data and checks for object in proximity to the Si1147.
int16_t Si114xWriteToRegister(HANDLE si114x_handle, uint8_t address, uint8_t data)
Writes to Si114x Register.
int16_t si114x_set_ucoef(HANDLE si114x_handle, uint8_t *input_ucoef, SI114X_CAL_S *si114x_cal)
Initializes the Si113x/46/47/48 UCOEF Registers.
int16_t Si114xPsAlsForce(HANDLE si114x_handle)
Sends a PSALSFORCE command to the Si113x/4x.
int Si1147_GetInterruptOutputEnable(I2C_TypeDef *i2c, uint8_t addr, int *enable)
Get the enable status of the Si1147 interrupt pin.
int16_t Si114xReadFromRegister(HANDLE si114x_handle, uint8_t address)
Reads from Si114x register.
gesture_t Si1147_NewSample(I2C_TypeDef *i2c, uint8_t addr, uint32_t timestamp)
Reads new measurement data and processes a new sample. This function should be called every time an i...
int Si1147_SetInterruptOutputEnable(I2C_TypeDef *i2c, uint8_t addr, int enable)
Enables or disables the Si1147 interrupt pin.
int Si1147_ConfigureDetection(I2C_TypeDef *i2c, uint8_t addr, int lowpower)
Initializes and configures the Si1147 sensor.
int16_t si114x_get_calibration(HANDLE si114x_handle, SI114X_CAL_S *si114x_cal, uint8_t security)
Populates the SI114X_CAL_S structure.
Swipe algorithm for Si114x.
static void * si114x_handle
Si114x PGM toolkit functions uses a void* to pass hardware parameters through to the lower level i2c ...
int16_t Si114xPsAlsAuto(HANDLE si114x_handle)
Sends a PSALSAUTO command to the Si113x/4x.
int Si1147_Detect_Device(I2C_TypeDef *i2c, uint8_t addr)
Detects whether Si1147 is on the i2c bus.
int16_t Si114xReset(HANDLE si114x_handle)
Resets the Si113x/4x, clears any interrupts and initializes the HW_KEY register.