Browse Source

Add camera driver and examples for edu-riscv64 from Wu_zheng

it is OK
prepare_for_master
xuedongliang 4 months ago
parent
commit
e5bf0cee41
  1. 33
      APP_Framework/Applications/app_test/Kconfig
  2. 10
      APP_Framework/Applications/app_test/Makefile
  3. 108
      APP_Framework/Applications/app_test/test_camera.c
  4. 19
      APP_Framework/Applications/app_test/test_hwtimer.c
  5. 68
      APP_Framework/Applications/app_test/test_touch.c
  6. 4
      APP_Framework/Applications/sensor_app/humidity_hs300x.c
  7. 4
      APP_Framework/Applications/sensor_app/temperature_hs300x.c
  8. 4
      APP_Framework/Framework/connection/wifi/Makefile
  9. 6
      APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig
  10. 5
      APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile
  11. 106
      APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c
  12. 6
      APP_Framework/Framework/sensor/Makefile
  13. 1
      APP_Framework/Framework/transform_layer/xizi/transform.c
  14. 27
      APP_Framework/Framework/transform_layer/xizi/transform.h
  15. 189
      APP_Framework/lib/lvgl/examples/porting/lv_port_indev_template.c
  16. 6
      APP_Framework/lib/lvgl/lvgl.mk
  17. 3
      APP_Framework/lib/lvgl/porting/lv_port_indev_template.c
  18. 6
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/board.c
  19. 9
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/Kconfig
  20. 4
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/Makefile
  21. 46
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/Kconfig
  22. 4
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/Makefile
  23. 243
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/connect_dvp.c
  24. 288
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/dvp.c
  25. 463
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/ov2640.c
  26. 38
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/gpio/drv_io_config.c
  27. 34
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/include/connect_dvp.h
  28. 4
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/include/connect_touch.h
  29. 86
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/include/drv_io_config.h
  30. 38
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/include/ov2640.h
  31. 13
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/lcd/connect_lcd.c
  32. 26
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/soft_spi/connect_soft_spi.c
  33. 15
      Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/touch/connect_touch.c
  34. 8
      Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/touch/connect_touch.c
  35. 16
      Ubiquitous/XiZi_IIoT/board/xidatong-riscv64/third_party_driver/Kconfig
  36. 4
      Ubiquitous/XiZi_IIoT/board/xidatong-riscv64/third_party_driver/Makefile
  37. 14
      Ubiquitous/XiZi_IIoT/board/xidatong-riscv64/third_party_driver/include/connect_soft_spi.h
  38. 43
      Ubiquitous/XiZi_IIoT/board/xidatong-riscv64/third_party_driver/soft_spi/Kconfig
  39. 3
      Ubiquitous/XiZi_IIoT/board/xidatong-riscv64/third_party_driver/soft_spi/Makefile
  40. 295
      Ubiquitous/XiZi_IIoT/board/xidatong-riscv64/third_party_driver/soft_spi/connect_soft_spi.c
  41. 6
      Ubiquitous/XiZi_IIoT/resources/Kconfig
  42. 4
      Ubiquitous/XiZi_IIoT/resources/Makefile
  43. 5
      Ubiquitous/XiZi_IIoT/resources/camera/Makefile
  44. 123
      Ubiquitous/XiZi_IIoT/resources/camera/bus_camera.c
  45. 200
      Ubiquitous/XiZi_IIoT/resources/camera/dev_camera.c
  46. 68
      Ubiquitous/XiZi_IIoT/resources/camera/drv_camera.c
  47. 3
      Ubiquitous/XiZi_IIoT/resources/include/bus.h
  48. 69
      Ubiquitous/XiZi_IIoT/resources/include/bus_camera.h
  49. 69
      Ubiquitous/XiZi_IIoT/resources/include/dev_camera.h
  50. 5
      Ubiquitous/XiZi_IIoT/resources/include/device.h
  51. 1
      Ubiquitous/XiZi_IIoT/tool/shell/letter-shell/cmd.c

33
APP_Framework/Applications/app_test/Kconfig

@ -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

10
APP_Framework/Applications/app_test/Makefile

@ -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

108
APP_Framework/Applications/app_test/test_camera.c

@ -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);

19
APP_Framework/Applications/app_test/test_hwtimer.c

@ -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);
}

68
APP_Framework/Applications/app_test/test_touch.c

@ -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);

4
APP_Framework/Applications/sensor_app/humidity_hs300x.c

@ -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);
}

4
APP_Framework/Applications/sensor_app/temperature_hs300x.c

@ -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);

4
APP_Framework/Framework/connection/wifi/Makefile

@ -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

6
APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig

@ -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
APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile

@ -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

106
APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c

@ -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
APP_Framework/Framework/sensor/Makefile

@ -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

1
APP_Framework/Framework/transform_layer/xizi/transform.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:

27
APP_Framework/Framework/transform_layer/xizi/transform.h

@ -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;

189
APP_Framework/lib/lvgl/examples/porting/lv_port_indev_template.c

@ -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;
}
}

6
APP_Framework/lib/lvgl/lvgl.mk

@ -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

3
APP_Framework/lib/lvgl/porting/lv_port_indev_template.c

@ -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);

6
Ubiquitous/XiZi_IIoT/board/edu-riscv64/board.c

@ -47,6 +47,7 @@ Modification:
#include "connect_uart.h"
#include "connect_w5500.h"
#include "connect_wdt.h"
#include "connect_dvp.h"
#include "dmac.h"
#include "encoding.h"
#include "fpioa.h"
@ -217,7 +218,10 @@ struct InitSequenceDesc _board_init[] = {
#ifdef BSP_USING_W5500
{"w5500", HwWiznetInit},
#endif
{" NONE ", NONE},
#ifdef BSP_USING_CAMERA
{"hw_camera", HwDvpInit },
#endif
{ " NONE ",NONE },
};
void InitBoardHardware(void) {

9
Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/Kconfig

@ -120,3 +120,12 @@ menuconfig BSP_USING_WIZCHIP
if BSP_USING_WIZCHIP
source "$BSP_DIR/third_party_driver/ethernet/Kconfig"
endif
menuconfig BSP_USING_CAMERA
bool "Using camera device"
default y
select RESOURCES_CAMERA
if BSP_USING_CAMERA
source "$BSP_DIR/third_party_driver/dvp/Kconfig"
endif

4
Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/Makefile

@ -59,5 +59,9 @@ endif
ifeq ($(CONFIG_BSP_USING_WIZCHIP),y)
SRC_DIR += ethernet
endif
ifeq ($(CONFIG_BSP_USING_CAMERA),y)
SRC_DIR += dvp
endif
include $(KERNEL_ROOT)/compiler.mk

46
Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/Kconfig

@ -0,0 +1,46 @@
if BSP_USING_CAMERA
config DVP_XCLK_RATE
int "Camera interface clk rate"
default 24000000
config IMAGE_WIDTH
int "Camera photo width"
default 320
config IMAGE_HEIGHT
int "Camera photo height"
default 240
config DVP_BURST_ENABLE
bool "brust mode enable"
default y
config DVP_AUTO_ENABLE
bool "auto recv image mode enable"
default n
config DVP_AI_OUTPUT
bool "ai output enable"
default n
config DVP_INTERRUPT_ENABLE
bool "interrupt enable"
default y
config CAMERA_BUS_NAME
string "camera bus name"
default "camera"
config CAMERA_DRV_NAME
string "camera driver name"
default "camera_drv"
config CAMERA_DEVICE_NAME
string "camera device name"
default "camera_dev"
choice
prompt "set camera framesize and fps"
default SVGA_25FPS_MODE
config UXGA_15FPS_MODE
bool "using uxga in 15fps"
config SVGA_25FPS_MODE
bool "using svag in 25fps"
endchoice
endif

4
Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/Makefile

@ -0,0 +1,4 @@
SRC_FILES := connect_dvp.c dvp.c ov2640.c
include $(KERNEL_ROOT)/compiler.mk

243
Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/connect_dvp.c

@ -0,0 +1,243 @@
#include <connect_dvp.h>
#include <dvp.h>
#include <board.h>
#include "sysctl.h"
#include "bsp.h"
#include "plic.h"
#include <ov2640.h>
#define REG_SCCB_READ 0x12U
#define REG_SCCB_WRITE 0x13U
#define SCCB_REG_LENGTH 0x08U
// irq interrupt function
static int on_irq_dvp(int irq, void *arg)
{
if (dvp_get_interrupt(DVP_STS_FRAME_FINISH))
{
dvp_clear_interrupt(DVP_STS_FRAME_FINISH);
}
else
{
dvp_start_convert();
dvp_clear_interrupt(DVP_STS_FRAME_START);
}
return 0;
}
struct DvpRegConfigureInfo
{
uint8_t device_addr;
uint16_t reg_addr;
uint8_t reg_value;
};
static struct CameraCfg sensor_config = {
.output_h = IMAGE_HEIGHT,//will be resize from window below in ov2640
.output_w = IMAGE_WIDTH,
.window_h = 600, //register configure in ov2640.h
.window_w = 800, //to make window as large as cmos selected size
.window_xoffset = 0,
.window_yoffset = 0,
.gain_manu_enable = 0,
.gain = 0x00
};
static uint32 DvpDrvInit(void)
{
x_err_t ret = EOK;
dvp_init(SCCB_REG_LENGTH);
dvp_set_xclk_rate(DVP_XCLK_RATE);
dvp_set_image_format(DVP_CFG_RGB_FORMAT);
dvp_set_image_size(IMAGE_WIDTH, IMAGE_HEIGHT);
dvp_set_output_enable(DVP_OUTPUT_DISPLAY, 0);
dvp_set_output_enable(DVP_OUTPUT_AI, 0);
ov2640_init();
SensorConfigure(&sensor_config);
sysctl_set_spi0_dvp_data(1);
#ifdef DVP_BURST_ENABLE
dvp_enable_burst();
#endif
#ifdef DVP_AUTO_ENABLE
dvp_disable_auto();
#endif
#ifdef DVP_AI_OUTPUT
dvp_set_output_enable(DVP_OUTPUT_AI, 1);
dvp_set_ai_addr((uint32_t)DVP_AI_RED_ADRESS, (uint32_t)DVP_AI_GREEN_ADRESS, (uint32_t)DVP_AI_BLUE_ADRESS);
#endif
#ifdef DVP_INTERRUPT_ENABLE
dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 0);
isrManager.done->registerIrq(IRQN_DVP_INTERRUPT, (IsrHandlerType)on_irq_dvp, NULL);
isrManager.done->enableIrq(IRQN_DVP_INTERRUPT);
dvp_clear_interrupt(DVP_STS_FRAME_START | DVP_STS_FRAME_FINISH);
dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 1);
KPrintf("camera interrupt has open!\n");
#endif
return ret;
}
static uint32 ReadDvpReg(void *drv, struct DvpRegConfigureInfo *reg_info)
{
x_err_t ret = EOK;
reg_info->reg_value = dvp_sccb_receive_data(reg_info->device_addr, reg_info->reg_addr);
return ret;
}
static uint32 WriteDvpReg(void *drv, struct DvpRegConfigureInfo *reg_info)
{
x_err_t ret = EOK;
dvp_sccb_send_data(reg_info->device_addr, reg_info->reg_addr, reg_info->reg_value);
return ret;
}
static uint32 DvpOpen(void *dev)
{
x_err_t ret = EOK;
DvpDrvInit();
return ret;
}
static uint32 DvpClose(void *dev)
{
x_err_t ret = EOK;
dvp_config_interrupt(DVP_CFG_START_INT_ENABLE | DVP_CFG_FINISH_INT_ENABLE, 0);
dvp_set_output_enable(DVP_OUTPUT_AI, 0);
dvp_set_output_enable(DVP_OUTPUT_DISPLAY, 0);
return ret;
}
static uint32 DvpRead(void *dev, struct BusBlockReadParam *read_param)
{
x_err_t ret = EOK;
// change the output buff address by read
dvp_set_output_enable(DVP_OUTPUT_DISPLAY, 0);
dvp_set_display_addr((uintptr_t)read_param->buffer);
dvp_set_output_enable(DVP_OUTPUT_DISPLAY, 1);
return ret;
}
static uint32 DvpDrvConfigure(void *drv, struct BusConfigureInfo *args)
{
x_err_t ret = EOK;
int cmd_type = args->configure_cmd;
struct CameraCfg* tmp_cfg;
switch (cmd_type)
{
case OPE_INT:
break;
case OPE_CFG:
tmp_cfg = (struct CameraCfg *)args->private_data;
SensorConfigure(tmp_cfg);
dvp_set_image_size(tmp_cfg->output_w, tmp_cfg->output_h);
break;
case REG_SCCB_READ:
ReadDvpReg(drv, (struct DvpRegConfigureInfo *)args->private_data);
break;
case REG_SCCB_WRITE:
//for ov2640,write reg 0x04 to Horizontal mirror or Vertical flip
WriteDvpReg(drv, (struct DvpRegConfigureInfo *)args->private_data);
break;
default:
break;
}
return ret;
}
/*manage the camera device operations*/
static const struct CameraDevDone camera_dev_done =
{
.dev_open = DvpOpen,
.dev_close = DvpClose,
.dev_write = NONE,
.dev_read = DvpRead,
};
/*Init camera bus*/
static int BoardCameraBusInit(struct CameraBus *camera_bus, struct CameraDriver *camera_driver)
{
x_err_t ret = EOK;
/*Init the camera bus */
camera_bus->private_data = (void *)&camera_dev_done;
ret = CameraBusInit(camera_bus, CAMERA_BUS_NAME);
if (EOK != ret)
{
KPrintf("board_camera_init CameraBusInit error %d\n", ret);
return ERROR;
}
/*Init the camera driver*/
camera_driver->private_data = (void *)&camera_dev_done;
ret = CameraDriverInit(camera_driver, CAMERA_DRV_NAME);
if (EOK != ret)
{
KPrintf("board_camera_init CameraDriverInit error %d\n", ret);
return ERROR;
}
/*Attach the camera driver to the camera bus*/
ret = CameraDriverAttachToBus(CAMERA_DRV_NAME, CAMERA_BUS_NAME);
if (EOK != ret)
{
KPrintf("board_camera_init CameraDriverAttachToBus error %d\n", ret);
return ERROR;
}
return ret;
}
/*Attach the camera device to the camera bus*/
static int BoardCameraDevBend(void)
{
x_err_t ret = EOK;
static struct CameraHardwareDevice camera_device;
memset(&camera_device, 0, sizeof(struct CameraHardwareDevice));
camera_device.camera_dev_done = &camera_dev_done;
ret = CameraDeviceRegister(&camera_device, NONE, CAMERA_DEVICE_NAME);
if (EOK != ret)
{
KPrintf("board_camera_init CameraDeviceInit device %s error %d\n", CAMERA_DEVICE_NAME, ret);
return ERROR;
}
ret = CameraDeviceAttachToBus(CAMERA_DEVICE_NAME, CAMERA_BUS_NAME);
if (EOK != ret)
{
KPrintf("board_camera_init CameraDeviceAttachToBus device %s error %d\n", CAMERA_DEVICE_NAME, ret);
return ERROR;
}
return ret;
}
int HwDvpInit(void)
{
x_err_t ret = EOK;
static struct CameraBus camera_bus;
memset(&camera_bus, 0, sizeof(struct CameraBus));
static struct CameraDriver camera_driver;
memset(&camera_driver, 0, sizeof(struct CameraDriver));
camera_driver.configure = DvpDrvConfigure;
ret = BoardCameraBusInit(&camera_bus, &camera_driver);
if (EOK != ret)
{
KPrintf("board_camera_Init error ret %u\n", ret);
return ERROR;
}
ret = BoardCameraDevBend();
if (EOK != ret)
{
KPrintf("board_camera_Init error ret %u\n", ret);
return ERROR;
}
return ret;
}

288
Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/dvp.c

@ -0,0 +1,288 @@
/* Copyright 2018 Canaan Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stddef.h>
#include <stdint.h>
#include "dvp.h"
#include "utils.h"
#include "fpioa.h"
#include "sysctl.h"
#include <math.h>
#include <sleep.h>
volatile dvp_t* const dvp = (volatile dvp_t*)DVP_BASE_ADDR;
static uint8_t g_sccb_reg_len = 8;
static void dvp_sccb_clk_init(void)
{
uint32_t tmp;
tmp = dvp->sccb_cfg & (~(DVP_SCCB_SCL_LCNT_MASK | DVP_SCCB_SCL_HCNT_MASK));
tmp |= DVP_SCCB_SCL_LCNT(255) | DVP_SCCB_SCL_HCNT(255);
dvp->sccb_cfg = tmp;
}
uint32_t dvp_sccb_set_clk_rate(uint32_t clk_rate)
{
uint32_t tmp;
uint32_t v_sccb_freq = SysctlClockGetFreq(SYSCTL_CLOCK_APB1);
uint16_t v_period_clk_cnt = round(v_sccb_freq / clk_rate / 2.0);
if(v_period_clk_cnt > 255)
{
return 0;
}
tmp = dvp->sccb_cfg & (~(DVP_SCCB_SCL_LCNT_MASK | DVP_SCCB_SCL_HCNT_MASK));
tmp |= DVP_SCCB_SCL_LCNT(v_period_clk_cnt) | DVP_SCCB_SCL_HCNT(v_period_clk_cnt);
dvp->sccb_cfg = tmp;
return SysctlClockGetFreq(SYSCTL_CLOCK_DVP) / (v_period_clk_cnt * 2);
}
static void dvp_sccb_start_transfer(void)
{
while (dvp->sts & DVP_STS_SCCB_EN)