diff --git a/.gitignore b/.gitignore index 418e208..a7a9db2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,9 +18,9 @@ GPATH .DS_Store # Example project files -# examples/**/sdkconfig -examples/**/sdkconfig.old -examples/**/build +# example/**/sdkconfig +example/**/sdkconfig.old +example/**/build # gcov coverage reports *.gcda diff --git a/README.md b/README.md index 7e195f1..74eb9df 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,7 @@ # Todo list -- [ ] Porting awtk to support ESP32 -- [ ] Support touch events +- [x] Porting awtk to support ESP32 +- [x] Running first demo on ESP-WROVER-KIT +- [ ] Support touch input events +- [ ] Implement framebuffer to improve speed diff --git a/components/awtk b/components/awtk index ad86871..cd002a0 160000 --- a/components/awtk +++ b/components/awtk @@ -1 +1 @@ -Subproject commit ad86871b204fa22c02977af404866f7382db355e +Subproject commit cd002a018ceab415be8b6e6652178507c1d0dba7 diff --git a/components/awtk-port/.clang-format b/components/esp32-port/.clang-format similarity index 100% rename from components/awtk-port/.clang-format rename to components/esp32-port/.clang-format diff --git a/components/esp32-port/CMakeLists.txt b/components/esp32-port/CMakeLists.txt new file mode 100644 index 0000000..1c42a24 --- /dev/null +++ b/components/esp32-port/CMakeLists.txt @@ -0,0 +1,4 @@ +set(COMPONENT_SRCS "lcd_esp32_raw.c" "main_loop_esp32_raw.c" "platform.c") +set(COMPONENT_ADD_INCLUDEDIRS "awtk_config.h") + +register_component() diff --git a/components/awtk-port/awtk_config.h b/components/esp32-port/awtk_config.h similarity index 70% rename from components/awtk-port/awtk_config.h rename to components/esp32-port/awtk_config.h index a2879dd..38adf36 100644 --- a/components/awtk-port/awtk_config.h +++ b/components/esp32-port/awtk_config.h @@ -40,6 +40,30 @@ */ #define WITH_NULL_IM 1 +/** + * 如果支持极速模式,请定义本宏。极速模式不支持控件透明半透明效果,只有在CPU配置极低时启用。 + * + * #define USE_FAST_MODE 1 + */ + +/** + * 如果有标准的malloc/free/calloc等函数,请定义本宏 + * + */ +// #define HAS_STD_MALLOC 1 + +/** + * 如果有标准的fopen/fclose等函数,请定义本宏 + * + */ +#define HAS_STDIO 1 + +/** + * 如果有优化版本的memcpy函数,请定义本宏 + * + */ +#define HAS_FAST_MEMCPY 1 + /** * 如果禁用控件动画,请定义本宏 * @@ -60,4 +84,6 @@ #define WITHOUT_EXT_WIDGETS 1 +#define FRAGMENT_FRAME_BUFFER_SIZE 32 * 1024 + #endif/*AWTK_CONFIG_H*/ diff --git a/components/esp32-port/component.mk b/components/esp32-port/component.mk new file mode 100644 index 0000000..5c92de5 --- /dev/null +++ b/components/esp32-port/component.mk @@ -0,0 +1,7 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) + +COMPONENT_ADD_INCLUDEDIRS := ./ +COMPONENT_SRCDIRS := ./ diff --git a/components/awtk-port/format.sh b/components/esp32-port/format.sh similarity index 100% rename from components/awtk-port/format.sh rename to components/esp32-port/format.sh diff --git a/components/awtk-port/lcd_esp32_raw.c b/components/esp32-port/lcd_esp32_raw.c similarity index 58% rename from components/awtk-port/lcd_esp32_raw.c rename to components/esp32-port/lcd_esp32_raw.c index 31371f0..2624203 100644 --- a/components/awtk-port/lcd_esp32_raw.c +++ b/components/esp32-port/lcd_esp32_raw.c @@ -19,34 +19,34 @@ * */ -#include "gui.h" #include "ili9341.h" -#include "tkc/mem.h" #include "lcd/lcd_reg.h" - +#include "stdio.h" typedef uint16_t pixel_t; #define LCD_FORMAT BITMAP_FMT_BGR565 #define pixel_from_rgb(r, g, b) ((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3)) #define pixel_to_rgba(p) {(0xff & ((p >> 11) << 3)), (0xff & ((p >> 5) << 2)), (0xff & (p << 3))} -#define set_window_func esp32_spi_lcd_write_data -#define write_data_func esp32_spi_lcd_set_window +extern ili9341_lcd_t *lcd; +extern void write_data_func(uint16_t dat); +extern void set_window_func(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end); -extern ili9341_lcd_t * lcd; -void esp32_spi_lcd_write_data(uint16_t dat) -{ - ili9341_start_pixels(lcd); - ili9341_write_pixel(lcd, dat); - // ili9341_write_pixels(lcd, frame, 320*240); - ili9341_end_pixels(lcd); +void write_data_func(uint16_t dat) +{ + ili9341_start_pixels(lcd); + ili9341_write_pixel(lcd, dat); + ili9341_end_pixels(lcd); } -void esp32_spi_lcd_set_window(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end) +void set_window_func(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end) { - uint16_t w = (x_end - x_start + 1); - uint16_t h = (y_end - y_start + 1); - ili9341_set_window(lcd, x_start, y_start, w, h); + uint16_t w = (x_end - x_start + 1); + uint16_t h = (y_end - y_start + 1); + ESP_LOGI("LCD_SET_W", "%d-%d, %d-%d, w:%d,h:%d", x_start, x_end, y_start, y_end, w,h ); + ili9341_start_pixels(lcd); + ili9341_set_window(lcd, x_start, y_start, w, h); + ili9341_end_pixels(lcd); } #include "base/pixel.h" diff --git a/components/awtk-port/main_loop_esp32_raw.c b/components/esp32-port/main_loop_esp32_raw.c similarity index 93% rename from components/awtk-port/main_loop_esp32_raw.c rename to components/esp32-port/main_loop_esp32_raw.c index d4f5ec4..6814c65 100644 --- a/components/awtk-port/main_loop_esp32_raw.c +++ b/components/esp32-port/main_loop_esp32_raw.c @@ -24,6 +24,7 @@ #include "esp_log.h" #include "base/idle.h" #include "base/timer.h" +#include "lcd/lcd_reg.h" #include "lcd/lcd_mem_bgr565.h" #include "main_loop/main_loop_simple.h" @@ -32,13 +33,15 @@ /*----------------------------------------------------------------------------*/ // static struct aw_ts_state s_ts_state = {0}; -typdef struct { +typedef struct { int x; int y; int pressed; } touch_info_t; - +static lcd_t* platform_create_lcd(wh_t w, wh_t h) { + return lcd_reg_create(w, h); +} #define TS_STACK_SIZE 2 * 1024 static void __awtk_loop_task_entry(void *p_arg) { @@ -66,24 +69,27 @@ static void __awtk_loop_task_entry(void *p_arg) } } } - -ret_t platform_disaptch_input(main_loop_t* loop) { - static TaskHandle_t loop_handle = NULL; - if(loop_handle==NULL) { - if (xTaskCreatePinnedToCore(__awtk_loop_task_entry, - "awtk_loop_task_entry", - 4096, - NULL, - 5, - &loop_handle, 0) != pdTRUE) { - ESP_LOGE(TAG, "Error create AWTK main loop task"); - } - - } - +ret_t platform_disaptch_input(main_loop_t* l) { return RET_OK; } +// ret_t platform_disaptch_input(main_loop_t* loop) { +// static TaskHandle_t loop_handle = NULL; +// if(loop_handle==NULL) { +// if (xTaskCreatePinnedToCore(__awtk_loop_task_entry, +// "awtk_loop_task_entry", +// 4096, +// NULL, +// 5, +// &loop_handle, 0) != pdTRUE) { +// ESP_LOGE("TAG", "Error create AWTK main loop task"); +// } + +// } + +// return RET_OK; +// } + /*----------------------------------------------------------------------------*/ /* frame buffer刷新操作 */ /*----------------------------------------------------------------------------*/ diff --git a/components/awtk-port/platform.c b/components/esp32-port/platform.c similarity index 65% rename from components/awtk-port/platform.c rename to components/esp32-port/platform.c index 56cca28..24bde36 100644 --- a/components/awtk-port/platform.c +++ b/components/esp32-port/platform.c @@ -28,30 +28,6 @@ #include "freertos/task.h" #include -uint64_t get_time_ms64() { - struct timeval te; - gettimeofday(&te, NULL); - uint64_t milliseconds = te.tv_sec * 1000LL + te.tv_usec / 1000; - return milliseconds; -} - -static void sleep_ms_raw(uint32_t ms) { - uint32_t count = 0; - uint64_t start = get_time_ms64(); - - while (get_time_ms64() < (start + ms)) { - count++; - } -} - -void sleep_ms(uint32_t ms) { - vTaskDelay(1 / portTICK_PERIOD_MS); - // if (tos_knl_is_running()) { - // tos_task_delay(ms); - // } else { - // sleep_ms_raw(ms); - // } -} static bool_t s_inited = FALSE; static uint32_t s_heam_mem[4096]; diff --git a/components/lcd_driver/CMakeLists.txt b/components/lcd_driver/CMakeLists.txt new file mode 100644 index 0000000..9dc385c --- /dev/null +++ b/components/lcd_driver/CMakeLists.txt @@ -0,0 +1,4 @@ +set(COMPONENT_SRCS "esp32-spi.c" "ili9341.c") +set(COMPONENT_ADD_INCLUDEDIRS "ili9341.h" "esp32-spi.h") + +register_component() diff --git a/components/lcd_driver/component.mk b/components/lcd_driver/component.mk new file mode 100644 index 0000000..5c92de5 --- /dev/null +++ b/components/lcd_driver/component.mk @@ -0,0 +1,7 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) + +COMPONENT_ADD_INCLUDEDIRS := ./ +COMPONENT_SRCDIRS := ./ diff --git a/example/main/esp32-spi.c b/components/lcd_driver/esp32-spi.c similarity index 100% rename from example/main/esp32-spi.c rename to components/lcd_driver/esp32-spi.c diff --git a/example/main/esp32-spi.h b/components/lcd_driver/esp32-spi.h similarity index 98% rename from example/main/esp32-spi.h rename to components/lcd_driver/esp32-spi.h index 71cc8f2..427bf49 100644 --- a/example/main/esp32-spi.h +++ b/components/lcd_driver/esp32-spi.h @@ -21,6 +21,7 @@ extern "C" { #include #include +#include "esp_types.h" #define FSPI 1 //SPI bus attached to the flash (can use the same data lines but different SS) #define HSPI 2 //SPI bus normally mapped to pins 12 - 15, but can be matrixed to any pins diff --git a/example/main/ili9341.c b/components/lcd_driver/ili9341.c similarity index 100% rename from example/main/ili9341.c rename to components/lcd_driver/ili9341.c diff --git a/example/main/ili9341.h b/components/lcd_driver/ili9341.h similarity index 100% rename from example/main/ili9341.h rename to components/lcd_driver/ili9341.h diff --git a/esp-idf b/esp-idf index 2e6398a..90af68b 160000 --- a/esp-idf +++ b/esp-idf @@ -1 +1 @@ -Subproject commit 2e6398affaeeac2f7ce40457a881f2dda57ad11f +Subproject commit 90af68bd3c1941d9f5513bee22a12de7250208d7 diff --git a/example/Makefile b/example/Makefile index b2ebc3f..524a475 100644 --- a/example/Makefile +++ b/example/Makefile @@ -5,9 +5,8 @@ PROJECT_NAME := esp32_awtk_demo -EXTRA_COMPONENT_DIRS += ../awtk-port/ - - +EXTRA_COMPONENT_DIRS += ../components/ include $(IDF_PATH)/make/project.mk + # include $(ADF_PATH)/project.mk diff --git a/example/esp32-awtk-partitions.csv b/example/esp32-awtk-partitions.csv new file mode 100644 index 0000000..cf521ac --- /dev/null +++ b/example/esp32-awtk-partitions.csv @@ -0,0 +1,9 @@ +# Espressif ESP32 Partition Table +# +# Note: if you change the phy_init or app partition offset +# make sure to change the offset in Kconfig.projbuild +# +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x6000, +phy_init, data, phy, 0xf000, 0x1000, +factory, app, factory, 0x10000, 2000000, diff --git a/example/main/esp32_awtk_main.c b/example/main/esp32_awtk_main.c index 4a539fe..994f1b9 100644 --- a/example/main/esp32_awtk_main.c +++ b/example/main/esp32_awtk_main.c @@ -36,8 +36,7 @@ #define PIEXL_READ_TASK_STACK (3*1024) #define PIEXL_READ_TASK_PRIO (21) -static ili9341_lcd_t * lcd = NULL; -static uint16_t * frame = NULL; +ili9341_lcd_t * lcd; extern const uint8_t rgb565_piexl_start[] asm("_binary_rgb565_piexl_start"); extern const uint8_t rgb565_piexl_end[] asm("_binary_rgb565_piexl_end"); @@ -47,53 +46,41 @@ static const char *TAG = "PLAY_RGB565_EXAMPLE"; void setup_ili9341() { spi_init(LCD_SPI_NUM, LCD_SPI_SCK, LCD_SPI_MISO, LCD_SPI_MOSI, LCD_SPI_FREQ, LCD_SPI_MODE, LCD_SPI_ORDER); lcd = ili9341_init(LCD_SPI_NUM, LCD_SPI_FREQ, LCD_SPI_CS, LCD_SPI_DC, LCD_SPI_RST, LCD_SPI_BL); - ili9341_set_rotation(lcd, 1); + ili9341_set_rotation(lcd, 3); - ili9341_start_pixels(lcd); - ili9341_set_window(lcd, 0, 0, 120, 40); - // ili9341_write_color(lcd, ILI9341_BLACK, 120*40); - //ili9341_set_window(lcd, 0, 0, 320, 240); - //ili9341_write_color(lcd, ILI9341_BLACK, 320*240); - ili9341_end_pixels(lcd); - - frame = (uint16_t *)heap_caps_malloc(VIDEO_FRAME_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); } -int gui_app_start(int lcd_w, int lcd_h); +extern int gui_app_start(int lcd_w, int lcd_h); static void __awtk_task_entry(void *p_arg) { - gui_app_start(320, 240); + ESP_LOGI(TAG, "__awtk_task_entry started"); + gui_app_start(320, 240); + ESP_LOGI(TAG, "__awtk_task_entry deleted"); + vTaskDelete(NULL); } static void _lcd_render_task(void *pv) { ESP_LOGI(TAG, "Start LCD render task"); setup_ili9341(); - - uint32_t piexl_size = rgb565_piexl_end - rgb565_piexl_start; - memcpy(frame, rgb565_piexl_start, piexl_size); + if (xTaskCreatePinnedToCore(__awtk_task_entry, + "__awtk_task_entry", + 4096, + NULL, + 5, + NULL, 0) != pdTRUE) { + ESP_LOGE(TAG, "Error create LCD render task"); + } + uint16_t * esp32_frame = (uint16_t *)heap_caps_malloc(VIDEO_FRAME_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); + memcpy(esp32_frame, rgb565_piexl_start, rgb565_piexl_end - rgb565_piexl_start); ili9341_start_pixels(lcd); ili9341_set_window(lcd, 0, 0, 320, 240); - ili9341_write_pixels(lcd, frame, 320*240); - vTaskDelay(3000 / portTICK_PERIOD_MS); + ili9341_write_pixels(lcd, esp32_frame, 320*240); ili9341_end_pixels(lcd); + ESP_LOGE(TAG, "__lcd_render_task started,lcd:%p", lcd); while (1) { vTaskDelay(3000 / portTICK_PERIOD_MS); - // ili9341_start_pixels(lcd); - // ili9341_set_window(lcd, 0, 0, 320, 240); - // uint64_t st; //= (uint64_t)esp_timer_get_time(); - // if (raw_stream_read(raw_read, frame, VIDEO_FRAME_SIZE) > 0) { - // st = (uint64_t)esp_timer_get_time(); - // ili9341_write_pixels(lcd, frame, 320*240); - // } else { - // //ili9341_write_color(lcd, ILI9341_BLACK, 320*240); - // break; - // } - // uint64_t en = (uint64_t)esp_timer_get_time(); - // uint32_t dif = en - st; - // printf("Frame: %uus (%u fps)\n", dif, 1000000/dif); - // ili9341_end_pixels(lcd); } vTaskDelete(NULL); @@ -101,15 +88,6 @@ static void _lcd_render_task(void *pv) void app_main() { - if (xTaskCreatePinnedToCore(__awtk_task_entry, - "__awtk_task_entry", - 4096, - NULL, - 5, - NULL, 0) != pdTRUE) { - ESP_LOGE(TAG, "Error create LCD render task"); - } - if (xTaskCreatePinnedToCore(_lcd_render_task, "_lcd_render_task", LCD_RENDER_TASK_STACK, diff --git a/example/sdkconfig b/example/sdkconfig index e8f21ca..74b3f2e 100644 --- a/example/sdkconfig +++ b/example/sdkconfig @@ -84,11 +84,11 @@ CONFIG_MONITOR_BAUD=115200 # # Partition Table # -CONFIG_PARTITION_TABLE_SINGLE_APP=y +CONFIG_PARTITION_TABLE_SINGLE_APP= CONFIG_PARTITION_TABLE_TWO_OTA= -CONFIG_PARTITION_TABLE_CUSTOM= -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" -CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv" +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="esp32-awtk-partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="esp32-awtk-partitions.csv" CONFIG_PARTITION_TABLE_OFFSET=0x8000 CONFIG_PARTITION_TABLE_MD5=y @@ -239,9 +239,9 @@ CONFIG_CONSOLE_UART_BAUDRATE=115200 CONFIG_ULP_COPROC_ENABLED= CONFIG_ULP_COPROC_RESERVE_MEM=0 CONFIG_ESP32_PANIC_PRINT_HALT= -CONFIG_ESP32_PANIC_PRINT_REBOOT=y +CONFIG_ESP32_PANIC_PRINT_REBOOT= CONFIG_ESP32_PANIC_SILENT_REBOOT= -CONFIG_ESP32_PANIC_GDBSTUB= +CONFIG_ESP32_PANIC_GDBSTUB=y CONFIG_ESP32_DEBUG_OCDAWARE=y CONFIG_ESP32_DEBUG_STUBS_ENABLE=y CONFIG_INT_WDT=y @@ -436,10 +436,12 @@ CONFIG_FREERTOS_DEBUG_INTERNALS= # # Heap memory debugging # -CONFIG_HEAP_POISONING_DISABLED=y -CONFIG_HEAP_POISONING_LIGHT= +CONFIG_HEAP_POISONING_DISABLED= +CONFIG_HEAP_POISONING_LIGHT=y CONFIG_HEAP_POISONING_COMPREHENSIVE= -CONFIG_HEAP_TRACING= +CONFIG_HEAP_TRACING=y +CONFIG_HEAP_TRACING_STACK_DEPTH=2 +CONFIG_HEAP_TASK_TRACKING=y # # libsodium