Add camera driver and examples for edu-riscv64 from Wu_zheng

it is OK
This commit is contained in:
xuedongliang
2022-11-25 10:25:38 +08:00
51 changed files with 2594 additions and 270 deletions
@@ -105,6 +105,8 @@ menu "test app"
menuconfig USER_TEST_HWTIMER
select BSP_USING_HWTIMER
select BSP_USING_GPIO
select RESOURCES_PIN
select BSP_USING_LED
bool "Config test hwtimer"
default n
if USER_TEST_HWTIMER
@@ -139,6 +141,21 @@ menu "test app"
endif
endif
menuconfig USER_TEST_TOUCH
select BSP_USING_TOUCH
bool "Config test touch"
default n
if USER_TEST_TOUCH
if ADD_XIZI_FETURES
config TOUCH_DEV_DRIVER
string "Set touch dev path"
default "/dev/touch_dev"
config TOUCH_LCD_DEV_DRIVER
string "Set lcd dev path"
default "/dev/lcd_dev"
endif
endif
menuconfig USER_TEST_I2C
select BSP_USING_I2C
bool "Config test i2c"
@@ -151,6 +168,22 @@ menu "test app"
endif
endif
menuconfig USER_TEST_CAMERA
select BSP_USING_CAMERA
select BSP_USING_LCD
bool "Config test camera with lcd"
default n
if USER_TEST_CAMERA
if ADD_XIZI_FETURES
config CAMERA_DEV_DRIVER
string "Set camera dev path"
default "/dev/camera_dev"
config CAMERA_LCD_DEV_DRIVER
string "Set lcd dev path"
default "/dev/lcd_dev"
endif
endif
config USER_TEST_SEMC
bool "Config test semc sdram"
default n
+9 -1
View File
@@ -75,7 +75,15 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
ifeq ($(CONFIG_USER_TEST_WDT),y)
SRC_FILES += test_wdt.c
endif
endif
ifeq ($(CONFIG_USER_TEST_TOUCH),y)
SRC_FILES += test_touch.c
endif
ifeq ($(CONFIG_USER_TEST_CAMERA),y)
SRC_FILES += test_camera.c
endif
include $(KERNEL_ROOT)/compiler.mk
endif
@@ -0,0 +1,108 @@
#include <stdio.h>
#include <string.h>
#include <transform.h>
#define NULL_PARAMETER 0
#define DVP_INIT 0x00U
#define REG_SCCB_READ 0x12U
#define REG_SCCB_WRITE 0x13U
#define OUTPUT_CONFIG 0x20U
#define LCD_STRING_TYPE 0
#define LCD_DOT_TYPE 1
#define LCD_SIZE 320
static uint16_t image_buff[384000];
void TestCamera(int argc, char *argv[])
{
int frame_counter = 10000;
if (argc > 1)
{
frame_counter = atoi(argv[1]);
}
printf("This test will refresh %d frames\n", frame_counter);
int camera_fd = PrivOpen(CAMERA_DEV_DRIVER, O_RDWR);
if (camera_fd < 0)
{
printf("open camera fd error:%d\n", camera_fd);
return;
}
int lcd_fd = PrivOpen(CAMERA_LCD_DEV_DRIVER, O_RDWR);
if (lcd_fd < 0)
{
printf("open lcd fd error:%d\n", lcd_fd);
return;
}
//configure the camera's output address
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = CAMERA_TYPE;
struct CameraCfg camera_cfg ={
.gain_manu_enable = 0,
.gain = 0xFF,
.window_w = 800,
.window_h = 600,
.output_w = IMAGE_WIDTH,
.output_h = IMAGE_HEIGHT,
.window_xoffset = 0,
.window_yoffset = 0
};
ioctl_cfg.args = &camera_cfg;
if (0 != PrivIoctl(camera_fd, OPE_CFG, &ioctl_cfg))
{
printf("camera pin fd error %d\n", camera_fd);
PrivClose(camera_fd);
return;
}
ioctl_cfg.args = (void *)image_buff;
if (0 != PrivRead(camera_fd, image_buff, NULL_PARAMETER))
{
printf("camera pin fd error %d\n", camera_fd);
PrivClose(camera_fd);
return;
}
printf("address buff is %x\n", image_buff);
LcdWriteParam graph_param;
graph_param.type = LCD_DOT_TYPE;
//clear the LCD
uint16_t back_color[LCD_SIZE];
memset(back_color,0,sizeof(back_color));
for (int i = 0; i < LCD_SIZE; i++)
{
graph_param.pixel_info.pixel_color = &back_color;
graph_param.pixel_info.x_startpos = 0;
graph_param.pixel_info.y_startpos = i;
graph_param.pixel_info.x_endpos = LCD_SIZE -1;
graph_param.pixel_info.y_endpos = i;
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
}
//refresh the LCD using photo of camera
while (frame_counter--)
{
for (int i = 0; i < IMAGE_HEIGHT; i++)
{
graph_param.pixel_info.pixel_color = image_buff + i * IMAGE_WIDTH;
graph_param.pixel_info.x_startpos = 0;
graph_param.pixel_info.y_startpos = i + (LCD_SIZE - IMAGE_HEIGHT) / 2;
graph_param.pixel_info.x_endpos = IMAGE_WIDTH - 1;
graph_param.pixel_info.y_endpos = i + (LCD_SIZE - IMAGE_HEIGHT) / 2;
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
}
}
// close test
PrivClose(lcd_fd);
PrivClose(camera_fd);
printf("The camera test is finished successfully\n");
}
PRIV_SHELL_CMD_FUNCTION(TestCamera, a camera test sample, PRIV_SHELL_CMD_MAIN_ATTR);
@@ -6,28 +6,23 @@
#define NULL_PARAMETER 0
static uint16_t pinval=0;
static uint16_t pin_fd=0;
void ledflip(void *parameter)
{
int tmp_fd = *(int*)parameter;
struct PinStat pin_led;
pin_led.pin = BSP_LED_PIN;
pin_led.val = !pinval;
pinval = !pinval;
PrivWrite(tmp_fd,&pin_led,NULL_PARAMETER);
printf("Timer has callback once\n");
PrivWrite(pin_fd,&pin_led,NULL_PARAMETER);
// printf("Timer has callback once:%d\n",pinval);
}
void TestHwTimer(int argc, char *argv[])
void TestHwTimer(void)
{
x_ticks_t period = 100;//uint:10ms
if(argc>1){
period = (x_ticks_t)atoi(argv[1]);
}
int pin_fd = PrivOpen(HWTIMER_PIN_DEV_DRIVER, O_RDWR);
pin_fd = PrivOpen(HWTIMER_PIN_DEV_DRIVER, O_RDWR);
if(pin_fd<0){
printf("open pin fd error:%d\n",pin_fd);
return;
@@ -52,10 +47,6 @@ void TestHwTimer(int argc, char *argv[])
int32 timer_handle = KCreateTimer("LED on and off by 1s",&ledflip,&pin_fd,period,TIMER_TRIGGER_PERIODIC);
KTimerStartRun(timer_handle);
PrivTaskDelay(10000);
KTimerQuitRun(timer_handle);
KDeleteTimer(timer_handle);
}
@@ -41,3 +41,71 @@ void TestTouch(void)
#endif
#endif
#include <stdio.h>
#include <string.h>
#include <transform.h>
#define NULL_PARAMETER 0
#define LCD_DOT_TYPE 1
#define LCD_SIZE 320
void TestTouch(void)
{
int touch_fd = PrivOpen(TOUCH_DEV_DRIVER, O_RDWR);
if (touch_fd < 0)
{
printf("open touch fd error:%d\n", touch_fd);
return;
}
int lcd_fd = PrivOpen(TOUCH_LCD_DEV_DRIVER, O_RDWR);
if (lcd_fd < 0)
{
printf("open lcd fd error:%d\n", lcd_fd);
return;
}
// draw text
struct TouchDataStandard touch_pixel;
memset(&touch_pixel,0,sizeof(touch_pixel));
LcdWriteParam graph_param;
graph_param.type = LCD_DOT_TYPE;
uint16_t back_color[LCD_SIZE];
memset(back_color,0x00,sizeof(back_color));
for (int i = 0; i < LCD_SIZE; i++)
{
graph_param.pixel_info.pixel_color = &back_color;
graph_param.pixel_info.x_startpos = 0;
graph_param.pixel_info.y_startpos = i;
graph_param.pixel_info.x_endpos = LCD_SIZE -1;
graph_param.pixel_info.y_endpos = i;
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
}
uint16 color_select[LCD_SIZE];
memset(color_select,0xff,sizeof(color_select));
graph_param.pixel_info.pixel_color = &color_select;
while(1){
if(0 > PrivRead(touch_fd, &touch_pixel, NULL_PARAMETER)){
printf("read touch error\n");
return;
}
printf("touch pixel position x:%d,y:%d\n",touch_pixel.x,touch_pixel.y);
graph_param.pixel_info.x_startpos = touch_pixel.x-10>0?touch_pixel.x-10:0;
graph_param.pixel_info.y_startpos = touch_pixel.y;
graph_param.pixel_info.x_endpos = touch_pixel.x+10;
graph_param.pixel_info.y_endpos = touch_pixel.y;
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
graph_param.pixel_info.x_startpos = touch_pixel.x;
graph_param.pixel_info.y_startpos = touch_pixel.y-10>0?touch_pixel.y-10:0;
graph_param.pixel_info.x_endpos = touch_pixel.x;
graph_param.pixel_info.y_endpos = touch_pixel.y+10;
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
}
PrivClose(touch_fd);
}
PRIV_SHELL_CMD_FUNCTION(TestTouch, a touch test sample, PRIV_SHELL_CMD_MAIN_ATTR);
@@ -30,10 +30,10 @@ void HumiHs300x(void)
int32_t humidity;
struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI);
SensorQuantityOpen(humi);
for (i = 0; i < 100; i ++) {
for (i = 0; i < 10; i ++) {
humidity = SensorQuantityReadValue(humi);
printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10);
PrivTaskDelay(5000);
PrivTaskDelay(500);
}
SensorQuantityClose(humi);
}
@@ -30,14 +30,14 @@ void TempHs300x(void)
int32_t temperature;
struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP);
SensorQuantityOpen(temp);
for (i = 0; i < 100; i ++) {
for (i = 0; i < 10; i ++) {
temperature = SensorQuantityReadValue(temp);
if (temperature > 0)
printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10);
else
printf("Temperature : %d.%d ℃\n", temperature/10, -temperature%10);
PrivTaskDelay(5000);
PrivTaskDelay(500);
}
SensorQuantityClose(temp);
@@ -17,5 +17,9 @@ ifeq ($(CONFIG_ADAPTER_ESP07S_WIFI),y)
SRC_DIR += esp07s_wifi
endif
ifeq ($(CONFIG_ADAPTER_ESP8285_WIFI),y)
SRC_DIR += esp8285_wifi
endif
include $(KERNEL_ROOT)/compiler.mk
endif
@@ -8,3 +8,9 @@ if ADD_NUTTX_FETURES
default "/dev/ttyS1"
endif
if ADD_XIZI_FETURES
config ADAPTER_ESP8285_DRIVER
string "ESP8285 device uart driver path"
default "/dev/uart1_dev1"
endif
@@ -5,3 +5,8 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Application.mk
endif
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
SRC_FILES := esp8285_wifi.c
include $(KERNEL_ROOT)/compiler.mk
endif
@@ -205,16 +205,16 @@ static int Esp8285WifiSetUp(struct Adapter *adapter)
PrivTaskDelay(2000);
/* connect the router */
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"AT+CWJAP=",strlen("AT+CWJAP="));
strncat(cmd,"\"",1);
strncat(cmd,param->wifi_ssid,strlen(param->wifi_ssid));
strcat(cmd,"AT+CWJAP=");
strcat(cmd,"\"");
strcat(cmd,param->wifi_ssid);
strncat(cmd,"\"",1);
strncat(cmd,",",1);
strncat(cmd,"\"",1);
strncat(cmd,param->wifi_pwd,strlen(param->wifi_pwd));
strcat(cmd,"\"");
strcat(cmd,",");
strcat(cmd,"\"");
strcat(cmd,param->wifi_pwd);
strncat(cmd,"\"",1);
strcat(cmd,"\"");
strcat(cmd,"\r\n");
ret = AtCmdConfigAndCheck(agent, cmd, "OK");
@@ -279,17 +279,17 @@ static int Esp8285WifiSetAddr(struct Adapter *adapter, const char *ip, const cha
/* e.g. AT+CIPSTA_DEF="192.168.6.100","192.168.6.1","255.255.255.0" */
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"AT+CIPAP_DEF=",strlen(" AT+CIPAP_DEF="));
strncat(cmd,"\"",1);
strncat(cmd,ip,strlen(ip));
strncat(cmd,"\"",1);
strncat(cmd,",",1);
strncat(cmd,"\"",1);
strncat(cmd,gateway,strlen(gateway));
strncat(cmd,"\"",1);
strncat(cmd,",",1);
strncat(cmd,"\"",1);
strncat(cmd,netmask,strlen(netmask));
strncat(cmd,"\"",1);
strcat(cmd,"\"");
strcat(cmd,ip);
strcat(cmd,"\"");
strcat(cmd,",");
strcat(cmd,"\"");
strcat(cmd,gateway);
strcat(cmd,"\"");
strcat(cmd,",");
strcat(cmd,"\"");
strcat(cmd,netmask);
strcat(cmd,"\"");
strcat(cmd,"\r\n");
ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK");
@@ -314,9 +314,9 @@ static int Esp8285WifiPing(struct Adapter *adapter, const char *destination)
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"AT+PING=",strlen("AT+PING="));
strncat(cmd,"\"",1);
strncat(cmd,destination,strlen(destination));
strncat(cmd,"\"",1);
strcat(cmd,"\"");
strcat(cmd,destination);
strcat(cmd,"\"");
strcat(cmd,"\r\n");
ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK"); ///< config as softAP+station mode
@@ -387,15 +387,15 @@ static int Esp8285WifiConnect(struct Adapter *adapter, enum NetRoleType net_role
{
//e.g. AT+CIPSTART="TCP","192.168.3.116",8080 protocol, server IP and port
strncpy(cmd,"AT+CIPSTART=",strlen("AT+CIPSTART="));
strncat(cmd,"\"",1);
strncat(cmd,"TCP",strlen("TCP"));
strncat(cmd,"\"",1);
strncat(cmd, ",", 1);
strncat(cmd,"\"",1);
strncat(cmd, ip, strlen(ip));
strncat(cmd, "\"", 1);
strncat(cmd, ",", 1);
strncat(cmd, port, strlen(port));
strcat(cmd,"\"");
strcat(cmd,"TCP");
strcat(cmd,"\"");
strcat(cmd, ",");
strcat(cmd,"\"");
strcat(cmd, ip);
strcat(cmd, "\"");
strcat(cmd, ",");
strcat(cmd, port);
strcat(cmd,"\r\n");
ret = AtCmdConfigAndCheck(agent, cmd, "OK");
@@ -408,19 +408,19 @@ static int Esp8285WifiConnect(struct Adapter *adapter, enum NetRoleType net_role
{
//e.g. AT+CIPSTART="UDP","192.168.3.116",8080,2233,0 UDP protocol, server IP, port,local port,udp mode
strncpy(cmd,"AT+CIPSTART=",strlen("AT+CIPSTART="));
strncat(cmd,"\"",1);
strncat(cmd,"UDP",strlen("UDP"));
strncat(cmd,"\"",1);
strncat(cmd, ",", 1);
strncat(cmd,"\"",1);
strncat(cmd, ip, strlen(ip));
strncat(cmd, "\"", 1);
strncat(cmd, ",", 1);
strncat(cmd, port, strlen(port));
strncat(cmd, ",", 1);
strncat(cmd, "2233", strlen("2233")); ///< local port
strncat(cmd, ",", 1);
strncat(cmd, "0", 1); ///< udp transparent transmission mode must be 0
strcat(cmd,"\"");
strcat(cmd,"UDP");
strcat(cmd,"\"");
strcat(cmd, ",");
strcat(cmd,"\"");
strcat(cmd, ip);
strcat(cmd, "\"");
strcat(cmd, ",");
strcat(cmd, port);
strcat(cmd, ",");
strcat(cmd, "2233"); ///< local port
strcat(cmd, ",");
strcat(cmd, "0"); ///< udp transparent transmission mode must be 0
strcat(cmd,"\r\n");
ret = AtCmdConfigAndCheck(agent, cmd, "OK");
@@ -523,15 +523,15 @@ static int Esp8285WifiIoctl(struct Adapter *adapter, int cmd, void *args)
itoa(baud_rate, baud_str, 10);
strncpy(at_cmd, "AT+UART_DEF=", strlen("AT+UART_DEF="));
strncat(at_cmd, baud_str, strlen(baud_str));
strncat(at_cmd, ",", 1);
strncat(at_cmd, "8", 1);
strncat(at_cmd, ",", 1);
strncat(at_cmd, "1", 1);
strncat(at_cmd, ",", 1);
strncat(at_cmd, "0", 1);
strncat(at_cmd, ",", 1);
strncat(at_cmd, "3", 1);
strcat(at_cmd, baud_str);
strcat(at_cmd, ",");
strcat(at_cmd, "8");
strcat(at_cmd, ",");
strcat(at_cmd, "1");
strcat(at_cmd, ",");
strcat(at_cmd, "0");
strcat(at_cmd, ",");
strcat(at_cmd, "3");
strcat(at_cmd,"\r\n");
ret = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
+6
View File
@@ -6,6 +6,12 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
endif
ifeq ($(ADD_XIZI_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += sensor.c
include $(APPDIR)/Application.mk
endif
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
SRC_FILES := sensor.c
@@ -173,6 +173,7 @@ int PrivIoctl(int fd, int cmd, void *args)
case ADC_TYPE:
case DAC_TYPE:
case WDT_TYPE:
case CAMERA_TYPE:
ret = ioctl(fd, cmd, ioctl_cfg->args);
break;
default:
@@ -150,9 +150,18 @@ enum IoctlDriverType
DAC_TYPE,
WDT_TYPE,
RTC_TYPE,
CAMERA_TYPE,
DEFAULT_TYPE,
};
struct DvpRegConfigureInfo
{
uint8_t device_addr;
uint16_t reg_addr;
uint8_t reg_value;
} ;
struct PrivIoctlCfg
{
enum IoctlDriverType ioctl_driver_type;
@@ -180,6 +189,18 @@ typedef struct
void* pixel_color;
}LcdPixelParam;
struct CameraCfg
{
uint16_t window_w;
uint16_t window_h;
uint16_t window_xoffset;
uint16_t window_yoffset;
uint16_t output_w;
uint16_t output_h;
uint8_t gain;
uint8_t gain_manu_enable;
};
typedef struct
{
char type; // 0:write string;1:write dot
@@ -194,6 +215,12 @@ typedef struct
uint16_t press;
}TouchDataParam;
struct TouchDataStandard
{
uint16 x;
uint16 y;
};
struct RtcDrvConfigureParam
{
int rtc_operation_cmd;
@@ -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;
}
}
+3 -3
View File
@@ -1,10 +1,10 @@
# include $(LVGL_DIR)/$(LVGL_DIR_NAME)/examples/examples.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/porting/porting.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/examples/examples.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/extra/extra.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/core/lv_core.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/draw/lv_draw.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/font/lv_font.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/gpu/lv_gpu.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/hal/lv_hal.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/misc/lv_misc.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/widgets/lv_widgets.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/widgets/lv_widgets.mk
@@ -12,7 +12,6 @@
#include "lv_port_indev_template.h"
#include "../lvgl.h"
#include <dev_touch.h>
static int touch_fd = 0;
/*********************
@@ -292,7 +291,7 @@ static bool touchpad_is_pressed(struct TouchDataStandard* touch_data_ptr)
press_failed_cnt = 0;
return true;
}
printf("lv_touch:%d,%d\n",touch_data_ptr->x,touch_data_ptr->y);
press_failed_cnt++;
if (press_failed_cnt >= PRESS_FAILED_LIMIT) {
PrivClose(touch_fd);