move lv port specific and lv driver specific files to lv_bindings. update lv_bindings. Initial work on esp32
This commit is contained in:
parent
5ea04d50b8
commit
59e5b193f8
@ -1 +1 @@
|
||||
Subproject commit c0d7b649146aa127320a9656bbebb8d0b3421a6c
|
||||
Subproject commit 19a99a7e3fcc007d354997c6484831ed9ce955c1
|
||||
@ -28,7 +28,6 @@
|
||||
/* Enable GC for Micropython */
|
||||
#define LV_ENABLE_GC 1
|
||||
#if LV_ENABLE_GC == 1
|
||||
long unsigned int gc_nbytes(const void *ptr);
|
||||
# define LV_MEM_CUSTOM_REALLOC m_realloc /*Wrapper to realloc*/
|
||||
# define LV_MEM_CUSTOM_GET_SIZE gc_nbytes /*Wrapper to lv_mem_get_size*/
|
||||
# define LV_GC_INCLUDE "py/mpstate.h"
|
||||
|
||||
@ -7,6 +7,7 @@ MICROPY_PY_USSL = 0
|
||||
MICROPY_SSL_AXTLS = 0
|
||||
MICROPY_FATFS = 1
|
||||
MICROPY_PY_BTREE = 1
|
||||
MICROPY_PY_LVGL = 1
|
||||
|
||||
#FROZEN_DIR = scripts
|
||||
FROZEN_MPY_DIR = modules
|
||||
|
||||
@ -53,6 +53,7 @@
|
||||
#define MICROPY_SCHEDULER_DEPTH (8)
|
||||
#define MICROPY_VFS (1)
|
||||
#define MICROPY_VFS_FAT (1)
|
||||
#define MICROPY_PY_LVGL (1)
|
||||
|
||||
// control over Python builtins
|
||||
#define MICROPY_PY_FUNCTION_ATTRS (1)
|
||||
@ -178,6 +179,7 @@ extern const struct _mp_obj_module_t mp_module_usocket;
|
||||
extern const struct _mp_obj_module_t mp_module_machine;
|
||||
extern const struct _mp_obj_module_t mp_module_network;
|
||||
extern const struct _mp_obj_module_t mp_module_onewire;
|
||||
extern const struct _mp_obj_module_t mp_module_lvgl;
|
||||
|
||||
#define MICROPY_PORT_BUILTIN_MODULES \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \
|
||||
@ -207,10 +209,18 @@ extern const struct _mp_obj_module_t mp_module_onewire;
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&utime_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_zlib), (mp_obj_t)&mp_module_uzlib }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl }, \
|
||||
|
||||
#define MP_STATE_PORT MP_STATE_VM
|
||||
|
||||
#if MICROPY_PY_LVGL
|
||||
#include "lib/lv_bindings/lvgl/lv_misc/lv_gc.h"
|
||||
#else
|
||||
#define LV_ROOTS
|
||||
#endif
|
||||
|
||||
#define MICROPY_PORT_ROOT_POINTERS \
|
||||
LV_ROOTS \
|
||||
const char *readline_hist[8]; \
|
||||
mp_obj_t machine_pin_irq_handler[40]; \
|
||||
|
||||
|
||||
@ -152,12 +152,12 @@ SRC_C = \
|
||||
alloc.c \
|
||||
coverage.c \
|
||||
fatfs_port.c \
|
||||
lv_mpy_hal.c \
|
||||
monitor.c \
|
||||
mouse.c \
|
||||
$(SRC_MOD)
|
||||
|
||||
LIB_SRC_C = $(addprefix lib/,\
|
||||
lv_bindings/port/unix/lv_mpy_hal.c \
|
||||
lv_bindings/driver/SDL/monitor.c \
|
||||
lv_bindings/driver/SDL/mouse.c \
|
||||
$(LIB_SRC_C_EXTRA) \
|
||||
timeutils/timeutils.c \
|
||||
)
|
||||
|
||||
@ -1,235 +0,0 @@
|
||||
/**
|
||||
* @file lv_drv_conf.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRV_CONF_H
|
||||
#define LV_DRV_CONF_H
|
||||
/*
|
||||
* COPY THIS FILE AS lv_drv_conf.h
|
||||
*/
|
||||
|
||||
#if 1 /*Set it to "1" to enable the content*/
|
||||
|
||||
#include "../../lib/lv_bindings/lvgl/lvgl.h"
|
||||
|
||||
/*********************
|
||||
* DELAY INTERFACE
|
||||
*********************/
|
||||
#define LV_DRV_DELAY_INCLUDE <stdint.h> /*Dummy include by default*/
|
||||
#define LV_DRV_DELAY_US(us) /*delay_us(us)*/ /*Delay the given number of microseconds*/
|
||||
#define LV_DRV_DELAY_MS(ms) /*delay_ms(ms)*/ /*Delay the given number of milliseconds*/
|
||||
|
||||
/*********************
|
||||
* DISPLAY INTERFACE
|
||||
*********************/
|
||||
|
||||
/*------------
|
||||
* Common
|
||||
*------------*/
|
||||
#define LV_DRV_DISP_INCLUDE <stdint.h> /*Dummy include by default*/
|
||||
#define LV_DRV_DISP_CMD_DATA(val) /*pin_x_set(val)*/ /*Set the command/data pin to 'val'*/
|
||||
#define LV_DRV_DISP_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
|
||||
|
||||
/*---------
|
||||
* SPI
|
||||
*---------*/
|
||||
#define LV_DRV_DISP_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
|
||||
#define LV_DRV_DISP_SPI_WR_BYTE(data) /*spi_wr(data)*/ /*Write a byte the SPI bus*/
|
||||
#define LV_DRV_DISP_SPI_WR_ARRAY(adr, n) /*spi_wr_mem(adr, n)*/ /*Write 'n' bytes to SPI bus from 'adr'*/
|
||||
|
||||
/*------------------
|
||||
* Parallel port
|
||||
*-----------------*/
|
||||
#define LV_DRV_DISP_PAR_CS(val) /*par_cs_set(val)*/ /*Set the Parallel port's Chip select to 'val'*/
|
||||
#define LV_DRV_DISP_PAR_SLOW /*par_slow()*/ /*Set low speed on the parallel port*/
|
||||
#define LV_DRV_DISP_PAR_FAST /*par_fast()*/ /*Set high speed on the parallel port*/
|
||||
#define LV_DRV_DISP_PAR_WR_WORD(data) /*par_wr(data)*/ /*Write a word to the parallel port*/
|
||||
#define LV_DRV_DISP_PAR_WR_ARRAY(adr, n) /*par_wr_mem(adr,n)*/ /*Write 'n' bytes to Parallel ports from 'adr'*/
|
||||
|
||||
/***************************
|
||||
* INPUT DEVICE INTERFACE
|
||||
***************************/
|
||||
|
||||
/*----------
|
||||
* Common
|
||||
*----------*/
|
||||
#define LV_DRV_INDEV_INCLUDE <stdint.h> /*Dummy include by default*/
|
||||
#define LV_DRV_INDEV_RST(val) /*pin_x_set(val)*/ /*Set the reset pin to 'val'*/
|
||||
#define LV_DRV_INDEV_IRQ_READ 0 /*pn_x_read()*/ /*Read the IRQ pin*/
|
||||
|
||||
/*---------
|
||||
* SPI
|
||||
*---------*/
|
||||
#define LV_DRV_INDEV_SPI_CS(val) /*spi_cs_set(val)*/ /*Set the SPI's Chip select to 'val'*/
|
||||
#define LV_DRV_INDEV_SPI_XCHG_BYTE(data) 0 /*spi_xchg(val)*/ /*Write 'val' to SPI and give the read value*/
|
||||
|
||||
/*---------
|
||||
* I2C
|
||||
*---------*/
|
||||
#define LV_DRV_INDEV_I2C_START /*i2c_start()*/ /*Make an I2C start*/
|
||||
#define LV_DRV_INDEV_I2C_STOP /*i2c_stop()*/ /*Make an I2C stop*/
|
||||
#define LV_DRV_INDEV_I2C_RESTART /*i2c_restart()*/ /*Make an I2C restart*/
|
||||
#define LV_DRV_INDEV_I2C_WR(data) /*i2c_wr(data)*/ /*Write a byte to the I1C bus*/
|
||||
#define LV_DRV_INDEV_I2C_READ(last_read) 0 /*i2c_rd()*/ /*Read a byte from the I2C bud*/
|
||||
|
||||
|
||||
/*********************
|
||||
* DISPLAY DRIVERS
|
||||
*********************/
|
||||
|
||||
/*-------------------
|
||||
* Monitor of PC
|
||||
*-------------------*/
|
||||
#define USE_MONITOR 1
|
||||
#if USE_MONITOR
|
||||
#define MONITOR_HOR_RES LV_HOR_RES
|
||||
#define MONITOR_VER_RES LV_VER_RES
|
||||
#define MONITOR_ZOOM 1 /* Scale window by this factor (useful when simulating small screens) */
|
||||
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h> /*Eclipse: <SDL2/SDL.h> Visual Studio: <SDL.h>*/
|
||||
#define MONITOR_VIRTUAL_MACHINE 0 /*Different rendering should be used if running in a Virtual machine*/
|
||||
#endif
|
||||
|
||||
/*----------------
|
||||
* SSD1963
|
||||
*--------------*/
|
||||
#define USE_SSD1963 0
|
||||
#if USE_SSD1963
|
||||
#define SSD1963_HOR_RES LV_HOR_RES
|
||||
#define SSD1963_VER_RES LV_VER_RES
|
||||
#define SSD1963_HT 531
|
||||
#define SSD1963_HPS 43
|
||||
#define SSD1963_LPS 8
|
||||
#define SSD1963_HPW 10
|
||||
#define SSD1963_VT 288
|
||||
#define SSD1963_VPS 12
|
||||
#define SSD1963_FPS 4
|
||||
#define SSD1963_VPW 10
|
||||
#define SSD1963_HS_NEG 0 /*Negative hsync*/
|
||||
#define SSD1963_VS_NEG 0 /*Negative vsync*/
|
||||
#define SSD1963_ORI 0 /*0, 90, 180, 270*/
|
||||
#define SSD1963_COLOR_DEPTH 16
|
||||
#endif
|
||||
|
||||
/*----------------
|
||||
* R61581
|
||||
*--------------*/
|
||||
#define USE_R61581 0
|
||||
#if USE_R61581 != 0
|
||||
#define R61581_HOR_RES LV_HOR_RES
|
||||
#define R61581_VER_RES LV_VER_RES
|
||||
#define R61581_HSPL 0 /*HSYNC signal polarity*/
|
||||
#define R61581_HSL 10 /*HSYNC length (Not Implemented)*/
|
||||
#define R61581_HFP 10 /*Horitontal Front poarch (Not Implemented)*/
|
||||
#define R61581_HBP 10 /*Horitontal Back poarch (Not Implemented */
|
||||
#define R61581_VSPL 0 /*VSYNC signal polarity*/
|
||||
#define R61581_VSL 10 /*VSYNC length (Not Implemented)*/
|
||||
#define R61581_VFP 8 /*Vertical Front poarch*/
|
||||
#define R61581_VBP 8 /*Vertical Back poarch */
|
||||
#define R61581_DPL 0 /*DCLK signal polarity*/
|
||||
#define R61581_EPL 1 /*ENABLE signal polarity*/
|
||||
#define R61581_ORI 0 /*0, 180*/
|
||||
#define R61581_LV_COLOR_DEPTH 16 /*Fix 16 bit*/
|
||||
#endif
|
||||
|
||||
/*------------------------------
|
||||
* ST7565 (Monochrome, low res.)
|
||||
*-----------------------------*/
|
||||
#define USE_ST7565 0
|
||||
#if USE_ST7565 != 0
|
||||
/*No settings*/
|
||||
#endif /*USE_ST7565*/
|
||||
|
||||
/*-----------------------------------------
|
||||
* Linux frame buffer device (/dev/fbx)
|
||||
*-----------------------------------------*/
|
||||
#define USE_FBDEV 1
|
||||
#if USE_FBDEV != 0
|
||||
#define FBDEV_PATH "/dev/fb0"
|
||||
#endif
|
||||
|
||||
/*====================
|
||||
* Input devices
|
||||
*===================*/
|
||||
|
||||
/*--------------
|
||||
* XPT2046
|
||||
*--------------*/
|
||||
#define USE_XPT2046 0
|
||||
#if USE_XPT2046 != 0
|
||||
#define XPT2046_HOR_RES 480
|
||||
#define XPT2046_VER_RES 320
|
||||
#define XPT2046_X_MIN 200
|
||||
#define XPT2046_Y_MIN 200
|
||||
#define XPT2046_X_MAX 3800
|
||||
#define XPT2046_Y_MAX 3800
|
||||
#define XPT2046_AVG 4
|
||||
#define XPT2046_INV 0
|
||||
#endif
|
||||
|
||||
/*-----------------
|
||||
* FT5406EE8
|
||||
*-----------------*/
|
||||
#define USE_FT5406EE8 0
|
||||
#if USE_FT5406EE8
|
||||
#define FT5406EE8_I2C_ADR 0x38 /*7 bit address*/
|
||||
#endif
|
||||
|
||||
/*---------------
|
||||
* AD TOUCH
|
||||
*--------------*/
|
||||
#define USE_AD_TOUCH 0
|
||||
#if USE_AD_TOUCH != 0
|
||||
/*No settings*/
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------
|
||||
* Mouse or touchpad on PC (using SDL)
|
||||
*-------------------------------------*/
|
||||
#define USE_MOUSE 1
|
||||
#if USE_MOUSE
|
||||
/*No settings*/
|
||||
#endif
|
||||
/*-------------------------------------------
|
||||
* Mousewheel as encoder on PC (using SDL)
|
||||
*------------------------------------------*/
|
||||
#define USE_MOUSEWHEEL 0
|
||||
#if USE_MOUSEWHEEL
|
||||
/*No settings*/
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------
|
||||
* Mouse or touchpad as evdev interface (for Linux based systems)
|
||||
*------------------------------------------------*/
|
||||
#define USE_EVDEV 0
|
||||
#if USE_EVDEV
|
||||
#define EVDEV_NAME "/dev/input/event0" /*You can use the "evtest" Linux tool to get the list of devices and test them*/
|
||||
#define EVDEV_SWAP_AXES 0 /*Swap the x and y axes of the touchscreen*/
|
||||
|
||||
#define EVDEV_SCALE 0 /* Scale input, e.g. if touchscreen resolution does not match display resolution */
|
||||
#if EVDEV_SCALE
|
||||
#define EVDEV_SCALE_HOR_RES (4096) /* Horizontal resolution of touchscreen */
|
||||
#define EVDEV_SCALE_VER_RES (4096) /* Vertical resolution of touchscreen */
|
||||
#endif /*EVDEV_SCALE*/
|
||||
|
||||
#define EVDEV_CALIBRATE 0 /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
|
||||
#if EVDEV_CALIBRATE
|
||||
#define EVDEV_HOR_MIN 3800 /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
|
||||
#define EVDEV_HOR_MAX 200
|
||||
#define EVDEV_VER_MIN 200
|
||||
#define EVDEV_VER_MAX 3800
|
||||
#endif /*EVDEV_SCALE*/
|
||||
#endif /*USE_EVDEV*/
|
||||
|
||||
/*-------------------------------
|
||||
* Keyboard of a PC (using SDL)
|
||||
*------------------------------*/
|
||||
#define USE_KEYBOARD 0
|
||||
#if USE_KEYBOARD
|
||||
/*No settings*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRV_CONF_H*/
|
||||
|
||||
#endif /*End of "Content enable"*/
|
||||
@ -1,76 +0,0 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include "../../lib/lv_bindings/lvgl/lvgl.h"
|
||||
#include "monitor.h"
|
||||
#include "mouse.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/obj.h"
|
||||
|
||||
STATIC mp_obj_t mp_lv_task_handler(mp_obj_t arg)
|
||||
{
|
||||
lv_task_handler();
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_lv_task_handler_obj, mp_lv_task_handler);
|
||||
|
||||
/**
|
||||
* A task to measure the elapsed time for LittlevGL
|
||||
* @param data unused
|
||||
* @return never return
|
||||
*/
|
||||
static int tick_thread(void * data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
while(1) {
|
||||
SDL_Delay(5); /*Sleep for 5 millisecond*/
|
||||
lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/
|
||||
mp_sched_schedule((mp_obj_t)&mp_lv_task_handler_obj, mp_const_none);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library
|
||||
*/
|
||||
static void hal_init(void)
|
||||
{
|
||||
/* Add a display
|
||||
* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
|
||||
monitor_init();
|
||||
lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
|
||||
disp_drv.disp_flush = monitor_flush; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/
|
||||
disp_drv.disp_fill = monitor_fill; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/
|
||||
disp_drv.disp_map = monitor_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/
|
||||
lv_disp_drv_register(&disp_drv);
|
||||
|
||||
/* Add the mouse as input device
|
||||
* Use the 'mouse' driver which reads the PC's mouse*/
|
||||
mouse_init();
|
||||
lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read = mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
|
||||
/*Set a cursor for the mouse*/
|
||||
// LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
|
||||
// lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL); /*Create an image object for the cursor */
|
||||
// lv_img_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/
|
||||
// lv_indev_set_cursor(mouse_indev, cursor_obj); /*Connect the image object to the driver*/
|
||||
|
||||
/* Tick init.
|
||||
* You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed
|
||||
* Create an SDL thread to do this*/
|
||||
SDL_CreateThread(tick_thread, "tick", NULL);
|
||||
}
|
||||
|
||||
|
||||
void lv_mp_init(void)
|
||||
{
|
||||
lv_init();
|
||||
hal_init();
|
||||
}
|
||||
|
||||
@ -1,337 +0,0 @@
|
||||
/**
|
||||
* @file monitor.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "monitor.h"
|
||||
#if USE_MONITOR
|
||||
|
||||
#ifndef MONITOR_SDL_INCLUDE_PATH
|
||||
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include MONITOR_SDL_INCLUDE_PATH
|
||||
#include "lv_core/lv_vdb.h"
|
||||
#include "mouse.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define SDL_REFR_PERIOD 50 /*ms*/
|
||||
|
||||
#ifndef MONITOR_ZOOM
|
||||
#define MONITOR_ZOOM 1
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && defined(TARGET_OS_MAC)
|
||||
# if __APPLE__ && TARGET_OS_MAC
|
||||
#define MONITOR_APPLE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static int monitor_sdl_refr_thread(void * param);
|
||||
|
||||
|
||||
/***********************
|
||||
* GLOBAL PROTOTYPES
|
||||
***********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static SDL_Window * window;
|
||||
static SDL_Renderer * renderer;
|
||||
static SDL_Texture * texture;
|
||||
static uint32_t tft_fb[MONITOR_HOR_RES * MONITOR_VER_RES];
|
||||
static volatile bool sdl_inited = false;
|
||||
static volatile bool sdl_refr_qry = false;
|
||||
static volatile bool sdl_quit_qry = false;
|
||||
|
||||
int quit_filter(void * userdata, SDL_Event * event);
|
||||
static void monitor_sdl_clean_up(void);
|
||||
static void monitor_sdl_init(void);
|
||||
static void monitor_sdl_refr_core(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the monitor
|
||||
*/
|
||||
void monitor_init(void)
|
||||
{
|
||||
/*OSX needs to initialize SDL here*/
|
||||
#ifdef MONITOR_APPLE
|
||||
monitor_sdl_init();
|
||||
#endif
|
||||
|
||||
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
|
||||
while(sdl_inited == false); /*Wait until 'sdl_refr' initializes the SDL*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flush a buffer to the display. Calls 'lv_flush_ready()' when finished
|
||||
* @param x1 left coordinate
|
||||
* @param y1 top coordinate
|
||||
* @param x2 right coordinate
|
||||
* @param y2 bottom coordinate
|
||||
* @param color_p array of colors to be flushed
|
||||
*/
|
||||
void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
|
||||
{
|
||||
/*Return if the area is out the screen*/
|
||||
if(x2 < 0 || y2 < 0 || x1 > MONITOR_HOR_RES - 1 || y1 > MONITOR_VER_RES - 1) {
|
||||
lv_flush_ready();
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t y;
|
||||
#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 /*32 is valid but support 24 for backward compatibility too*/
|
||||
int32_t x;
|
||||
for(y = y1; y <= y2; y++) {
|
||||
for(x = x1; x <= x2; x++) {
|
||||
tft_fb[y * MONITOR_HOR_RES + x] = lv_color_to32(*color_p);
|
||||
color_p++;
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
uint32_t w = x2 - x1 + 1;
|
||||
for(y = y1; y <= y2; y++) {
|
||||
memcpy(&tft_fb[y * MONITOR_HOR_RES + x1], color_p, w * sizeof(lv_color_t));
|
||||
|
||||
color_p += w;
|
||||
}
|
||||
#endif
|
||||
|
||||
sdl_refr_qry = true;
|
||||
|
||||
/*IMPORTANT! It must be called to tell the system the flush is ready*/
|
||||
lv_flush_ready();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fill out the marked area with a color
|
||||
* @param x1 left coordinate
|
||||
* @param y1 top coordinate
|
||||
* @param x2 right coordinate
|
||||
* @param y2 bottom coordinate
|
||||
* @param color fill color
|
||||
*/
|
||||
void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
|
||||
{
|
||||
/*Return if the area is out the screen*/
|
||||
if(x2 < 0) return;
|
||||
if(y2 < 0) return;
|
||||
if(x1 > MONITOR_HOR_RES - 1) return;
|
||||
if(y1 > MONITOR_VER_RES - 1) return;
|
||||
|
||||
/*Truncate the area to the screen*/
|
||||
int32_t act_x1 = x1 < 0 ? 0 : x1;
|
||||
int32_t act_y1 = y1 < 0 ? 0 : y1;
|
||||
int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2;
|
||||
int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2;
|
||||
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
uint32_t color32 = lv_color_to32(color);
|
||||
|
||||
for(x = act_x1; x <= act_x2; x++) {
|
||||
for(y = act_y1; y <= act_y2; y++) {
|
||||
tft_fb[y * MONITOR_HOR_RES + x] = color32;
|
||||
}
|
||||
}
|
||||
|
||||
sdl_refr_qry = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a color map to the marked area
|
||||
* @param x1 left coordinate
|
||||
* @param y1 top coordinate
|
||||
* @param x2 right coordinate
|
||||
* @param y2 bottom coordinate
|
||||
* @param color_p an array of colors
|
||||
*/
|
||||
void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
|
||||
{
|
||||
/*Return if the area is out the screen*/
|
||||
if(x2 < 0) return;
|
||||
if(y2 < 0) return;
|
||||
if(x1 > MONITOR_HOR_RES - 1) return;
|
||||
if(y1 > MONITOR_VER_RES - 1) return;
|
||||
|
||||
/*Truncate the area to the screen*/
|
||||
int32_t act_x1 = x1 < 0 ? 0 : x1;
|
||||
int32_t act_y1 = y1 < 0 ? 0 : y1;
|
||||
int32_t act_x2 = x2 > MONITOR_HOR_RES - 1 ? MONITOR_HOR_RES - 1 : x2;
|
||||
int32_t act_y2 = y2 > MONITOR_VER_RES - 1 ? MONITOR_VER_RES - 1 : y2;
|
||||
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
|
||||
for(y = act_y1; y <= act_y2; y++) {
|
||||
for(x = act_x1; x <= act_x2; x++) {
|
||||
tft_fb[y * MONITOR_HOR_RES + x] = lv_color_to32(*color_p);
|
||||
color_p++;
|
||||
}
|
||||
|
||||
color_p += x2 - act_x2;
|
||||
}
|
||||
|
||||
sdl_refr_qry = true;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* SDL main thread. All SDL related task have to be handled here!
|
||||
* It initializes SDL, handles drawing and the mouse.
|
||||
*/
|
||||
|
||||
static int monitor_sdl_refr_thread(void * param)
|
||||
{
|
||||
(void)param;
|
||||
|
||||
/*If not OSX initialize SDL in the Thread*/
|
||||
#ifndef MONITOR_APPLE
|
||||
monitor_sdl_init();
|
||||
#endif
|
||||
|
||||
/*Run until quit event not arrives*/
|
||||
while(sdl_quit_qry == false) {
|
||||
/*Refresh handling*/
|
||||
monitor_sdl_refr_core();
|
||||
}
|
||||
|
||||
monitor_sdl_clean_up();
|
||||
exit(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int quit_filter(void * userdata, SDL_Event * event)
|
||||
{
|
||||
(void)userdata;
|
||||
|
||||
if(event->type == SDL_QUIT) {
|
||||
sdl_quit_qry = true;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void monitor_sdl_clean_up(void)
|
||||
{
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
static void monitor_sdl_init(void)
|
||||
{
|
||||
/*Initialize the SDL*/
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
SDL_SetEventFilter(quit_filter, NULL);
|
||||
|
||||
window = SDL_CreateWindow("TFT Simulator",
|
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
|
||||
|
||||
#if MONITOR_VIRTUAL_MACHINE
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
|
||||
#else
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
#endif
|
||||
texture = SDL_CreateTexture(renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, MONITOR_VER_RES);
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
/*Initialize the frame buffer to gray (77 is an empirical value) */
|
||||
memset(tft_fb, 77, MONITOR_HOR_RES * MONITOR_VER_RES * sizeof(uint32_t));
|
||||
SDL_UpdateTexture(texture, NULL, tft_fb, MONITOR_HOR_RES * sizeof(uint32_t));
|
||||
sdl_refr_qry = true;
|
||||
sdl_inited = true;
|
||||
}
|
||||
|
||||
void lv_task_handler(void);
|
||||
|
||||
static void monitor_sdl_refr_core(void)
|
||||
{
|
||||
// lv_task_handler() ;
|
||||
if(sdl_refr_qry != false) {
|
||||
sdl_refr_qry = false;
|
||||
SDL_UpdateTexture(texture, NULL, tft_fb, MONITOR_HOR_RES * sizeof(uint32_t));
|
||||
SDL_RenderClear(renderer);
|
||||
/*Test: Draw a background to test transparent screens (LV_COLOR_SCREEN_TRANSP)*/
|
||||
// SDL_SetRenderDrawColor(renderer, 0xff, 0, 0, 0xff);
|
||||
// SDL_Rect r;
|
||||
// r.x = 0; r.y = 0; r.w = MONITOR_HOR_RES; r.w = MONITOR_VER_RES;
|
||||
// SDL_RenderDrawRect(renderer, &r);
|
||||
|
||||
/*Update the renderer with the texture containing the rendered image*/
|
||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
#ifndef MONITOR_APPLE
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
#if USE_MOUSE != 0
|
||||
mouse_handler(&event);
|
||||
#endif
|
||||
|
||||
#if USE_MOUSEWHEEL != 0
|
||||
mousewheel_handler(&event);
|
||||
#endif
|
||||
|
||||
#if USE_KEYBOARD
|
||||
keyboard_handler(&event);
|
||||
#endif
|
||||
if((&event)->type == SDL_WINDOWEVENT) {
|
||||
switch((&event)->window.event) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
||||
case SDL_WINDOWEVENT_TAKE_FOCUS:
|
||||
#endif
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
SDL_UpdateTexture(texture, NULL, tft_fb, MONITOR_HOR_RES * sizeof(uint32_t));
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /*MONITOR_APPLE*/
|
||||
|
||||
/*Sleep some time*/
|
||||
SDL_Delay(SDL_REFR_PERIOD);
|
||||
|
||||
}
|
||||
|
||||
#endif /*USE_MONITOR*/
|
||||
@ -1,52 +0,0 @@
|
||||
/**
|
||||
* @file monitor.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MONITOR_H
|
||||
#define MONITOR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "lv_drv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_MONITOR
|
||||
|
||||
#include "lv_misc/lv_color.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void monitor_init(void);
|
||||
void monitor_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t *color_p);
|
||||
void monitor_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
|
||||
void monitor_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* USE_MONITOR */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* MONITOR_H */
|
||||
@ -1,95 +0,0 @@
|
||||
/**
|
||||
* @file mouse.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "mouse.h"
|
||||
#if USE_MOUSE != 0
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef MONITOR_ZOOM
|
||||
#define MONITOR_ZOOM 1
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static bool left_button_down = false;
|
||||
static int16_t last_x = 0;
|
||||
static int16_t last_y = 0;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the mouse
|
||||
*/
|
||||
void mouse_init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current position and state of the mouse
|
||||
* @param data store the mouse data here
|
||||
* @return false: because the points are not buffered, so no more data to be read
|
||||
*/
|
||||
bool mouse_read(lv_indev_data_t * data)
|
||||
{
|
||||
/*Store the collected data*/
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
data->state = left_button_down ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* It will be called from the main SDL thread
|
||||
*/
|
||||
void mouse_handler(SDL_Event * event)
|
||||
{
|
||||
switch(event->type) {
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if(event->button.button == SDL_BUTTON_LEFT)
|
||||
left_button_down = false;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if(event->button.button == SDL_BUTTON_LEFT) {
|
||||
left_button_down = true;
|
||||
last_x = event->motion.x / MONITOR_ZOOM;
|
||||
last_y = event->motion.y / MONITOR_ZOOM;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
last_x = event->motion.x / MONITOR_ZOOM;
|
||||
last_y = event->motion.y / MONITOR_ZOOM;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif
|
||||
@ -1,73 +0,0 @@
|
||||
/**
|
||||
* @file mouse.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MOUSE_H
|
||||
#define MOUSE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_drv_conf.h"
|
||||
#else
|
||||
#include "lv_drv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_MOUSE
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include "lv_hal/lv_hal_indev.h"
|
||||
|
||||
|
||||
#ifndef MONITOR_SDL_INCLUDE_PATH
|
||||
#define MONITOR_SDL_INCLUDE_PATH <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#include MONITOR_SDL_INCLUDE_PATH
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the mouse
|
||||
*/
|
||||
void mouse_init(void);
|
||||
/**
|
||||
* Get the current position and state of the mouse
|
||||
* @param data store the mouse data here
|
||||
* @return false: because the points are not buffered, so no more data to be read
|
||||
*/
|
||||
bool mouse_read(lv_indev_data_t * data);
|
||||
|
||||
/**
|
||||
* It will be called from the main SDL thread
|
||||
*/
|
||||
void mouse_handler(SDL_Event *event);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* USE_MOUSE */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* MOUSE_H */
|
||||
@ -116,6 +116,7 @@
|
||||
#define MICROPY_STACKLESS_STRICT (0)
|
||||
#endif
|
||||
|
||||
#define MICROPY_PY_LVGL (1)
|
||||
#define MICROPY_PY_OS_STATVFS (1)
|
||||
#define MICROPY_PY_UTIME (1)
|
||||
#define MICROPY_PY_UTIME_MP_HAL (1)
|
||||
@ -220,6 +221,13 @@ extern const struct _mp_obj_module_t mp_module_lvgl;
|
||||
#else
|
||||
#define MICROPY_PY_USELECT_DEF
|
||||
#endif
|
||||
#if MICROPY_PY_LVGL
|
||||
#include "lib/lv_bindings/lvgl/lv_misc/lv_gc.h"
|
||||
#define MICROPY_PY_LVGL_DEF { MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl },
|
||||
#else
|
||||
#define LV_ROOTS
|
||||
#define MICROPY_PY_LVGL_DEF
|
||||
#endif
|
||||
|
||||
#define MICROPY_PORT_BUILTIN_MODULES \
|
||||
MICROPY_PY_FFI_DEF \
|
||||
@ -230,7 +238,7 @@ extern const struct _mp_obj_module_t mp_module_lvgl;
|
||||
MICROPY_PY_UOS_DEF \
|
||||
MICROPY_PY_USELECT_DEF \
|
||||
MICROPY_PY_TERMIOS_DEF \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl }, \
|
||||
MICROPY_PY_LVGL_DEF \
|
||||
|
||||
// type definitions for the specific machine
|
||||
|
||||
@ -296,7 +304,6 @@ void mp_unix_mark_exec(void);
|
||||
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
|
||||
|
||||
#define MP_STATE_PORT MP_STATE_VM
|
||||
#include "lib/lv_bindings/lvgl/lv_misc/lv_gc.h"
|
||||
#define MICROPY_PORT_ROOT_POINTERS \
|
||||
LV_ROOTS \
|
||||
const char *readline_hist[50]; \
|
||||
|
||||
6
py/py.mk
6
py/py.mk
@ -122,15 +122,15 @@ endif
|
||||
#LittlevGL
|
||||
LVGL_BINDING_DIR = $(TOP)/lib/lv_bindings
|
||||
LVGL_DIR = $(LVGL_BINDING_DIR)/lvgl
|
||||
INC += -I$(LVGL_DIR) -I$(LVGL_BINDING_DIR)/micropython/include
|
||||
INC += -I$(LVGL_DIR) -I$(LVGL_BINDING_DIR)/include
|
||||
ALL_LVGL_SRC = $(shell find $(LVGL_DIR) -type f) $(TOP)/lib/lv_conf.h
|
||||
LVGL_MPY = $(BUILD)/lvgl/lv_mpy.c
|
||||
QSTR_GLOBAL_DEPENDENCIES += $(LVGL_MPY)
|
||||
|
||||
$(LVGL_MPY): $(ALL_LVGL_SRC)
|
||||
$(LVGL_MPY): $(ALL_LVGL_SRC) $(LVGL_BINDING_DIR)/gen/gen_mpy.py
|
||||
$(ECHO) "LVGL-GEN $@"
|
||||
$(Q)mkdir -p $(dir $@)
|
||||
$(Q)$(PYTHON) $(LVGL_BINDING_DIR)/micropython/gen_mpy.py -X anim -X group -X task $(INC) -I $(LVGL_BINDING_DIR)/micropython/pycparser/utils/fake_libc_include $(LVGL_DIR)/lvgl.h > $@
|
||||
$(Q)$(PYTHON) $(LVGL_BINDING_DIR)/gen/gen_mpy.py -X anim -X group -X task $(INC) -I $(LVGL_BINDING_DIR)/pycparser/utils/fake_libc_include $(LVGL_DIR)/lvgl.h > $@
|
||||
|
||||
CFLAGS_MOD += -Wno-unused-function
|
||||
SRC_MOD += $(subst $(TOP)/,,$(shell find $(LVGL_DIR) -type f -name "*.c") $(LVGL_MPY))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user