reloj lvgl esp32 — Xiao Esp32 S3 simulation

An interactive Xiao Esp32 S3 circuit simulation you can run free in your browser on Velxio, by dave.

Components

Sketch code

// Reloj - XIAO ESP32-S3 + Round Display for XIAO (GC9A01 240x240)
//
// D8=SCK  D10=MOSI  D9=MISO  D1=LCD CS  D3=LCD DC  (RST = reset placa)
// D4/D5 = I2C (tactil CHSC6X + RTC PCF8563)   D2 = microSD CS
// El panel GC9A01 del simulador habla el dialecto de comandos ILI9341.
//
//   USE_LVGL 1 -> interfaz construida con LVGL (arc + labels)
//   USE_LVGL 0 -> mismo reloj dibujado directo con Adafruit_GFX
#define USE_LVGL 0

#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#if USE_LVGL
#include <lvgl.h>
#endif

#define TFT_CS    D1
#define TFT_DC    D3
#define TFT_SCK   D8
#define TFT_MISO  D9
#define TFT_MOSI  D10

#define SCR_W 240
#define SCR_H 240
#define CX    120
#define CY    120

SPIClass tftSPI(FSPI);
Adafruit_ILI9341 tft(&tftSPI, TFT_DC, TFT_CS, -1);

// Hora de arranque (sin NTP: se cuenta con millis())
static int hh = 10;
static int mm = 9;
static int ss = 0;
static const char *fechaTexto = "VIE 28 AGO";

#if USE_LVGL
// ============================ version LVGL ============================
#define LVBUF_LINES 40
static lv_color_t lvBuf[SCR_W * LVBUF_LINES];

static lv_obj_t *arcSeg;
static lv_obj_t *lblHora;
static lv_obj_t *lblSeg;
static lv_obj_t *lblFecha;

// Volcado por bloques (setAddrWindow + writePixels): los caminos pixel
// a pixel de Adafruit_GFX son ~20x mas lentos dentro del emulador.
#if LVGL_VERSION_MAJOR >= 9
static void flushDisplay(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map) {
  uint32_t w = area->x2 - area->x1 + 1;
  uint32_t h = area->y2 - area->y1 + 1;
  tft.startWrite();
  tft.setAddrWindow(area->x1, area->y1, w, h);
  tft.writePixels((uint16_t *)px_map, w * h, true, false);
  tft.endWrite();
  lv_display_flush_ready(disp);
}
#else
static void flushDisplay(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p) {
  uint32_t w = area->x2 - area->x1 + 1;
  uint32_t h = area->y2 - area->y1 + 1;
  tft.startWrite();
  tft.setAddrWindow(area->x1, area->y1, w, h);
  tft.writePixels((uint16_t *)color_p, w * h, true, false);
  tft.endWrite();
  lv_disp_flush_ready(drv);
}

static lv_disp_draw_buf_t drawBuf;
static lv_disp_drv_t dispDrv;
#endif

static void construirUI() {
  lv_obj_t *scr = lv_scr_act();
  lv_obj_set_style_bg_color(scr, lv_color_hex(0x05070D), LV_PART_MAIN);
  lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, LV_PART_MAIN);

  arcSeg = lv_arc_create(scr);
  lv_obj_set_size(arcSeg, 228, 228);
  lv_obj_center(arcSeg);
  lv_arc_set_rotation(arcSeg, 270);
  lv_arc_set_bg_angles(arcSeg, 0, 360);
  lv_arc_set_range(arcSeg, 0, 60);
  lv_arc_set_value(arcSeg, 0);
  lv_obj_remove_style(arcSeg, NULL, LV_PART_KNOB);
  lv_obj_clear_flag(arcSeg, LV_OBJ_FLAG_CLICKABLE);
  lv_obj_set_style_arc_width(arcSeg, 8, LV_PART_MAIN);
  lv_obj_set_style_arc_width(arcSeg, 8, LV_PART_INDICATOR);
  lv_obj_set_style_arc_color(arcSeg, lv_color_hex(0x1B2233), LV_PART_MAIN);
  lv_obj_set_style_arc_color(arcSeg, lv_color_hex(0x00E5A0), LV_PART_INDICATOR);

  lblHora = lv_label_

More projects by dave