Skip to content

Commit

Permalink
Running image demo success
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-mao committed Oct 30, 2019
1 parent 595bd6a commit 8c01056
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 117 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion components/awtk
Submodule awtk updated 602 files
File renamed without changes.
4 changes: 4 additions & 0 deletions components/esp32-port/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
* 如果禁用控件动画,请定义本宏
*
Expand All @@ -60,4 +84,6 @@

#define WITHOUT_EXT_WIDGETS 1

#define FRAGMENT_FRAME_BUFFER_SIZE 32 * 1024

#endif/*AWTK_CONFIG_H*/
7 changes: 7 additions & 0 deletions components/esp32-port/component.mk
Original file line number Diff line number Diff line change
@@ -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 := ./
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
{
Expand Down Expand Up @@ -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刷新操作 */
/*----------------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,6 @@
#include "freertos/task.h"
#include <sys/time.h>

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];
Expand Down
4 changes: 4 additions & 0 deletions components/lcd_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(COMPONENT_SRCS "esp32-spi.c" "ili9341.c")
set(COMPONENT_ADD_INCLUDEDIRS "ili9341.h" "esp32-spi.h")

register_component()
7 changes: 7 additions & 0 deletions components/lcd_driver/component.mk
Original file line number Diff line number Diff line change
@@ -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 := ./
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern "C" {

#include <stdint.h>
#include <stdbool.h>
#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
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion esp-idf
Submodule esp-idf updated 4330 files
5 changes: 2 additions & 3 deletions example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 9 additions & 0 deletions example/esp32-awtk-partitions.csv
Original file line number Diff line number Diff line change
@@ -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,
60 changes: 19 additions & 41 deletions example/main/esp32_awtk_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -47,69 +46,48 @@ 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);
}

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,
Expand Down
Loading

0 comments on commit 8c01056

Please sign in to comment.