Skip to content

Commit

Permalink
Merge pull request #68 from fbiego/esp32
Browse files Browse the repository at this point in the history
esp32 support
  • Loading branch information
fbiego authored Dec 3, 2024
2 parents a111bc6 + 4597dd7 commit 3875e8c
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 0 deletions.
99 changes: 99 additions & 0 deletions hal/esp32/app_hal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

#include "app_hal.h"
#include "lvgl.h"
#include "PanelLan.h"


/* Set the board type. (Uses LovyanGFX internally to manage display drivers) */
PanelLan tft(BOARD_SC01_PLUS);

static const uint32_t screenWidth = 480;
static const uint32_t screenHeight = 320;

const unsigned int lvBufferSize = screenWidth * 30;
uint8_t lvBuffer[2][lvBufferSize];

static lv_display_t *lvDisplay;
static lv_indev_t *lvInput;

#if LV_USE_LOG != 0
static void lv_log_print_g_cb(lv_log_level_t level, const char *buf)
{
LV_UNUSED(level);
LV_UNUSED(buf);
}
#endif

/* Display flushing */
void my_disp_flush(lv_display_t *display, const lv_area_t *area, unsigned char *data)
{

uint32_t w = lv_area_get_width(area);
uint32_t h = lv_area_get_height(area);
lv_draw_sw_rgb565_swap(data, w * h);

if (tft.getStartCount() == 0)
{
tft.endWrite();
}
tft.pushImageDMA(area->x1, area->y1, area->x2 - area->x1 + 1, area->y2 - area->y1 + 1, (uint16_t *)data);
lv_display_flush_ready(display); /* tell lvgl that flushing is done */
}

/*Read the touchpad*/
void my_touchpad_read(lv_indev_t *indev_driver, lv_indev_data_t *data)
{
uint16_t touchX, touchY;
bool touched = tft.getTouch(&touchX, &touchY);
if (!touched)
{
data->state = LV_INDEV_STATE_REL;
}
else
{
data->state = LV_INDEV_STATE_PR;
/*Set the coordinates*/
data->point.x = touchX;
data->point.y = touchY;
}
}

/* Tick source, tell LVGL how much time (milliseconds) has passed */
static uint32_t my_tick(void)
{
return millis();
}

void hal_setup(void)
{

/* Initialize the display drivers */
tft.init();
tft.initDMA();
tft.startWrite();
tft.fillScreen(TFT_BLACK);

/* Set display rotation to landscape */
tft.setRotation(1);

/* Set the tick callback */
lv_tick_set_cb(my_tick);

/* Create LVGL display and set the flush function */
lvDisplay = lv_display_create(screenWidth, screenHeight);
lv_display_set_color_format(lvDisplay, LV_COLOR_FORMAT_RGB565);
lv_display_set_flush_cb(lvDisplay, my_disp_flush);
lv_display_set_buffers(lvDisplay, lvBuffer[0], lvBuffer[1], lvBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

/* Set the touch input function */
lvInput = lv_indev_create();
lv_indev_set_type(lvInput, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(lvInput, my_touchpad_read);
}

void hal_loop(void)
{
/* NO while loop in this function! (handled by framework) */
lv_timer_handler(); // Update the UI-
delay(5);
}
27 changes: 27 additions & 0 deletions hal/esp32/app_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef APP_HAL_H
#define APP_HAL_H

#ifdef __cplusplus
extern "C" {
#endif


/**
* This function runs once and typically includes:
* - Setting up display drivers.
* - Configuring LVGL display and input devices
*/
void hal_setup(void);

/**
* This function is continuously executed and typically includes:
* - Updating LVGL's internal state & UI.
*/
void hal_loop(void);


#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*APP_HAL_H*/
18 changes: 18 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,21 @@ build_src_filter =
+<../hal/stm32f429_disco>
; Force compile LVGL demo, remove when working on your own project
+<../.pio/libdeps/stm32f429_disco/lvgl/demos>

[env:esp32_sc01_plus]
platform = espressif32
board = esp32-s3-devkitm-1
framework = arduino
build_flags =
${env.build_flags}
-D LV_LOG_LEVEL=LV_LOG_LEVEL_NONE
; Add recursive dirs for hal headers search
!python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/esp32')]))"
lib_deps =
${env.lib_deps}
smartpanle/PanelLan@^0.0.1
build_src_filter =
+<*>
+<../hal/esp32>
; Force compile LVGL demo, remove when working on your own project
+<../.pio/libdeps/esp32_sc01_plus/lvgl/demos>
17 changes: 17 additions & 0 deletions src/main.c → src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@

#include "demos/lv_demos.h"

#ifdef ARDUINO
#include <Arduino.h>

void setup() {
lv_init();
hal_setup();
lv_demo_widgets();
}

void loop() {
hal_loop(); /* Do not use while loop in this function */
}

#else

int main(void)
{
lv_init();
Expand All @@ -24,3 +39,5 @@ int main(void)

hal_loop();
}

#endif /*ARDUINO*/

0 comments on commit 3875e8c

Please sign in to comment.