# abaschen/lilygo-epd47 architecture

> Architecture diagram of the GitHub repository abaschen/lilygo-epd47, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abaschen/lilygo-epd47
- Repository: https://github.com/abaschen/lilygo-epd47

## Overview

##### Project Type and Purpose
- This is an embedded‐firmware and driver library project for the LilyGo EPD47 e-paper display, targeting the ESP32-S3 SoC.
- It provides low-level drivers, image and font handling, compression (zlib), JPEG decoding, plus Arduino/PlatformIO examples, documentation, CI workflows, schematics and mechanical shells.

##### Top-Level Components
A. Hardware Platform
- ESP32-S3 module (16 MB QSPI flash, 8 MB OPI PSRAM)
- EPD47 e-paper panel (SPI-like parallel bus, control signals CKV, STH, CKH)
- Touch panel sensor (via I2C + IRQ)
- User button (GPIO wakeup)
- Optional SD-card interface (SPI signals)
- GPIO breakout for free pins
B. Firmware/Software Layers
- Build system (PlatformIO / ESP-IDF via CMakeLists.txt & component.mk)
- Driver layer (`src/epd_driver.*`, `i2s_data_bus.*`, `rmt_pulse.*`)
- Image codec libraries (`src/libjpeg`, `src/zlib`)
- Font & waveform data (`Waveform_header`, `src/font.c`, `src/firasans.h`)
- Utility code (`src/utilities.h`)
- Touch handling (`src/touch.*`)
- Example applications (Arduino sketches in `examples/`)
C. Tooling & CI
- Image/font conversion scripts (`scripts/`)
- Documentation (Sphinx under `docs/`)
- CI workflows (.github/workflows for Arduino CI, PlatformIO CI)
D. Assets & Docs
- Schematics (`schematic/`)
- Mechanical shell designs (`shell/`)
- Datasheet (`datasheet/ED047TC1.pdf`)
- Metadata (`library.json`, `library.properties`)

##### Interactions and Data Flow
- Developer edits /examples or library code → Build system compiles via PlatformIO/ESP-IDF → Firmware image → Flashed onto ESP32-S3 → On power-up, firmware initializes hardware buses (I2S/RMT/SPI/I2C), loads waveform tables, invokes EPD driver to update display
- Script tools preprocess images/fonts into C headers → Embedded in firmware
- User interaction (button, touch) → GPIO/IRQ → touch driver → application logic → triggers screen update
- Optional SD‐card reads assets via SPI → image codec modules decompress (zlib/jpg) → pass to driver

##### Architectural Patterns & Principles
- Layered architecture: Hardware Abstraction → Driver Modules → Codec & Utility Libraries → Application Examples
- Component‐based build (ESP-IDF or PlatformIO components)
- Separation of concerns: low-level timing (RMT/I2S), high-level image processing, user-facing examples
- Reusability: common waveform headers, generic font conversion

##### Essential Elements
- Clear component names and roles
- Related files/folders under each module to convey structure
- CI workflows tied to GitHub repo

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Platform
    subgraph "Hardware Platform"
        ESP32["ESP32-S3 Module"]:::hardware
        Flash["16MB QSPI Flash"]:::hardware
        PSRAM["8MB OPI PSRAM"]:::hardware
        EPD["EPD47 E-paper Panel"]:::hardware
        TouchHW["Touch Panel Sensor"]:::hardware
        Button["User Button (GPIO)"]:::hardware
        SDCard["Optional SD-Card"]:::hardware
        GPIO["GPIO Breakout"]:::hardware
        ESP32 -->|QSPI| Flash
        ESP32 -->|OPI| PSRAM
        ESP32 -->|SPI| EPD
        ESP32 -->|I2C + IRQ| TouchHW
        ESP32 -->|GPIO| Button
        ESP32 -->|SPI| SDCard
        ESP32 -->|GPIO| GPIO
    end

    %% Firmware Modules
    subgraph "Firmware Modules"
        subgraph "Driver Layer"
            EPDDrvC["epd_driver.c"]:::firmware
            EPDDrvH["epd_driver.h"]:::firmware
            I2SC["i2s_data_bus.c"]:::firmware
            I2SH["i2s_data_bus.h"]:::firmware
            RMTC["rmt_pulse.c"]:::firmware
            RMTH["rmt_pulse.h"]:::firmware
        end
        subgraph "Image Codec Libraries"
            JPEG["JPEG Decoder"]:::firmware
            Zlib["Zlib Compression"]:::firmware
        end
        subgraph "Font & Waveform"
            Waveform["ED047TC2.h"]:::firmware
            FontC["font.c"]:::firmware
            FontH["firasans.h"]:::firmware
        end
        Utils["utilities.h"]:::firmware
        TouchDrvC["touch.cpp"]:::firmware
        TouchDrvH["touch.h"]:::firmware
        Examples["Example Applications"]:::firmware
        %% Dependencies
        Examples -->|uses| EPDDrvC
        Examples -->|uses| Utils
        EPDDrvC -->|includes| Waveform
        EPDDrvC -->|calls| I2SC
        EPDDrvC -->|calls| RMTC
        JPEG -->|linked| Examples
        Zlib -->|linked| Examples
        TouchDrvC -->|interfaces| TouchHW
    end

    %% Build & Tooling
    subgraph "Build & Tooling"
        PlatformIO["platformio.ini"]:::tooling
        CMake["src/CMakeLists.txt"]:::tooling
        CompMk["src/component.mk"]:::tooling
        ConfMk["component_conf.mk"]:::tooling
        ImgConv["imgconvert.py"]:::tooling
        FontConv["fontconvert.py"]:::tooling
        Docs["Sphinx Docs"]:::tooling
        RTD[".readthedocs.yml"]:::tooling
        ArduinoCI["arduino_ci.yml"]:::tooling
        PlatformioCI["platformio.yml"]:::tooling
        IssuesCI["issues.yaml"]:::tooling
        LibraryJSON["library.json"]:::tooling
        LibraryProp["library.properties"]:::tooling
        Scripts["scripts/"]:::tooling
        CI[".github/workflows/"]:::tooling
        Docs -->|config| RTD
        CI -->|includes| ArduinoCI
        CI -->|includes| PlatformioCI
        CI -->|includes| IssuesCI
        Scripts -->|contains| ImgConv
        Scripts -->|contains| FontConv
    end

    %% Assets & Docs
    subgraph "Assets & Documentation"
        Datasheet["ED047TC1.pdf"]:::hardware
        Schematic["Schematics"]:::hardware
        Shell["Mechanical Shells"]:::hardware
    end

    %% Build Pipeline
    subgraph "Build Pipeline"
        Source["Source Code"]:::firmware
        Compiler["PlatformIO / ESP-IDF"]:::tooling
        FirmwareBin["Firmware Image"]:::firmware
        FlashTool["Flash Tool"]:::tooling
        Device["ESP32-S3 Device"]:::hardware
        Source -->|compile| Compiler
        Compiler -->|outputs| FirmwareBin
        FirmwareBin -->|flash| FlashTool
        FlashTool -->|writes| Device
    end

    %% Preprocessing
    ImgConv -->|generates| Waveform
    FontConv -->|generates| FontH

    %% Runtime Data Flow
    AppLogic["Application Logic"]:::firmware
    AppLogic -->|calls| EPDDrvC
    EPDDrvC -->|I2S/RMT/SPI/I2C| ESP32
    ESP32 -->|updates| EPD

    TouchHW -->|IRQ| TouchDrvC
    TouchDrvC -->|notifies| AppLogic

    SDCard -->|SPI read| Zlib
    Zlib -->|decompress| EPDDrvC

    %% Click Events
    click ESP32 "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/boards/T5-ePaper-S3.json"
    click Flash "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/boards/T5-ePaper-S3.json"
    click PSRAM "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/boards/T5-ePaper-S3.json"
    click Datasheet "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/datasheet/ED047TC1.pdf"
    click Schematic "https://github.com/abaschen/lilygo-epd47/tree/esp32s3/schematic/"
    click Shell "https://github.com/abaschen/lilygo-epd47/tree/esp32s3/shell/"
    click PlatformIO "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/platformio.ini"
    click CMake "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/CMakeLists.txt"
    click CompMk "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/component.mk"
    click ConfMk "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/component_conf.mk"
    click EPDDrvC "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/epd_driver.c"
    click EPDDrvH "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/epd_driver.h"
    click I2SC "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/i2s_data_bus.c"
    click I2SH "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/i2s_data_bus.h"
    click RMTC "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/rmt_pulse.c"
    click RMTH "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/rmt_pulse.h"
    click JPEG "https://github.com/abaschen/lilygo-epd47/tree/esp32s3/src/libjpeg/"
    click Zlib "https://github.com/abaschen/lilygo-epd47/tree/esp32s3/src/zlib/"
    click Waveform "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/Waveform_header/ED047TC2.h"
    click FontC "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/font.c"
    click FontH "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/firasans.h"
    click Utils "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/utilities.h"
    click TouchDrvC "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/touch.cpp"
    click TouchDrvH "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/src/touch.h"
    click Examples "https://github.com/abaschen/lilygo-epd47/tree/esp32s3/examples/"
    click ImgConv "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/scripts/imgconvert.py"
    click FontConv "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/scripts/fontconvert.py"
    click Docs "https://github.com/abaschen/lilygo-epd47/tree/esp32s3/docs/"
    click RTD "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/.readthedocs.yml"
    click ArduinoCI "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/.github/workflows/arduino_ci.yml"
    click PlatformioCI "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/.github/workflows/platformio.yml"
    click IssuesCI "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/.github/workflows/issues.yaml"
    click LibraryJSON "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/library.json"
    click LibraryProp "https://github.com/abaschen/lilygo-epd47/blob/esp32s3/library.properties"

    %% Styles
    classDef hardware fill:#f9f,stroke:#333,stroke-width:1px
    classDef firmware fill:#9f9,stroke:#333,stroke-width:1px
    classDef tooling fill:#99f,stroke:#333,stroke-width:1px
```
