demo工程暂存 优化菜单界面UI和功能
This commit is contained in:
383
Demo/lv_drivers/indev/AD_touch.c
Normal file
383
Demo/lv_drivers/indev/AD_touch.c
Normal file
@ -0,0 +1,383 @@
|
||||
/**
|
||||
* @file AD_touch.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include "AD_touch.h"
|
||||
|
||||
#if USE_AD_TOUCH
|
||||
|
||||
#include LV_DRV_INDEV_INCLUDE
|
||||
#include LV_DRV_DELAY_INCLUDE
|
||||
|
||||
#define SAMPLE_POINTS 4
|
||||
|
||||
#define CALIBRATIONINSET 20 // range 0 <= CALIBRATIONINSET <= 40
|
||||
|
||||
#define RESISTIVETOUCH_AUTO_SAMPLE_MODE
|
||||
#define TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD 350 // between 0-0x03ff the lesser this value
|
||||
|
||||
|
||||
// Current ADC values for X and Y channels
|
||||
int16_t adcX = 0;
|
||||
int16_t adcY = 0;
|
||||
volatile unsigned int adcTC = 0;
|
||||
|
||||
// coefficient values
|
||||
volatile long _trA;
|
||||
volatile long _trB;
|
||||
volatile long _trC;
|
||||
volatile long _trD;
|
||||
|
||||
volatile int16_t xRawTouch[SAMPLE_POINTS] = {TOUCHCAL_ULX, TOUCHCAL_URX, TOUCHCAL_LRX, TOUCHCAL_LLX};
|
||||
volatile int16_t yRawTouch[SAMPLE_POINTS] = {TOUCHCAL_ULY, TOUCHCAL_URY, TOUCHCAL_LRY, TOUCHCAL_LLY};
|
||||
|
||||
#define TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR 8
|
||||
|
||||
// use this scale factor to avoid working in floating point numbers
|
||||
#define SCALE_FACTOR (1 << TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR)
|
||||
|
||||
typedef enum {
|
||||
IDLE, //0
|
||||
SET_X, //1
|
||||
RUN_X, //2
|
||||
GET_X, //3
|
||||
RUN_CHECK_X, //4
|
||||
CHECK_X, //5
|
||||
SET_Y, //6
|
||||
RUN_Y, //7
|
||||
GET_Y, //8
|
||||
CHECK_Y, //9
|
||||
SET_VALUES, //10
|
||||
GET_POT, //11
|
||||
RUN_POT //12
|
||||
} TOUCH_STATES;
|
||||
|
||||
volatile TOUCH_STATES state = IDLE;
|
||||
|
||||
#define CAL_X_INSET (((GetMaxX() + 1) * (CALIBRATIONINSET >> 1)) / 100)
|
||||
#define CAL_Y_INSET (((GetMaxY() + 1) * (CALIBRATIONINSET >> 1)) / 100)
|
||||
|
||||
int stat;
|
||||
int16_t temp_x, temp_y;
|
||||
|
||||
|
||||
static int16_t TouchGetX(void);
|
||||
static int16_t TouchGetRawX(void);
|
||||
static int16_t TouchGetY(void);
|
||||
static int16_t TouchGetRawY(void);
|
||||
static int16_t TouchDetectPosition(void);
|
||||
static void TouchCalculateCalPoints(void);
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
void ad_touch_init(void)
|
||||
{
|
||||
// Initialize ADC for auto sampling mode
|
||||
AD1CON1 = 0; // reset
|
||||
AD1CON2 = 0; // AVdd, AVss, int every conversion, MUXA only
|
||||
AD1CON3 = 0x1FFF; // 31 Tad auto-sample, Tad = 256*Tcy
|
||||
AD1CON1 = 0x80E0; // Turn on A/D module, use auto-convert
|
||||
|
||||
|
||||
ADPCFG_XPOS = RESISTIVETOUCH_ANALOG;
|
||||
ADPCFG_YPOS = RESISTIVETOUCH_ANALOG;
|
||||
|
||||
AD1CSSL = 0; // No scanned inputs
|
||||
|
||||
state = SET_X; // set the state of the state machine to start the sampling
|
||||
|
||||
/*Load calibration data*/
|
||||
xRawTouch[0] = TOUCHCAL_ULX;
|
||||
yRawTouch[0] = TOUCHCAL_ULY;
|
||||
xRawTouch[1] = TOUCHCAL_URX;
|
||||
yRawTouch[1] = TOUCHCAL_URY;
|
||||
xRawTouch[3] = TOUCHCAL_LLX;
|
||||
yRawTouch[3] = TOUCHCAL_LLY;
|
||||
xRawTouch[2] = TOUCHCAL_LRX;
|
||||
yRawTouch[2] = TOUCHCAL_LRY;
|
||||
|
||||
TouchCalculateCalPoints();
|
||||
}
|
||||
|
||||
/*Use this in lv_indev_drv*/
|
||||
bool ad_touch_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
static int16_t last_x = 0;
|
||||
static int16_t last_y = 0;
|
||||
|
||||
int16_t x, y;
|
||||
|
||||
x = TouchGetX();
|
||||
y = TouchGetY();
|
||||
|
||||
if((x > 0) && (y > 0)) {
|
||||
data->point.x = x;
|
||||
data->point.y = y;
|
||||
last_x = data->point.x;
|
||||
last_y = data->point.y;
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
} else {
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Call periodically (e.g. in every 1 ms) to handle reading with ADC*/
|
||||
int16_t ad_touch_handler(void)
|
||||
{
|
||||
static int16_t tempX, tempY;
|
||||
int16_t temp;
|
||||
|
||||
switch(state) {
|
||||
case IDLE:
|
||||
adcX = 0;
|
||||
adcY = 0;
|
||||
break;
|
||||
|
||||
case SET_VALUES:
|
||||
if(!TOUCH_ADC_DONE)
|
||||
break;
|
||||
if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD < (WORD)ADC1BUF0) {
|
||||
adcX = 0;
|
||||
adcY = 0;
|
||||
} else {
|
||||
adcX = tempX;
|
||||
adcY = tempY;
|
||||
}
|
||||
state = SET_X;
|
||||
return 1; // touch screen acquisition is done
|
||||
|
||||
case SET_X:
|
||||
TOUCH_ADC_INPUT_SEL = ADC_XPOS;
|
||||
|
||||
ResistiveTouchScreen_XPlus_Config_As_Input();
|
||||
ResistiveTouchScreen_YPlus_Config_As_Input();
|
||||
ResistiveTouchScreen_XMinus_Config_As_Input();
|
||||
ResistiveTouchScreen_YMinus_Drive_Low();
|
||||
ResistiveTouchScreen_YMinus_Config_As_Output();
|
||||
|
||||
ADPCFG_YPOS = RESISTIVETOUCH_DIGITAL; // set to digital pin
|
||||
ADPCFG_XPOS = RESISTIVETOUCH_ANALOG; // set to analog pin
|
||||
|
||||
TOUCH_ADC_START = 1; // run conversion
|
||||
state = CHECK_X;
|
||||
break;
|
||||
|
||||
case CHECK_X:
|
||||
case CHECK_Y:
|
||||
|
||||
if(TOUCH_ADC_DONE == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD > (WORD)ADC1BUF0) {
|
||||
if(state == CHECK_X) {
|
||||
ResistiveTouchScreen_YPlus_Drive_High();
|
||||
ResistiveTouchScreen_YPlus_Config_As_Output();
|
||||
tempX = 0;
|
||||
state = RUN_X;
|
||||
} else {
|
||||
ResistiveTouchScreen_XPlus_Drive_High();
|
||||
ResistiveTouchScreen_XPlus_Config_As_Output();
|
||||
tempY = 0;
|
||||
state = RUN_Y;
|
||||
}
|
||||
} else {
|
||||
adcX = 0;
|
||||
adcY = 0;
|
||||
state = SET_X;
|
||||
return 1; // touch screen acquisition is done
|
||||
break;
|
||||
}
|
||||
|
||||
case RUN_X:
|
||||
case RUN_Y:
|
||||
TOUCH_ADC_START = 1;
|
||||
state = (state == RUN_X) ? GET_X : GET_Y;
|
||||
// no break needed here since the next state is either GET_X or GET_Y
|
||||
break;
|
||||
|
||||
case GET_X:
|
||||
case GET_Y:
|
||||
if(!TOUCH_ADC_DONE)
|
||||
break;
|
||||
|
||||
temp = ADC1BUF0;
|
||||
if(state == GET_X) {
|
||||
if(temp != tempX) {
|
||||
tempX = temp;
|
||||
state = RUN_X;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if(temp != tempY) {
|
||||
tempY = temp;
|
||||
state = RUN_Y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(state == GET_X)
|
||||
ResistiveTouchScreen_YPlus_Config_As_Input();
|
||||
else
|
||||
ResistiveTouchScreen_XPlus_Config_As_Input();
|
||||
TOUCH_ADC_START = 1;
|
||||
state = (state == GET_X) ? SET_Y : SET_VALUES;
|
||||
break;
|
||||
|
||||
case SET_Y:
|
||||
if(!TOUCH_ADC_DONE)
|
||||
break;
|
||||
|
||||
if((WORD)TOUCHSCREEN_RESISTIVE_PRESS_THRESHOLD < (WORD)ADC1BUF0) {
|
||||
adcX = 0;
|
||||
adcY = 0;
|
||||
state = SET_X;
|
||||
return 1; // touch screen acquisition is done
|
||||
break;
|
||||
}
|
||||
|
||||
TOUCH_ADC_INPUT_SEL = ADC_YPOS;
|
||||
|
||||
ResistiveTouchScreen_XPlus_Config_As_Input();
|
||||
ResistiveTouchScreen_YPlus_Config_As_Input();
|
||||
ResistiveTouchScreen_XMinus_Drive_Low();
|
||||
ResistiveTouchScreen_XMinus_Config_As_Output();
|
||||
ResistiveTouchScreen_YMinus_Config_As_Input();
|
||||
|
||||
ADPCFG_YPOS = RESISTIVETOUCH_ANALOG; // set to analog pin
|
||||
ADPCFG_XPOS = RESISTIVETOUCH_DIGITAL; // set to digital pin
|
||||
TOUCH_ADC_START = 1; // run conversion
|
||||
state = CHECK_Y;
|
||||
break;
|
||||
|
||||
default:
|
||||
state = SET_X;
|
||||
return 1; // touch screen acquisition is done
|
||||
}
|
||||
stat = state;
|
||||
temp_x = adcX;
|
||||
temp_y = adcY;
|
||||
|
||||
return 0; // touch screen acquisition is not done
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/********************************************************************/
|
||||
static int16_t TouchGetX(void)
|
||||
{
|
||||
long result;
|
||||
|
||||
result = TouchGetRawX();
|
||||
|
||||
if(result > 0) {
|
||||
result = (long)((((long)_trC * result) + _trD) >> TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR);
|
||||
|
||||
}
|
||||
return ((int16_t)result);
|
||||
}
|
||||
/********************************************************************/
|
||||
static int16_t TouchGetRawX(void)
|
||||
{
|
||||
#ifdef TOUCHSCREEN_RESISTIVE_SWAP_XY
|
||||
return adcY;
|
||||
#else
|
||||
return adcX;
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
static int16_t TouchGetY(void)
|
||||
{
|
||||
|
||||
long result;
|
||||
|
||||
result = TouchGetRawY();
|
||||
|
||||
if(result > 0) {
|
||||
result = (long)((((long)_trA * result) + (long)_trB) >> TOUCHSCREEN_RESISTIVE_CALIBRATION_SCALE_FACTOR);
|
||||
|
||||
}
|
||||
return ((int16_t)result);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
static int16_t TouchGetRawY(void)
|
||||
{
|
||||
#ifdef TOUCHSCREEN_RESISTIVE_SWAP_XY
|
||||
return adcX;
|
||||
#else
|
||||
return adcY;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void TouchCalculateCalPoints(void)
|
||||
{
|
||||
long trA, trB, trC, trD; // variables for the coefficients
|
||||
long trAhold, trBhold, trChold, trDhold;
|
||||
long test1, test2; // temp variables (must be signed type)
|
||||
|
||||
int16_t xPoint[SAMPLE_POINTS], yPoint[SAMPLE_POINTS];
|
||||
|
||||
yPoint[0] = yPoint[1] = CAL_Y_INSET;
|
||||
yPoint[2] = yPoint[3] = (GetMaxY() - CAL_Y_INSET);
|
||||
xPoint[0] = xPoint[3] = CAL_X_INSET;
|
||||
xPoint[1] = xPoint[2] = (GetMaxX() - CAL_X_INSET);
|
||||
|
||||
// calculate points transfer functiona
|
||||
// based on two simultaneous equations solve for the
|
||||
// constants
|
||||
|
||||
// use sample points 1 and 4
|
||||
// Dy1 = aTy1 + b; Dy4 = aTy4 + b
|
||||
// Dx1 = cTx1 + d; Dy4 = aTy4 + b
|
||||
|
||||
test1 = (long)yPoint[0] - (long)yPoint[3];
|
||||
test2 = (long)yRawTouch[0] - (long)yRawTouch[3];
|
||||
|
||||
trA = ((long)((long)test1 * SCALE_FACTOR) / test2);
|
||||
trB = ((long)((long)yPoint[0] * SCALE_FACTOR) - (trA * (long)yRawTouch[0]));
|
||||
|
||||
test1 = (long)xPoint[0] - (long)xPoint[2];
|
||||
test2 = (long)xRawTouch[0] - (long)xRawTouch[2];
|
||||
|
||||
trC = ((long)((long)test1 * SCALE_FACTOR) / test2);
|
||||
trD = ((long)((long)xPoint[0] * SCALE_FACTOR) - (trC * (long)xRawTouch[0]));
|
||||
|
||||
trAhold = trA;
|
||||
trBhold = trB;
|
||||
trChold = trC;
|
||||
trDhold = trD;
|
||||
|
||||
// use sample points 2 and 3
|
||||
// Dy2 = aTy2 + b; Dy3 = aTy3 + b
|
||||
// Dx2 = cTx2 + d; Dy3 = aTy3 + b
|
||||
|
||||
test1 = (long)yPoint[1] - (long)yPoint[2];
|
||||
test2 = (long)yRawTouch[1] - (long)yRawTouch[2];
|
||||
|
||||
trA = ((long)(test1 * SCALE_FACTOR) / test2);
|
||||
trB = ((long)((long)yPoint[1] * SCALE_FACTOR) - (trA * (long)yRawTouch[1]));
|
||||
|
||||
test1 = (long)xPoint[1] - (long)xPoint[3];
|
||||
test2 = (long)xRawTouch[1] - (long)xRawTouch[3];
|
||||
|
||||
trC = ((long)((long)test1 * SCALE_FACTOR) / test2);
|
||||
trD = ((long)((long)xPoint[1] * SCALE_FACTOR) - (trC * (long)xRawTouch[1]));
|
||||
|
||||
// get the average and use the average
|
||||
_trA = (trA + trAhold) >> 1;
|
||||
_trB = (trB + trBhold) >> 1;
|
||||
_trC = (trC + trChold) >> 1;
|
||||
_trD = (trD + trDhold) >> 1;
|
||||
}
|
||||
|
||||
#endif
|
120
Demo/lv_drivers/indev/AD_touch.h
Normal file
120
Demo/lv_drivers/indev/AD_touch.h
Normal file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
* @file AD_touch.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AD_TOUCH_H
|
||||
#define AD_TOUCH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifndef LV_DRV_NO_CONF
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "../../lv_drv_conf.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_AD_TOUCH
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
#define _SUPPRESS_PLIB_WARNING
|
||||
#include <plib.h>
|
||||
|
||||
#include "GenericTypeDefs.h"
|
||||
|
||||
#define DISP_ORIENTATION 0
|
||||
#define DISP_HOR_RESOLUTION 320
|
||||
#define DISP_VER_RESOLUTION 240
|
||||
|
||||
/*GetMaxX Macro*/
|
||||
#if (DISP_ORIENTATION == 90) || (DISP_ORIENTATION == 270)
|
||||
#define GetMaxX() (DISP_VER_RESOLUTION - 1)
|
||||
#elif (DISP_ORIENTATION == 0) || (DISP_ORIENTATION == 180)
|
||||
#define GetMaxX() (DISP_HOR_RESOLUTION - 1)
|
||||
#endif
|
||||
|
||||
/*GetMaxY Macro*/
|
||||
#if (DISP_ORIENTATION == 90) || (DISP_ORIENTATION == 270)
|
||||
#define GetMaxY() (DISP_HOR_RESOLUTION - 1)
|
||||
#elif (DISP_ORIENTATION == 0) || (DISP_ORIENTATION == 180)
|
||||
#define GetMaxY() (DISP_VER_RESOLUTION - 1)
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* HARDWARE PROFILE FOR THE RESISTIVE TOUCHSCREEN
|
||||
*********************************************************************/
|
||||
|
||||
#define TOUCH_ADC_INPUT_SEL AD1CHS
|
||||
|
||||
// ADC Sample Start
|
||||
#define TOUCH_ADC_START AD1CON1bits.SAMP
|
||||
|
||||
// ADC Status
|
||||
#define TOUCH_ADC_DONE AD1CON1bits.DONE
|
||||
|
||||
#define RESISTIVETOUCH_ANALOG 1
|
||||
#define RESISTIVETOUCH_DIGITAL 0
|
||||
|
||||
// ADC channel constants
|
||||
#define ADC_XPOS ADC_CH0_POS_SAMPLEA_AN12
|
||||
#define ADC_YPOS ADC_CH0_POS_SAMPLEA_AN13
|
||||
|
||||
// ADC Port Control Bits
|
||||
#define ADPCFG_XPOS AD1PCFGbits.PCFG12 //XR
|
||||
#define ADPCFG_YPOS AD1PCFGbits.PCFG13 //YD
|
||||
|
||||
// X port definitions
|
||||
#define ResistiveTouchScreen_XPlus_Drive_High() LATBbits.LATB12 = 1
|
||||
#define ResistiveTouchScreen_XPlus_Drive_Low() LATBbits.LATB12 = 0 //LAT_XPOS
|
||||
#define ResistiveTouchScreen_XPlus_Config_As_Input() TRISBbits.TRISB12 = 1 //TRIS_XPOS
|
||||
#define ResistiveTouchScreen_XPlus_Config_As_Output() TRISBbits.TRISB12 = 0
|
||||
|
||||
#define ResistiveTouchScreen_XMinus_Drive_High() LATFbits.LATF0 = 1
|
||||
#define ResistiveTouchScreen_XMinus_Drive_Low() LATFbits.LATF0 = 0 //LAT_XNEG
|
||||
#define ResistiveTouchScreen_XMinus_Config_As_Input() TRISFbits.TRISF0 = 1 //TRIS_XNEG
|
||||
#define ResistiveTouchScreen_XMinus_Config_As_Output() TRISFbits.TRISF0 = 0
|
||||
|
||||
// Y port definitions
|
||||
#define ResistiveTouchScreen_YPlus_Drive_High() LATBbits.LATB13 = 1
|
||||
#define ResistiveTouchScreen_YPlus_Drive_Low() LATBbits.LATB13 = 0 //LAT_YPOS
|
||||
#define ResistiveTouchScreen_YPlus_Config_As_Input() TRISBbits.TRISB13 = 1 //TRIS_YPOS
|
||||
#define ResistiveTouchScreen_YPlus_Config_As_Output() TRISBbits.TRISB13 = 0
|
||||
|
||||
#define ResistiveTouchScreen_YMinus_Drive_High() LATFbits.LATF1 = 1
|
||||
#define ResistiveTouchScreen_YMinus_Drive_Low() LATFbits.LATF1 = 0 //LAT_YNEG
|
||||
#define ResistiveTouchScreen_YMinus_Config_As_Input() TRISFbits.TRISF1 = 1 //TRIS_YNEG
|
||||
#define ResistiveTouchScreen_YMinus_Config_As_Output() TRISFbits.TRISF1 = 0
|
||||
|
||||
// Default calibration points
|
||||
#define TOUCHCAL_ULX 0x0348
|
||||
#define TOUCHCAL_ULY 0x00CC
|
||||
#define TOUCHCAL_URX 0x00D2
|
||||
#define TOUCHCAL_URY 0x00CE
|
||||
#define TOUCHCAL_LLX 0x034D
|
||||
#define TOUCHCAL_LLY 0x0335
|
||||
#define TOUCHCAL_LRX 0x00D6
|
||||
#define TOUCHCAL_LRY 0x032D
|
||||
|
||||
void ad_touch_init(void);
|
||||
bool ad_touch_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
int16_t ad_touch_handler(void);
|
||||
|
||||
#endif /* USE_AD_TOUCH */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* AD_TOUCH_H */
|
179
Demo/lv_drivers/indev/FT5406EE8.c
Normal file
179
Demo/lv_drivers/indev/FT5406EE8.c
Normal file
@ -0,0 +1,179 @@
|
||||
/**
|
||||
* @file FT5406EE8.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "FT5406EE8.h"
|
||||
#if USE_FT5406EE8
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include LV_DRV_INDEV_INCLUDE
|
||||
#include LV_DRV_DELAY_INCLUDE
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
#define I2C_WR_BIT 0x00
|
||||
#define I2C_RD_BIT 0x01
|
||||
|
||||
/*DEVICE MODES*/
|
||||
#define OPERAT_MD 0x00
|
||||
#define TEST_MD 0x04
|
||||
#define SYS_INF_MD 0x01
|
||||
|
||||
/*OPERATING MODE*/
|
||||
#define DEVICE_MODE 0x00
|
||||
#define GEST_ID 0x01
|
||||
#define TD_STATUS 0x02
|
||||
|
||||
#define FT5406EE8_FINGER_MAX 10
|
||||
|
||||
/*Register adresses*/
|
||||
#define FT5406EE8_REG_DEVICE_MODE 0x00
|
||||
#define FT5406EE8_REG_GEST_ID 0x01
|
||||
#define FT5406EE8_REG_TD_STATUS 0x02
|
||||
#define FT5406EE8_REG_YH 0x03
|
||||
#define FT5406EE8_REG_YL 0x04
|
||||
#define FT5406EE8_REG_XH 0x05
|
||||
#define FT5406EE8_REG_XL 0x06
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
static bool ft5406ee8_get_touch_num(void);
|
||||
static bool ft5406ee8_read_finger1(int16_t * x, int16_t * y);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void ft5406ee8_init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current position and state of the touchpad
|
||||
* @param data store the read data here
|
||||
* @return false: because no ore data to be read
|
||||
*/
|
||||
bool ft5406ee8_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
static int16_t x_last;
|
||||
static int16_t y_last;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
bool valid = true;
|
||||
|
||||
valid = ft5406ee8_get_touch_num();
|
||||
if(valid == true) {
|
||||
valid = ft5406ee8_read_finger1(&x, &y);
|
||||
}
|
||||
|
||||
if(valid == true) {
|
||||
x = (uint32_t)((uint32_t)x * 320) / 2048;
|
||||
y = (uint32_t)((uint32_t)y * 240) / 2048;
|
||||
|
||||
|
||||
x_last = x;
|
||||
y_last = y;
|
||||
} else {
|
||||
x = x_last;
|
||||
y = y_last;
|
||||
}
|
||||
|
||||
data->point.x = x;
|
||||
data->point.y = y;
|
||||
data->state = valid == false ? LV_INDEV_STATE_REL : LV_INDEV_STATE_PR;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static bool ft5406ee8_get_touch_num(void)
|
||||
{
|
||||
bool ok = true;
|
||||
uint8_t t_num = 0;
|
||||
|
||||
LV_DRV_INDEV_I2C_START;
|
||||
LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_WR_BIT);
|
||||
LV_DRV_INDEV_I2C_WR(FT5406EE8_REG_TD_STATUS)
|
||||
LV_DRV_INDEV_I2C_RESTART;
|
||||
LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_RD_BIT);
|
||||
t_num = LV_DRV_INDEV_I2C_READ(0);
|
||||
|
||||
/* Error if not touched or too much finger */
|
||||
if(t_num > FT5406EE8_FINGER_MAX || t_num == 0) {
|
||||
ok = false;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the x and y coordinated
|
||||
* @param x store the x coordinate here
|
||||
* @param y store the y coordinate here
|
||||
* @return false: not valid point; true: valid point
|
||||
*/
|
||||
static bool ft5406ee8_read_finger1(int16_t * x, int16_t * y)
|
||||
{
|
||||
uint8_t temp_xH = 0;
|
||||
uint8_t temp_xL = 0;
|
||||
uint8_t temp_yH = 0;
|
||||
uint8_t temp_yL = 0;
|
||||
|
||||
/*Read Y High and low byte*/
|
||||
LV_DRV_INDEV_I2C_START;
|
||||
LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_WR_BIT);
|
||||
LV_DRV_INDEV_I2C_WR(FT5406EE8_REG_YH)
|
||||
LV_DRV_INDEV_I2C_RESTART;
|
||||
LV_DRV_INDEV_I2C_WR((FT5406EE8_I2C_ADR << 1) | I2C_RD_BIT);
|
||||
temp_yH = LV_DRV_INDEV_I2C_READ(1);
|
||||
temp_yL = LV_DRV_INDEV_I2C_READ(1);
|
||||
|
||||
/*The upper two bit must be 2 on valid press*/
|
||||
if(((temp_yH >> 6) & 0xFF) != 2) {
|
||||
(void) LV_DRV_INDEV_I2C_READ(0); /*Dummy read to close read sequence*/
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Read X High and low byte*/
|
||||
temp_xH = LV_DRV_INDEV_I2C_READ(1);
|
||||
temp_xL = LV_DRV_INDEV_I2C_READ(0);
|
||||
|
||||
/*Save the result*/
|
||||
*x = (temp_xH & 0x0F) << 8;
|
||||
*x += temp_xL;
|
||||
*y = (temp_yH & 0x0F) << 8;
|
||||
*y += temp_yL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
56
Demo/lv_drivers/indev/FT5406EE8.h
Normal file
56
Demo/lv_drivers/indev/FT5406EE8.h
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @file FT5406EE8.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FT5406EE8_H
|
||||
#define FT5406EE8_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifndef LV_DRV_NO_CONF
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "../../lv_drv_conf.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_FT5406EE8
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void ft5406ee8_init(void);
|
||||
bool ft5406ee8_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* USE_FT5406EE8 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* FT5406EE8_H */
|
174
Demo/lv_drivers/indev/XPT2046.c
Normal file
174
Demo/lv_drivers/indev/XPT2046.c
Normal file
@ -0,0 +1,174 @@
|
||||
/**
|
||||
* @file XPT2046.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "XPT2046.h"
|
||||
#if USE_XPT2046
|
||||
|
||||
#include <stddef.h>
|
||||
#include LV_DRV_INDEV_INCLUDE
|
||||
#include LV_DRV_DELAY_INCLUDE
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define CMD_X_READ 0b10010000
|
||||
#define CMD_Y_READ 0b11010000
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void xpt2046_corr(int16_t * x, int16_t * y);
|
||||
static void xpt2046_avg(int16_t * x, int16_t * y);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
int16_t avg_buf_x[XPT2046_AVG];
|
||||
int16_t avg_buf_y[XPT2046_AVG];
|
||||
uint8_t avg_last;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the XPT2046
|
||||
*/
|
||||
void xpt2046_init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current position and state of the touchpad
|
||||
* @param data store the read data here
|
||||
* @return false: because no ore data to be read
|
||||
*/
|
||||
bool xpt2046_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
static int16_t last_x = 0;
|
||||
static int16_t last_y = 0;
|
||||
uint8_t buf;
|
||||
|
||||
int16_t x = 0;
|
||||
int16_t y = 0;
|
||||
|
||||
uint8_t irq = LV_DRV_INDEV_IRQ_READ;
|
||||
|
||||
if(irq == 0) {
|
||||
LV_DRV_INDEV_SPI_CS(0);
|
||||
|
||||
LV_DRV_INDEV_SPI_XCHG_BYTE(CMD_X_READ); /*Start x read*/
|
||||
|
||||
buf = LV_DRV_INDEV_SPI_XCHG_BYTE(0); /*Read x MSB*/
|
||||
x = buf << 8;
|
||||
buf = LV_DRV_INDEV_SPI_XCHG_BYTE(CMD_Y_READ); /*Until x LSB converted y command can be sent*/
|
||||
x += buf;
|
||||
|
||||
buf = LV_DRV_INDEV_SPI_XCHG_BYTE(0); /*Read y MSB*/
|
||||
y = buf << 8;
|
||||
|
||||
buf = LV_DRV_INDEV_SPI_XCHG_BYTE(0); /*Read y LSB*/
|
||||
y += buf;
|
||||
|
||||
/*Normalize Data*/
|
||||
x = x >> 3;
|
||||
y = y >> 3;
|
||||
xpt2046_corr(&x, &y);
|
||||
xpt2046_avg(&x, &y);
|
||||
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
|
||||
LV_DRV_INDEV_SPI_CS(1);
|
||||
} else {
|
||||
x = last_x;
|
||||
y = last_y;
|
||||
avg_last = 0;
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
data->point.x = x;
|
||||
data->point.y = y;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
static void xpt2046_corr(int16_t * x, int16_t * y)
|
||||
{
|
||||
#if XPT2046_XY_SWAP != 0
|
||||
int16_t swap_tmp;
|
||||
swap_tmp = *x;
|
||||
*x = *y;
|
||||
*y = swap_tmp;
|
||||
#endif
|
||||
|
||||
if((*x) > XPT2046_X_MIN)(*x) -= XPT2046_X_MIN;
|
||||
else(*x) = 0;
|
||||
|
||||
if((*y) > XPT2046_Y_MIN)(*y) -= XPT2046_Y_MIN;
|
||||
else(*y) = 0;
|
||||
|
||||
(*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES) /
|
||||
(XPT2046_X_MAX - XPT2046_X_MIN);
|
||||
|
||||
(*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES) /
|
||||
(XPT2046_Y_MAX - XPT2046_Y_MIN);
|
||||
|
||||
#if XPT2046_X_INV != 0
|
||||
(*x) = XPT2046_HOR_RES - (*x);
|
||||
#endif
|
||||
|
||||
#if XPT2046_Y_INV != 0
|
||||
(*y) = XPT2046_VER_RES - (*y);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void xpt2046_avg(int16_t * x, int16_t * y)
|
||||
{
|
||||
/*Shift out the oldest data*/
|
||||
uint8_t i;
|
||||
for(i = XPT2046_AVG - 1; i > 0 ; i--) {
|
||||
avg_buf_x[i] = avg_buf_x[i - 1];
|
||||
avg_buf_y[i] = avg_buf_y[i - 1];
|
||||
}
|
||||
|
||||
/*Insert the new point*/
|
||||
avg_buf_x[0] = *x;
|
||||
avg_buf_y[0] = *y;
|
||||
if(avg_last < XPT2046_AVG) avg_last++;
|
||||
|
||||
/*Sum the x and y coordinates*/
|
||||
int32_t x_sum = 0;
|
||||
int32_t y_sum = 0;
|
||||
for(i = 0; i < avg_last ; i++) {
|
||||
x_sum += avg_buf_x[i];
|
||||
y_sum += avg_buf_y[i];
|
||||
}
|
||||
|
||||
/*Normalize the sums*/
|
||||
(*x) = (int32_t)x_sum / avg_last;
|
||||
(*y) = (int32_t)y_sum / avg_last;
|
||||
}
|
||||
|
||||
#endif
|
56
Demo/lv_drivers/indev/XPT2046.h
Normal file
56
Demo/lv_drivers/indev/XPT2046.h
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @file XPT2046.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XPT2046_H
|
||||
#define XPT2046_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifndef LV_DRV_NO_CONF
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "../../lv_drv_conf.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_XPT2046
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void xpt2046_init(void);
|
||||
bool xpt2046_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* USE_XPT2046 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* XPT2046_H */
|
244
Demo/lv_drivers/indev/evdev.c
Normal file
244
Demo/lv_drivers/indev/evdev.c
Normal file
@ -0,0 +1,244 @@
|
||||
/**
|
||||
* @file evdev.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "evdev.h"
|
||||
#if USE_EVDEV != 0 || USE_BSD_EVDEV
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#if USE_BSD_EVDEV
|
||||
#include <dev/evdev/input.h>
|
||||
#else
|
||||
#include <linux/input.h>
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
int map(int x, int in_min, int in_max, int out_min, int out_max);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
int evdev_fd;
|
||||
int evdev_root_x;
|
||||
int evdev_root_y;
|
||||
int evdev_button;
|
||||
|
||||
int evdev_key_val;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the evdev interface
|
||||
*/
|
||||
void evdev_init(void)
|
||||
{
|
||||
#if USE_BSD_EVDEV
|
||||
evdev_fd = open(EVDEV_NAME, O_RDWR | O_NOCTTY);
|
||||
#else
|
||||
evdev_fd = open(EVDEV_NAME, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
#endif
|
||||
if(evdev_fd == -1) {
|
||||
perror("unable open evdev interface:");
|
||||
return;
|
||||
}
|
||||
|
||||
#if USE_BSD_EVDEV
|
||||
fcntl(evdev_fd, F_SETFL, O_NONBLOCK);
|
||||
#else
|
||||
fcntl(evdev_fd, F_SETFL, O_ASYNC | O_NONBLOCK);
|
||||
#endif
|
||||
|
||||
evdev_root_x = 0;
|
||||
evdev_root_y = 0;
|
||||
evdev_key_val = 0;
|
||||
evdev_button = LV_INDEV_STATE_REL;
|
||||
}
|
||||
/**
|
||||
* reconfigure the device file for evdev
|
||||
* @param dev_name set the evdev device filename
|
||||
* @return true: the device file set complete
|
||||
* false: the device file doesn't exist current system
|
||||
*/
|
||||
bool evdev_set_file(char* dev_name)
|
||||
{
|
||||
if(evdev_fd != -1) {
|
||||
close(evdev_fd);
|
||||
}
|
||||
#if USE_BSD_EVDEV
|
||||
evdev_fd = open(dev_name, O_RDWR | O_NOCTTY);
|
||||
#else
|
||||
evdev_fd = open(dev_name, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
#endif
|
||||
|
||||
if(evdev_fd == -1) {
|
||||
perror("unable open evdev interface:");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if USE_BSD_EVDEV
|
||||
fcntl(evdev_fd, F_SETFL, O_NONBLOCK);
|
||||
#else
|
||||
fcntl(evdev_fd, F_SETFL, O_ASYNC | O_NONBLOCK);
|
||||
#endif
|
||||
|
||||
evdev_root_x = 0;
|
||||
evdev_root_y = 0;
|
||||
evdev_key_val = 0;
|
||||
evdev_button = LV_INDEV_STATE_REL;
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Get the current position and state of the evdev
|
||||
* @param data store the evdev data here
|
||||
* @return false: because the points are not buffered, so no more data to be read
|
||||
*/
|
||||
bool evdev_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
|
||||
{
|
||||
struct input_event in;
|
||||
|
||||
while(read(evdev_fd, &in, sizeof(struct input_event)) > 0) {
|
||||
if(in.type == EV_REL) {
|
||||
if(in.code == REL_X)
|
||||
#if EVDEV_SWAP_AXES
|
||||
evdev_root_y += in.value;
|
||||
#else
|
||||
evdev_root_x += in.value;
|
||||
#endif
|
||||
else if(in.code == REL_Y)
|
||||
#if EVDEV_SWAP_AXES
|
||||
evdev_root_x += in.value;
|
||||
#else
|
||||
evdev_root_y += in.value;
|
||||
#endif
|
||||
} else if(in.type == EV_ABS) {
|
||||
if(in.code == ABS_X)
|
||||
#if EVDEV_SWAP_AXES
|
||||
evdev_root_y = in.value;
|
||||
#else
|
||||
evdev_root_x = in.value;
|
||||
#endif
|
||||
else if(in.code == ABS_Y)
|
||||
#if EVDEV_SWAP_AXES
|
||||
evdev_root_x = in.value;
|
||||
#else
|
||||
evdev_root_y = in.value;
|
||||
#endif
|
||||
else if(in.code == ABS_MT_POSITION_X)
|
||||
#if EVDEV_SWAP_AXES
|
||||
evdev_root_y = in.value;
|
||||
#else
|
||||
evdev_root_x = in.value;
|
||||
#endif
|
||||
else if(in.code == ABS_MT_POSITION_Y)
|
||||
#if EVDEV_SWAP_AXES
|
||||
evdev_root_x = in.value;
|
||||
#else
|
||||
evdev_root_y = in.value;
|
||||
#endif
|
||||
else if(in.code == ABS_MT_TRACKING_ID)
|
||||
if(in.value == -1)
|
||||
evdev_button = LV_INDEV_STATE_REL;
|
||||
else if(in.value == 0)
|
||||
evdev_button = LV_INDEV_STATE_PR;
|
||||
} else if(in.type == EV_KEY) {
|
||||
if(in.code == BTN_MOUSE || in.code == BTN_TOUCH) {
|
||||
if(in.value == 0)
|
||||
evdev_button = LV_INDEV_STATE_REL;
|
||||
else if(in.value == 1)
|
||||
evdev_button = LV_INDEV_STATE_PR;
|
||||
} else if(drv->type == LV_INDEV_TYPE_KEYPAD) {
|
||||
data->state = (in.value) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
|
||||
switch(in.code) {
|
||||
case KEY_BACKSPACE:
|
||||
data->key = LV_KEY_BACKSPACE;
|
||||
break;
|
||||
case KEY_ENTER:
|
||||
data->key = LV_KEY_ENTER;
|
||||
break;
|
||||
case KEY_UP:
|
||||
data->key = LV_KEY_UP;
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
data->key = LV_KEY_PREV;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
data->key = LV_KEY_NEXT;
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
data->key = LV_KEY_DOWN;
|
||||
break;
|
||||
default:
|
||||
data->key = 0;
|
||||
break;
|
||||
}
|
||||
evdev_key_val = data->key;
|
||||
evdev_button = data->state;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(drv->type == LV_INDEV_TYPE_KEYPAD) {
|
||||
/* No data retrieved */
|
||||
data->key = evdev_key_val;
|
||||
data->state = evdev_button;
|
||||
return false;
|
||||
}
|
||||
if(drv->type != LV_INDEV_TYPE_POINTER)
|
||||
return false;
|
||||
/*Store the collected data*/
|
||||
|
||||
#if EVDEV_CALIBRATE
|
||||
data->point.x = map(evdev_root_x, EVDEV_HOR_MIN, EVDEV_HOR_MAX, 0, drv->disp->driver.hor_res);
|
||||
data->point.y = map(evdev_root_y, EVDEV_VER_MIN, EVDEV_VER_MAX, 0, drv->disp->driver.ver_res);
|
||||
#else
|
||||
data->point.x = evdev_root_x;
|
||||
data->point.y = evdev_root_y;
|
||||
#endif
|
||||
|
||||
data->state = evdev_button;
|
||||
|
||||
if(data->point.x < 0)
|
||||
data->point.x = 0;
|
||||
if(data->point.y < 0)
|
||||
data->point.y = 0;
|
||||
if(data->point.x >= drv->disp->driver.hor_res)
|
||||
data->point.x = drv->disp->driver.hor_res - 1;
|
||||
if(data->point.y >= drv->disp->driver.ver_res)
|
||||
data->point.y = drv->disp->driver.ver_res - 1;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
int map(int x, int in_min, int in_max, int out_min, int out_max)
|
||||
{
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
#endif
|
73
Demo/lv_drivers/indev/evdev.h
Normal file
73
Demo/lv_drivers/indev/evdev.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @file evdev.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EVDEV_H
|
||||
#define EVDEV_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifndef LV_DRV_NO_CONF
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "../../lv_drv_conf.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_EVDEV || USE_BSD_EVDEV
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the evdev
|
||||
*/
|
||||
void evdev_init(void);
|
||||
/**
|
||||
* reconfigure the device file for evdev
|
||||
* @param dev_name set the evdev device filename
|
||||
* @return true: the device file set complete
|
||||
* false: the device file doesn't exist current system
|
||||
*/
|
||||
bool evdev_set_file(char* dev_name);
|
||||
/**
|
||||
* Get the current position and state of the evdev
|
||||
* @param data store the evdev data here
|
||||
* @return false: because the points are not buffered, so no more data to be read
|
||||
*/
|
||||
bool evdev_read(lv_indev_drv_t * drv, lv_indev_data_t * data);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* USE_EVDEV */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* EVDEV_H */
|
134
Demo/lv_drivers/indev/keyboard.c
Normal file
134
Demo/lv_drivers/indev/keyboard.c
Normal file
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* @file sdl_kb.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "keyboard.h"
|
||||
#if USE_KEYBOARD
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static uint32_t keycode_to_ascii(uint32_t sdl_key);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static uint32_t last_key;
|
||||
static lv_indev_state_t state;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the keyboard
|
||||
*/
|
||||
void keyboard_init(void)
|
||||
{
|
||||
/*Nothing to init*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last pressed or released character from the PC's keyboard
|
||||
* @param indev_drv pointer to the related input device driver
|
||||
* @param data store the read data here
|
||||
* @return false: because the points are not buffered, so no more data to be read
|
||||
*/
|
||||
void keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
(void) indev_drv; /*Unused*/
|
||||
data->state = state;
|
||||
data->key = keycode_to_ascii(last_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* It is called periodically from the SDL thread to check a key is pressed/released
|
||||
* @param event describes the event
|
||||
*/
|
||||
void keyboard_handler(SDL_Event * event)
|
||||
{
|
||||
/* We only care about SDL_KEYDOWN and SDL_KEYUP events */
|
||||
switch(event->type) {
|
||||
case SDL_KEYDOWN: /*Button press*/
|
||||
last_key = event->key.keysym.sym; /*Save the pressed key*/
|
||||
state = LV_INDEV_STATE_PRESSED; /*Save the key is pressed now*/
|
||||
break;
|
||||
case SDL_KEYUP: /*Button release*/
|
||||
state = LV_INDEV_STATE_RELEASED; /*Save the key is released but keep the last key*/
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Convert the key code LV_KEY_... "codes" or leave them if they are not control characters
|
||||
* @param sdl_key the key code
|
||||
* @return
|
||||
*/
|
||||
static uint32_t keycode_to_ascii(uint32_t sdl_key)
|
||||
{
|
||||
/*Remap some key to LV_KEY_... to manage groups*/
|
||||
switch(sdl_key) {
|
||||
case SDLK_RIGHT:
|
||||
case SDLK_KP_PLUS:
|
||||
return LV_KEY_RIGHT;
|
||||
|
||||
case SDLK_LEFT:
|
||||
case SDLK_KP_MINUS:
|
||||
return LV_KEY_LEFT;
|
||||
|
||||
case SDLK_UP:
|
||||
return LV_KEY_UP;
|
||||
|
||||
case SDLK_DOWN:
|
||||
return LV_KEY_DOWN;
|
||||
|
||||
case SDLK_ESCAPE:
|
||||
return LV_KEY_ESC;
|
||||
|
||||
#ifdef LV_KEY_BACKSPACE /*For backward compatibility*/
|
||||
case SDLK_BACKSPACE:
|
||||
return LV_KEY_BACKSPACE;
|
||||
#endif
|
||||
|
||||
#ifdef LV_KEY_DEL /*For backward compatibility*/
|
||||
case SDLK_DELETE:
|
||||
return LV_KEY_DEL;
|
||||
#endif
|
||||
case SDLK_KP_ENTER:
|
||||
case '\r':
|
||||
return LV_KEY_ENTER;
|
||||
|
||||
case SDLK_PAGEDOWN:
|
||||
return LV_KEY_NEXT;
|
||||
|
||||
case SDLK_PAGEUP:
|
||||
return LV_KEY_PREV;
|
||||
|
||||
default:
|
||||
return sdl_key;
|
||||
}
|
||||
}
|
||||
#endif
|
77
Demo/lv_drivers/indev/keyboard.h
Normal file
77
Demo/lv_drivers/indev/keyboard.h
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @file keyboard.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef KEYBOARD_H
|
||||
#define KEYBOARD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifndef LV_DRV_NO_CONF
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "../../lv_drv_conf.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_KEYBOARD
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
#ifndef MONITOR_SDL_INCLUDE_PATH
|
||||
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#include MONITOR_SDL_INCLUDE_PATH
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/**
|
||||
* Initialize the keyboard
|
||||
*/
|
||||
void keyboard_init(void);
|
||||
|
||||
/**
|
||||
* Get the last pressed or released character from the PC's keyboard
|
||||
* @param indev_drv pointer to the related input device driver
|
||||
* @param data store the read data here
|
||||
*/
|
||||
void keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
|
||||
/**
|
||||
* It is called periodically from the SDL thread to check a key is pressed/released
|
||||
* @param event describes the event
|
||||
*/
|
||||
void keyboard_handler(SDL_Event *event);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_KEYBOARD*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*KEYBOARD_H*/
|
175
Demo/lv_drivers/indev/libinput.c
Normal file
175
Demo/lv_drivers/indev/libinput.c
Normal file
@ -0,0 +1,175 @@
|
||||
/**
|
||||
* @file libinput.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "libinput_drv.h"
|
||||
#if USE_LIBINPUT != 0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/limits.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <poll.h>
|
||||
#include <libinput.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static int open_restricted(const char *path, int flags, void *user_data);
|
||||
static void close_restricted(int fd, void *user_data);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static int libinput_fd;
|
||||
static int libinput_button;
|
||||
static const int timeout = 0; // do not block
|
||||
static const nfds_t nfds = 1;
|
||||
static struct pollfd fds[1];
|
||||
static lv_point_t most_recent_touch_point = { .x = 0, .y = 0};
|
||||
|
||||
static struct libinput *libinput_context;
|
||||
static struct libinput_device *libinput_device;
|
||||
const static struct libinput_interface interface = {
|
||||
.open_restricted = open_restricted,
|
||||
.close_restricted = close_restricted,
|
||||
};
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* reconfigure the device file for libinput
|
||||
* @param dev_name set the libinput device filename
|
||||
* @return true: the device file set complete
|
||||
* false: the device file doesn't exist current system
|
||||
*/
|
||||
bool libinput_set_file(char* dev_name)
|
||||
{
|
||||
// This check *should* not be necessary, yet applications crashes even on NULL handles.
|
||||
// citing libinput.h:libinput_path_remove_device:
|
||||
// > If no matching device exists, this function does nothing.
|
||||
if (libinput_device) {
|
||||
libinput_device = libinput_device_unref(libinput_device);
|
||||
libinput_path_remove_device(libinput_device);
|
||||
}
|
||||
|
||||
libinput_device = libinput_path_add_device(libinput_context, dev_name);
|
||||
if(!libinput_device) {
|
||||
perror("unable to add device to libinput context:");
|
||||
return false;
|
||||
}
|
||||
libinput_device = libinput_device_ref(libinput_device);
|
||||
if(!libinput_device) {
|
||||
perror("unable to reference device within libinput context:");
|
||||
return false;
|
||||
}
|
||||
|
||||
libinput_button = LV_INDEV_STATE_REL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the libinput interface
|
||||
*/
|
||||
void libinput_init(void)
|
||||
{
|
||||
libinput_device = NULL;
|
||||
libinput_context = libinput_path_create_context(&interface, NULL);
|
||||
if(!libinput_set_file(LIBINPUT_NAME)) {
|
||||
perror("unable to add device \"" LIBINPUT_NAME "\" to libinput context:");
|
||||
return;
|
||||
}
|
||||
libinput_fd = libinput_get_fd(libinput_context);
|
||||
|
||||
/* prepare poll */
|
||||
fds[0].fd = libinput_fd;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].revents = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current position and state of the libinput
|
||||
* @param indev_drv driver object itself
|
||||
* @param data store the libinput data here
|
||||
* @return false: because the points are not buffered, so no more data to be read
|
||||
*/
|
||||
bool libinput_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
struct libinput_event *event;
|
||||
struct libinput_event_touch *touch_event = NULL;
|
||||
int rc = 0;
|
||||
|
||||
rc = poll(fds, nfds, timeout);
|
||||
switch (rc){
|
||||
case -1:
|
||||
perror(NULL);
|
||||
case 0:
|
||||
goto report_most_recent_state;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
libinput_dispatch(libinput_context);
|
||||
while((event = libinput_get_event(libinput_context)) != NULL) {
|
||||
enum libinput_event_type type = libinput_event_get_type(event);
|
||||
switch (type) {
|
||||
case LIBINPUT_EVENT_TOUCH_MOTION:
|
||||
case LIBINPUT_EVENT_TOUCH_DOWN:
|
||||
touch_event = libinput_event_get_touch_event(event);
|
||||
most_recent_touch_point.x = libinput_event_touch_get_x_transformed(touch_event, LV_HOR_RES);
|
||||
most_recent_touch_point.y = libinput_event_touch_get_y_transformed(touch_event, LV_VER_RES);
|
||||
libinput_button = LV_INDEV_STATE_PR;
|
||||
break;
|
||||
case LIBINPUT_EVENT_TOUCH_UP:
|
||||
libinput_button = LV_INDEV_STATE_REL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
libinput_event_destroy(event);
|
||||
}
|
||||
report_most_recent_state:
|
||||
data->point.x = most_recent_touch_point.x;
|
||||
data->point.y = most_recent_touch_point.y;
|
||||
data->state = libinput_button;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static int open_restricted(const char *path, int flags, void *user_data)
|
||||
{
|
||||
int fd = open(path, flags);
|
||||
return fd < 0 ? -errno : fd;
|
||||
}
|
||||
|
||||
static void close_restricted(int fd, void *user_data)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
#endif
|
74
Demo/lv_drivers/indev/libinput_drv.h
Normal file
74
Demo/lv_drivers/indev/libinput_drv.h
Normal file
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @file libinput.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LVGL_LIBINPUT_H
|
||||
#define LVGL_LIBINPUT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifndef LV_DRV_NO_CONF
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "../../lv_drv_conf.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_LIBINPUT
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the libinput
|
||||
*/
|
||||
void libinput_init(void);
|
||||
/**
|
||||
* reconfigure the device file for libinput
|
||||
* @param dev_name set the libinput device filename
|
||||
* @return true: the device file set complete
|
||||
* false: the device file doesn't exist current system
|
||||
*/
|
||||
bool libinput_set_file(char* dev_name);
|
||||
/**
|
||||
* Get the current position and state of the libinput
|
||||
* @param indev_drv driver object itself
|
||||
* @param data store the libinput data here
|
||||
* @return false: because the points are not buffered, so no more data to be read
|
||||
*/
|
||||
bool libinput_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* USE_LIBINPUT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* LVGL_LIBINPUT_H */
|
109
Demo/lv_drivers/indev/mouse.c
Normal file
109
Demo/lv_drivers/indev/mouse.c
Normal file
@ -0,0 +1,109 @@
|
||||
/**
|
||||
* @file mouse.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "mouse.h"
|
||||
#if USE_MOUSE != 0
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef MONITOR_ZOOM
|
||||
#define MONITOR_ZOOM 1
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static bool left_button_down = false;
|
||||
static int16_t last_x = 0;
|
||||
static int16_t last_y = 0;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the mouse
|
||||
*/
|
||||
void mouse_init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current position and state of the mouse
|
||||
* @param indev_drv pointer to the related input device driver
|
||||
* @param data store the mouse data here
|
||||
*/
|
||||
void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
(void) indev_drv; /*Unused*/
|
||||
|
||||
/*Store the collected data*/
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
data->state = left_button_down ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
|
||||
/**
|
||||
* It will be called from the main SDL thread
|
||||
*/
|
||||
void mouse_handler(SDL_Event * event)
|
||||
{
|
||||
switch(event->type) {
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if(event->button.button == SDL_BUTTON_LEFT)
|
||||
left_button_down = false;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if(event->button.button == SDL_BUTTON_LEFT) {
|
||||
left_button_down = true;
|
||||
last_x = event->motion.x / MONITOR_ZOOM;
|
||||
last_y = event->motion.y / MONITOR_ZOOM;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
last_x = event->motion.x / MONITOR_ZOOM;
|
||||
last_y = event->motion.y / MONITOR_ZOOM;
|
||||
break;
|
||||
|
||||
case SDL_FINGERUP:
|
||||
left_button_down = false;
|
||||
last_x = LV_HOR_RES * event->tfinger.x / MONITOR_ZOOM;
|
||||
last_y = LV_VER_RES * event->tfinger.y / MONITOR_ZOOM;
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
left_button_down = true;
|
||||
last_x = LV_HOR_RES * event->tfinger.x / MONITOR_ZOOM;
|
||||
last_y = LV_VER_RES * event->tfinger.y / MONITOR_ZOOM;
|
||||
break;
|
||||
case SDL_FINGERMOTION:
|
||||
last_x = LV_HOR_RES * event->tfinger.x / MONITOR_ZOOM;
|
||||
last_y = LV_VER_RES * event->tfinger.y / MONITOR_ZOOM;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif
|
77
Demo/lv_drivers/indev/mouse.h
Normal file
77
Demo/lv_drivers/indev/mouse.h
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @file mouse.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MOUSE_H
|
||||
#define MOUSE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifndef LV_DRV_NO_CONF
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "../../lv_drv_conf.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_MOUSE
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
#ifndef MONITOR_SDL_INCLUDE_PATH
|
||||
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#include MONITOR_SDL_INCLUDE_PATH
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the mouse
|
||||
*/
|
||||
void mouse_init(void);
|
||||
|
||||
/**
|
||||
* Get the current position and state of the mouse
|
||||
* @param indev_drv pointer to the related input device driver
|
||||
* @param data store the mouse data here
|
||||
*/
|
||||
void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
|
||||
/**
|
||||
* It will be called from the main SDL thread
|
||||
*/
|
||||
void mouse_handler(SDL_Event *event);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* USE_MOUSE */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* MOUSE_H */
|
97
Demo/lv_drivers/indev/mousewheel.c
Normal file
97
Demo/lv_drivers/indev/mousewheel.c
Normal file
@ -0,0 +1,97 @@
|
||||
/**
|
||||
* @file mousewheel.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "mousewheel.h"
|
||||
#if USE_MOUSEWHEEL
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static int16_t enc_diff = 0;
|
||||
static lv_indev_state_t state = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the mousewheel
|
||||
*/
|
||||
void mousewheel_init(void)
|
||||
{
|
||||
/*Nothing to init*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Get encoder (i.e. mouse wheel) ticks difference and pressed state
|
||||
* @param indev_drv pointer to the related input device driver
|
||||
* @param data store the read data here
|
||||
*/
|
||||
void mousewheel_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
(void) indev_drv; /*Unused*/
|
||||
|
||||
data->state = state;
|
||||
data->enc_diff = enc_diff;
|
||||
enc_diff = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* It is called periodically from the SDL thread to check mouse wheel state
|
||||
* @param event describes the event
|
||||
*/
|
||||
void mousewheel_handler(SDL_Event * event)
|
||||
{
|
||||
switch(event->type) {
|
||||
case SDL_MOUSEWHEEL:
|
||||
// Scroll down (y = -1) means positive encoder turn,
|
||||
// so invert it
|
||||
#ifdef __EMSCRIPTEN__
|
||||
/*Escripten scales it wrong*/
|
||||
if(event->wheel.y < 0) enc_diff++;
|
||||
if(event->wheel.y > 0) enc_diff--;
|
||||
#else
|
||||
enc_diff = -event->wheel.y;
|
||||
#endif
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if(event->button.button == SDL_BUTTON_MIDDLE) {
|
||||
state = LV_INDEV_STATE_PRESSED;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if(event->button.button == SDL_BUTTON_MIDDLE) {
|
||||
state = LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif
|
78
Demo/lv_drivers/indev/mousewheel.h
Normal file
78
Demo/lv_drivers/indev/mousewheel.h
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @file mousewheel.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MOUSEWHEEL_H
|
||||
#define MOUSEWHEEL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifndef LV_DRV_NO_CONF
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "../../lv_drv_conf.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_MOUSEWHEEL
|
||||
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
#ifndef MONITOR_SDL_INCLUDE_PATH
|
||||
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#include MONITOR_SDL_INCLUDE_PATH
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the encoder
|
||||
*/
|
||||
void mousewheel_init(void);
|
||||
|
||||
/**
|
||||
* Get encoder (i.e. mouse wheel) ticks difference and pressed state
|
||||
* @param indev_drv pointer to the related input device driver
|
||||
* @param data store the read data here
|
||||
*/
|
||||
void mousewheel_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
|
||||
/**
|
||||
* It is called periodically from the SDL thread to check a key is pressed/released
|
||||
* @param event describes the event
|
||||
*/
|
||||
void mousewheel_handler(SDL_Event *event);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_MOUSEWHEEL*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*MOUSEWHEEL_H*/
|
Reference in New Issue
Block a user