add softspi in xidatong-riscv64

This commit is contained in:
wuzheng
2022-11-22 10:20:15 +08:00
parent 987fd6c798
commit 49df162734
14 changed files with 550 additions and 76 deletions

View File

@@ -3,7 +3,7 @@
*
*/
/*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/
/*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/
#if 1
/*********************
@@ -12,18 +12,18 @@
#include "lv_port_indev_template.h"
#include "../../lvgl.h"
static int touch_fd = -1;
static TouchDataParam touch_data;
static int touch_fd = 0;
/*********************
* DEFINES
*********************/
#define LV_USE_INDEV_TOUCHPAD 0x1u
#define LV_USE_INDEV_MOUSE 0x2u
#define LV_USE_INDEV_KEYPAD 0x4u
#define LV_USE_INDEV_ENCODER 0x8u
#define LV_USE_INDEV_BUTTUN 0x10u
#define LV_USE_INDEV_MOUSE 0x2u
#define LV_USE_INDEV_KEYPAD 0x4u
#define LV_USE_INDEV_ENCODER 0x8u
#define LV_USE_INDEV_BUTTUN 0x10u
#define LV_USE_INDEV LV_USE_INDEV_TOUCHPAD ///< modify this DEFINE to enable the indev device. e.g #define LV_USE_INDEV LV_USE_INDEV_TOUCHPAD | LV_USE_INDEV_KEYPAD
#define PRESS_FAILED_LIMIT 15
#define LV_USE_INDEV LV_USE_INDEV_TOUCHPAD ///< modify this DEFINE to enable the indev device. e.g #define LV_USE_INDEV LV_USE_INDEV_TOUCHPAD | LV_USE_INDEV_KEYPAD
/**********************
* TYPEDEFS
@@ -34,33 +34,36 @@ static TouchDataParam touch_data;
**********************/
#if (LV_USE_INDEV & LV_USE_INDEV_TOUCHPAD) == LV_USE_INDEV_TOUCHPAD
static void touchpad_init(void);
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static bool touchpad_is_pressed(void);
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
static void touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
// static bool touchpad_is_pressed(void);
// static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
static bool touchpad_is_pressed(struct TouchDataStandard *touch_data_ptr);
static void touchpad_get_xy(struct TouchDataStandard *touch_data_ptr,
lv_coord_t *x, lv_coord_t *y);
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_MOUSE) == LV_USE_INDEV_MOUSE
static void mouse_init(void);
static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static void mouse_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
static bool mouse_is_pressed(void);
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
static void mouse_get_xy(lv_coord_t *x, lv_coord_t *y);
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_KEYPAD) == LV_USE_INDEV_KEYPAD
static void keypad_init(void);
static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static void keypad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
static uint32_t keypad_get_key(void);
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_ENCODER) == LV_USE_INDEV_ENCODER
static void encoder_init(void);
static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static void encoder_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
static void encoder_handler(void);
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_BUTTUN) == LV_USE_INDEV_BUTTUN
static void button_init(void);
static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
static void button_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
static int8_t button_get_pressed_id(void);
static bool button_is_pressed(uint8_t id);
#endif
@@ -69,23 +72,23 @@ static bool button_is_pressed(uint8_t id);
* STATIC VARIABLES
**********************/
#if (LV_USE_INDEV & LV_USE_INDEV_TOUCHPAD) == LV_USE_INDEV_TOUCHPAD
lv_indev_t * indev_touchpad;
lv_indev_t *indev_touchpad;
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_MOUSE) == LV_USE_INDEV_MOUSE
lv_indev_t * indev_mouse;
lv_indev_t *indev_mouse;
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_KEYPAD) == LV_USE_INDEV_KEYPAD
lv_indev_t * indev_keypad;
lv_indev_t *indev_keypad;
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_ENCODER) == LV_USE_INDEV_ENCODER
lv_indev_t * indev_encoder;
lv_indev_t *indev_encoder;
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_BUTTUN) == LV_USE_INDEV_BUTTUN
lv_indev_t * indev_button;
lv_indev_t *indev_button;
#endif
static int32_t encoder_diff;
@@ -144,7 +147,7 @@ void lv_port_indev_init(void)
indev_mouse = lv_indev_drv_register(&indev_drv);
/*Set cursor. For simplicity set a HOME symbol now.*/
lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act());
lv_obj_t *mouse_cursor = lv_img_create(lv_scr_act());
lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME);
lv_indev_set_cursor(indev_mouse, mouse_cursor);
#endif
@@ -169,8 +172,6 @@ void lv_port_indev_init(void)
*`lv_indev_set_group(indev_keypad, group);`*/
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_ENCODER) == LV_USE_INDEV_ENCODER
/*------------------
* Encoder
@@ -207,8 +208,8 @@ void lv_port_indev_init(void)
/*Assign buttons to points on the screen*/
static const lv_point_t btn_points[2] = {
{10, 10}, /*Button 0 -> x:10; y:10*/
{40, 100}, /*Button 1 -> x:40; y:100*/
{10, 10}, /*Button 0 -> x:10; y:10*/
{40, 100}, /*Button 1 -> x:40; y:100*/
};
lv_indev_set_button_points(indev_button, btn_points);
#endif
@@ -225,27 +226,37 @@ void lv_port_indev_init(void)
/*Initialize your touchpad*/
static void touchpad_init(void)
{
touch_fd = PrivOpen(PRIV_TOUCH_DEV,O_RDWR);
if(touch_fd >= 0) {
touch_fd = PrivOpen(PRIV_TOUCH_DEV, O_RDWR);
if (touch_fd >= 0)
{
printf("touch fd = %d\n",touch_fd);
} else {
printf("open %s touch fd = %d failed.\n",PRIV_TOUCH_DEV,touch_fd);
touch_fd = -1;
}
else
{
printf("open %s touch fd = %d failed.\n", PRIV_TOUCH_DEV, touch_fd);
}
/*Your code comes here*/
}
// static struct TouchDataStandard touch_data;
/*Will be called by the library to read the touchpad*/
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
static void touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
static lv_coord_t last_x = 0;
static lv_coord_t last_y = 0;
static struct TouchDataStandard touch_data;
/*Save the pressed coordinates and the state*/
if(touchpad_is_pressed()) {
touchpad_get_xy(&last_x, &last_y);
if (touchpad_is_pressed(&touch_data))
{
touchpad_get_xy(&touch_data, &last_x, &last_y);
data->state = LV_INDEV_STATE_PR;
} else {
}
else
{
data->state = LV_INDEV_STATE_REL;
}
@@ -255,34 +266,68 @@ static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
}
/*Return true is the touchpad is pressed*/
static bool touchpad_is_pressed(void)
// static bool touchpad_is_pressed(void)
// {
// int ret;
// /*Your code comes here*/
// // memset(&touch_data, 0 ,sizeof(TouchDataParam));
// memset(&touch_data, 0 ,sizeof(struct TouchDataStandard));
// ret = PrivRead(touch_fd, &touch_data, 1);
// if (ret && touch_data.x >= 0 && touch_data.x < MY_INDEV_X
// && touch_data.y >= 0 && touch_data.y < MY_INDEV_Y)
// {
// // printf("touch x %d touch y %d\n",touch_data.x,touch_data.y);
// return true;
// }
// return false;
// }
uint32_t press_failed_cnt = 0;
static bool touchpad_is_pressed(struct TouchDataStandard *touch_data_ptr)
{
int ret;
/*Your code comes here*/
memset(&touch_data, 0 ,sizeof(TouchDataParam));
if (touch_fd < 0) {
return false;
}
ret = PrivRead(touch_fd, &touch_data, 1);
if(ret && touch_data.x >= 0 && touch_data.x < MY_INDEV_X && touch_data.y >= 0 && touch_data.y < MY_INDEV_Y)
memset(touch_data_ptr, 0, sizeof(struct TouchDataStandard));
ret = PrivRead(touch_fd, touch_data_ptr, 1);
if (ret)
{
printf("touch x %d touch y %d\n",touch_data.x,touch_data.y);
return true;
if (touch_data_ptr->x > 0 && touch_data_ptr->x < MY_INDEV_X && touch_data_ptr->y > 0 && touch_data_ptr->y < MY_INDEV_Y)
{
press_failed_cnt = 0;
return true;
}
else
{
press_failed_cnt++;
if (press_failed_cnt >= PRESS_FAILED_LIMIT)
{
PrivClose(touch_fd);
touchpad_init();
press_failed_cnt = 0;
}
}
}
return false;
}
/*Get the x and y coordinates if the touchpad is pressed*/
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
static void touchpad_get_xy(struct TouchDataStandard *touch_data_ptr,
lv_coord_t *x, lv_coord_t *y)
{
/*Your code comes here*/
(*x) = touch_data.x;
(*y) = touch_data.y;
(*x) = touch_data_ptr->x;
(*y) = touch_data_ptr->y;
}
// static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
// {
// /*Your code comes here*/
// (*x) = touch_data.x;
// (*y) = touch_data.y;
// }
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_MOUSE) == LV_USE_INDEV_MOUSE
@@ -297,15 +342,18 @@ static void mouse_init(void)
}
/*Will be called by the library to read the mouse*/
static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
static void mouse_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
/*Get the current x and y coordinates*/
mouse_get_xy(&data->point.x, &data->point.y);
/*Get whether the mouse button is pressed or released*/
if(mouse_is_pressed()) {
if (mouse_is_pressed())
{
data->state = LV_INDEV_STATE_PR;
} else {
}
else
{
data->state = LV_INDEV_STATE_REL;
}
}
@@ -319,7 +367,7 @@ static bool mouse_is_pressed(void)
}
/*Get the x and y coordinates if the mouse is pressed*/
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
static void mouse_get_xy(lv_coord_t *x, lv_coord_t *y)
{
/*Your code comes here*/
@@ -328,8 +376,6 @@ static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
}
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_KEYPAD) == LV_USE_INDEV_KEYPAD
/*------------------
* Keypad
@@ -342,7 +388,7 @@ static void keypad_init(void)
}
/*Will be called by the library to read the mouse*/
static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
static void keypad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
static uint32_t last_key = 0;
@@ -351,11 +397,13 @@ static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
/*Get whether the a key is pressed and save the pressed key*/
uint32_t act_key = keypad_get_key();
if(act_key != 0) {
if (act_key != 0)
{
data->state = LV_INDEV_STATE_PR;
/*Translate the keys to LVGL control characters according to your key definitions*/
switch(act_key) {
switch (act_key)
{
case 1:
act_key = LV_KEY_NEXT;
break;
@@ -374,7 +422,9 @@ static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
}
last_key = act_key;
} else {
}
else
{
data->state = LV_INDEV_STATE_REL;
}
@@ -390,8 +440,6 @@ static uint32_t keypad_get_key(void)
}
#endif
#if (LV_USE_INDEV & LV_USE_INDEV_ENCODER) == LV_USE_INDEV_ENCODER
/*------------------
* Encoder
@@ -404,7 +452,7 @@ static void encoder_init(void)
}
/*Will be called by the library to read the encoder*/
static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
static void encoder_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
data->enc_diff = encoder_diff;
@@ -433,7 +481,7 @@ static void button_init(void)
}
/*Will be called by the library to read the button*/
static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
static void button_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
static uint8_t last_btn = 0;
@@ -441,10 +489,13 @@ static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
/*Get the pressed button's ID*/
int8_t btn_act = button_get_pressed_id();
if(btn_act >= 0) {
if (btn_act >= 0)
{
data->state = LV_INDEV_STATE_PR;
last_btn = btn_act;
} else {
}
else
{
data->state = LV_INDEV_STATE_REL;
}
@@ -458,9 +509,11 @@ static int8_t button_get_pressed_id(void)
uint8_t i;
/*Check to buttons see which is being pressed (assume there are 2 buttons)*/
for(i = 0; i < 2; i++) {
for (i = 0; i < 2; i++)
{
/*Return the pressed button's ID*/
if(button_is_pressed(i)) {
if (button_is_pressed(i))
{
return i;
}
}

View File

@@ -12,7 +12,6 @@
#include "lv_port_indev_template.h"
#include "../lvgl.h"
#include <dev_touch.h>
static int touch_fd = 0;
/*********************