24 #include "calibrate.h"
26 #ifndef TOUCH_WITHOUT_STORE
32 #define CALIBRATION_MAGIC_NUMBER 0xCA71B4A7
33 #define CALIBRATION_EEPROM_OFFSET 0x80
37 #define ADC_X adcSingleInpCh1
38 #define ADC_Y adcSingleInpCh4
41 #define TOUCH_X1_PORT gpioPortD
42 #define TOUCH_X1_PIN 5
43 #define TOUCH_X2_PORT gpioPortD
44 #define TOUCH_X2_PIN 4
45 #define TOUCH_Y1_PORT gpioPortD
46 #define TOUCH_Y1_PIN 3
47 #define TOUCH_Y2_PORT gpioPortD
48 #define TOUCH_Y2_PIN 1
67 uint32_t touch_ignore_move;
74 #ifndef TOUCH_WITHOUT_STORE
91 static uint32_t touch_CountChecksum(uint32_t magic, uint32_t *data, uint32_t len)
93 unsigned long checksum = magic;
97 if (checksum & 0x80000000)
110 static void touch_LoadCalibration(
void)
113 uint32_t temp, checksum;
117 #if !defined( BSP_STK )
127 if (count ==
sizeof(new_matrix) + 4)
129 if (temp == CALIBRATION_MAGIC_NUMBER)
131 checksum = touch_CountChecksum(temp, (uint32_t*) &new_matrix,
sizeof(new_matrix) / 4);
133 if (temp == checksum)
144 static void touch_StoreCalibration(
void)
147 uint32_t temp = CALIBRATION_MAGIC_NUMBER, checksum;
165 POINT old_pos, new_pos;
169 old_pos.x = pos->
adcx;
170 old_pos.y = pos->
adcy;
173 if (new_pos.x >= 0) pos->
x = new_pos.x;
175 if (new_pos.y >= 0) pos->
y = new_pos.y;
207 if (newpos.
pen && !current_pos.
pen) result = 1;
211 if (abs(diff) > (
int) touch_ignore_move) result = 1;
215 if (abs(diff) > (
int) touch_ignore_move) result = 1;
239 touch_state = TOUCH_MEASURE_Y;
249 case TOUCH_CHECK_PRESS:
252 touch_state = TOUCH_MEASURE_Y;
260 current_pos.
pen = newpos.
pen;
267 current_pos.
x = newpos.
x;
268 current_pos.
y = newpos.
y;
279 touch_state = TOUCH_INIT;
285 case TOUCH_MEASURE_Y:
293 touch_state = TOUCH_MEASURE_X;
295 case TOUCH_MEASURE_X:
303 touch_state = TOUCH_CHECK_PRESS;
305 default: touch_state = TOUCH_INIT;
320 if( (touch_state == TOUCH_INIT) )
325 if( (touch_state == TOUCH_CHECK_PRESS) )
327 return TOUCH_BUSY_CHECK;
330 return(TOUCH_BUSY_SCAN);
343 #ifndef TOUCH_WITHOUT_STORE
344 touch_LoadCalibration();
349 touch_ignore_move = config->
ignore;
358 touch_state = TOUCH_INIT;
375 pos.
pen = current_pos.
pen;
376 pos.
x = current_pos.
x;
377 pos.
y = current_pos.
y;
414 #ifndef TOUCH_WITHOUT_STORE
416 touch_StoreCalibration();
Clock management unit (CMU) API.
void TOUCH_Init(TOUCH_Config_TypeDef *config)
Initialize touch panel driver.
Board support package API definitions.
void I2CSPM_Init(I2CSPM_Init_TypeDef *init)
Initalize I2C peripheral.
int EEPROM_Write(I2C_TypeDef *i2c, uint8_t addr, unsigned int offset, uint8_t *data, unsigned int len)
Write data to EEPROM.
ADC_AcqTime_TypeDef acqTime
#define ADC_INITSINGLE_DEFAULT
__STATIC_INLINE void ADC_IntClear(ADC_TypeDef *adc, uint32_t flags)
Clear one or more pending ADC interrupts.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
__STATIC_INLINE uint32_t ADC_DataSingleGet(ADC_TypeDef *adc)
Get single conversion result.
EEPROM driver for 24AA024 (2Kbit) EEPROM device on the DK.
__STATIC_INLINE void ADC_IntEnable(ADC_TypeDef *adc, uint32_t flags)
Enable one or more ADC interrupts.
Touch panel driver prototypes and definitions.
void ADC_Init(ADC_TypeDef *adc, const ADC_Init_TypeDef *init)
Initialize ADC.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
int TOUCH_StateChanged(void)
Check if cursor state changed (down or move)
General Purpose IO (GPIO) peripheral API.
I2C simple poll-based master mode driver for the DK/STK.
#define I2CSPM_INIT_DEFAULT
void ADC0_IRQHandler(void)
Interrupt handler is executed with frequency ~28Hz when panel is not pressed and with frequency ~140H...
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
ADC_Res_TypeDef resolution
void TOUCH_RecalculatePosition(volatile TOUCH_Pos_TypeDef *pos)
Convert ADC readings into XY position.
__STATIC_INLINE void ADC_IntDisable(ADC_TypeDef *adc, uint32_t flags)
Disable one or more ADC interrupts.
void ADC_InitSingle(ADC_TypeDef *adc, const ADC_InitSingle_TypeDef *init)
Initialize single ADC sample conversion.
int EEPROM_Read(I2C_TypeDef *i2c, uint8_t addr, unsigned int offset, uint8_t *data, unsigned int len)
Read data from EEPROM.
int TOUCH_IsBusy(void)
Check status of the touch panel.
int BSP_PeripheralAccess(BSP_Peripheral_TypeDef perf, bool enable)
DK Peripheral Access Control Enable or disable access to on-board peripherals through switches and SP...
void TOUCH_RegisterUpcall(TOUCH_Upcall_TypeDef *new_upcall)
Register upcall which will be call every position or state change.
uint8_t ADC_PrescaleCalc(uint32_t adcFreq, uint32_t hfperFreq)
Calculate prescaler value used to determine ADC clock.
TOUCH_Pos_TypeDef * TOUCH_GetPos(void)
Returns current touch position and state.
__STATIC_INLINE void ADC_Start(ADC_TypeDef *adc, ADC_Start_TypeDef cmd)
Start scan sequence and/or single conversion.
Analog to Digital Converter (ADC) peripheral API.
ADC_Ref_TypeDef reference
ADC_OvsRateSel_TypeDef ovsRateSel
void( TOUCH_Upcall_TypeDef)(TOUCH_Pos_TypeDef *)
__STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port, unsigned int pin)
Read the pad value for a single pin in a GPIO port.
void TOUCH_CallUpcall(void)
Function that calls registered upcall.
int TOUCH_CalibrationTable(POINT *displayPtr, POINT *screenPtr)
Set calibration table.
ADC_OvsRateSel_TypeDef oversampling