From 96af00339870f69eb911d8ff5220e7411ed6e394 Mon Sep 17 00:00:00 2001 From: Wang_Weigen Date: Fri, 18 Jun 2021 17:37:03 +0800 Subject: [PATCH 1/3] add kconfig for application framework --- APP_Framework/Applications/Kconfig | 83 ++----------------- APP_Framework/Applications/Makefile | 48 +++-------- APP_Framework/Applications/app_test/Kconfig | 30 +++---- .../{ => app_test}/sd_card_mount.c | 0 .../{ => app_test}/spi_sd_card_mount.c | 0 .../Applications/connection_app/Kconfig | 14 ++++ .../Applications/connection_app/Makefile | 0 .../adhoc_lora_demo/Makefile | 0 .../adhoc_lora_demo/client.c | 0 .../adhoc_lora_demo/gateway.c | 0 .../bluetooth_demo/Makefile | 0 .../bluetooth_demo/bluetooth_receive_demo.c | 0 .../bluetooth_demo/bluetooth_send_demo.c | 0 .../ethernet_demo/Makefile | 0 .../ethernet_demo/ethernet_demo.c | 0 .../nbiot_demo/Makefile | 0 .../nbiot_demo/nbiot_demo.c | 0 .../wifi_demo/Makefile | 0 .../wifi_demo/wifi_demo.c | 0 .../zigbee_demo/Makefile | 0 .../zigbee_demo/zigbee_receive_demo.c | 0 .../zigbee_demo/zigbee_send_demo.c | 0 .../Applications/control_app/Kconfig | 8 ++ .../Applications/control_app/Makefile | 0 .../Applications/knowing_app/Kconfig | 7 ++ .../Applications/knowing_app/Makefile | 0 APP_Framework/Applications/sensor_app/Kconfig | 70 ++++++++++++++++ APP_Framework/Framework/Kconfig | 41 +++++---- APP_Framework/Framework/Makefile | 9 ++ APP_Framework/Framework/control/Kconfig | 3 + APP_Framework/Framework/control/Makefile | 3 + APP_Framework/Framework/know/Kconfig | 8 ++ APP_Framework/Framework/know/Makefile | 13 +++ .../Framework/know/tflite_mnist/Kconfig | 2 +- .../Framework/know/tflite_sin/Kconfig | 2 +- APP_Framework/Kconfig | 2 + APP_Framework/lib/Kconfig | 14 ++++ APP_Framework/lib/Makefile | 7 +- 38 files changed, 214 insertions(+), 150 deletions(-) rename APP_Framework/Applications/{ => app_test}/sd_card_mount.c (100%) rename APP_Framework/Applications/{ => app_test}/spi_sd_card_mount.c (100%) create mode 100755 APP_Framework/Applications/connection_app/Kconfig create mode 100755 APP_Framework/Applications/connection_app/Makefile rename APP_Framework/Applications/{connection_demo => connection_app}/adhoc_lora_demo/Makefile (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/adhoc_lora_demo/client.c (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/adhoc_lora_demo/gateway.c (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/bluetooth_demo/Makefile (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/bluetooth_demo/bluetooth_receive_demo.c (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/bluetooth_demo/bluetooth_send_demo.c (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/ethernet_demo/Makefile (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/ethernet_demo/ethernet_demo.c (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/nbiot_demo/Makefile (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/nbiot_demo/nbiot_demo.c (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/wifi_demo/Makefile (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/wifi_demo/wifi_demo.c (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/zigbee_demo/Makefile (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/zigbee_demo/zigbee_receive_demo.c (100%) rename APP_Framework/Applications/{connection_demo => connection_app}/zigbee_demo/zigbee_send_demo.c (100%) create mode 100755 APP_Framework/Applications/control_app/Kconfig create mode 100755 APP_Framework/Applications/control_app/Makefile create mode 100755 APP_Framework/Applications/knowing_app/Kconfig create mode 100755 APP_Framework/Applications/knowing_app/Makefile create mode 100755 APP_Framework/Applications/sensor_app/Kconfig create mode 100755 APP_Framework/Framework/control/Kconfig create mode 100755 APP_Framework/Framework/control/Makefile create mode 100755 APP_Framework/Framework/know/Kconfig create mode 100755 APP_Framework/Framework/know/Makefile create mode 100755 APP_Framework/lib/Kconfig diff --git a/APP_Framework/Applications/Kconfig b/APP_Framework/Applications/Kconfig index e08b6f7c..7c559204 100644 --- a/APP_Framework/Applications/Kconfig +++ b/APP_Framework/Applications/Kconfig @@ -11,83 +11,10 @@ menu "Applications" default 85 if KTASK_PRIORITY_256 endmenu -menuconfig APPLICATION_SENSOR - bool "Using sensor apps" - default n - select PERCEPTION_SENSORDEVICE - - if APPLICATION_SENSOR - menuconfig APPLICATION_SENSOR_CO2 - bool "Using sensor CO2 apps" - default n - select PERCEPTION_CO2 - - if APPLICATION_SENSOR_CO2 - config APPLICATION_SENSOR_CO2_ZG09 - bool "Using sensor ZG09 apps" - default n - select PERCEPTION_ZG09 - endif - - menuconfig APPLICATION_SENSOR_PM1_0 - bool "Using sensor PM1.0 apps" - default n - select PERCEPTION_PM - - if APPLICATION_SENSOR_PM1_0 - config APPLICATION_SENSOR_PM1_0_PS5308 - bool "Using sensor PS5308 apps" - default n - select PERCEPTION_PS5308 - endif - - menuconfig APPLICATION_SENSOR_VOICE - bool "Using sensor voice apps" - default n - select PERCEPTION_VOICE - - if APPLICATION_SENSOR_VOICE - config APPLICATION_SENSOR_VOICE_D124 - bool "Using sensor D124 apps" - default n - select PERCEPTION_D124 - endif - - menuconfig APPLICATION_SENSOR_HUMIDITY - bool "Using sensor humidity apps" - default n - select PERCEPTION_HUMIDITY - - if APPLICATION_SENSOR_HUMIDITY - config APPLICATION_SENSOR_HUMIDITY_HS300X - bool "Using sensor HS300x apps" - default n - select PERCEPTION_HS300X - endif - - menuconfig APPLICATION_SENSOR_TEMPERATURE - bool "Using sensor temperature apps" - default n - select PERCEPTION_TEMPERATURE - - if APPLICATION_SENSOR_TEMPERATURE - config APPLICATION_SENSOR_TEMPERATURE_HS300X - bool "Using sensor HS300x apps" - default n - select PERCEPTION_HS300X - endif - endif - -menuconfig CONNECTION_COMMUNICATION_ZIGBEE - bool "enable zigbee demo" - default n - select CONFIG_CONNECTION_COMMUNICATION_ZIGBEE - if CONNECTION_COMMUNICATION_ZIGBEE - source "$KERNEL_DIR/framework/connection/Adapter/zigbee/Kconfig" - endif - - - -source "$APP_DIR/Applications/app_test/Kconfig" + source "$APP_DIR/Applications/app_test/Kconfig" + source "$APP_DIR/Applications/connection_app/Kconfig" + source "$APP_DIR/Applications/control_app/Kconfig" + source "$APP_DIR/Applications/knowing_app/Kconfig" + source "$APP_DIR/Applications/sensor_app/Kconfig" endmenu diff --git a/APP_Framework/Applications/Makefile b/APP_Framework/Applications/Makefile index 3e11b654..7451edb7 100644 --- a/APP_Framework/Applications/Makefile +++ b/APP_Framework/Applications/Makefile @@ -2,44 +2,20 @@ SRC_DIR := general_functions SRC_FILES := main.c framework_init.c -ifeq ($(CONFIG_RESOURCES_SDIO), y) - SRC_FILES += sd_card_mount.c -endif - -ifeq ($(CONFIG_RESOURCES_SPI_SD), y) - SRC_FILES += spi_sd_card_mount.c -endif - -ifeq ($(CONFIG_CONNECTION_COMMUNICATION_BOOTSTART_LORA_NET_SAMPLE), y) - SRC_DIR += connection_demo/adhoc_lora_demo -endif - -ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ZIGBEE), y) - SRC_DIR += connection_demo/zigbee_demo -endif - -ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ETHERNET), y) - SRC_DIR += connection_demo/ethernet_demo -endif - -ifeq ($(CONFIG_CONNECTION_COMMUNICATION_WIFI), y) - SRC_DIR += connection_demo/wifi_demo -endif - -ifeq ($(CONFIG_CONNECTION_COMMUNICATION_NB_IOT), y) - SRC_DIR += connection_demo/nbiot_demo -endif - -# ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y) -# SRC_DIR += connection_demo/4G_demo -# endif - -ifeq ($(CONFIG_CONNECTION_COMMUNICATION_BLUETOOTH), y) - SRC_DIR += connection_demo/bluetooth_demo -endif - ifeq ($(CONFIG_APPLICATION_SENSOR),y) SRC_DIR += sensor_app endif +ifeq ($(CONFIG_APPLICATION_CONNECTION),y) + SRC_DIR += connection_app +endif + +ifeq ($(CONFIG_APPLICATION_KNOWING),y) + SRC_DIR += knowing_app +endif + +ifeq ($(CONFIG_APPLICATION_CONTROL),y) + SRC_DIR += control_app +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/app_test/Kconfig b/APP_Framework/Applications/app_test/Kconfig index 09b464f2..66837a94 100644 --- a/APP_Framework/Applications/app_test/Kconfig +++ b/APP_Framework/Applications/app_test/Kconfig @@ -1,18 +1,20 @@ -menuconfig USER_TEST - bool "Enable application test function " - default n +menu "test app" + menuconfig USER_TEST + bool "Enable application test function " + default n - if USER_TEST - config USER_TEST_LORA_ADHOC - bool "Config test lora adhoc" - default n + if USER_TEST + config USER_TEST_LORA_ADHOC + bool "Config test lora adhoc" + default n - config USER_TEST_SPI_LORA - bool "Config test spi lora" - default n + config USER_TEST_SPI_LORA + bool "Config test spi lora" + default n - config USER_TEST_SPI_FLASH - bool "Config test spi flash" - default n + config USER_TEST_SPI_FLASH + bool "Config test spi flash" + default n - endif + endif +endmenu diff --git a/APP_Framework/Applications/sd_card_mount.c b/APP_Framework/Applications/app_test/sd_card_mount.c similarity index 100% rename from APP_Framework/Applications/sd_card_mount.c rename to APP_Framework/Applications/app_test/sd_card_mount.c diff --git a/APP_Framework/Applications/spi_sd_card_mount.c b/APP_Framework/Applications/app_test/spi_sd_card_mount.c similarity index 100% rename from APP_Framework/Applications/spi_sd_card_mount.c rename to APP_Framework/Applications/app_test/spi_sd_card_mount.c diff --git a/APP_Framework/Applications/connection_app/Kconfig b/APP_Framework/Applications/connection_app/Kconfig new file mode 100755 index 00000000..27a8e1d4 --- /dev/null +++ b/APP_Framework/Applications/connection_app/Kconfig @@ -0,0 +1,14 @@ +menu "connection app" + menuconfig APPLICATION_CONNECTION + bool "Using connection apps" + default n + + menuconfig CONNECTION_COMMUNICATION_ZIGBEE + bool "enable zigbee demo" + default n + select CONFIG_CONNECTION_COMMUNICATION_ZIGBEE + if CONNECTION_COMMUNICATION_ZIGBEE + source "$KERNEL_DIR/framework/connection/Adapter/zigbee/Kconfig" + endif + +endmenu diff --git a/APP_Framework/Applications/connection_app/Makefile b/APP_Framework/Applications/connection_app/Makefile new file mode 100755 index 00000000..e69de29b diff --git a/APP_Framework/Applications/connection_demo/adhoc_lora_demo/Makefile b/APP_Framework/Applications/connection_app/adhoc_lora_demo/Makefile similarity index 100% rename from APP_Framework/Applications/connection_demo/adhoc_lora_demo/Makefile rename to APP_Framework/Applications/connection_app/adhoc_lora_demo/Makefile diff --git a/APP_Framework/Applications/connection_demo/adhoc_lora_demo/client.c b/APP_Framework/Applications/connection_app/adhoc_lora_demo/client.c similarity index 100% rename from APP_Framework/Applications/connection_demo/adhoc_lora_demo/client.c rename to APP_Framework/Applications/connection_app/adhoc_lora_demo/client.c diff --git a/APP_Framework/Applications/connection_demo/adhoc_lora_demo/gateway.c b/APP_Framework/Applications/connection_app/adhoc_lora_demo/gateway.c similarity index 100% rename from APP_Framework/Applications/connection_demo/adhoc_lora_demo/gateway.c rename to APP_Framework/Applications/connection_app/adhoc_lora_demo/gateway.c diff --git a/APP_Framework/Applications/connection_demo/bluetooth_demo/Makefile b/APP_Framework/Applications/connection_app/bluetooth_demo/Makefile similarity index 100% rename from APP_Framework/Applications/connection_demo/bluetooth_demo/Makefile rename to APP_Framework/Applications/connection_app/bluetooth_demo/Makefile diff --git a/APP_Framework/Applications/connection_demo/bluetooth_demo/bluetooth_receive_demo.c b/APP_Framework/Applications/connection_app/bluetooth_demo/bluetooth_receive_demo.c similarity index 100% rename from APP_Framework/Applications/connection_demo/bluetooth_demo/bluetooth_receive_demo.c rename to APP_Framework/Applications/connection_app/bluetooth_demo/bluetooth_receive_demo.c diff --git a/APP_Framework/Applications/connection_demo/bluetooth_demo/bluetooth_send_demo.c b/APP_Framework/Applications/connection_app/bluetooth_demo/bluetooth_send_demo.c similarity index 100% rename from APP_Framework/Applications/connection_demo/bluetooth_demo/bluetooth_send_demo.c rename to APP_Framework/Applications/connection_app/bluetooth_demo/bluetooth_send_demo.c diff --git a/APP_Framework/Applications/connection_demo/ethernet_demo/Makefile b/APP_Framework/Applications/connection_app/ethernet_demo/Makefile similarity index 100% rename from APP_Framework/Applications/connection_demo/ethernet_demo/Makefile rename to APP_Framework/Applications/connection_app/ethernet_demo/Makefile diff --git a/APP_Framework/Applications/connection_demo/ethernet_demo/ethernet_demo.c b/APP_Framework/Applications/connection_app/ethernet_demo/ethernet_demo.c similarity index 100% rename from APP_Framework/Applications/connection_demo/ethernet_demo/ethernet_demo.c rename to APP_Framework/Applications/connection_app/ethernet_demo/ethernet_demo.c diff --git a/APP_Framework/Applications/connection_demo/nbiot_demo/Makefile b/APP_Framework/Applications/connection_app/nbiot_demo/Makefile similarity index 100% rename from APP_Framework/Applications/connection_demo/nbiot_demo/Makefile rename to APP_Framework/Applications/connection_app/nbiot_demo/Makefile diff --git a/APP_Framework/Applications/connection_demo/nbiot_demo/nbiot_demo.c b/APP_Framework/Applications/connection_app/nbiot_demo/nbiot_demo.c similarity index 100% rename from APP_Framework/Applications/connection_demo/nbiot_demo/nbiot_demo.c rename to APP_Framework/Applications/connection_app/nbiot_demo/nbiot_demo.c diff --git a/APP_Framework/Applications/connection_demo/wifi_demo/Makefile b/APP_Framework/Applications/connection_app/wifi_demo/Makefile similarity index 100% rename from APP_Framework/Applications/connection_demo/wifi_demo/Makefile rename to APP_Framework/Applications/connection_app/wifi_demo/Makefile diff --git a/APP_Framework/Applications/connection_demo/wifi_demo/wifi_demo.c b/APP_Framework/Applications/connection_app/wifi_demo/wifi_demo.c similarity index 100% rename from APP_Framework/Applications/connection_demo/wifi_demo/wifi_demo.c rename to APP_Framework/Applications/connection_app/wifi_demo/wifi_demo.c diff --git a/APP_Framework/Applications/connection_demo/zigbee_demo/Makefile b/APP_Framework/Applications/connection_app/zigbee_demo/Makefile similarity index 100% rename from APP_Framework/Applications/connection_demo/zigbee_demo/Makefile rename to APP_Framework/Applications/connection_app/zigbee_demo/Makefile diff --git a/APP_Framework/Applications/connection_demo/zigbee_demo/zigbee_receive_demo.c b/APP_Framework/Applications/connection_app/zigbee_demo/zigbee_receive_demo.c similarity index 100% rename from APP_Framework/Applications/connection_demo/zigbee_demo/zigbee_receive_demo.c rename to APP_Framework/Applications/connection_app/zigbee_demo/zigbee_receive_demo.c diff --git a/APP_Framework/Applications/connection_demo/zigbee_demo/zigbee_send_demo.c b/APP_Framework/Applications/connection_app/zigbee_demo/zigbee_send_demo.c similarity index 100% rename from APP_Framework/Applications/connection_demo/zigbee_demo/zigbee_send_demo.c rename to APP_Framework/Applications/connection_app/zigbee_demo/zigbee_send_demo.c diff --git a/APP_Framework/Applications/control_app/Kconfig b/APP_Framework/Applications/control_app/Kconfig new file mode 100755 index 00000000..6128642c --- /dev/null +++ b/APP_Framework/Applications/control_app/Kconfig @@ -0,0 +1,8 @@ +menu "control app" + + menuconfig APPLICATION_CONTROL + bool "Using control apps" + default n + +endmenu + diff --git a/APP_Framework/Applications/control_app/Makefile b/APP_Framework/Applications/control_app/Makefile new file mode 100755 index 00000000..e69de29b diff --git a/APP_Framework/Applications/knowing_app/Kconfig b/APP_Framework/Applications/knowing_app/Kconfig new file mode 100755 index 00000000..c49a45e5 --- /dev/null +++ b/APP_Framework/Applications/knowing_app/Kconfig @@ -0,0 +1,7 @@ +menu "knowing app" + + menuconfig APPLICATION_KNOWING + bool "Using knowing apps" + default n + +endmenu diff --git a/APP_Framework/Applications/knowing_app/Makefile b/APP_Framework/Applications/knowing_app/Makefile new file mode 100755 index 00000000..e69de29b diff --git a/APP_Framework/Applications/sensor_app/Kconfig b/APP_Framework/Applications/sensor_app/Kconfig new file mode 100755 index 00000000..e413885e --- /dev/null +++ b/APP_Framework/Applications/sensor_app/Kconfig @@ -0,0 +1,70 @@ +menu "sensor app" + + menuconfig APPLICATION_SENSOR + bool "Using sensor apps" + default n + select PERCEPTION_SENSORDEVICE + + if APPLICATION_SENSOR + menuconfig APPLICATION_SENSOR_CO2 + bool "Using sensor CO2 apps" + default n + select PERCEPTION_CO2 + + if APPLICATION_SENSOR_CO2 + config APPLICATION_SENSOR_CO2_ZG09 + bool "Using sensor ZG09 apps" + default n + select PERCEPTION_ZG09 + endif + + menuconfig APPLICATION_SENSOR_PM1_0 + bool "Using sensor PM1.0 apps" + default n + select PERCEPTION_PM + + if APPLICATION_SENSOR_PM1_0 + config APPLICATION_SENSOR_PM1_0_PS5308 + bool "Using sensor PS5308 apps" + default n + select PERCEPTION_PS5308 + endif + + menuconfig APPLICATION_SENSOR_VOICE + bool "Using sensor voice apps" + default n + select PERCEPTION_VOICE + + if APPLICATION_SENSOR_VOICE + config APPLICATION_SENSOR_VOICE_D124 + bool "Using sensor D124 apps" + default n + select PERCEPTION_D124 + endif + + menuconfig APPLICATION_SENSOR_HUMIDITY + bool "Using sensor humidity apps" + default n + select PERCEPTION_HUMIDITY + + if APPLICATION_SENSOR_HUMIDITY + config APPLICATION_SENSOR_HUMIDITY_HS300X + bool "Using sensor HS300x apps" + default n + select PERCEPTION_HS300X + endif + + menuconfig APPLICATION_SENSOR_TEMPERATURE + bool "Using sensor temperature apps" + default n + select PERCEPTION_TEMPERATURE + + if APPLICATION_SENSOR_TEMPERATURE + config APPLICATION_SENSOR_TEMPERATURE_HS300X + bool "Using sensor HS300x apps" + default n + select PERCEPTION_HS300X + endif + endif + +endmenu diff --git a/APP_Framework/Framework/Kconfig b/APP_Framework/Framework/Kconfig index a8f1638a..66e1ec19 100644 --- a/APP_Framework/Framework/Kconfig +++ b/APP_Framework/Framework/Kconfig @@ -1,22 +1,27 @@ -config TRANSFORM_LAYER_ATTRIUBUTE - bool "support transform layer" - default y - choice - prompt "select os features" - default ADD_XIUOS_FETURES +menu "Framework" - config ADD_XIUOS_FETURES - bool "add xiuos fetures" - - config ADD_NUTTX_FETURES - bool "add nuttx fetures" + config TRANSFORM_LAYER_ATTRIUBUTE + bool "support transform layer" + default y + choice + prompt "select os features" + default ADD_XIUOS_FETURES - config ADD_RTTHREAD_FETURES - bool "add rt_thread fetures" - endchoice + config ADD_XIUOS_FETURES + bool "add xiuos fetures" + + config ADD_NUTTX_FETURES + bool "add nuttx fetures" + + config ADD_RTTHREAD_FETURES + bool "add rt_thread fetures" + endchoice -source "$APP_DIR/Framework/sensor/Kconfig" -source "$APP_DIR/Framework/connection/Kconfig" -source "$APP_DIR/Framework/know/tflite_sin/Kconfig" -source "$APP_DIR/Framework/know/tflite_mnist/Kconfig" \ No newline at end of file + source "$APP_DIR/Framework/sensor/Kconfig" + source "$APP_DIR/Framework/connection/Kconfig" + source "$APP_DIR/Framework/know/Kconfig" + source "$APP_DIR/Framework/control/Kconfig" + + +endmenu diff --git a/APP_Framework/Framework/Makefile b/APP_Framework/Framework/Makefile index 88bebb00..fc5bf385 100644 --- a/APP_Framework/Framework/Makefile +++ b/APP_Framework/Framework/Makefile @@ -8,5 +8,14 @@ ifeq ($(CONFIG_SUPPORT_CONNECTION_FRAMEWORK),y) SRC_DIR += connection endif +ifeq ($(CONFIG_SUPPORT_KNOWING_FRAMEWORK),y) + SRC_DIR += know +endif + +ifeq ($(CONFIG_SUPPORT_CONTROL_FRAMEWORK),y) + SRC_DIR += control +endif + + include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/control/Kconfig b/APP_Framework/Framework/control/Kconfig new file mode 100755 index 00000000..b84fe5ac --- /dev/null +++ b/APP_Framework/Framework/control/Kconfig @@ -0,0 +1,3 @@ +menuconfig SUPPORT_CONTROL_FRAMEWORK + bool "support control framework" + default n \ No newline at end of file diff --git a/APP_Framework/Framework/control/Makefile b/APP_Framework/Framework/control/Makefile new file mode 100755 index 00000000..f75f2e60 --- /dev/null +++ b/APP_Framework/Framework/control/Makefile @@ -0,0 +1,3 @@ +SRC_DIR := + +include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/know/Kconfig b/APP_Framework/Framework/know/Kconfig new file mode 100755 index 00000000..0da0afa0 --- /dev/null +++ b/APP_Framework/Framework/know/Kconfig @@ -0,0 +1,8 @@ +menuconfig SUPPORT_KNOWING_FRAMEWORK + bool "support knowing framework" + default y + +if SUPPORT_KNOWING_FRAMEWORK + source "$APP_DIR/Framework/know/tflite_sin/Kconfig" + source "$APP_DIR/Framework/know/tflite_mnist/Kconfig" +endif diff --git a/APP_Framework/Framework/know/Makefile b/APP_Framework/Framework/know/Makefile new file mode 100755 index 00000000..60ec20c0 --- /dev/null +++ b/APP_Framework/Framework/know/Makefile @@ -0,0 +1,13 @@ +SRC_DIR := +ifeq ($(CONFIG_SUPPORT_KNOW_FRAMEWORK),y) + ifeq ($(CONFIG_USING_TFLITE_MNIST),y) + SRC_DIR += tflite_mnist + endif + + ifeq ($(CONFIG_USING_TFLITE_SIN),y) + SRC_DIR += tflite_sin + endif +endif + + +include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/know/tflite_mnist/Kconfig b/APP_Framework/Framework/know/tflite_mnist/Kconfig index 7b77ef27..75f35dba 100644 --- a/APP_Framework/Framework/know/tflite_mnist/Kconfig +++ b/APP_Framework/Framework/know/tflite_mnist/Kconfig @@ -1,4 +1,4 @@ -config USING_TFLITE_MNIST +menuconfig USING_TFLITE_MNIST bool "mnist demo app for tflite micro" depends on INTELLIGENT_TFLITE default n diff --git a/APP_Framework/Framework/know/tflite_sin/Kconfig b/APP_Framework/Framework/know/tflite_sin/Kconfig index dfe2fd0f..ef8f6fb0 100644 --- a/APP_Framework/Framework/know/tflite_sin/Kconfig +++ b/APP_Framework/Framework/know/tflite_sin/Kconfig @@ -1,4 +1,4 @@ -config USING_TFLITE_SIN +menuconfig USING_TFLITE_SIN bool "sin(x) demo app for tflite micro" depends on INTELLIGENT_TFLITE default n diff --git a/APP_Framework/Kconfig b/APP_Framework/Kconfig index f04bdf0a..e63a1a14 100644 --- a/APP_Framework/Kconfig +++ b/APP_Framework/Kconfig @@ -7,5 +7,7 @@ menu "APP_Framework" source "$APP_DIR/Applications/Kconfig" source "$APP_DIR/Framework/Kconfig" +source "$APP_DIR/lib/Kconfig" + endmenu diff --git a/APP_Framework/lib/Kconfig b/APP_Framework/lib/Kconfig new file mode 100755 index 00000000..bec09361 --- /dev/null +++ b/APP_Framework/lib/Kconfig @@ -0,0 +1,14 @@ +menu "app lib" + + choice + prompt "chose a kind of lib for app" + default APP_SELECT_NEWLIB + + config APP_SELECT_NEWLIB + bool "app select newlib" + + config APP_SELECT_OTHER_LIB + bool "app select other lib" + endchoice + +endmenu diff --git a/APP_Framework/lib/Makefile b/APP_Framework/lib/Makefile index e205bf8a..ec6061b7 100644 --- a/APP_Framework/lib/Makefile +++ b/APP_Framework/lib/Makefile @@ -1,7 +1,10 @@ SRC_DIR := -ifeq ($(CONFIG_SEPARATE_COMPILE),y) - SRC_DIR += app_newlib +ifeq ($(CONFIG_APP_SELECT_NEWLIB),y) + ifeq ($(CONFIG_SEPARATE_COMPILE),y) + SRC_DIR += app_newlib + endif endif + include $(KERNEL_ROOT)/compiler.mk From fedd6affc9705765e06a5353604c46602a93b239 Mon Sep 17 00:00:00 2001 From: chunyexixiaoyu <834670833@qq.com> Date: Mon, 21 Jun 2021 17:17:16 +0800 Subject: [PATCH 2/3] Ubiquitous/RT_Thread/:add rw007 driver and ov2640 driver --- .gitignore | 3 +- Ubiquitous/RT_Thread/bsp/k210/.config | 38 +- .../bsp/k210/applications/ov2640_test.c | 106 + .../bsp/k210/applications/rw007_test.c | 105 + Ubiquitous/RT_Thread/bsp/k210/rtconfig.h | 26 +- .../bsp/stm32f407-atk-coreboard/.config | 47 +- .../applications/ov2640_test.c | 97 + .../applications/rw007_test.c | 106 + .../bsp/stm32f407-atk-coreboard/rtconfig.h | 25 + Ubiquitous/RT_Thread/drivers/Kconfig | 4 +- Ubiquitous/RT_Thread/drivers/ov2640/Kconfig | 14 + .../RT_Thread/drivers/ov2640/SConscript | 7 + .../drivers/ov2640/ov2640_source/SConscript | 14 + .../drivers/ov2640/ov2640_source/drv_ov2640.c | 1736 +++++++++++++++++ .../drivers/ov2640/ov2640_source/drv_ov2640.h | 168 ++ Ubiquitous/RT_Thread/drivers/rw007/Kconfig | 59 + Ubiquitous/RT_Thread/drivers/rw007/SConscript | 7 + .../drivers/rw007/rw007-source/.gitignore | 52 + .../drivers/rw007/rw007-source/LICENSE | 201 ++ .../drivers/rw007/rw007-source/README.md | 59 + .../drivers/rw007/rw007-source/README_ZH.md | 59 + .../drivers/rw007/rw007-source/SConscript | 87 + .../rw007-source/example/rw007_stm32_port.c | 70 + .../rw007/rw007-source/inc/spi_wifi_rw007.h | 221 +++ .../rw007/rw007-source/src/spi_wifi_rw007.c | 873 +++++++++ 25 files changed, 4149 insertions(+), 35 deletions(-) create mode 100644 Ubiquitous/RT_Thread/bsp/k210/applications/ov2640_test.c create mode 100644 Ubiquitous/RT_Thread/bsp/k210/applications/rw007_test.c create mode 100644 Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/applications/ov2640_test.c create mode 100644 Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/applications/rw007_test.c create mode 100644 Ubiquitous/RT_Thread/drivers/ov2640/Kconfig create mode 100644 Ubiquitous/RT_Thread/drivers/ov2640/SConscript create mode 100644 Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/SConscript create mode 100644 Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/drv_ov2640.c create mode 100644 Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/drv_ov2640.h create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/Kconfig create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/SConscript create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/rw007-source/.gitignore create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/rw007-source/LICENSE create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/rw007-source/README.md create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/rw007-source/README_ZH.md create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/rw007-source/SConscript create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/rw007-source/example/rw007_stm32_port.c create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/rw007-source/inc/spi_wifi_rw007.h create mode 100644 Ubiquitous/RT_Thread/drivers/rw007/rw007-source/src/spi_wifi_rw007.c diff --git a/.gitignore b/.gitignore index 722d5e71..874eb330 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.vscode +*.vscode +*.o diff --git a/Ubiquitous/RT_Thread/bsp/k210/.config b/Ubiquitous/RT_Thread/bsp/k210/.config index 043507ae..1e5665b6 100644 --- a/Ubiquitous/RT_Thread/bsp/k210/.config +++ b/Ubiquitous/RT_Thread/bsp/k210/.config @@ -368,22 +368,20 @@ CONFIG_BSP_UART1_RXD_PIN=21 # CONFIG_BSP_USING_UART2 is not set # CONFIG_BSP_USING_UART3 is not set # CONFIG_BSP_USING_I2C1 is not set -# CONFIG_BSP_USING_SPI1 is not set +CONFIG_BSP_USING_SPI1=y +# CONFIG_BSP_USING_SPI1_AS_QSPI is not set +CONFIG_BSP_SPI1_CLK_PIN=27 +CONFIG_BSP_SPI1_D0_PIN=28 +CONFIG_BSP_SPI1_D1_PIN=26 +CONFIG_BSP_SPI1_USING_SS0=y +CONFIG_BSP_SPI1_SS0_PIN=29 +CONFIG_BSP_SPI1_USING_SS1=y +CONFIG_BSP_SPI1_SS1_PIN=8 +# CONFIG_BSP_SPI1_USING_SS2 is not set +# CONFIG_BSP_SPI1_USING_SS3 is not set # CONFIG_BSP_USING_LCD is not set -# CONFIG_BSP_USING_SDCARD is not set -CONFIG_BSP_USING_DVP=y - -# -# The default pin assignment is based on the Maix Duino K210 development board -# -CONFIG_BSP_DVP_SCCB_SDA_PIN=40 -CONFIG_BSP_DVP_SCCB_SCLK_PIN=41 -CONFIG_BSP_DVP_CMOS_RST_PIN=42 -CONFIG_BSP_DVP_CMOS_VSYNC_PIN=43 -CONFIG_BSP_DVP_CMOS_PWDN_PIN=44 -CONFIG_BSP_DVP_CMOS_XCLK_PIN=46 -CONFIG_BSP_DVP_CMOS_PCLK_PIN=47 -CONFIG_BSP_DVP_CMOS_HREF_PIN=45 +CONFIG_BSP_USING_SDCARD=y +# CONFIG_BSP_USING_DVP is not set # # Kendryte SDK Config @@ -393,4 +391,14 @@ CONFIG_PKG_KENDRYTE_SDK_VERNUM=0x0055 # # More Drivers # +# CONFIG_PKG_USING_RW007 is not set +# CONFIG_DRV_USING_OV2640 is not set + +# +# Applications +# + +# +# Framework +# CONFIG___STACKSIZE__=4096 diff --git a/Ubiquitous/RT_Thread/bsp/k210/applications/ov2640_test.c b/Ubiquitous/RT_Thread/bsp/k210/applications/ov2640_test.c new file mode 100644 index 00000000..b9401ff0 --- /dev/null +++ b/Ubiquitous/RT_Thread/bsp/k210/applications/ov2640_test.c @@ -0,0 +1,106 @@ +#include +#include +#include "stdio.h" +#include "string.h" +#include "dvp.h" +#include "fpioa.h" +#include "plic.h" +#include "sysctl.h" +#if(defined DRV_USING_OV2640 && defined BSP_USING_LCD) +#include +#define RGB_BUF_SIZE (320*240*2) +#ifdef RT_USING_POSIX +#include +#include +#include +#include +#ifdef RT_USING_POSIX_TERMIOS +#include +#endif +#endif +static int g_fd = 0; +static _ioctl_shoot_para shoot_para_t = {0}; + + +void ov2640_test(int argc, char **argv) +{ + extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t *ptr); + + g_fd = open("/dev/ov2640",O_RDONLY); + if(g_fd < 0) + { + printf("open ov2640 fail !!"); + return; + } + if (argc < 2) + { + printf("Usage:ov2640 display images in real time or take photos \n"); + printf("Like: ov2640_test 1(take photos )\n"); + printf("Like: ov2640_test 0(display images in real time )\n"); + close(g_fd); + return ; + } + uint32_t* rgbbuffer = rt_malloc(RGB_BUF_SIZE); + rt_thread_t tid; + rt_err_t ret = 0; + int temf = 0; + if(NULL == rgbbuffer) + { + printf("malloc rgbbuffer failed ! \n"); + close(g_fd); + return; + } + temf = strtoul(argv[1],0, 10); + printf("ov2640_test choose %d mode \n",temf); + shoot_para_t.pdata = (uint32_t)(rgbbuffer); + shoot_para_t.length = RGB_BUF_SIZE; + if(temf == 0) + { + void lcd_show_ov2640_thread(uint32_t* rgbbuffer); + tid = rt_thread_create("lcdshow", lcd_show_ov2640_thread, rgbbuffer,3000, 9, 20); + rt_thread_startup(tid); + } + else + { + memset(rgbbuffer,0,320*240*2); + ret = ioctl(g_fd,IOCTRL_CAMERA_START_SHOT,&shoot_para_t); +// ret = rt_ov2640_start_shoot((uint32_t)(rgbbuffer), RGB_BUF_SIZE); + if(RT_ERROR == ret) + { + printf("ov2640 can't wait event flag"); + close(g_fd); + return; + } + lcd_draw_picture(0, 0, 320, 240, rgbbuffer); + rt_thread_mdelay(100); + printf("the lcd has shown the image \n"); + rt_free(rgbbuffer); + close(g_fd); + } +} +MSH_CMD_EXPORT(ov2640_test,lcd show camera shot image); + +void lcd_show_ov2640_thread(uint32_t* rgbbuffer) +{ + extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t *ptr); + rt_err_t ret = 0; + while(1) + { + + ret = ioctl(g_fd,IOCTRL_CAMERA_START_SHOT,&shoot_para_t); + if(RT_ERROR == ret) + { + printf("ov2640 can't wait event flag"); + rt_free(rgbbuffer); + return; + } + lcd_draw_picture(0, 0, 320, 240, rgbbuffer); + rt_thread_mdelay(2); + } + +} + + +#endif + + diff --git a/Ubiquitous/RT_Thread/bsp/k210/applications/rw007_test.c b/Ubiquitous/RT_Thread/bsp/k210/applications/rw007_test.c new file mode 100644 index 00000000..675ef210 --- /dev/null +++ b/Ubiquitous/RT_Thread/bsp/k210/applications/rw007_test.c @@ -0,0 +1,105 @@ +#include +#ifdef PKG_USING_RW007 +#include +#include +#include +#include +static const char send_data[] = "This is TCP Client from AIIT"; +void rw007_test(int argc, char **argv) +{ + int ret; + char *recv_data; + struct hostent *host; + int sock, bytes_received; + struct sockaddr_in server_addr; + const char *url; + int port; + extern rt_bool_t rt_wlan_is_connected(void); + if (rt_wlan_is_connected() != 1) + { + printf("Please connect a wifi firstly\n"); + return; + } + if (argc < 3) + { + printf("Usage: rw007 URL PORT\n"); + printf("Like: rw007 192.168.12.44 5000\n"); + return ; + } + + url = argv[1]; + port = strtoul(argv[2], 0, 10); + host = gethostbyname(url); + recv_data = rt_malloc(1024); + if (recv_data == RT_NULL) + { + printf("No memory\n"); + return; + } + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) + { + printf("Socket error\n"); + rt_free(recv_data); + return; + } + server_addr.sin_family = AF_INET; + server_addr.sin_port = htons(port); + server_addr.sin_addr = *((struct in_addr *)host->h_addr); + rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero)); + if (connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) + { + printf("Connect fail!\n"); + closesocket(sock); + rt_free(recv_data); + return; + } + else + { + printf("Connect successful\n"); + } + while (1) + { + bytes_received = recv(sock, recv_data, 1024 - 1, 0); + if (bytes_received < 0) + { + closesocket(sock); + printf("\nreceived error,close the socket.\r\n"); + rt_free(recv_data); + break; + } + else if (bytes_received == 0) + { + closesocket(sock); + printf("\nreceived error,close the socket.\r\n"); + rt_free(recv_data); + break; + } + recv_data[bytes_received] = '\0'; + if (strncmp(recv_data, "q", 1) == 0 || strncmp(recv_data, "Q", 1) == 0) + { + closesocket(sock); + printf("\n got a 'q' or 'Q',close the socket.\r\n"); + rt_free(recv_data); + break; + } + else + { + printf("\nReceived data = %s ", recv_data); + } + ret = send(sock, send_data, strlen(send_data), 0); + if (ret < 0) + { + closesocket(sock); + printf("\nsend error,close the socket.\r\n"); + rt_free(recv_data); + break; + } + else if (ret == 0) + { + printf("\n Send warning,send function return 0.\r\n"); + } + } + return; +} +MSH_CMD_EXPORT(rw007_test, a tcp client sample); +#endif diff --git a/Ubiquitous/RT_Thread/bsp/k210/rtconfig.h b/Ubiquitous/RT_Thread/bsp/k210/rtconfig.h index dad02eee..e69acbc0 100644 --- a/Ubiquitous/RT_Thread/bsp/k210/rtconfig.h +++ b/Ubiquitous/RT_Thread/bsp/k210/rtconfig.h @@ -246,18 +246,15 @@ #define BSP_USING_UART1 #define BSP_UART1_TXD_PIN 20 #define BSP_UART1_RXD_PIN 21 -#define BSP_USING_DVP - -/* The default pin assignment is based on the Maix Duino K210 development board */ - -#define BSP_DVP_SCCB_SDA_PIN 40 -#define BSP_DVP_SCCB_SCLK_PIN 41 -#define BSP_DVP_CMOS_RST_PIN 42 -#define BSP_DVP_CMOS_VSYNC_PIN 43 -#define BSP_DVP_CMOS_PWDN_PIN 44 -#define BSP_DVP_CMOS_XCLK_PIN 46 -#define BSP_DVP_CMOS_PCLK_PIN 47 -#define BSP_DVP_CMOS_HREF_PIN 45 +#define BSP_USING_SPI1 +#define BSP_SPI1_CLK_PIN 27 +#define BSP_SPI1_D0_PIN 28 +#define BSP_SPI1_D1_PIN 26 +#define BSP_SPI1_USING_SS0 +#define BSP_SPI1_SS0_PIN 29 +#define BSP_SPI1_USING_SS1 +#define BSP_SPI1_SS1_PIN 8 +#define BSP_USING_SDCARD /* Kendryte SDK Config */ @@ -265,6 +262,11 @@ /* More Drivers */ + +/* Applications */ + +/* Framework */ + #define __STACKSIZE__ 4096 #endif diff --git a/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/.config b/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/.config index ad741717..c6e292ea 100644 --- a/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/.config +++ b/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/.config @@ -126,7 +126,28 @@ CONFIG_DFS_FILESYSTEMS_MAX=2 CONFIG_DFS_FILESYSTEM_TYPES_MAX=2 CONFIG_DFS_FD_MAX=16 # CONFIG_RT_USING_DFS_MNTTABLE is not set -# CONFIG_RT_USING_DFS_ELMFAT is not set +CONFIG_RT_USING_DFS_ELMFAT=y + +# +# elm-chan's FatFs, Generic FAT Filesystem Module +# +CONFIG_RT_DFS_ELM_CODE_PAGE=437 +CONFIG_RT_DFS_ELM_WORD_ACCESS=y +# CONFIG_RT_DFS_ELM_USE_LFN_0 is not set +# CONFIG_RT_DFS_ELM_USE_LFN_1 is not set +# CONFIG_RT_DFS_ELM_USE_LFN_2 is not set +CONFIG_RT_DFS_ELM_USE_LFN_3=y +CONFIG_RT_DFS_ELM_USE_LFN=3 +CONFIG_RT_DFS_ELM_LFN_UNICODE_0=y +# CONFIG_RT_DFS_ELM_LFN_UNICODE_1 is not set +# CONFIG_RT_DFS_ELM_LFN_UNICODE_2 is not set +# CONFIG_RT_DFS_ELM_LFN_UNICODE_3 is not set +CONFIG_RT_DFS_ELM_LFN_UNICODE=0 +CONFIG_RT_DFS_ELM_MAX_LFN=255 +CONFIG_RT_DFS_ELM_DRIVES=2 +CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512 +# CONFIG_RT_DFS_ELM_USE_ERASE is not set +CONFIG_RT_DFS_ELM_REENTRANT=y CONFIG_RT_USING_DFS_DEVFS=y # CONFIG_RT_USING_DFS_ROMFS is not set # CONFIG_RT_USING_DFS_RAMFS is not set @@ -162,7 +183,7 @@ CONFIG_RT_USING_PIN=y # CONFIG_RT_USING_SDIO is not set CONFIG_RT_USING_SPI=y # CONFIG_RT_USING_QSPI is not set -# CONFIG_RT_USING_SPI_MSD is not set +CONFIG_RT_USING_SPI_MSD=y # CONFIG_RT_USING_SFUD is not set # CONFIG_RT_USING_ENC28J60 is not set # CONFIG_RT_USING_SPI_WIFI is not set @@ -348,10 +369,12 @@ CONFIG_BSP_USING_USB_TO_USART=y CONFIG_BSP_USING_SRAM=y # CONFIG_BSP_USING_SPI_FLASH is not set # CONFIG_BSP_USING_EEPROM is not set -# CONFIG_BSP_USING_OV2640 is not set +CONFIG_BSP_USING_OV2640=y # CONFIG_BSP_USING_ETH is not set # CONFIG_BSP_USING_MPU6050 is not set -# CONFIG_BSP_USING_SDCARD is not set +CONFIG_BSP_USING_SDCARD=y +CONFIG_SDCARD_SPI2_CS_PIN=28 +CONFIG_SDCARD_SPI_BUS_NAME="spi2" # # On-chip Peripheral Drivers @@ -373,7 +396,9 @@ CONFIG_BSP_USING_SPI=y CONFIG_BSP_USING_SPI1=y # CONFIG_BSP_SPI1_TX_USING_DMA is not set # CONFIG_BSP_SPI1_RX_USING_DMA is not set -# CONFIG_BSP_USING_SPI2 is not set +CONFIG_BSP_USING_SPI2=y +# CONFIG_BSP_SPI2_TX_USING_DMA is not set +# CONFIG_BSP_SPI2_RX_USING_DMA is not set # CONFIG_BSP_USING_ADC is not set CONFIG_BSP_USING_I2C1=y CONFIG_BSP_I2C1_SCL_PIN=54 @@ -397,3 +422,15 @@ CONFIG_BSP_USING_FMC=y # # More Drivers # +# CONFIG_PKG_USING_RW007 is not set +# CONFIG_RW007_NOT_USE_EXAMPLE_DRIVERS is not set +# CONFIG_RW007_USING_STM32_DRIVERS is not set +# CONFIG_DRV_USING_OV2640 is not set + +# +# Applications +# + +# +# Framework +# diff --git a/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/applications/ov2640_test.c b/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/applications/ov2640_test.c new file mode 100644 index 00000000..9a3f67b9 --- /dev/null +++ b/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/applications/ov2640_test.c @@ -0,0 +1,97 @@ +#include +#include +#include "stdio.h" +#include "string.h" +#ifdef DRV_USING_OV2640 +#ifdef RT_USING_POSIX +#include +#include +#ifdef RT_USING_POSIX_TERMIOS +#include +#endif +#endif +#include +#define JPEG_BUF_SIZE (1024*200) +#define UART_NUMBER2 "uart2" + +void ov2640_test(int argc, char **argv) +{ + + rt_err_t ret = 0; + int fd = 0; + fd = open("/dev/ov2640",O_RDONLY); + if(fd < 0) + { + printf("open ov2640 fail !!"); + return; + } + rt_uint8_t* JpegBuffer = rt_malloc(JPEG_BUF_SIZE); + _ioctl_shoot_para shoot_para_t = {0}; + if (RT_NULL == JpegBuffer) + { + printf("JpegBuffer senddata buf malloc error!\n"); + return; + } + printf("ov2640 test by printing the image value in memory \r\n"); + shoot_para_t.pdata = (uint32_t)JpegBuffer; + shoot_para_t.length = JPEG_BUF_SIZE; + ret = ioctl(fd,IOCTRL_CAMERA_START_SHOT,&shoot_para_t); + if(RT_ERROR == ret) + { + printf("ov2640 can't wait event flag"); + return; + } + printf("print the vaule:\r\n\r\n"); + ret = rt_ov2640_calculate_jpeg_len(JpegBuffer,JPEG_BUF_SIZE); + printf("photo leghth is %d :\r\n\r\n",ret); + #ifdef BSP_USING_UART2 + void img_output_uart2(rt_uint8_t* jpegbuf,rt_uint16_t len); + img_output_uart2(JpegBuffer,ret); + #endif + for(int i =0;i +#ifdef PKG_USING_RW007 +#include +#include +#include +#include +static const char send_data[] = "This is TCP Client from AIIT"; +void rw007_test(int argc, char **argv) +{ + int ret; + char *recv_data; + struct hostent *host; + int sock, bytes_received; + struct sockaddr_in server_addr; + const char *url; + int port; + extern rt_bool_t rt_wlan_is_connected(void); + if (rt_wlan_is_connected() != 1) + { + printf("Please connect a wifi firstly\n"); + return; + } + if (argc < 3) + { + printf("Usage: tcpclient URL PORT\n"); + printf("Like: tcpclient 192.168.12.44 5000\n"); + return ; + } + + url = argv[1]; + port = strtoul(argv[2], 0, 10); + host = gethostbyname(url); + recv_data = rt_malloc(1024); + if (recv_data == RT_NULL) + { + printf("No memory\n"); + return; + } + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) + { + printf("Socket error\n"); + rt_free(recv_data); + return; + } + server_addr.sin_family = AF_INET; + server_addr.sin_port = htons(port); + server_addr.sin_addr = *((struct in_addr *)host->h_addr); + rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero)); + if (connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) + { + printf("Connect fail!\n"); + closesocket(sock); + rt_free(recv_data); + return; + } + else + { + printf("Connect successful\n"); + } + while (1) + { + bytes_received = recv(sock, recv_data, 1024 - 1, 0); + if (bytes_received < 0) + { + closesocket(sock); + printf("\nreceived error,close the socket.\r\n"); + rt_free(recv_data); + break; + } + else if (bytes_received == 0) + { + closesocket(sock); + printf("\nreceived error,close the socket.\r\n"); + rt_free(recv_data); + break; + } + recv_data[bytes_received] = '\0'; + if (strncmp(recv_data, "q", 1) == 0 || strncmp(recv_data, "Q", 1) == 0) + { + closesocket(sock); + printf("\n got a 'q' or 'Q',close the socket.\r\n"); + rt_free(recv_data); + break; + } + else + { + printf("\nReceived data = %s ", recv_data); + } + ret = send(sock, send_data, strlen(send_data), 0); + if (ret < 0) + { + closesocket(sock); + printf("\nsend error,close the socket.\r\n"); + rt_free(recv_data); + break; + } + else if (ret == 0) + { + printf("\n Send warning,send function return 0.\r\n"); + } + } + return; +} +MSH_CMD_EXPORT(rw007_test, a tcp client sample); +#endif + diff --git a/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/rtconfig.h b/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/rtconfig.h index 64e11397..3cd87e39 100644 --- a/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/rtconfig.h +++ b/Ubiquitous/RT_Thread/bsp/stm32f407-atk-coreboard/rtconfig.h @@ -91,6 +91,20 @@ #define DFS_FILESYSTEMS_MAX 2 #define DFS_FILESYSTEM_TYPES_MAX 2 #define DFS_FD_MAX 16 +#define RT_USING_DFS_ELMFAT + +/* elm-chan's FatFs, Generic FAT Filesystem Module */ + +#define RT_DFS_ELM_CODE_PAGE 437 +#define RT_DFS_ELM_WORD_ACCESS +#define RT_DFS_ELM_USE_LFN_3 +#define RT_DFS_ELM_USE_LFN 3 +#define RT_DFS_ELM_LFN_UNICODE_0 +#define RT_DFS_ELM_LFN_UNICODE 0 +#define RT_DFS_ELM_MAX_LFN 255 +#define RT_DFS_ELM_DRIVES 2 +#define RT_DFS_ELM_MAX_SECTOR_SIZE 512 +#define RT_DFS_ELM_REENTRANT #define RT_USING_DFS_DEVFS /* Device Drivers */ @@ -107,6 +121,7 @@ #define RT_USING_I2C_BITOPS #define RT_USING_PIN #define RT_USING_SPI +#define RT_USING_SPI_MSD #define RT_USING_WIFI #define RT_WLAN_DEVICE_STA_NAME "wlan0" #define RT_WLAN_DEVICE_AP_NAME "wlan1" @@ -230,6 +245,10 @@ #define BSP_USING_USB_TO_USART #define BSP_USING_SRAM +#define BSP_USING_OV2640 +#define BSP_USING_SDCARD +#define SDCARD_SPI2_CS_PIN 28 +#define SDCARD_SPI_BUS_NAME "spi2" /* On-chip Peripheral Drivers */ @@ -238,6 +257,7 @@ #define BSP_USING_UART1 #define BSP_USING_SPI #define BSP_USING_SPI1 +#define BSP_USING_SPI2 #define BSP_USING_I2C1 #define BSP_I2C1_SCL_PIN 54 #define BSP_I2C1_SDA_PIN 55 @@ -250,4 +270,9 @@ /* More Drivers */ +/* Applications */ + +/* Framework */ + + #endif diff --git a/Ubiquitous/RT_Thread/drivers/Kconfig b/Ubiquitous/RT_Thread/drivers/Kconfig index cde6fe64..b6893957 100644 --- a/Ubiquitous/RT_Thread/drivers/Kconfig +++ b/Ubiquitous/RT_Thread/drivers/Kconfig @@ -1,5 +1,5 @@ menu "More Drivers" -#source "$RT_Thread_DIR/drivers/rw007/Kconfig" -#source "$RT_Thread_DIR/drivers/ov2640/Kconfig" +source "$RT_Thread_DIR/drivers/rw007/Kconfig" +source "$RT_Thread_DIR/drivers/ov2640/Kconfig" endmenu diff --git a/Ubiquitous/RT_Thread/drivers/ov2640/Kconfig b/Ubiquitous/RT_Thread/drivers/ov2640/Kconfig new file mode 100644 index 00000000..2620f011 --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/ov2640/Kconfig @@ -0,0 +1,14 @@ + +menuconfig DRV_USING_OV2640 + bool "ov2640 driver" + default n + +if SOC_FAMILY_STM32 + config DRV_USING_OV2640 + select BSP_USING_DCMI +endif + +if BOARD_K210_EVB + config DRV_USING_OV2640 + select BSP_USING_DVP +endif diff --git a/Ubiquitous/RT_Thread/drivers/ov2640/SConscript b/Ubiquitous/RT_Thread/drivers/ov2640/SConscript new file mode 100644 index 00000000..2aceb999 --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/ov2640/SConscript @@ -0,0 +1,7 @@ +Import('RTT_ROOT') +from building import * + +cwd = GetCurrentDir() +objs = SConscript(os.path.join(cwd, 'ov2640_source', 'SConscript')) + +Return('objs') diff --git a/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/SConscript b/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/SConscript new file mode 100644 index 00000000..ba3763b4 --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/SConscript @@ -0,0 +1,14 @@ +import os +from building import * +Import('RTT_ROOT') +Import('rtconfig') +cwd = GetCurrentDir() +DEPENDS = ["DRV_USING_OV2640"] + +SOURCES = [] +if GetDepend(['DRV_USING_OV2640']): + SOURCES += ['drv_ov2640.c'] +path = [cwd] +objs = DefineGroup('ov2640', src = SOURCES, depend = DEPENDS,CPPPATH = path) + +Return("objs") \ No newline at end of file diff --git a/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/drv_ov2640.c b/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/drv_ov2640.c new file mode 100644 index 00000000..de8aa1f6 --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/drv_ov2640.c @@ -0,0 +1,1736 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-08-03 thread-liu the first version + * 2021-1-15 xiaoyu add set resolution function and the way of reset different manufactures's ov2640 egg:zhendianyuanzi and weixue + */ + +#include "board.h" +#include +#include + + +#ifdef DRV_USING_OV2640 +#include +#ifdef RT_USING_POSIX +#include +#include +#ifdef RT_USING_POSIX_TERMIOS +#include +#endif +#endif +#define DRV_DEBUG +#define LOG_TAG "drv.ov2640" +#define DBG_LVL DBG_LOG +#include + +/* +resolution grade: + 160,120, //QQVGA 0 + 176,144, //QCIF 1 + 320,240, //QVGA 2 + 400,240, //WQVGA 3 + 352,288, //CIF 4 + 640,480, //VGA 5 + 800,600, //SVGA 6 + 1024,768, //XGA 7 + 1280,800, //WXGA 8 + 1280,960, //XVGA 9 + 1440,900, //WXGA+ 10 + 1280,1024, //SXGA 11 + 1600,1200, //UXGA 12 +*/ +#ifdef SOC_FAMILY_STM32 +static rt_uint8_t g_ov2640_reso_level = 6; //resolution level variable 0 ~ 12 +#elif defined BOARD_K210_EVB +static rt_uint8_t g_ov2640_reso_level = 2; +#endif + +static struct camera_device _ov2640_device; +const rt_uint8_t OV2640_AUTOEXPOSURE_LEVEL[5][8]= +{ + { + 0xFF,0x01, + 0x24,0x20, + 0x25,0x18, + 0x26,0x60, + }, + { + 0xFF,0x01, + 0x24,0x34, + 0x25,0x1c, + 0x26,0x00, + }, + { + 0xFF,0x01, + 0x24,0x3e, + 0x25,0x38, + 0x26,0x81, + }, + { + 0xFF,0x01, + 0x24,0x48, + 0x25,0x40, + 0x26,0x81, + }, + { + 0xFF,0x01, + 0x24,0x58, + 0x25,0x50, + 0x26,0x92, + }, +}; +//SXGA(1600*1200) +#ifdef OV2640_ZDYZ +const rt_uint8_t ov2640_sxga_init_reg_tbl[][2]= +{ + 0xff, 0x00, + 0x2c, 0xff, + 0x2e, 0xdf, + 0xff, 0x01, + 0x3c, 0x32, + // + 0x11, 0x00, + 0x09, 0x02, + 0x04, 0xD8, + 0x13, 0xe5, + 0x14, 0x48, + 0x2c, 0x0c, + 0x33, 0x78, + 0x3a, 0x33, + 0x3b, 0xfB, + // + 0x3e, 0x00, + 0x43, 0x11, + 0x16, 0x10, + // + 0x39, 0x92, + // + 0x35, 0xda, + 0x22, 0x1a, + 0x37, 0xc3, + 0x23, 0x00, + 0x34, 0xc0, + 0x36, 0x1a, + 0x06, 0x88, + 0x07, 0xc0, + 0x0d, 0x87, + 0x0e, 0x41, + 0x4c, 0x00, + + 0x48, 0x00, + 0x5B, 0x00, + 0x42, 0x03, + // + 0x4a, 0x81, + 0x21, 0x99, + // + 0x24, 0x40, + 0x25, 0x38, + 0x26, 0x82, + 0x5c, 0x00, + 0x63, 0x00, + 0x46, 0x00, + 0x0c, 0x3c, + // + 0x61, 0x70, + 0x62, 0x80, + 0x7c, 0x05, + // + 0x20, 0x80, + 0x28, 0x30, + 0x6c, 0x00, + 0x6d, 0x80, + 0x6e, 0x00, + 0x70, 0x02, + 0x71, 0x94, + 0x73, 0xc1, + 0x3d, 0x34, + 0x5a, 0x57, + // + 0x12, 0x00,//UXGA 1600*1200 + + 0x17, 0x11, + 0x18, 0x75, + 0x19, 0x01, + 0x1a, 0x97, + 0x32, 0x36, + 0x03, 0x0f, + 0x37, 0x40, + // + 0x4f, 0xca, + 0x50, 0xa8, + 0x5a, 0x23, + 0x6d, 0x00, + 0x6d, 0x38, + // + 0xff, 0x00, + 0xe5, 0x7f, + 0xf9, 0xc0, + 0x41, 0x24, + 0xe0, 0x14, + 0x76, 0xff, + 0x33, 0xa0, + 0x42, 0x20, + 0x43, 0x18, + 0x4c, 0x00, + 0x87, 0xd5, + 0x88, 0x3f, + 0xd7, 0x03, + 0xd9, 0x10, + 0xd3, 0x82, + // + 0xc8, 0x08, + 0xc9, 0x80, + // + 0x7c, 0x00, + 0x7d, 0x00, + 0x7c, 0x03, + 0x7d, 0x48, + 0x7d, 0x48, + 0x7c, 0x08, + 0x7d, 0x20, + 0x7d, 0x10, + 0x7d, 0x0e, + // + 0x90, 0x00, + 0x91, 0x0e, + 0x91, 0x1a, + 0x91, 0x31, + 0x91, 0x5a, + 0x91, 0x69, + 0x91, 0x75, + 0x91, 0x7e, + 0x91, 0x88, + 0x91, 0x8f, + 0x91, 0x96, + 0x91, 0xa3, + 0x91, 0xaf, + 0x91, 0xc4, + 0x91, 0xd7, + 0x91, 0xe8, + 0x91, 0x20, + // + 0x92, 0x00, + 0x93, 0x06, + 0x93, 0xe3, + 0x93, 0x05, + 0x93, 0x05, + 0x93, 0x00, + 0x93, 0x04, + 0x93, 0x00, + 0x93, 0x00, + 0x93, 0x00, + 0x93, 0x00, + 0x93, 0x00, + 0x93, 0x00, + 0x93, 0x00, + // + 0x96, 0x00, + 0x97, 0x08, + 0x97, 0x19, + 0x97, 0x02, + 0x97, 0x0c, + 0x97, 0x24, + 0x97, 0x30, + 0x97, 0x28, + 0x97, 0x26, + 0x97, 0x02, + 0x97, 0x98, + 0x97, 0x80, + 0x97, 0x00, + 0x97, 0x00, + // + 0xc3, 0xef, + + 0xa4, 0x00, + 0xa8, 0x00, + 0xc5, 0x11, + 0xc6, 0x51, + 0xbf, 0x80, + 0xc7, 0x10, + 0xb6, 0x66, + 0xb8, 0xA5, + 0xb7, 0x64, + 0xb9, 0x7C, + 0xb3, 0xaf, + 0xb4, 0x97, + 0xb5, 0xFF, + 0xb0, 0xC5, + 0xb1, 0x94, + 0xb2, 0x0f, + 0xc4, 0x5c, + // + 0xc0, 0xc8, + 0xc1, 0x96, + 0x8c, 0x00, + 0x86, 0x3d, + 0x50, 0x00, + 0x51, 0x90, + 0x52, 0x2c, + 0x53, 0x00, + 0x54, 0x00, + 0x55, 0x88, + + 0x5a, 0x90, + 0x5b, 0x2C, + 0x5c, 0x05, + + 0xd3, 0x04,//auto xiaoxin + // + 0xc3, 0xed, + 0x7f, 0x00, + + 0xda, 0x09, + + 0xe5, 0x1f, + 0xe1, 0x67, + 0xe0, 0x00, + 0xdd, 0x7f, + 0x05, 0x00, +}; +#else +const rt_uint8_t ov2640_sxga_init_reg_tbl[][2]= +{ + {0xff, 0x00}, + {0x2c, 0xff}, + {0x2e, 0xdf}, + {0xff, 0x01}, + {0x3c, 0x32}, + {0x11, 0x00}, + {0x09, 0x02}, + {0x04, 0xD8}, + {0x13, 0xe5}, + {0x14, 0x48}, + {0x2c, 0x0c}, + {0x33, 0x78}, + {0x3a, 0x33}, + {0x3b, 0xfB}, + {0x3e, 0x00}, + {0x43, 0x11}, + {0x16, 0x10}, + {0x39, 0x92}, + {0x35, 0xda}, + {0x22, 0x1a}, + {0x37, 0xc3}, + {0x23, 0x00}, + {0x34, 0xc0}, + {0x36, 0x1a}, + {0x06, 0x88}, + {0x07, 0xc0}, + {0x0d, 0x87}, + {0x0e, 0x41}, + {0x4c, 0x00}, + {0x48, 0x00}, + {0x5B, 0x00}, + {0x42, 0x03}, + {0x4a, 0x81}, + {0x21, 0x99}, + {0x24, 0x40}, + {0x25, 0x38}, + {0x26, 0x82}, + {0x5c, 0x00}, + {0x63, 0x00}, + {0x46, 0x00}, + {0x0c, 0x3c}, + {0x61, 0x70}, + {0x62, 0x80}, + {0x7c, 0x05}, + {0x20, 0x80}, + {0x28, 0x30}, + {0x6c, 0x00}, + {0x6d, 0x80}, + {0x6e, 0x00}, + {0x70, 0x02}, + {0x71, 0x94}, + {0x73, 0xc1}, + {0x3d, 0x34}, + {0x5a, 0x57}, + {0x12, 0x00}, + {0x17, 0x11}, + {0x18, 0x75}, + {0x19, 0x01}, + {0x1a, 0x97}, + {0x32, 0x36}, + {0x03, 0x0f}, + {0x37, 0x40}, + {0x4f, 0xca}, + {0x50, 0xa8}, + {0x5a, 0x23}, + {0x6d, 0x00}, + {0x6d, 0x38}, + {0xff, 0x00}, + {0xe5, 0x7f}, + {0xf9, 0xc0}, + {0x41, 0x24}, + {0xe0, 0x14}, + {0x76, 0xff}, + {0x33, 0xa0}, + {0x42, 0x20}, + {0x43, 0x18}, + {0x4c, 0x00}, + {0x87, 0xd5}, + {0x88, 0x3f}, + {0xd7, 0x03}, + {0xd9, 0x10}, + {0xd3, 0x82}, + {0xc8, 0x08}, + {0xc9, 0x80}, + {0x7c, 0x00}, + {0x7d, 0x00}, + {0x7c, 0x03}, + {0x7d, 0x48}, + {0x7d, 0x48}, + {0x7c, 0x08}, + {0x7d, 0x20}, + {0x7d, 0x10}, + {0x7d, 0x0e}, + {0x90, 0x00}, + {0x91, 0x0e}, + {0x91, 0x1a}, + {0x91, 0x31}, + {0x91, 0x5a}, + {0x91, 0x69}, + {0x91, 0x75}, + {0x91, 0x7e}, + {0x91, 0x88}, + {0x91, 0x8f}, + {0x91, 0x96}, + {0x91, 0xa3}, + {0x91, 0xaf}, + {0x91, 0xc4}, + {0x91, 0xd7}, + {0x91, 0xe8}, + {0x91, 0x20}, + {0x92, 0x00}, + {0x93, 0x06}, + {0x93, 0xe3}, + {0x93, 0x05}, + {0x93, 0x05}, + {0x93, 0x00}, + {0x93, 0x04}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x96, 0x00}, + {0x97, 0x08}, + {0x97, 0x19}, + {0x97, 0x02}, + {0x97, 0x0c}, + {0x97, 0x24}, + {0x97, 0x30}, + {0x97, 0x28}, + {0x97, 0x26}, + {0x97, 0x02}, + {0x97, 0x98}, + {0x97, 0x80}, + {0x97, 0x00}, + {0x97, 0x00}, + {0xc3, 0xef}, + {0xa4, 0x00}, + {0xa8, 0x00}, + {0xc5, 0x11}, + {0xc6, 0x51}, + {0xbf, 0x80}, + {0xc7, 0x10}, + {0xb6, 0x66}, + {0xb8, 0xA5}, + {0xb7, 0x64}, + {0xb9, 0x7C}, + {0xb3, 0xaf}, + {0xb4, 0x97}, + {0xb5, 0xFF}, + {0xb0, 0xC5}, + {0xb1, 0x94}, + {0xb2, 0x0f}, + {0xc4, 0x5c}, + {0xc0, 0xc8}, + {0xc1, 0x96}, + {0x8c, 0x00}, + {0x86, 0x3d}, + {0x50, 0x00}, + {0x51, 0x90}, + {0x52, 0x2c}, + {0x53, 0x00}, + {0x54, 0x00}, + {0x55, 0x88}, + {0x5a, 0x90}, + {0x5b, 0x2C}, + {0x5c, 0x05}, + {0xd3, 0x02}, + {0xc3, 0xed}, + {0x7f, 0x00}, + {0xda, 0x09}, + {0xe5, 0x1f}, + {0xe1, 0x67}, + {0xe0, 0x00}, + {0xdd, 0x7f}, + {0x05, 0x00}, +}; +#endif +/* SVGA 800*600 */ +const rt_uint8_t ov2640_svga_init_reg_tbl[][2]= +{ + {0xff, 0x00}, + {0x2c, 0xff}, + {0x2e, 0xdf}, + {0xff, 0x01}, + {0x3c, 0x32}, + {0x11, 0x00}, + {0x09, 0x02}, + {0x04, 0xD8}, + {0x13, 0xe5}, + {0x14, 0x48}, + {0x2c, 0x0c}, + {0x33, 0x78}, + {0x3a, 0x33}, + {0x3b, 0xfB}, + {0x3e, 0x00}, + {0x43, 0x11}, + {0x16, 0x10}, + {0x39, 0x92}, + {0x35, 0xda}, + {0x22, 0x1a}, + {0x37, 0xc3}, + {0x23, 0x00}, + {0x34, 0xc0}, + {0x36, 0x1a}, + {0x06, 0x88}, + {0x07, 0xc0}, + {0x0d, 0x87}, + {0x0e, 0x41}, + {0x4c, 0x00}, + {0x48, 0x00}, + {0x5B, 0x00}, + {0x42, 0x03}, + {0x4a, 0x81}, + {0x21, 0x99}, + {0x24, 0x40}, + {0x25, 0x38}, + {0x26, 0x82}, + {0x5c, 0x00}, + {0x63, 0x00}, + {0x46, 0x22}, + {0x0c, 0x3c}, + {0x61, 0x70}, + {0x62, 0x80}, + {0x7c, 0x05}, + {0x20, 0x80}, + {0x28, 0x30}, + {0x6c, 0x00}, + {0x6d, 0x80}, + {0x6e, 0x00}, + {0x70, 0x02}, + {0x71, 0x94}, + {0x73, 0xc1}, + {0x3d, 0x34}, + {0x5a, 0x57}, + {0x12, 0x40}, + {0x17, 0x11}, + {0x18, 0x43}, + {0x19, 0x00}, + {0x1a, 0x4b}, + {0x32, 0x09}, + {0x37, 0xc0}, + {0x4f, 0xca}, + {0x50, 0xa8}, + {0x5a, 0x23}, + {0x6d, 0x00}, + {0x3d, 0x38}, + {0xff, 0x00}, + {0xe5, 0x7f}, + {0xf9, 0xc0}, + {0x41, 0x24}, + {0xe0, 0x14}, + {0x76, 0xff}, + {0x33, 0xa0}, + {0x42, 0x20}, + {0x43, 0x18}, + {0x4c, 0x00}, + {0x87, 0xd5}, + {0x88, 0x3f}, + {0xd7, 0x03}, + {0xd9, 0x10}, + {0xd3, 0x82}, + {0xc8, 0x08}, + {0xc9, 0x80}, + {0x7c, 0x00}, + {0x7d, 0x00}, + {0x7c, 0x03}, + {0x7d, 0x48}, + {0x7d, 0x48}, + {0x7c, 0x08}, + {0x7d, 0x20}, + {0x7d, 0x10}, + {0x7d, 0x0e}, + {0x90, 0x00}, + {0x91, 0x0e}, + {0x91, 0x1a}, + {0x91, 0x31}, + {0x91, 0x5a}, + {0x91, 0x69}, + {0x91, 0x75}, + {0x91, 0x7e}, + {0x91, 0x88}, + {0x91, 0x8f}, + {0x91, 0x96}, + {0x91, 0xa3}, + {0x91, 0xaf}, + {0x91, 0xc4}, + {0x91, 0xd7}, + {0x91, 0xe8}, + {0x91, 0x20}, + {0x92, 0x00}, + {0x93, 0x06}, + {0x93, 0xe3}, + {0x93, 0x05}, + {0x93, 0x05}, + {0x93, 0x00}, + {0x93, 0x04}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x93, 0x00}, + {0x96, 0x00}, + {0x97, 0x08}, + {0x97, 0x19}, + {0x97, 0x02}, + {0x97, 0x0c}, + {0x97, 0x24}, + {0x97, 0x30}, + {0x97, 0x28}, + {0x97, 0x26}, + {0x97, 0x02}, + {0x97, 0x98}, + {0x97, 0x80}, + {0x97, 0x00}, + {0x97, 0x00}, + {0xc3, 0xed}, + {0xa4, 0x00}, + {0xa8, 0x00}, + {0xc5, 0x11}, + {0xc6, 0x51}, + {0xbf, 0x80}, + {0xc7, 0x10}, + {0xb6, 0x66}, + {0xb8, 0xA5}, + {0xb7, 0x64}, + {0xb9, 0x7C}, + {0xb3, 0xaf}, + {0xb4, 0x97}, + {0xb5, 0xFF}, + {0xb0, 0xC5}, + {0xb1, 0x94}, + {0xb2, 0x0f}, + {0xc4, 0x5c}, + {0xc0, 0x64}, + {0xc1, 0x4B}, + {0x8c, 0x00}, + {0x86, 0x3D}, + {0x50, 0x00}, + {0x51, 0xC8}, + {0x52, 0x96}, + {0x53, 0x00}, + {0x54, 0x00}, + {0x55, 0x00}, + {0x5a, 0xC8}, + {0x5b, 0x96}, + {0x5c, 0x00}, + {0xd3, 0x02}, + {0xc3, 0xed}, + {0x7f, 0x00}, + {0xda, 0x09}, + {0xe5, 0x1f}, + {0xe1, 0x67}, + {0xe0, 0x00}, + {0xdd, 0x7f}, + {0x05, 0x00}, +}; + +const rt_uint8_t ov2640_jpeg_reg_tbl[][2]= +{ + {0xff, 0x01}, + {0xe0, 0x14}, + {0xe1, 0x77}, + {0xe5, 0x1f}, + {0xd7, 0x03}, + {0xda, 0x10}, + {0xe0, 0x00}, +}; + +const rt_uint8_t ov2640_rgb565_reg_tbl[][2]= +{ + {0xFF, 0x00}, + {0xDA, 0x08}, + {0xD7, 0x03}, + {0xDF, 0x02}, + {0x33, 0xa0}, + {0x3C, 0x00}, + {0xe1, 0x67}, + + {0xff, 0x01}, + {0xe0, 0x00}, + {0xe1, 0x00}, + {0xe5, 0x00}, + {0xd7, 0x00}, + {0xda, 0x00}, + {0xe0, 0x00}, +}; +const rt_uint8_t ov2640_yuv422_reg_tbl[][2] = +{ + {0xFF, 0x00}, + {0xDA, 0x10}, + {0xD7, 0x03}, + {0xDF, 0x00}, + {0x33, 0x80}, + {0x3C, 0x40}, + {0xe1, 0x77}, + {0x00, 0x00}, +}; + + +const rt_uint16_t jpeg_img_size_tbl[][2]= +{ + 160,120, //QQVGA 0 + 176,144, //QCIF 1 + 320,240, //QVGA 2 + 400,240, //WQVGA 3 + 352,288, //CIF 4 + 640,480, //VGA 5 + 800,600, //SVGA 6 + 1024,768, //XGA 7 + 1280,800, //WXGA 8 + 1280,960, //XVGA 9 + 1440,900, //WXGA+ 10 + 1280,1024, //SXGA 11 + 1600,1200, //UXGA 12 +}; + +struct rt_i2c_bus_device *i2c_bus = RT_NULL; +/* event control block*/ +static struct rt_event g_rec_photo_event; +/*ov2640 mutex */ +static rt_mutex_t g_ov2640_mutex = RT_NULL; + +static rt_err_t sccb_read_reg(struct rt_i2c_bus_device *bus, rt_uint8_t reg, rt_uint8_t *buf) +{ + if(NULL == buf) + { + LOG_E("buf == NULL"); + return RT_ERROR; + } + #ifdef SOC_FAMILY_STM32 + //stm32 bsp + struct rt_i2c_msg msg[2]; + + RT_ASSERT(bus != RT_NULL); + + msg[0].addr = DEV_ADDRESS; + msg[0].flags = RT_I2C_WR; + msg[0].buf = ® + msg[0].len = 2; + msg[1].addr = DEV_ADDRESS; + msg[1].flags = RT_I2C_RD; + msg[1].len = 1; + msg[1].buf = buf; + if (rt_i2c_transfer(bus, msg, 2) == 2) + { + return RT_EOK; + } + return RT_ERROR; + #elif defined BOARD_K210_EVB + //k210 bsp + *buf =dvp_sccb_receive_data(DEV_ADDRESS,reg); + return RT_EOK; + #endif +} + +/* i2c write reg */ +static rt_err_t sccb_write_reg(struct rt_i2c_bus_device *bus, rt_uint8_t reg, rt_uint8_t data) +{ + #ifdef SOC_FAMILY_STM32 + rt_uint8_t buf[2]; + struct rt_i2c_msg msgs; + + RT_ASSERT(bus != RT_NULL); + + buf[0] = reg ; + buf[1] = data; + + msgs.addr = DEV_ADDRESS; + msgs.flags = RT_I2C_WR; + msgs.buf = buf; + msgs.len = 2; + if (rt_i2c_transfer(bus, &msgs, 1) == 1) + { + return RT_EOK; + } + return RT_ERROR; + #elif defined BOARD_K210_EVB + dvp_sccb_send_data(DEV_ADDRESS,reg,data); + return RT_EOK; + #endif +} + +static rt_err_t ov2640_read_id(struct rt_i2c_bus_device *bus) +{ + rt_uint8_t read_value[2]; + rt_uint16_t id = 0; + sccb_read_reg(bus, OV2640_SENSOR_MIDH,&read_value[0]); + sccb_read_reg(bus, OV2640_SENSOR_MIDL,&read_value[1]); + id = ((rt_uint16_t)(read_value[0] << 8) & 0xFF00); + id |= ((rt_uint16_t)(read_value[1]) & 0x00FF); + + if (id != OV2640_MID) + { + LOG_E("ov2640 init error, mid: 0x%x ", id); + return RT_ERROR; + } + + LOG_I("ov2640 read mid success, mid: 0x%x ", id); + + sccb_read_reg(bus, OV2640_SENSOR_PIDH, &read_value[0]); + sccb_read_reg(bus, OV2640_SENSOR_PIDL, &read_value[1]); + id = ((rt_uint16_t)(read_value[0] << 8) & 0xFF00); + id |= ((rt_uint16_t)(read_value[1]) & 0x00FF); + + if (id != OV2640_PID) + { + LOG_E("ov2640 init error, pid: 0x%04x ", id); + return RT_ERROR; + } + + LOG_I("ov2640 read hid success, pid: 0x%04x", id); + + return RT_EOK; +} + +/* change ov2640 to jpeg mode */ +void ov2640_jpeg_mode(void) +{ + rt_uint16_t i=0; + /* set yun422 mode */ + for (i = 0; i < (sizeof(ov2640_yuv422_reg_tbl) / 2); i++) + { + sccb_write_reg(i2c_bus, ov2640_yuv422_reg_tbl[i][0],ov2640_yuv422_reg_tbl[i][1]); + } + + /* set jpeg mode */ + for(i=0;i<(sizeof(ov2640_jpeg_reg_tbl)/2);i++) + { + sccb_write_reg(i2c_bus, ov2640_jpeg_reg_tbl[i][0],ov2640_jpeg_reg_tbl[i][1]); + } +} + +/* change ov2640 to rgb565 mode */ +void ov2640_rgb565_mode(void) +{ + rt_uint16_t i=0; + for (i = 0; i < (sizeof(ov2640_rgb565_reg_tbl) / 2); i++) + { + sccb_write_reg(i2c_bus, ov2640_rgb565_reg_tbl[i][0],ov2640_rgb565_reg_tbl[i][1]); + } +} + + + +/* set auto exposure level value must be 0 ~4 */ +void ov2640_set_auto_exposure(rt_uint8_t level) +{ + rt_uint8_t i = 0; + rt_uint8_t *p = (rt_uint8_t*)OV2640_AUTOEXPOSURE_LEVEL[level]; + for (i = 0; i < 4; i++) + { + sccb_write_reg(i2c_bus, p[i*2],p[i*2+1]); + } +} + +/* set light mode + * 0: auto + * 1: sunny + * 2: cloudy + * 3: office + * 4: home + * */ +void ov2640_set_light_mode(rt_uint8_t mode) +{ + rt_uint8_t regccval, regcdval, regceval; + + switch(mode) + { + case 0: + sccb_write_reg(i2c_bus, 0xFF, 0x00); + sccb_write_reg(i2c_bus, 0xC7, 0x10); + return; + + case 2: + regccval = 0x65; + regcdval = 0x41; + regceval = 0x4F; + break; + + case 3: + regccval = 0x52; + regcdval = 0x41; + regceval = 0x66; + break; + + case 4: + regccval = 0x42; + regcdval = 0x3F; + regceval = 0x71; + break; + + default: + regccval = 0x5E; + regcdval = 0x41; + regceval = 0x54; + break; + } + + sccb_write_reg(i2c_bus, 0xFF, 0x00); + sccb_write_reg(i2c_bus, 0xC7, 0x40); + sccb_write_reg(i2c_bus, 0xCC, regccval); + sccb_write_reg(i2c_bus, 0xCD, regcdval); + sccb_write_reg(i2c_bus, 0xCE, regceval); +} + +/* set color saturation + * 0: -2 + * 1: -1 + * 2: 0 + * 3: +1 + * 4: +2 + * */ +void ov2640_set_color_saturation(rt_uint8_t sat) +{ + rt_uint8_t reg7dval = ((sat+2)<<4) | 0x08; + sccb_write_reg(i2c_bus, 0xFF, 0X00); + sccb_write_reg(i2c_bus, 0x7C, 0X00); + sccb_write_reg(i2c_bus, 0x7D, 0X02); + sccb_write_reg(i2c_bus, 0x7C, 0X03); + sccb_write_reg(i2c_bus, 0x7D, reg7dval); + sccb_write_reg(i2c_bus, 0x7D, reg7dval); +} + +/* set brightness + * 0: -2 + * 1: -1 + * 2: 0 + * 3: 1 + * 4: 2 + * */ +void ov2640_set_brightness(rt_uint8_t bright) +{ + sccb_write_reg(i2c_bus, 0xff, 0x00); + sccb_write_reg(i2c_bus, 0x7c, 0x00); + sccb_write_reg(i2c_bus, 0x7d, 0x04); + sccb_write_reg(i2c_bus, 0x7c, 0x09); + sccb_write_reg(i2c_bus, 0x7d, bright << 4); + sccb_write_reg(i2c_bus, 0x7d, 0x00); +} + +/* set contrast + * 0: -2 + * 1: -1 + * 2: 0 + * 3: 1 + * 4: 2 + * */ +void ov2640_set_contrast(rt_uint8_t contrast) +{ + rt_uint8_t reg7d0val, reg7d1val; + + switch(contrast) + { + case 0: + reg7d0val = 0x18; + reg7d1val = 0x34; + break; + + case 1: + reg7d0val = 0x1C; + reg7d1val = 0x2A; + break; + + case 3: + reg7d0val = 0x24; + reg7d1val = 0x16; + break; + + case 4: + reg7d0val = 0x28; + reg7d1val = 0x0C; + break; + + default: + reg7d0val = 0x20; + reg7d1val = 0x20; + break; + } + sccb_write_reg(i2c_bus, 0xff, 0x00); + sccb_write_reg(i2c_bus, 0x7c, 0x00); + sccb_write_reg(i2c_bus, 0x7d, 0x04); + sccb_write_reg(i2c_bus, 0x7c, 0x07); + sccb_write_reg(i2c_bus, 0x7d, 0x20); + sccb_write_reg(i2c_bus, 0x7d, reg7d0val); + sccb_write_reg(i2c_bus, 0x7d, reg7d1val); + sccb_write_reg(i2c_bus, 0x7d, 0x06); +} + +/* set special effects + * 0: noraml + * 1: negative film + * 2: black-and-white + * 3: the red + * 4: the green + * 5: the blue + * 6: Retro +*/ +void ov2640_set_special_effects(rt_uint8_t eft) +{ + rt_uint8_t reg7d0val, reg7d1val, reg7d2val; + + switch(eft) + { + case 1: + reg7d0val = 0x40; + break; + case 2: + reg7d0val = 0x18; + break; + case 3: + reg7d0val = 0x18; + reg7d1val = 0x40; + reg7d2val = 0xC0; + break; + case 4: + reg7d0val = 0x18; + reg7d1val = 0x40; + reg7d2val = 0x40; + break; + case 5: + reg7d0val = 0x18; + reg7d1val = 0xA0; + reg7d2val = 0x40; + break; + case 6: + reg7d0val = 0x18; + reg7d1val = 0x40; + reg7d2val = 0xA6; + break; + default: + reg7d0val = 0x00; + reg7d1val = 0x80; + reg7d2val = 0x80; + break; + } + sccb_write_reg(i2c_bus, 0xff, 0x00); + sccb_write_reg(i2c_bus, 0x7c, 0x00); + sccb_write_reg(i2c_bus, 0x7d, reg7d0val); + sccb_write_reg(i2c_bus, 0x7c, 0x05); + sccb_write_reg(i2c_bus, 0x7d, reg7d1val); + sccb_write_reg(i2c_bus, 0x7d, reg7d2val); +} + +/* set the image output window */ +void ov2640_set_window_size(rt_uint16_t sx,rt_uint16_t sy,rt_uint16_t width,rt_uint16_t height) +{ + rt_uint16_t endx; + rt_uint16_t endy; + rt_uint8_t temp; + endx = sx + width / 2; + endy = sy + height / 2; + + sccb_write_reg(i2c_bus, 0xFF, 0x01); + sccb_read_reg(i2c_bus, 0x03, &temp); + temp &= 0xF0; + temp |= ((endy & 0x03) << 2) | (sy & 0x03); + sccb_write_reg(i2c_bus, 0x03, temp); + sccb_write_reg(i2c_bus, 0x19, sy>>2); + sccb_write_reg(i2c_bus, 0x1A, endy>>2); + + sccb_read_reg(i2c_bus, 0x32, &temp); + temp &= 0xC0; + temp |= ((endx & 0x07) << 3) | (sx & 0x07); + sccb_write_reg(i2c_bus, 0x32, temp); + sccb_write_reg(i2c_bus, 0x17, sx>>3); + sccb_write_reg(i2c_bus, 0x18, endx>>3); +} + +/* set the image output size */ +rt_uint8_t ov2640_set_image_out_size(rt_uint16_t width,rt_uint16_t height) +{ + rt_uint16_t outh, outw; + rt_uint8_t temp; + + if(width%4)return 1; + if(height%4)return 2; + outw = width /4; + outh = height/4; + sccb_write_reg(i2c_bus, 0xFF, 0x00); + sccb_write_reg(i2c_bus, 0xE0, 0x04); + sccb_write_reg(i2c_bus, 0x5A, outw & 0XFF); + sccb_write_reg(i2c_bus, 0x5B, outh & 0XFF); + temp = (outw >> 8) & 0x03; + temp |= (outh >> 6) & 0x04; + sccb_write_reg(i2c_bus, 0x5C, temp); + sccb_write_reg(i2c_bus, 0xE0, 0X00); + + return RT_EOK; +} + +/* set the image window size */ +rt_uint8_t ov2640_set_image_window_size(rt_uint16_t offx, rt_uint16_t offy, rt_uint16_t width, rt_uint16_t height) +{ + rt_uint16_t hsize, vsize; + rt_uint8_t temp; + if ((width % 4) || (height%4)) + { + return RT_ERROR; + } + hsize = width /4; + vsize = height/4; + sccb_write_reg(i2c_bus, 0XFF,0X00); + sccb_write_reg(i2c_bus, 0XE0,0X04); + sccb_write_reg(i2c_bus, 0X51,hsize&0XFF); + sccb_write_reg(i2c_bus, 0X52,vsize&0XFF); + sccb_write_reg(i2c_bus, 0X53,offx&0XFF); + sccb_write_reg(i2c_bus, 0X54,offy&0XFF); + temp=(vsize>>1)&0X80; + temp|=(offy>>4)&0X70; + temp|=(hsize>>5)&0X08; + temp|=(offx>>8)&0X07; + sccb_write_reg(i2c_bus, 0X55,temp); // + sccb_write_reg(i2c_bus, 0X57,(hsize>>2)&0X80); // + sccb_write_reg(i2c_bus, 0XE0,0X00); + return 0; +} + +/* set output resolution */ +rt_uint8_t ov2640_set_image_size(rt_uint16_t width ,rt_uint16_t height) +{ + rt_uint8_t temp; + sccb_write_reg(i2c_bus, 0xFF, 0x00); + sccb_write_reg(i2c_bus, 0xE0, 0x04); + sccb_write_reg(i2c_bus, 0xC0, (width >>3) & 0xFF); + sccb_write_reg(i2c_bus, 0xC1, (height >> 3) & 0xFF); + temp = (width & 0x07) << 3; + temp |= height & 0x07; + temp |= (width >> 4) & 0x80; + sccb_write_reg(i2c_bus, 0x8C, temp); + sccb_write_reg(i2c_bus, 0xE0, 0x00); + + return RT_EOK; +} + + +int rt_ov2640_readid_test() +{ + #ifdef SOC_FAMILY_STM32 + i2c_bus = rt_i2c_bus_device_find(I2C_NAME); + if (i2c_bus == RT_NULL) + { + LOG_E("can't find %c deivce", I2C_NAME); + return RT_ERROR; + } + #endif + sccb_write_reg(i2c_bus, OV2640_DSP_RA_DLMT, 0x01); + rt_thread_delay(10); + sccb_write_reg(i2c_bus, OV2640_SENSOR_COM7, 0x80); + + ov2640_read_id(i2c_bus); + return RT_EOK; +} + +rt_uint32_t rt_ov2640_calculate_jpeg_len(rt_uint8_t* pdata,rt_uint32_t maxlength) +{ + rt_uint32_t length = 0; + if((*pdata != 0xFF)&&(*(pdata+1) != 0xD8)) + { + LOG_E("the data is error this time "); + return 0; + } + for(;lengthPWDN PG15------>RST + GPIO_Initure.Mode=GPIO_MODE_OUTPUT_PP; + GPIO_Initure.Pull=GPIO_PULLUP; + GPIO_Initure.Speed=GPIO_SPEED_HIGH; + HAL_GPIO_Init(GPIOG,&GPIO_Initure); + rt_thread_mdelay(10); + HAL_GPIO_WritePin(GPIOG,GPIO_PIN_9,GPIO_PIN_RESET); + rt_thread_mdelay(10); + HAL_GPIO_WritePin(GPIOG,GPIO_PIN_15,GPIO_PIN_RESET); + rt_thread_mdelay(10); + HAL_GPIO_WritePin(GPIOG,GPIO_PIN_15,GPIO_PIN_SET); + + + +} +#else +void rt_ov2460_rcc_int(void) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + __HAL_RCC_GPIOA_CLK_ENABLE(); + GPIO_InitStruct.Pin = GPIO_PIN_8; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF0_MCO; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); +} +#endif + +#endif + +void ov2640_set_resolution(int value) +{ + int i = 0; + if(value < 0 || value >13) + { + LOG_E("resolution parameter is error!"); + return; + } + if(13 == value) + { + LOG_I("set image :"); + LOG_I(" 160,120, QQVGA 0 "); + LOG_I(" 176,144, QCIF 1 "); + LOG_I(" 320,240, QVGA 2" ); + LOG_I(" 400,240, WQVGA 3 "); + LOG_I(" 352,288, CIF 4" ); + LOG_I(" 640,480, VGA 5 "); + LOG_I(" 800,600, SVGA 6"); + LOG_I(" 1024,768, XGA 7 "); + LOG_I(" 1280,800, WXGA 8 "); + LOG_I(" 1280,960, XVGA 9 "); + LOG_I(" 1440,900, WXGA+ 10"); + LOG_I(" 1280,1024, SXGA 11"); + LOG_I(" 1280,1024, UXGA 12"); + return; + } + g_ov2640_reso_level = value; + #ifdef SOC_FAMILY_STM32 + #ifdef OV2640_ZDYZ + rt_stm32407_atk_miniexpolre(); + #else + /* + At present, the design of RST reset pin is not carried out by Micro Snow Electronics, + which can be added later. Therefore, there will be problems if the micro snow electronic setting is connected here + */ + rt_ov2460_rcc_int(); + #endif + #endif + sccb_write_reg(i2c_bus, OV2640_DSP_RA_DLMT, 0x01); + sccb_write_reg(i2c_bus, OV2640_SENSOR_COM7, 0x80); + ov2640_read_id(i2c_bus); + if(g_ov2640_reso_level > LARGE_PHOTO_MODE) + { + for (i = 0; i < sizeof(ov2640_sxga_init_reg_tbl) / 2; i++) + { + sccb_write_reg(i2c_bus, ov2640_sxga_init_reg_tbl[i][0], ov2640_sxga_init_reg_tbl[i][1]); + } + LOG_I("out put big picture mode "); + } + else + { + for (i = 0; i < sizeof(ov2640_svga_init_reg_tbl) / 2; i++) + { + sccb_write_reg(i2c_bus, ov2640_svga_init_reg_tbl[i][0], ov2640_svga_init_reg_tbl[i][1]); + } + LOG_I("out put small picture mode "); + } + ov2640_rgb565_mode(); + ov2640_jpeg_mode(); + ov2640_set_image_window_size(0, 0, jpeg_img_size_tbl[g_ov2640_reso_level ][0],jpeg_img_size_tbl[g_ov2640_reso_level ][1]); + ov2640_set_image_out_size(jpeg_img_size_tbl[g_ov2640_reso_level ][0], jpeg_img_size_tbl[g_ov2640_reso_level ][1]); + LOG_I("set image resolution is %d * %d success\n\r",jpeg_img_size_tbl[g_ov2640_reso_level ][0],jpeg_img_size_tbl[g_ov2640_reso_level ][1]); +} + + +/* +set ov2640 configuration function +*/ +void set_ov2640_config(int argc, char **argv) +{ + rt_int8_t cmd = 0; + rt_int16_t value = 0; + LOG_I("set ov2640 configuration :"); + if(argc < 2) + { + LOG_E("Usage: set_ov2640_config grade"); + LOG_E("like: set_ov2640_config 25(CMD) 2(value) (cmd 25 (color saturation) value is 2 (0~4)"); + return; + } + + if(NULL != strstr(argv[1],"help")) + { + LOG_I(" set_ov2640_config CMD value"); + #ifdef SOC_FAMILY_STM32 + LOG_I(" CMD 23 is setting resolution,value should be 0~12(0-12 is resolution level value 13 display particulars)"); + #endif + LOG_I(" CMD 24 is setting light mode,value should be 0~4(0: auto 1: sunny,2: cloudy,3: office,4:home)"); + LOG_I(" CMD 25 is setting color saturation,value should be 0~4(0: -2 1:-1,2:0,3:1,4: 2)"); + LOG_I(" CMD 26 is setting brightness,value should be 0~4(0: -2 1:-1,2:0,3:1,4: 2)"); + LOG_I(" CMD 27 is setting contrast,value should be 0~4(0: -2 1:-1,2:0,3:1,4: 2)"); + LOG_I(" CMD 28 is setting effects,value should be 0~6:"); + LOG_I("(0: noraml 1: negative film 2: black-and-white 3: the red 4: the green 5: the blue 6: Retro)"); + LOG_I(" CMD 29 is setting exposure,value should be 0~4(0: -2 1:-1,2:0,3:1,4: 2)"); + } + cmd = strtoul(argv[1], 0, 10); + value = strtoul(argv[2], 0, 10); + LOG_I("CMD is %d vaule is %d \n",cmd,value); + if(cmd < IOCTRL_CAMERA_SET_RESO || cmd > IOCTRL_CAMERA_SET_EXPOSURE) + { + LOG_I("CMD value should be 24 ~29"); + return ; + } + switch(cmd) + { + #ifdef SOC_FAMILY_STM32 + case IOCTRL_CAMERA_SET_RESO: + if(value > 13 || value < 0) + { + LOG_I("value should be 0 ~13"); + return ; + } + ov2640_set_resolution(value); + break; + #endif + case IOCTRL_CAMERA_SET_LIGHT: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return ; + } + ov2640_set_light_mode(value); + break; + case IOCTRL_CAMERA_SET_COLOR: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return ; + } + ov2640_set_color_saturation(value); + break; + case IOCTRL_CAMERA_SET_BRIGHTNESS: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return ; + } + ov2640_set_brightness(value); + break; + case IOCTRL_CAMERA_SET_CONTRAST: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return ; + } + ov2640_set_contrast(value); + break; + case IOCTRL_CAMERA_SET_EFFECT: + if(value > 6 || value < 0) + { + LOG_I("value should be 0 ~13"); + return ; + } + ov2640_set_special_effects(value); + break; + case IOCTRL_CAMERA_SET_EXPOSURE: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return ; + } + ov2640_set_auto_exposure(value); + break; + default: + break; + } +} +MSH_CMD_EXPORT(set_ov2640_config,set ov2640 camera configuration); + + + + + + + + +void rt_ov2640_frame_irq_event() +{ + rt_event_send(&g_rec_photo_event, RECV_EVENT_FLAG); +} + + +rt_err_t rt_ov2640_set_irq_hander(void (*p)(void)) +{ + + #ifdef SOC_FAMILY_STM32 + return rt_set_irq_dcmi_callback_hander(p); + #elif defined BOARD_K210_EVB + return rt_set_irq_dvp_callback_hander(p); + #endif +} + +rt_err_t rt_ov2640_start_shoot(uint32_t pdata, uint32_t length) +{ + + rt_mutex_take(g_ov2640_mutex, RT_WAITING_FOREVER); + #ifdef SOC_FAMILY_STM32 + rt_dcmi_start(pdata,length); + #elif defined BOARD_K210_EVB + rt_dvp_start(pdata,length); + #endif + if (rt_event_recv(&g_rec_photo_event, RECV_EVENT_FLAG, + RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, + rt_tick_from_millisecond(1000*10), RT_NULL) == RT_EOK) + { + //LOG_I("receive the ov2640 data successfully."); + rt_mutex_release(g_ov2640_mutex); + return RT_EOK; + } + else + { + LOG_E("receive the ov2640 timeout(10s)"); + rt_mutex_release(g_ov2640_mutex); + return RT_ERROR; + } + +} + + + +static rt_err_t rt_ov2640_open(rt_device_t dev, rt_uint16_t oflag) +{ + RT_ASSERT(dev != RT_NULL); + + return RT_EOK; +} + +static rt_err_t rt_ov2640_close(rt_device_t dev) +{ + RT_ASSERT(dev != RT_NULL); + + return RT_EOK; +} + +static rt_err_t rt_ov2640_control(rt_device_t dev, int cmd, void *args) +{ + RT_ASSERT(dev != RT_NULL); + rt_err_t ret = RT_EOK; + if(cmd < IOCTRL_CAMERA_START_SHOT || cmd > IOCTRL_CAMERA_SET_EXPOSURE) + { + LOG_E("CMD value should be 22 ~29"); + return RT_ERROR; + } + int value = 0; + _ioctl_shoot_para shoot_para = {0}; + + if(IOCTRL_CAMERA_START_SHOT == cmd) + { + shoot_para = *((_ioctl_shoot_para*)args); + ret = rt_ov2640_start_shoot(shoot_para.pdata,shoot_para.length); + return ret; + } + else + { + value = *((int*)args); + switch(cmd) + { + #ifdef SOC_FAMILY_STM32 + case IOCTRL_CAMERA_SET_RESO: + if(value > 13 || value < 0) + { + LOG_I("value should be 0 ~13"); + return RT_EINVAL ; + } + ov2640_set_resolution(value); + break; + #endif + case IOCTRL_CAMERA_SET_LIGHT: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return RT_EINVAL ; + } + ov2640_set_light_mode(value); + break; + case IOCTRL_CAMERA_SET_COLOR: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return RT_EINVAL ; + } + ov2640_set_color_saturation(value); + break; + case IOCTRL_CAMERA_SET_BRIGHTNESS: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return RT_EINVAL ; + } + ov2640_set_brightness(value); + break; + case IOCTRL_CAMERA_SET_CONTRAST: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return RT_EINVAL ; + } + ov2640_set_contrast(value); + break; + case IOCTRL_CAMERA_SET_EFFECT: + if(value > 6 || value < 0) + { + LOG_I("value should be 0 ~13"); + return RT_EINVAL ; + } + ov2640_set_special_effects(value); + break; + case IOCTRL_CAMERA_SET_EXPOSURE: + if(value > 4 || value < 0) + { + LOG_I("value should be 0 ~13"); + return RT_EINVAL ; + } + ov2640_set_auto_exposure(value); + break; + default: + break; + } + return RT_EOK; + } +} + +static rt_size_t rt_ov2640_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size) +{ + RT_ASSERT(dev != RT_NULL); + + return RT_EOK; +} + +static rt_size_t rt_ov2640_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size) +{ + RT_ASSERT(dev != RT_NULL); + + return RT_EOK; +} + +static rt_err_t rt_ov2640_init(rt_device_t dev) +{ + RT_ASSERT(dev != RT_NULL); + rt_uint16_t i = 0; + int ret = RT_EOK; + #ifdef SOC_FAMILY_STM32 + #ifdef OV2640_ZDYZ + //zheng dian yuan zi manufacture ov2640 + rt_stm32407_atk_miniexpolre(); + #else + //weixue manufacture ov2640 + rt_ov2460_rcc_int(); + #endif + i2c_bus = rt_i2c_bus_device_find(I2C_NAME); + if (i2c_bus == RT_NULL) + { + LOG_E("can't find %c deivce", I2C_NAME); + return RT_ERROR; + } + #endif + sccb_write_reg(i2c_bus, OV2640_DSP_RA_DLMT, 0x01); + sccb_write_reg(i2c_bus, OV2640_SENSOR_COM7, 0x80); + rt_thread_mdelay(50); + ov2640_read_id(i2c_bus); + /* + set ov2640 register value + */ + if(g_ov2640_reso_level >LARGE_PHOTO_MODE )//large photo mode + { + for (i = 0; i < sizeof(ov2640_sxga_init_reg_tbl) / 2; i++) + { + sccb_write_reg(i2c_bus, ov2640_sxga_init_reg_tbl[i][0], ov2640_sxga_init_reg_tbl[i][1]); + } + } + else + { + for (i = 0; i < sizeof(ov2640_svga_init_reg_tbl) / 2; i++) + { + sccb_write_reg(i2c_bus, ov2640_svga_init_reg_tbl[i][0], ov2640_svga_init_reg_tbl[i][1]); + } + } + ov2640_rgb565_mode(); + ov2640_set_light_mode(0); + ov2640_set_color_saturation(0); + ov2640_set_brightness(2); + ov2640_set_contrast(1); + #ifdef SOC_FAMILY_STM32 + LOG_I("set ov2640 jpeg mode on stm32 board"); + ov2640_jpeg_mode(); + ov2640_set_image_window_size(0, 0, jpeg_img_size_tbl[g_ov2640_reso_level][0],jpeg_img_size_tbl[g_ov2640_reso_level][1]); + ov2640_set_image_out_size(jpeg_img_size_tbl[g_ov2640_reso_level][0], jpeg_img_size_tbl[g_ov2640_reso_level][1]); + LOG_I("set image resolution is %d * %d ",jpeg_img_size_tbl[g_ov2640_reso_level][0],jpeg_img_size_tbl[g_ov2640_reso_level][1]); + #elif defined BOARD_K210_EVB + ov2640_set_image_window_size(0, 0, jpeg_img_size_tbl[5][0],jpeg_img_size_tbl[5][1]); + ov2640_set_image_out_size(jpeg_img_size_tbl[2][0], jpeg_img_size_tbl[2][1]); + LOG_I("set ov2640 rgb565 mode on K210 board and set reselotion QVGA 320,240"); + #endif + /* + initialize rt_mutex about the using of ov2640 + */ + g_ov2640_mutex = rt_mutex_create("ov2640", RT_IPC_FLAG_FIFO); + if (g_ov2640_mutex == RT_NULL) + { + LOG_E("create g_ov2640_mutex mutex failed.\n"); + return -RT_ERROR; + } + /* + initialize receive event object + */ + ret = rt_event_init(&g_rec_photo_event, "r_photo", RT_IPC_FLAG_FIFO); + if (RT_EOK!= ret) + { + LOG_E("init rec_photo_event failed.\n"); + return -RT_ERROR; + } + /* + set dcmi or dvp interrupt callback function + */ + ret = rt_ov2640_set_irq_hander(rt_ov2640_frame_irq_event); + if(RT_EOK == ret) + { + LOG_I("ov2640 set irq hander successfully."); + } + else + { + LOG_E("ov2640 set irq hander failed"); + } + return RT_EOK; +} + +#ifdef RT_USING_POSIX +static int ov2640_fops_open(struct dfs_fd *fd) +{ + + rt_err_t ret = RT_EOK; + rt_uint16_t flags = 0; + rt_device_t device; + device = (rt_device_t)fd->data; + RT_ASSERT(device != RT_NULL); + flags = RT_DEVICE_FLAG_RDONLY; + ret = rt_device_open(device, flags); + if (ret == RT_EOK) + { + return RT_EOK; + } + return RT_ERROR; +} +static int ov2640_fops_close(struct dfs_fd *fd) +{ + rt_device_t device; + device = (rt_device_t)fd->data; + rt_device_set_rx_indicate(device, RT_NULL); + rt_device_close(device); + return RT_EOK; + +} +static int ov2640_fops_ioctl(struct dfs_fd *fd, int cmd, void *args) +{ + rt_device_t device; + device = (rt_device_t)fd->data; + return rt_device_control(device, cmd, args); +} +const static struct dfs_file_ops ov2640_fops = +{ + ov2640_fops_open, + ov2640_fops_close, + ov2640_fops_ioctl, + RT_NULL, + RT_NULL, + RT_NULL, /* flush */ + RT_NULL, /* lseek */ + RT_NULL, /* getdents */ + RT_NULL,/*poll*/ +}; +#endif + + + +int camera_ov2640_init() +{ + rt_err_t ret = RT_EOK; + _ov2640_device.parent.type = RT_Device_Class_Miscellaneous; + _ov2640_device.parent.init = rt_ov2640_init; + _ov2640_device.parent.open = rt_ov2640_open; + _ov2640_device.parent.close = rt_ov2640_close; + _ov2640_device.parent.read = rt_ov2640_read; + _ov2640_device.parent.write = rt_ov2640_write; + _ov2640_device.parent.control = rt_ov2640_control; + _ov2640_device.parent.user_data = RT_NULL; + ret = rt_device_register(&_ov2640_device.parent, "ov2640", RT_DEVICE_FLAG_RDONLY | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE); + #ifdef RT_USING_POSIX + _ov2640_device.parent.fops = &ov2640_fops; + #endif + if(ret != RT_EOK) + { + LOG_E("ov2640 register fail!!\n\r"); + return -RT_ERROR; + } + LOG_I("ov2640 register successfully"); + return RT_EOK; +} +INIT_APP_EXPORT(camera_ov2640_init); + +#endif + + + + + diff --git a/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/drv_ov2640.h b/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/drv_ov2640.h new file mode 100644 index 00000000..a6d0934f --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/ov2640/ov2640_source/drv_ov2640.h @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-07-27 thread-liu first version + * 2021-1-15 xiaoyu add set resolution function and the way of reset different manufactures's ov2640 egg:zhendianyuanzi and weixue + */ + +#ifndef __DRV_OV2640_H__ +#define __DRV_OV2640_H__ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SOC_FAMILY_STM32 +#include +#elif defined BOARD_K210_EVB +#include +#endif + + +#ifdef SOC_FAMILY_STM32 +#define DEV_ADDRESS 0x30 /* OV2640 address with rt-thread iic */ +#elif defined BOARD_K210_EVB +#define DEV_ADDRESS 0x60 /* OV2640 address */ +#endif + +#define LARGE_PHOTO_MODE (8) +#define I2C_NAME "i2c1" +#define RECV_EVENT_FLAG (1 << 1) //flag about event control block + +#define OV2640_MID 0X7FA2 +#define OV2640_PID 0X2642 +#define OV2640_ZDYZ //The macro definition of the manufacturer's product + +//DSP register address map table for OV2640 when DSP address (0xFF =0X00) is selected +#define OV2640_DSP_R_BYPASS 0x05 +#define OV2640_DSP_Qs 0x44 +#define OV2640_DSP_CTRL 0x50 +#define OV2640_DSP_HSIZE1 0x51 +#define OV2640_DSP_VSIZE1 0x52 +#define OV2640_DSP_XOFFL 0x53 +#define OV2640_DSP_YOFFL 0x54 +#define OV2640_DSP_VHYX 0x55 +#define OV2640_DSP_DPRP 0x56 +#define OV2640_DSP_TEST 0x57 +#define OV2640_DSP_ZMOW 0x5A +#define OV2640_DSP_ZMOH 0x5B +#define OV2640_DSP_ZMHH 0x5C +#define OV2640_DSP_BPADDR 0x7C +#define OV2640_DSP_BPDATA 0x7D +#define OV2640_DSP_CTRL2 0x86 +#define OV2640_DSP_CTRL3 0x87 +#define OV2640_DSP_SIZEL 0x8C +#define OV2640_DSP_HSIZE2 0xC0 +#define OV2640_DSP_VSIZE2 0xC1 +#define OV2640_DSP_CTRL0 0xC2 +#define OV2640_DSP_CTRL1 0xC3 +#define OV2640_DSP_R_DVP_SP 0xD3 +#define OV2640_DSP_IMAGE_MODE 0xDA +#define OV2640_DSP_RESET 0xE0 +#define OV2640_DSP_MS_SP 0xF0 +#define OV2640_DSP_SS_ID 0x7F +#define OV2640_DSP_SS_CTRL 0xF8 +#define OV2640_DSP_MC_BIST 0xF9 +#define OV2640_DSP_MC_AL 0xFA +#define OV2640_DSP_MC_AH 0xFB +#define OV2640_DSP_MC_D 0xFC +#define OV2640_DSP_P_STATUS 0xFE +#define OV2640_DSP_RA_DLMT 0xFF + + +//DSP register address map table for OV2640 when DSP address (0xFF =0X01) is selected +#define OV2640_SENSOR_GAIN 0x00 +#define OV2640_SENSOR_COM1 0x03 +#define OV2640_SENSOR_REG04 0x04 +#define OV2640_SENSOR_REG08 0x08 +#define OV2640_SENSOR_COM2 0x09 +#define OV2640_SENSOR_PIDH 0x0A +#define OV2640_SENSOR_PIDL 0x0B +#define OV2640_SENSOR_COM3 0x0C +#define OV2640_SENSOR_COM4 0x0D +#define OV2640_SENSOR_AEC 0x10 +#define OV2640_SENSOR_CLKRC 0x11 +#define OV2640_SENSOR_COM7 0x12 +#define OV2640_SENSOR_COM8 0x13 +#define OV2640_SENSOR_COM9 0x14 +#define OV2640_SENSOR_COM10 0x15 +#define OV2640_SENSOR_HREFST 0x17 +#define OV2640_SENSOR_HREFEND 0x18 +#define OV2640_SENSOR_VSTART 0x19 +#define OV2640_SENSOR_VEND 0x1A +#define OV2640_SENSOR_MIDH 0x1C +#define OV2640_SENSOR_MIDL 0x1D +#define OV2640_SENSOR_AEW 0x24 +#define OV2640_SENSOR_AEB 0x25 +#define OV2640_SENSOR_W 0x26 +#define OV2640_SENSOR_REG2A 0x2A +#define OV2640_SENSOR_FRARL 0x2B +#define OV2640_SENSOR_ADDVSL 0x2D +#define OV2640_SENSOR_ADDVHS 0x2E +#define OV2640_SENSOR_YAVG 0x2F +#define OV2640_SENSOR_REG32 0x32 +#define OV2640_SENSOR_ARCOM2 0x34 +#define OV2640_SENSOR_REG45 0x45 +#define OV2640_SENSOR_FLL 0x46 +#define OV2640_SENSOR_FLH 0x47 +#define OV2640_SENSOR_COM19 0x48 +#define OV2640_SENSOR_ZOOMS 0x49 +#define OV2640_SENSOR_COM22 0x4B +#define OV2640_SENSOR_COM25 0x4E +#define OV2640_SENSOR_BD50 0x4F +#define OV2640_SENSOR_BD60 0x50 +#define OV2640_SENSOR_REG5D 0x5D +#define OV2640_SENSOR_REG5E 0x5E +#define OV2640_SENSOR_REG5F 0x5F +#define OV2640_SENSOR_REG60 0x60 +#define OV2640_SENSOR_HISTO_LOW 0x61 +#define OV2640_SENSOR_HISTO_HIGH 0x62 + + + + + +#define IOCTRL_CAMERA_START_SHOT (22) // start shoot +#define IOCTRL_CAMERA_SET_RESO (23) //set resolution +#define IOCTRL_CAMERA_SET_LIGHT (24) //set light mode +#define IOCTRL_CAMERA_SET_COLOR (25) //set color saturation +#define IOCTRL_CAMERA_SET_BRIGHTNESS (26) //set color brightness +#define IOCTRL_CAMERA_SET_CONTRAST (27) //set contrast +#define IOCTRL_CAMERA_SET_EFFECT (28) //set effect +#define IOCTRL_CAMERA_SET_EXPOSURE (29) //set auto exposure + + +struct camera_device +{ + struct rt_device parent; /**< RT-Thread device struct */ +}; + +typedef struct +{ + uint32_t pdata; + uint32_t length; +}_ioctl_shoot_para; + +extern rt_uint32_t rt_ov2640_calculate_jpeg_len(rt_uint8_t* pdata,rt_uint32_t maxlength); +extern rt_err_t rt_ov2640_start_shoot(uint32_t pdata, uint32_t length); + + +#ifdef __cplusplus +} +#endif + +#endif + + + + + + + + + diff --git a/Ubiquitous/RT_Thread/drivers/rw007/Kconfig b/Ubiquitous/RT_Thread/drivers/rw007/Kconfig new file mode 100644 index 00000000..95f11b5f --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/Kconfig @@ -0,0 +1,59 @@ + +menuconfig PKG_USING_RW007 + bool "rw007: SPI WIFI rw007 driver" + select RT_USING_SPI + select RT_USING_PIN + select RT_USING_LWIP + default n + help + if "PKG_USING_RW007" is opened, "RT_USING_LWIP" will be default selected. + +if PKG_USING_RW007 + + choice + prompt "example driver port" + default RW007_USING_STM32_DRIVERS + config RW007_NOT_USE_EXAMPLE_DRIVERS + bool "not use example driver, porting by myself" + config RW007_USING_STM32_DRIVERS + bool "rw007 for stm32" + # config RW007_USING_IMXRT_DRIVERS + # bool "rw007 for imxrt" + endchoice + + config RW007_SPI_MAX_HZ + int "SPI Max Hz" + default 30000000 + + if !RW007_NOT_USE_EXAMPLE_DRIVERS + if RW007_USING_STM32_DRIVERS || RW007_USING_IMXRT_DRIVERS + config RW007_SPI_BUS_NAME + string "RW007 BUS NAME" + default "spi1" + + config RW007_CS_PIN + int "CS pin index" + default 86 + + endif + + config RW007_BOOT0_PIN + int "BOOT0 pin index (same as spi clk pin)" + default 19 + + config RW007_BOOT1_PIN + int "BOOT1 pin index (same as spi cs pin)" + default 86 + + config RW007_INT_BUSY_PIN + int "INT/BUSY pin index" + default 87 + + config RW007_RST_PIN + int "RESET pin index" + default 88 + + endif + + +endif diff --git a/Ubiquitous/RT_Thread/drivers/rw007/SConscript b/Ubiquitous/RT_Thread/drivers/rw007/SConscript new file mode 100644 index 00000000..0727c4e9 --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/SConscript @@ -0,0 +1,7 @@ +Import('RTT_ROOT') +from building import * + +cwd = GetCurrentDir() +objs = SConscript(os.path.join(cwd, 'rw007-source', 'SConscript')) + +Return('objs') diff --git a/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/.gitignore b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/.gitignore new file mode 100644 index 00000000..c6127b38 --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/.gitignore @@ -0,0 +1,52 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/LICENSE b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/LICENSE new file mode 100644 index 00000000..261eeb9e --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/README.md b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/README.md new file mode 100644 index 00000000..a009e4c8 --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/README.md @@ -0,0 +1,59 @@ +# rw007 + +[中文页](README_ZH.md) | English + +## 1. Introduction + +**RW007** is a SPI/UART high-speed wifi module based on Cortex-M4 WIFI SOC developed by Shanghai Ruiside Electronic Technology Co., Ltd. The warehouse is the SPI driver of **rw007** + +**RW007** The hardware design is simple. In SPI mode, users only need to reserve 1 set of SPI signals, one interrupt input, and one IO output, including a total of 8 pins for power and ground. + +### 1.1. File structure + +| Folder | Description | +| ---- | ---- | +| src | Core driver source code, which mainly implements communication logic | +| inc | Header file directory | +| example | Platform porting example | + +### 1.2 License + +The at_device package complies with the Apache 2.0 license, see the `LICENSE` file for details. + +### 1.3 Dependency + +- RT-Thread 3.0+ +- RT-Thread LWIP component +- RT-Thread SPI driver framework +- RT-Thread PIN driver framework (sample platform code dependency) + +### 1.4 Configuration Macro Description + +The relevant configuration macros will be configured in env during automatic configuration. The manual configuration is as follows + +Type description + +- bool: definition is valid, undefined, not valid +- string: string +- int: number + +|Macro|Type|Function| +|--|--|--| +|PKG_USING_RW007|bool|Enable rw007 driver, use this software package, you need to define this macro| +|RW007_USING_STM32_DRIVERS|bool|Enable STM32 platform migration example| +|RW007_USING_IMXRT_DRIVERS|bool|Enable IMXRT platform migration example| +|RW007_SPI_BUS_NAME|string|The SPI bus device name used in example| +|RW007_CS_PIN|int|The serial number of the SPI chip select pin used in the example in the pin driver| +|RW007_BOOT0_PIN|int|The serial number of the BOOT0 pin used in the example in the pin driver (the same pin is multiplexed with the CLK of SPI)| +|RW007_BOOT1_PIN|int|The serial number of the BOOT1 pin used in the example in the pin driver (the same pin is multiplexed with the CS of SPI)| +|RW007_INT_BUSY_PIN|int|The serial number of the INT/BUSY pin used in the example in the pin driver| +|RW007_RST_PIN|int|The serial number of the RST pin used in the example in the pin driver| + +## 2. Matters needing attention + +Because of the pin multiplexing situation, the driver of the bsp SPI needs to be configured during Config. + +## 4. Contact + +- Maintenance: RT-Thread development team +- Homepage: https://github.com/RT-Thread-packages/rw007 diff --git a/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/README_ZH.md b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/README_ZH.md new file mode 100644 index 00000000..0d691a1e --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/README_ZH.md @@ -0,0 +1,59 @@ +# rw007 + +中文页 | [English](README.md) + +## 1. 简介 + +**RW007**是由上海睿赛德电子科技有限公司开发基于Cortex-M4 WIFI SOC的SPI/UART 高速wifi模块。该仓库为**rw007**的SPI驱动 + +**RW007**硬件设计简单,SPI模式下用户只需要预留1组SPI信号,一个中断输入,一个IO输出即可,包含电源和地总共8个引脚。 + +### 1.1. 文件结构 + +| 文件夹 | 说明 | +| ---- | ---- | +| src | 核心驱动源码,主要实现通信逻辑 | +| inc | 头文件目录 | +| example | 平台移植示例 | + +### 1.2 许可证 + +at_device package 遵循 Apache 2.0 许可,详见 `LICENSE` 文件。 + +### 1.3 依赖 + +- RT-Thread 3.0+ +- RT-Thread LWIP 组件 +- RT-Thread SPI 驱动框架 +- RT-Thread PIN 驱动框架(示例平台代码依赖) + +### 1.4 配置宏说明 + +自动配置时相关配置宏将在env中被配置 手动配置参考如下 + +类型说明 + +- bool: 定义生效 未定义 不生效 +- string: 字符串 +- int: 数值 + +|宏|类型|功能| +|--|--|--| +|PKG_USING_RW007|bool|开启rw007驱动,使用该软件包则需要定义该宏| +|RW007_USING_STM32_DRIVERS|bool|使能STM32平台移植示例| +|RW007_USING_IMXRT_DRIVERS|bool|使能IMXRT平台移植示例| +|RW007_SPI_BUS_NAME|string|example中使用的SPI总线设备名称| +|RW007_CS_PIN|int|example中使用的SPI 片选引脚在pin驱动中的序号| +|RW007_BOOT0_PIN|int|example中使用的BOOT0引脚在pin驱动中的序号(与SPI的CLK是同一引脚复用)| +|RW007_BOOT1_PIN|int|example中使用的BOOT1引脚在pin驱动中的序号(与SPI的CS是同一引脚复用)| +|RW007_INT_BUSY_PIN|int|example中使用的INT/BUSY引脚在pin驱动中的序号| +|RW007_RST_PIN|int|example中使用的RST引脚在pin驱动中的序号| + +## 2. 注意事项 + +由于存在引脚复用情况,所以bsp的SPI的驱动需要引脚配置在Config时进行。 + +## 4. 联系方式 + +- 维护:RT-Thread 开发团队 +- 主页:https://github.com/RT-Thread-packages/rw007 diff --git a/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/SConscript b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/SConscript new file mode 100644 index 00000000..c4dfd96b --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/SConscript @@ -0,0 +1,87 @@ +#-*- encoding: utf-8 -*- +#--------------------------------------------------------------------------------- +# @File: Sconscript for package +# @Author: liu2guang +# @Date: 2018-09-19 18:07:00(v0.1.0) +# +# @LICENSE: GPLv3: https://github.com/rtpkgs/buildpkg/blob/master/LICENSE. +# +#--------------------------------------------------------------------------------- +import os +from building import * +Import('RTT_ROOT') +Import('rtconfig') + +#--------------------------------------------------------------------------------- +# Package configuration +#--------------------------------------------------------------------------------- +PKGNAME = "rw007" +VERSION = "v0.0.1" +DEPENDS = ["PKG_USING_RW007"] + +#--------------------------------------------------------------------------------- +# Compile the configuration +# +# SOURCES: Need to compile c and c++ source, auto search when SOURCES is empty +# +# LOCAL_CPPPATH: Local file path (.h/.c/.cpp) +# LOCAL_CCFLAGS: Local compilation parameter +# LOCAL_ASFLAGS: Local assembly parameters +# +# CPPPATH: Global file path (.h/.c/.cpp), auto search when LOCAL_CPPPATH/CPPPATH +# is empty # no pass!!! +# CCFLAGS: Global compilation parameter +# ASFLAGS: Global assembly parameters +# +# CPPDEFINES: Global macro definition +# LOCAL_CPPDEFINES: Local macro definition +# +# LIBS: Specify the static library that need to be linked +# LIBPATH: Specify the search directory for the library file (.lib/.a) +# +# LINKFLAGS: Link options +#--------------------------------------------------------------------------------- +SOURCES = ["src/spi_wifi_rw007.c"] + +if GetDepend(['RW007_USING_STM32_DRIVERS']): + SOURCES += ["example/rw007_stm32_port.c"] + +LOCAL_CPPPATH = [] +LOCAL_CCFLAGS = "" +LOCAL_ASFLAGS = "" + +CPPPATH = [GetCurrentDir(), os.path.join(GetCurrentDir(), 'inc')] +CCFLAGS = "" +ASFLAGS = "" + +CPPDEFINES = [] +LOCAL_CPPDEFINES = [] + +LIBS = [] +LIBPATH = [] + +LINKFLAGS = "" + +SOURCES_IGNORE = [] +CPPPATH_IGNORE = [] + +#--------------------------------------------------------------------------------- +# Main target +#--------------------------------------------------------------------------------- +objs = DefineGroup(name = PKGNAME, src = SOURCES, depend = DEPENDS, + CPPPATH = CPPPATH, + CCFLAGS = CCFLAGS, + ASFLAGS = ASFLAGS, + LOCAL_CPPPATH = LOCAL_CPPPATH, + LOCAL_CCFLAGS = LOCAL_CCFLAGS, + LOCAL_ASFLAGS = LOCAL_ASFLAGS, + CPPDEFINES = CPPDEFINES, + LOCAL_CPPDEFINES = LOCAL_CPPDEFINES, + LIBS = LIBS, + LIBPATH = LIBPATH, + LINKFLAGS = LINKFLAGS) + +Return("objs") +#--------------------------------------------------------------------------------- +# End +#--------------------------------------------------------------------------------- diff --git a/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/example/rw007_stm32_port.c b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/example/rw007_stm32_port.c new file mode 100644 index 00000000..f9369d5d --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/example/rw007_stm32_port.c @@ -0,0 +1,70 @@ +#include + +#ifdef RW007_USING_STM32_DRIVERS +#include +#include +#include +#include + +extern void spi_wifi_isr(int vector); + +static void rw007_gpio_init(void) +{ + /* Configure IO */ + rt_pin_mode(RW007_RST_PIN, PIN_MODE_OUTPUT); + rt_pin_mode(RW007_INT_BUSY_PIN, PIN_MODE_INPUT_PULLDOWN); + + /* Reset rw007 and config mode */ + rt_pin_write(RW007_RST_PIN, PIN_LOW); + rt_thread_delay(rt_tick_from_millisecond(100)); + rt_pin_write(RW007_RST_PIN, PIN_HIGH); + + /* Wait rw007 ready(exit busy stat) */ + while(!rt_pin_read(RW007_INT_BUSY_PIN)) + { + rt_thread_delay(5); + } + + rt_thread_delay(rt_tick_from_millisecond(200)); + rt_pin_mode(RW007_INT_BUSY_PIN, PIN_MODE_INPUT_PULLUP); +} + +int wifi_spi_device_init(void) +{ + char sn_version[32]; + + GPIO_TypeDef *cs_gpiox; + uint16_t cs_pin; + + cs_gpiox = (GPIO_TypeDef *)((rt_base_t)GPIOA + (rt_base_t)(RW007_CS_PIN / 16) * 0x0400UL); + cs_pin = (uint16_t)(1 << RW007_CS_PIN % 16); + + rw007_gpio_init(); + rt_hw_spi_device_attach(RW007_SPI_BUS_NAME, "wspi", cs_gpiox, cs_pin); + rt_hw_wifi_init("wspi"); + + rt_wlan_set_mode(RT_WLAN_DEVICE_STA_NAME, RT_WLAN_STATION); + rt_wlan_set_mode(RT_WLAN_DEVICE_AP_NAME, RT_WLAN_AP); + + rw007_sn_get(sn_version); + rt_kprintf("\nrw007 sn: [%s]\n", sn_version); + rw007_version_get(sn_version); + rt_kprintf("rw007 ver: [%s]\n\n", sn_version); + + return 0; +} +INIT_APP_EXPORT(wifi_spi_device_init); + +static void int_wifi_irq(void * p) +{ + ((void)p); + spi_wifi_isr(0); +} + +void spi_wifi_hw_init(void) +{ + rt_pin_attach_irq(RW007_INT_BUSY_PIN, PIN_IRQ_MODE_FALLING, int_wifi_irq, 0); + rt_pin_irq_enable(RW007_INT_BUSY_PIN, RT_TRUE); +} + +#endif /* RW007_USING_STM32_DRIVERS */ diff --git a/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/inc/spi_wifi_rw007.h b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/inc/spi_wifi_rw007.h new file mode 100644 index 00000000..1d16d521 --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/inc/spi_wifi_rw007.h @@ -0,0 +1,221 @@ +/* + * COPYRIGHT (C) 2018, Real-Thread Information Technology Ltd + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2014-07-31 aozima the first version + * 2014-09-18 aozima update command & response. + */ + +#ifndef SPI_WIFI_H_INCLUDED +#define SPI_WIFI_H_INCLUDED + +#include +#include +typedef enum +{ + master_cmd_phase = 0x01, + master_data_phase, + slave_cmd_phase, + slave_data_phase, +}phase_type; + +typedef enum +{ + TRANSFER_DATA_SUCCESS = 0x00, + TRANSFER_DATA_ERROR, + TRANSFER_DATA_CONTINUE, +}rw007_transfer_state; +/* little-endian */ +struct spi_master_request +{ + uint8_t reserve1; + uint8_t flag: 4; + uint8_t type: 4; + uint16_t reserve2; + uint16_t seq; + uint16_t M2S_len; // master to slave data len. + uint32_t magic1; + uint32_t magic2; +}; + +#define MASTER_MAGIC1 (0x67452301) +#define MASTER_MAGIC2 (0xEFCDAB89) + +#define MASTER_FLAG_MRDY (0x01) + +/* little-endian */ +struct spi_slave_response +{ + uint8_t reserve1; + uint8_t flag: 4; + uint8_t type: 4; + uint8_t slave_rx_buf: 4; + uint8_t slave_tx_buf: 4; + uint8_t reserve2; + uint16_t seq; + uint16_t S2M_len; // slave to master data len. + uint32_t magic1; + uint32_t magic2; +}; + +#define SLAVE_MAGIC1 (0x98BADCFE) +#define SLAVE_MAGIC2 (0x10325476) +#define SLAVE_FLAG_SRDY (0x01) + +#define SLAVE_DATA_FULL (0x01) + +/* spi buffer configure. */ +#define SPI_MAX_DATA_LEN 1520 +#define SPI_TX_POOL_SIZE 4 +#define SPI_RX_POOL_SIZE 4 +/* The slave interrupts wait timeout */ +#define SLAVE_INT_TIMEOUT 100 + +typedef enum +{ + RW007_SLAVE_INT = 1, + RW007_MASTER_DATA = 1<<1, +} wifi_event; + +typedef enum +{ + DATA_TYPE_STA_ETH_DATA = 1, + DATA_TYPE_AP_ETH_DATA, + DATA_TYPE_PROMISC_ETH_DATA, + DATA_TYPE_CMD, + DATA_TYPE_RESP, + DATA_TYPE_CB, +} app_data_type_t; + +struct spi_data_packet +{ + uint32_t data_len; /* length for buffer */ + uint32_t data_type; /* app_data_type_t */ + char buffer[SPI_MAX_DATA_LEN]; +}; + +typedef struct rw007_ap_info_value +{ + struct rt_wlan_info info; + char passwd[RT_WLAN_PASSWORD_MAX_LENGTH]; +} * rw007_ap_info_value_t; + +/* littel endian */ +typedef struct rw007_cmd +{ + uint32_t cmd; + uint32_t len; + + /* command parameter */ + union + { + uint32_t int_value; + uint8_t mac_value[8]; /* padding 2bytes */ + struct rw007_ap_info_value ap_info_value; + char string_value[UINT16_MAX]; + } value; +} * rw007_cmd_t; + +struct rw007_resp +{ + uint32_t cmd; + uint32_t len; + + int32_t result; /* result of CMD. */ + + /* response value */ + union + { + uint32_t int_value; + uint8_t mac_value[8]; /* padding 2bytes */ + struct rw007_ap_info_value ap_info_value; + char string_value[UINT16_MAX]; + } value; +}; + +/* tools */ +#define node_entry(node, type, member) ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member))) +#define member_offset(type, member) ((unsigned long)(&((type *)0)->member)) + +#define MAX_SPI_PACKET_SIZE (member_offset(struct spi_data_packet, buffer) + SPI_MAX_DATA_LEN) + +typedef enum +{ + RW00x_CMD_INIT = 0x00, + RW00x_CMD_SET_MODE, + RW00x_CMD_MAC_GET, + RW00x_CMD_MAC_SET, + RW00x_CMD_GET_SN, + RW00x_CMD_GET_VSR, + RW00x_CMD_SCAN, + RW00x_CMD_JOIN, + RW00x_CMD_SOFTAP, + RW00x_CMD_DISCONNECT, + RW00x_CMD_AP_STOP, + RW00x_CMD_AP_DEAUTH, + RW00x_CMD_SCAN_STOP, + RW00x_CMD_GET_RSSI, + RW00x_CMD_SET_PWR_SAVE, + RW00x_CMD_GET_PWR_SAVE, + RW00x_CMD_CFG_PROMISC, + RW00x_CMD_CFG_FILTER, + RW00x_CMD_SET_CHANNEL, + RW00x_CMD_GET_CHANNEL, + RW00x_CMD_SET_COUNTRY, + RW00x_CMD_GET_COUNTRY, + RW00x_CMD_AP_MAC_GET, + RW00x_CMD_AP_MAC_SET, + RW00x_CMD_MAX_NUM +}RW00x_CMD; + +struct rw007_spi +{ + /* Device handle for spi device */ + struct rt_spi_device *spi_device; + + /* Tx mempool and mailbox */ + struct rt_mempool spi_tx_mp; + ALIGN(RT_ALIGN_SIZE) + rt_uint8_t spi_tx_mempool[(sizeof(struct spi_data_packet) + 4) * SPI_TX_POOL_SIZE]; + struct rt_mailbox spi_tx_mb; + rt_ubase_t spi_tx_mb_pool[SPI_TX_POOL_SIZE + 1]; + + /* Rx mempool and mailbox */ + struct rt_mempool spi_rx_mp; + ALIGN(RT_ALIGN_SIZE) + rt_uint8_t spi_rx_mempool[(sizeof(struct spi_data_packet) + 4) * SPI_RX_POOL_SIZE]; + struct rt_mailbox spi_rx_mb; + rt_ubase_t spi_rx_mb_pool[SPI_RX_POOL_SIZE + 1]; + + /* response event */ + rt_event_t rw007_cmd_event; + /* response data */ + struct rw007_resp *resp[RW00x_CMD_MAX_NUM]; +}; + +#define RW00x_CMD_RESP_EVENT(n) (0x01UL << n) + +struct rw007_wifi +{ + /* inherit from ethernet device */ + struct rt_wlan_device *wlan; + /* spi transfer layer handle */ + struct rw007_spi * hspi; +}; + +/* porting */ +extern void spi_wifi_hw_init(void); + +/* end porting */ + +/* api exclude in wlan framework */ +extern rt_err_t rw007_sn_get(char sn[24]); +extern rt_err_t rw007_version_get(char version[16]); +/* end api exclude in wlan framework */ + +extern rt_err_t rt_hw_wifi_init(const char *spi_device_name); + +#endif /* SPI_WIFI_H_INCLUDED */ diff --git a/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/src/spi_wifi_rw007.c b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/src/spi_wifi_rw007.c new file mode 100644 index 00000000..8ca7aedd --- /dev/null +++ b/Ubiquitous/RT_Thread/drivers/rw007/rw007-source/src/spi_wifi_rw007.c @@ -0,0 +1,873 @@ +/* + * COPYRIGHT (C) 2018, Real-Thread Information Technology Ltd + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2014-07-31 aozima the first version + * 2014-09-18 aozima update command & response. + * 2017-07-28 armink fix auto reconnect feature + * 2018-12-24 zyh porting rw007 from rw009 + * 2019-02-25 zyh porting rw007 to wlan + * 2020-02-28 shaoguoji add spi transfer retry + * 2020-07-09 zj refactor the rw007 + */ +#include +#include + +#ifndef RW007_LOG_LEVEL +#define RW007_LOG_LEVEL DBG_LOG +#endif + +#define DBG_ENABLE +#define DBG_SECTION_NAME "[RW007]" +#define DBG_LEVEL RW007_LOG_LEVEL +#define DBG_COLOR +#include + +#include "spi_wifi_rw007.h" + +static struct rw007_spi rw007_spi; +static struct rw007_wifi wifi_sta, wifi_ap; +static struct rt_event spi_wifi_data_event; +static rt_bool_t inited = RT_FALSE; + +#ifdef WLAN_DEV_MONITOR +typedef struct +{ + rt_uint32_t total; + rt_uint32_t lose; + rt_uint32_t retry; + rt_uint32_t first_stage_err; + rt_uint32_t second_stage_err; +} net_packet; +net_packet packet; +#endif + +static int wifi_data_transfer(struct rw007_spi *dev, uint16_t seq, uint8_t *rx_buffer) +{ + static const struct spi_data_packet *send_packet = RT_NULL; + struct spi_master_request cmd; + struct spi_slave_response resp; + struct rt_spi_message message; + struct rt_spi_device *rt_spi_device = dev->spi_device; + rt_uint32_t max_data_len = 0; + + /* Clear cmd */ + rt_memset(&cmd, 0, sizeof(cmd)); + cmd.type = master_cmd_phase; + cmd.seq = seq; + /* Set magic word */ + cmd.magic1 = MASTER_MAGIC1; + cmd.magic2 = MASTER_MAGIC2; + + /* If the buffer is not full, Set master ready flag bit */ + if(rx_buffer != RT_NULL) + { + cmd.flag |= MASTER_FLAG_MRDY; + } + + if (send_packet == RT_NULL) + { + /* Check to see if any data needs to be sent */ + if (rt_mb_recv(&dev->spi_tx_mb, (rt_ubase_t *)&send_packet, RT_WAITING_NO) != RT_EOK) + { + send_packet = RT_NULL; + } + } + + /* Set length for master to slave when data ready*/ + if (send_packet != RT_NULL) + { + /* Invalid data packet */ + if((send_packet->data_len == 0) || (send_packet->data_len > SPI_MAX_DATA_LEN)) + { + rt_mp_free((void *)send_packet); + send_packet = RT_NULL; + } + else + { + cmd.M2S_len = send_packet->data_len + member_offset(struct spi_data_packet, buffer); + } + } + + /* Stage 1: Send command to rw007 */ + rt_memset(&resp, 0, sizeof(resp)); + rt_spi_transfer(rt_spi_device, &cmd, &resp, sizeof(resp)); + + /* Clear event */ + rt_event_recv(&spi_wifi_data_event, + RW007_SLAVE_INT, + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, + RT_WAITING_NO, + RT_NULL); + /* checkout Stage 1 slave status */ + if ((resp.magic1 != SLAVE_MAGIC1) || (resp.magic2 != SLAVE_MAGIC2) || (resp.type != slave_cmd_phase)) + { +#ifdef WLAN_DEV_MONITOR + packet.first_stage_err++; +#endif + LOG_E("The wifi Stage 1 status %x %x %x %d\r", resp.magic1, resp.magic2, resp.type, cmd.seq); + goto _cmderr; + } + + /* receive first event */ + if (rt_event_recv(&spi_wifi_data_event, + RW007_SLAVE_INT, + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, + SLAVE_INT_TIMEOUT, + RT_NULL) != RT_EOK) + { + LOG_E("The wifi slave response timed out\r"); + } + + /* Stage 2: Receive response from rw007 */ + cmd.type = master_data_phase; //data Stage + rt_memset(&resp, 0, sizeof(resp)); + message.send_buf = &cmd; + message.recv_buf = &resp; + message.length = sizeof(resp); + message.cs_take = 1; + message.cs_release = 0; + + /* Start a SPI transmit */ + rt_spi_take_bus(rt_spi_device); + + /* Receive response from rw007 */ + rt_spi_device->bus->ops->xfer(rt_spi_device, &message); + + /* Check response's magic word and seq */ + if ((resp.magic1 != SLAVE_MAGIC1) || (resp.magic2 != SLAVE_MAGIC2) || (resp.seq != seq) || (resp.type != slave_data_phase)) + { +#ifdef WLAN_DEV_MONITOR + packet.second_stage_err++; +#endif + LOG_E("The wifi Stage 2 status %x %x %x %x %d %d\r", resp.magic1, resp.magic2, resp.seq, resp.type, resp.S2M_len, cmd.seq); + goto _txerr; + } + + /* Check rw007's data ready flag */ + if (resp.flag & SLAVE_FLAG_SRDY) + { + max_data_len = cmd.M2S_len; + } + + if (resp.S2M_len > MAX_SPI_PACKET_SIZE) + { + /* Drop error data */ + resp.S2M_len = 0; + } + + if (resp.S2M_len > max_data_len) + { + max_data_len = resp.S2M_len; + } + + /* Setup message */ + if((resp.S2M_len == 0) && (rx_buffer != RT_NULL)) + { + rt_mp_free(rx_buffer); + rx_buffer = RT_NULL; + } + + message.send_buf = send_packet; + message.recv_buf = rx_buffer; + message.length = RT_ALIGN(max_data_len, 4);/* align clk to word */ + message.cs_take = 0; + message.cs_release = 1; + + /* Transmit data */ + rt_spi_device->bus->ops->xfer(rt_spi_device, &message); + + /* End a SPI transmit */ + rt_spi_release_bus(rt_spi_device); + + /* Free send data space */ + if ((resp.flag & SLAVE_FLAG_SRDY) && (send_packet != RT_NULL)) + { + rt_mp_free((void *)send_packet); + send_packet = RT_NULL; + } + + /* Parse recevied data */ + if(rx_buffer) + { + rt_mb_send(&dev->spi_rx_mb, (rt_ubase_t)rx_buffer); + } + + /* receive data end event */ + if (rt_event_recv(&spi_wifi_data_event, + RW007_SLAVE_INT, + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, + SLAVE_INT_TIMEOUT, + RT_NULL) != RT_EOK) + { + LOG_E("The wifi slave data response timed out\r"); + } + + /* The slave has data */ + if (resp.slave_tx_buf > 0) + { + return TRANSFER_DATA_CONTINUE; + } + return TRANSFER_DATA_SUCCESS; +_txerr: + /* END SPI transfer */ + message.send_buf = RT_NULL; + message.recv_buf = RT_NULL; + message.length = 0; + message.cs_take = 0; + message.cs_release = 1; + rt_spi_device->bus->ops->xfer(rt_spi_device, &message); + + rt_spi_release_bus(rt_spi_device); // End a SPI transmit +_cmderr: + rt_thread_delay(1); + return TRANSFER_DATA_ERROR; +} + +static int spi_wifi_transfer(struct rw007_spi *dev) +{ + static uint16_t cmd_seq = 0; + int result = TRANSFER_DATA_SUCCESS; + uint8_t * rx_buffer = rt_mp_alloc(&dev->spi_rx_mp, RT_WAITING_NO); + int32_t retry; + + /* Generate the transmission sequence number */ + cmd_seq++; + if (cmd_seq >= 65534) + { + cmd_seq = 1; + } +#ifdef WLAN_DEV_MONITOR + packet.total++; +#endif + /* set retry count */ + retry = 3; + while (retry > 0) + { + result = wifi_data_transfer(dev, cmd_seq, rx_buffer); + if (result != TRANSFER_DATA_ERROR) + { + break; + } + retry--; +#ifdef WLAN_DEV_MONITOR + packet.retry++; +#endif + } + + /* Receive response from rw007 error */ + if (retry <= 0) + { +#ifdef WLAN_DEV_MONITOR + packet.lose++; +#endif + LOG_E("rw007 transfer failed\r"); + goto _err; + } + + return result; +_err: + if(rx_buffer) + { + rt_mp_free((void *)rx_buffer); + } + return TRANSFER_DATA_ERROR; +} + +static void wifi_data_process_thread_entry(void *parameter) +{ + const struct spi_data_packet *data_packet = RT_NULL; + struct rw007_spi *dev = (struct rw007_spi *)parameter; + + while(1) + { + /* get the mempool memory for recv data package */ + if(rt_mb_recv(&dev->spi_rx_mb, (rt_ubase_t *)&data_packet, RT_WAITING_FOREVER) == RT_EOK) + { + if (data_packet->data_type == DATA_TYPE_STA_ETH_DATA) + { + /* Ethernet package from station device */ + rt_wlan_dev_report_data(wifi_sta.wlan, (void *)data_packet->buffer, data_packet->data_len); + } + else if (data_packet->data_type == DATA_TYPE_AP_ETH_DATA) + { + /* Ethernet package from ap device */ + rt_wlan_dev_report_data(wifi_ap.wlan, (void *)data_packet->buffer, data_packet->data_len); + } + else if (data_packet->data_type == DATA_TYPE_PROMISC_ETH_DATA) + { + /* air wifi package from promisc */ + rt_wlan_dev_promisc_handler(wifi_sta.wlan, (void *)data_packet->buffer, data_packet->data_len); + } + /* event callback */ + else if(data_packet->data_type == DATA_TYPE_CB) + { + struct rw007_resp * resp = (struct rw007_resp *)data_packet->buffer; + if(resp->cmd == RT_WLAN_DEV_EVT_SCAN_REPORT) + { + /* parse scan report event data */ + struct rt_wlan_buff buff; + struct rt_wlan_info * wlan_info; + wlan_info = (struct rt_wlan_info *)&resp->value; + buff.data = wlan_info; + buff.len = sizeof(struct rt_wlan_info); + + /* indicate scan report event */ + rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, RT_WLAN_DEV_EVT_SCAN_REPORT, &buff); + } + else + { + if(resp->cmd == RT_WLAN_DEV_EVT_AP_START || resp->cmd == RT_WLAN_DEV_EVT_AP_STOP || + resp->cmd == RT_WLAN_DEV_EVT_AP_ASSOCIATED || resp->cmd == RT_WLAN_DEV_EVT_AP_DISASSOCIATED) + { + /* indicate ap device event */ + rt_wlan_dev_indicate_event_handle(wifi_ap.wlan, (rt_wlan_dev_event_t)resp->cmd, RT_NULL); + } + else + { + /* indicate sta device event */ + rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, (rt_wlan_dev_event_t)resp->cmd, RT_NULL); + } + } + } + else if (data_packet->data_type == DATA_TYPE_RESP) + { + /* parse cmd's response */ + struct rw007_resp * resp = (struct rw007_resp *)data_packet->buffer; + if(resp->cmd < RW00x_CMD_MAX_NUM) + { + if(dev->resp[resp->cmd]) + { + rt_free(dev->resp[resp->cmd]); + } + + /* stash response result */ + dev->resp[resp->cmd] = rt_malloc(MAX_SPI_PACKET_SIZE); + if(dev->resp[resp->cmd]) + { + rt_memcpy(dev->resp[resp->cmd], resp, MAX_SPI_PACKET_SIZE); + + /* notify response arrived */ + rt_event_send(dev->rw007_cmd_event, RW00x_CMD_RESP_EVENT(resp->cmd)); + } + } + } + /* free recv mempool memory */ + rt_mp_free((void *)data_packet); + } + } +} + +static void spi_wifi_data_thread_entry(void *parameter) +{ + rt_bool_t empty_read = RT_TRUE; + rt_uint32_t event; + int state; + + while (1) + { + /* receive first event */ + if (rt_event_recv(&spi_wifi_data_event, + RW007_MASTER_DATA| + RW007_SLAVE_INT, + RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, + RT_WAITING_FOREVER, + &event) != RT_EOK) + + { + continue; + } + /* transfer */ + state = spi_wifi_transfer(&rw007_spi); + + /* Try reading again */ + if(state == TRANSFER_DATA_CONTINUE) + { + rt_event_send(&spi_wifi_data_event, RW007_SLAVE_INT); + empty_read = RT_TRUE; + } + else + { + if ((state == TRANSFER_DATA_SUCCESS) && (empty_read == RT_TRUE)) + { + rt_event_send(&spi_wifi_data_event, RW007_SLAVE_INT); + empty_read = RT_FALSE; + } + else + { + empty_read = RT_TRUE; + } + } + } +} + +rt_inline struct rw007_wifi *wifi_get_dev_by_wlan(struct rt_wlan_device *wlan) +{ + if (wlan == wifi_sta.wlan) + { + return &wifi_sta; + } + if (wlan == wifi_ap.wlan) + { + return &wifi_ap; + } + return RT_NULL; +} + +rt_inline void spi_send_cmd(struct rw007_spi * hspi, RW00x_CMD COMMAND, void * buffer, rt_uint32_t len) +{ + struct spi_data_packet * data_packet; + struct rw007_cmd * cmd; + + data_packet = rt_mp_alloc(&hspi->spi_tx_mp, RT_WAITING_FOREVER); + data_packet->data_type = DATA_TYPE_CMD; + + cmd = (struct rw007_cmd *)data_packet->buffer; + cmd->cmd = COMMAND; + cmd->len = len; + if(cmd->len) + { + rt_memcpy(&cmd->value, buffer, cmd->len); + } + + data_packet->data_len = member_offset(struct rw007_cmd, value) + cmd->len; + + rt_mb_send(&hspi->spi_tx_mb, (rt_ubase_t)data_packet); + rt_event_send(&spi_wifi_data_event, RW007_MASTER_DATA); +} + +rt_inline rt_err_t spi_set_data(struct rt_wlan_device *wlan, RW00x_CMD COMMAND, void * buffer, rt_uint32_t len) +{ + struct rw007_spi * hspi = wifi_get_dev_by_wlan(wlan)->hspi; + rt_uint32_t result_event; + rt_err_t result = RT_EOK; + spi_send_cmd(hspi, COMMAND, buffer, len); + if(rt_event_recv(hspi->rw007_cmd_event, + RW00x_CMD_RESP_EVENT(COMMAND), + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, + rt_tick_from_millisecond(10000), + &result_event) != RT_EOK) + { + return -RT_ETIMEOUT; + } + + if(hspi->resp[COMMAND]) + { + result = hspi->resp[COMMAND]->result; + rt_free(hspi->resp[COMMAND]); + hspi->resp[COMMAND] = RT_NULL; + return result; + } + return RT_EOK; +} + +rt_inline rt_err_t spi_get_data(struct rt_wlan_device *wlan, RW00x_CMD COMMAND, void * buffer, rt_uint32_t *len) +{ + struct rw007_spi * hspi = wifi_get_dev_by_wlan(wlan)->hspi; + rt_uint32_t result_event; + rt_err_t result = RT_EOK; + spi_send_cmd(hspi, COMMAND, RT_NULL, 0); + if(rt_event_recv(hspi->rw007_cmd_event, + RW00x_CMD_RESP_EVENT(COMMAND), + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, + rt_tick_from_millisecond(10000), + &result_event) != RT_EOK) + { + return -RT_ETIMEOUT; + } + + if(hspi->resp[COMMAND]) + { + *len = hspi->resp[COMMAND]->len; + rt_memcpy(buffer, &hspi->resp[COMMAND]->value, hspi->resp[COMMAND]->len); + result = hspi->resp[COMMAND]->result; + rt_free(hspi->resp[COMMAND]); + hspi->resp[COMMAND] = RT_NULL; + return result; + } + return RT_EOK; +} + +rt_err_t rw007_sn_get(char sn[24]) +{ + rt_uint32_t size_of_data; + return spi_get_data(wifi_sta.wlan, RW00x_CMD_GET_SN, sn, &size_of_data); +} + +rt_err_t rw007_version_get(char version[16]) +{ + rt_uint32_t size_of_data; + return spi_get_data(wifi_sta.wlan, RW00x_CMD_GET_VSR, version, &size_of_data); +} + +static rt_err_t wlan_init(struct rt_wlan_device *wlan) +{ + if(inited == RT_FALSE) + { + inited = RT_TRUE; + return spi_set_data(wlan, RW00x_CMD_INIT, RT_NULL, 0); + } + return RT_EOK; +} + +static rt_err_t wlan_mode(struct rt_wlan_device *wlan, rt_wlan_mode_t mode) +{ + return spi_set_data(wlan, RW00x_CMD_SET_MODE, &mode, sizeof(mode)); +} + +static rt_err_t wlan_scan(struct rt_wlan_device *wlan, struct rt_scan_info *scan_info) +{ + return spi_set_data(wlan, RW00x_CMD_SCAN, RT_NULL, 0); +} + +static rt_err_t wlan_join(struct rt_wlan_device *wlan, struct rt_sta_info *sta_info) +{ + struct rw007_ap_info_value value; + value.info.security = sta_info->security; + value.info.band = RT_802_11_BAND_2_4GHZ; + value.info.datarate = 0; + value.info.channel = sta_info->channel; + value.info.hidden = 0; + value.info.rssi = 0; + value.info.ssid = sta_info->ssid; + rt_memcpy(value.info.bssid, sta_info->bssid, 6); + strncpy(value.passwd, (const char *)&sta_info->key.val[0], sta_info->key.len); + value.passwd[sta_info->key.len] = '\0'; + return spi_set_data(wlan, RW00x_CMD_JOIN, &value, sizeof(value)); +} + +static rt_err_t wlan_softap(struct rt_wlan_device *wlan, struct rt_ap_info *ap_info) +{ + struct rw007_ap_info_value value; + value.info.security = ap_info->security; + value.info.band = RT_802_11_BAND_2_4GHZ; + value.info.datarate = 0; + value.info.channel = ap_info->channel; + value.info.hidden = ap_info->hidden; + value.info.rssi = 0; + value.info.ssid = ap_info->ssid; + strncpy(value.passwd, (const char *)&ap_info->key.val[0], ap_info->key.len); + value.passwd[ap_info->key.len] = '\0'; + return spi_set_data(wlan, RW00x_CMD_SOFTAP, &value, sizeof(value)); +} + +static rt_err_t wlan_disconnect(struct rt_wlan_device *wlan) +{ + return spi_set_data(wlan, RW00x_CMD_DISCONNECT, RT_NULL, 0); +} + +static rt_err_t wlan_ap_stop(struct rt_wlan_device *wlan) +{ + return spi_set_data(wlan, RW00x_CMD_AP_STOP, RT_NULL, 0); +} + +static rt_err_t wlan_ap_deauth(struct rt_wlan_device *wlan, rt_uint8_t mac[]) +{ + return spi_set_data(wlan, RW00x_CMD_AP_DEAUTH, mac, 6); +} + +static rt_err_t wlan_scan_stop(struct rt_wlan_device *wlan) +{ + return spi_set_data(wlan, RW00x_CMD_SCAN_STOP, RT_NULL, 0); +} + +static int wlan_get_rssi(struct rt_wlan_device *wlan) +{ + int rssi = -1; + rt_uint32_t size_of_data; + spi_get_data(wlan, RW00x_CMD_GET_RSSI, &rssi, &size_of_data); + return rssi; +} + +static rt_err_t wlan_set_powersave(struct rt_wlan_device *wlan, int level) +{ + return spi_set_data(wlan, RW00x_CMD_SET_PWR_SAVE, &level, sizeof(level)); +} + +static int wlan_get_powersave(struct rt_wlan_device *wlan) +{ + int level = -1; + rt_uint32_t size_of_data; + spi_get_data(wlan, RW00x_CMD_GET_PWR_SAVE, &level, &size_of_data); + return level; +} + +static rt_err_t wlan_cfg_promisc(struct rt_wlan_device *wlan, rt_bool_t start) +{ + return spi_set_data(wlan, RW00x_CMD_CFG_PROMISC, &start, sizeof(start)); +} + +static rt_err_t wlan_cfg_filter(struct rt_wlan_device *wlan, struct rt_wlan_filter *filter) +{ + return -RT_ENOSYS; +} + +static rt_err_t wlan_set_channel(struct rt_wlan_device *wlan, int channel) +{ + return spi_set_data(wlan, RW00x_CMD_SET_CHANNEL, &channel, sizeof(channel)); +} + +static int wlan_get_channel(struct rt_wlan_device *wlan) +{ + int channel = -1; + rt_uint32_t size_of_data; + spi_get_data(wlan, RW00x_CMD_GET_CHANNEL, &channel, &size_of_data); + return channel; +} + +static rt_err_t wlan_set_country(struct rt_wlan_device *wlan, rt_country_code_t country_code) +{ + return spi_set_data(wlan, RW00x_CMD_SET_COUNTRY, &country_code, sizeof(country_code)); +} + +static rt_country_code_t wlan_get_country(struct rt_wlan_device *wlan) +{ + rt_country_code_t code; + rt_uint32_t size_of_data; + spi_get_data(wlan, RW00x_CMD_GET_COUNTRY, &code, &size_of_data); + return code; +} + +static rt_err_t wlan_set_mac(struct rt_wlan_device *wlan, rt_uint8_t mac[]) +{ + if(wlan == wifi_sta.wlan) + { + return spi_set_data(wlan, RW00x_CMD_MAC_SET, mac, 6); + } + return spi_set_data(wlan, RW00x_CMD_AP_MAC_SET, mac, 6); +} + +static rt_err_t wlan_get_mac(struct rt_wlan_device *wlan, rt_uint8_t mac[]) +{ + rt_uint32_t size_of_data; + if(wlan == wifi_sta.wlan) + { + return spi_get_data(wlan, RW00x_CMD_MAC_GET, mac, &size_of_data); + } + return spi_get_data(wlan, RW00x_CMD_AP_MAC_GET, mac, &size_of_data); +} + +static int wlan_send(struct rt_wlan_device *wlan, void *buff, int len) +{ + struct rw007_spi * hspi = wifi_get_dev_by_wlan(wlan)->hspi; + struct spi_data_packet * data_packet; + + if(wlan == RT_NULL) + { + return -1; + } + + data_packet = rt_mp_alloc(&hspi->spi_tx_mp, RT_WAITING_FOREVER); + + if (wlan == wifi_sta.wlan) + { + data_packet->data_type = DATA_TYPE_STA_ETH_DATA; + } + else + { + data_packet->data_type = DATA_TYPE_AP_ETH_DATA; + } + data_packet->data_len = len; + + rt_memcpy(data_packet->buffer, buff, len); + + rt_mb_send(&hspi->spi_tx_mb, (rt_ubase_t)data_packet); + rt_event_send(&spi_wifi_data_event, RW007_MASTER_DATA); + return len; +} + +const static struct rt_wlan_dev_ops ops = +{ + .wlan_init = wlan_init, + .wlan_mode = wlan_mode, + .wlan_scan = wlan_scan, + .wlan_join = wlan_join, + .wlan_softap = wlan_softap, + .wlan_disconnect = wlan_disconnect, + .wlan_ap_stop = wlan_ap_stop, + .wlan_ap_deauth = wlan_ap_deauth, + .wlan_scan_stop = wlan_scan_stop, + .wlan_get_rssi = wlan_get_rssi, + .wlan_set_powersave = wlan_set_powersave, + .wlan_get_powersave = wlan_get_powersave, + .wlan_cfg_promisc = wlan_cfg_promisc, + .wlan_cfg_filter = wlan_cfg_filter, + .wlan_set_channel = wlan_set_channel, + .wlan_get_channel = wlan_get_channel, + .wlan_set_country = wlan_set_country, + .wlan_get_country = wlan_get_country, + .wlan_set_mac = wlan_set_mac, + .wlan_get_mac = wlan_get_mac, + .wlan_recv = RT_NULL, + .wlan_send = wlan_send, +}; + +rt_err_t rt_hw_wifi_init(const char *spi_device_name) +{ + static struct rt_wlan_device wlan_sta, wlan_ap; + rt_err_t ret; + wifi_sta.wlan = &wlan_sta; + wifi_sta.hspi = &rw007_spi; + wifi_ap.wlan = &wlan_ap; + wifi_ap.hspi = &rw007_spi; + /* align and struct size check. */ + RT_ASSERT((SPI_MAX_DATA_LEN & 0x03) == 0); + + memset(&rw007_spi, 0, sizeof(struct rw007_spi)); + + rw007_spi.spi_device = (struct rt_spi_device *)rt_device_find(spi_device_name); + + if (rw007_spi.spi_device == RT_NULL) + { + LOG_E("spi device %s not found!\r", spi_device_name); + return -RT_ENOSYS; + } + + /* config spi */ + { + struct rt_spi_configuration cfg; + cfg.data_width = 8; + cfg.mode = RT_SPI_MODE_0 | RT_SPI_MSB; /* SPI Compatible: Mode 0. */ + cfg.max_hz = RW007_SPI_MAX_HZ; /* 15M 007 max 30M */ + rt_spi_configure(rw007_spi.spi_device, &cfg); + } + + /* init spi send mempool */ + rt_mp_init(&rw007_spi.spi_tx_mp, + "spi_tx", + &rw007_spi.spi_tx_mempool[0], + sizeof(rw007_spi.spi_tx_mempool), + sizeof(struct spi_data_packet)); + + /* init spi send mailbox */ + rt_mb_init(&rw007_spi.spi_tx_mb, + "spi_tx", + &rw007_spi.spi_tx_mb_pool[0], + SPI_TX_POOL_SIZE, + RT_IPC_FLAG_PRIO); + + /* init spi recv mempool */ + rt_mp_init(&rw007_spi.spi_rx_mp, + "spi_rx", + &rw007_spi.spi_rx_mempool[0], + sizeof(rw007_spi.spi_rx_mempool), + sizeof(struct spi_data_packet)); + + /* init spi recv mailbox */ + rt_mb_init(&rw007_spi.spi_rx_mb, + "spi_rx", + &rw007_spi.spi_rx_mb_pool[0], + SPI_RX_POOL_SIZE, + RT_IPC_FLAG_PRIO); + + /* init spi data notify event */ + rt_event_init(&spi_wifi_data_event, "wifi", RT_IPC_FLAG_FIFO); + + rw007_spi.rw007_cmd_event = rt_event_create("wifi_cmd", RT_IPC_FLAG_FIFO); + + /* register wlan device for ap */ + ret = rt_wlan_dev_register(&wlan_ap, RT_WLAN_DEVICE_AP_NAME, &ops, 0, &wifi_ap); + if (ret != RT_EOK) + { + return ret; + } + + /* register wlan device for sta */ + ret = rt_wlan_dev_register(&wlan_sta, RT_WLAN_DEVICE_STA_NAME, &ops, 0, &wifi_sta); + if (ret != RT_EOK) + { + return ret; + } + + { + rt_thread_t tid; + + /* Create package parse thread */ + tid = rt_thread_create("wifi_handle", + wifi_data_process_thread_entry, + &rw007_spi, + 2048, + 8, + 20); + if(!tid) + { + return -RT_ERROR; + } + rt_thread_startup(tid); + + /* Create wifi transfer thread */ + tid = rt_thread_create("wifi_xfer", + spi_wifi_data_thread_entry, + RT_NULL, + 2048, + 9, + 20); + if(!tid) + { + return -RT_ERROR; + } + rt_thread_startup(tid); + } + + spi_wifi_hw_init(); + + return RT_EOK; +} + +void spi_wifi_isr(int vector) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + /* device has a package to ready transfer */ + rt_event_send(&spi_wifi_data_event, RW007_SLAVE_INT); + + /* leave interrupt */ + rt_interrupt_leave(); +} + +#ifdef WLAN_DEV_MONITOR +int rw007_dump(int argc, char **argv) +{ + if (argc == 1) + { + goto __usage; + } + + if (strcmp(argv[1], "--show") == 0) + { + rt_kprintf("Wifi Device transmission information:\n"); + rt_kprintf("Total packets : %d\n", packet.total); + rt_kprintf("Failed packets : %d\n", packet.lose); + rt_kprintf("Retry count : %d\n", packet.retry); + rt_kprintf("Stage 1 error : %d\n", packet.first_stage_err); + rt_kprintf("Stage 2 error : %d\n", packet.second_stage_err); + } + else if (strcmp(argv[1], "-h") == 0) + { + goto __usage; + } + else if (strcmp(argv[1], "-c") == 0) + { + rt_memset(&packet, 0, sizeof(packet)); + } + return 0; +__usage: + rt_kprintf("Usage: wifi_dump [-s|-c]\n"); + rt_kprintf("\n"); + rt_kprintf("Miscellaneous:\n"); + rt_kprintf(" -h print this message and quit\n"); + rt_kprintf(" --show show information\n"); + rt_kprintf(" -c Clear record data\n"); + return 0; +} + +#ifdef RT_USING_FINSH + #include + MSH_CMD_EXPORT(rw007_dump, the rw007 Informations Viewer); +#endif +#endif + From 5b9cbad759984696a6f8e60e9a0c0f155cc8803c Mon Sep 17 00:00:00 2001 From: chunyexixiaoyu <834670833@qq.com> Date: Mon, 21 Jun 2021 18:03:15 +0800 Subject: [PATCH 3/3] Ubiquitous/RT_Thread: fix lcd drive for k210 ,before lcd drive can't work with spi. --- .../bsp/k210/base-drivers/drv_io_config.c | 5 +++- .../RT_Thread/bsp/k210/base-drivers/drv_lcd.c | 25 +++++++++++-------- .../RT_Thread/bsp/k210/base-drivers/drv_lcd.h | 5 ++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_io_config.c b/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_io_config.c index c7e04668..56c1e07d 100644 --- a/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_io_config.c +++ b/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_io_config.c @@ -37,7 +37,7 @@ static struct io_config IOCONFIG(BSP_DVP_CMOS_HREF_PIN, FUNC_CMOS_HREF), #endif -#ifdef BSP_USING_LCD +#if 0 //here is a drv lcd bug now don't know why IOCONFIG(BSP_LCD_CS_PIN, FUNC_SPI0_SS3), /* LCD CS PIN */ IOCONFIG(BSP_LCD_WR_PIN, FUNC_SPI0_SCLK), /* LCD WR PIN */ IOCONFIG(BSP_LCD_DC_PIN, FUNC_GPIOHS2), /* LCD DC PIN */ @@ -123,6 +123,9 @@ int io_config_init(void) sysctl_set_power_mode(SYSCTL_POWER_BANK6, SYSCTL_POWER_V18); sysctl_set_power_mode(SYSCTL_POWER_BANK7, SYSCTL_POWER_V18); #endif +#ifdef FACE_DETECT + sysctl_clock_enable(SYSCTL_CLOCK_AI); +#endif } INIT_BOARD_EXPORT(io_config_init); diff --git a/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_lcd.c b/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_lcd.c index abbe5216..4b614622 100644 --- a/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_lcd.c +++ b/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_lcd.c @@ -52,9 +52,9 @@ static void init_rst(void) { gpiohs_set_drive_mode(RST_GPIONUM, GPIO_DM_OUTPUT); gpiohs_set_pin(RST_GPIONUM, GPIO_PV_LOW); - usleep(100000); + rt_thread_mdelay(10); gpiohs_set_pin(RST_GPIONUM, GPIO_PV_HIGH); - usleep(100000); + rt_thread_mdelay(10); } @@ -122,17 +122,26 @@ void lcd_interrupt_enable(void) lcd_ctl.mode = 1; } +void lcd_pre() +{ + fpioa_set_function(37, FUNC_GPIOHS0 + RST_GPIONUM); + fpioa_set_function(38, FUNC_GPIOHS0 + DCX_GPIONUM); + fpioa_set_function(36, FUNC_SPI0_SS0 + LCD_SPI_SLAVE_SELECT); + fpioa_set_function(39, FUNC_SPI0_SCLK); +} + int lcd_init(void) { uint8_t data = 0; + lcd_pre(); tft_hard_init(); /*soft reset*/ tft_write_command(SOFTWARE_RESET); - usleep(100000); + rt_thread_mdelay(10); /*exit sleep*/ tft_write_command(SLEEP_OFF); - usleep(100000); + rt_thread_mdelay(10); /*pixel format*/ tft_write_command(PIXEL_FORMAT_SET); data = 0x55; @@ -302,14 +311,8 @@ void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, lcd_set_area(x1, y1, x1 + width - 1, y1 + height - 1); tft_write_word(ptr, width * height / 2, lcd_ctl.mode ? 2 : 0); } -void lcd_pre() -{ - fpioa_set_function(38, FUNC_GPIOHS0 + DCX_GPIONUM); - fpioa_set_function(36, FUNC_SPI0_SS3); - fpioa_set_function(39, FUNC_SPI0_SCLK); - fpioa_set_function(37, FUNC_GPIOHS0 + RST_GPIONUM); -} + void lcd_test0() { char test[]={"xuos-intelligence framwork"}; diff --git a/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_lcd.h b/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_lcd.h index f7592694..92578036 100644 --- a/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_lcd.h +++ b/Ubiquitous/RT_Thread/bsp/k210/base-drivers/drv_lcd.h @@ -96,8 +96,9 @@ #define DIGITAL_GAMMA_CTL2 0xE3 #define INTERFACE_CTL 0xF6 -#define DCX_GPIONUM (2) -#define RST_GPIONUM (3) +#define DCX_GPIONUM (5) +#define RST_GPIONUM (4) +#define LCD_SPI_SLAVE_SELECT 3 #define SPI_CHANNEL 0 #define SPI_SLAVE_SELECT 3