start of the epd. Problem right now 0xff display black. Will have to investigate

This commit is contained in:
2026-03-29 21:36:37 -04:00
parent e5b72bbb20
commit be735990ff
14 changed files with 4498 additions and 35 deletions
Submodule Client/.tmp_seeed_gfx added at eefdf5f3fb
+62
View File
@@ -0,0 +1,62 @@
# EPD Reference Driver — GDEY075T7 (UC8179)
## Source
**Repository:** [ekosboard/firmware](https://github.com/ekosboard/firmware)
**File:** [`src/components/EPD/driver/epd_GDEY075T7.c`](https://github.com/ekosboard/firmware/blob/main/src/components/EPD/driver/epd_GDEY075T7.c)
## Panel Info
- **Controller:** UC8179
- **Panel:** GDEY075T7 (Good Display 7.5" B/W, 800×480)
- **Platform:** ESP-IDF (native SPI)
- **Grayscale:** 4-level support present but marked as "NOT TESTED"
## Key Implementation Details
### BUSY Pin Polarity
- **Reference driver:** HIGH = Busy, LOW = Idle
- **⚠️ Our board is INVERTED:** LOW = Busy, HIGH = Idle
- Wait loop polls `gpio_get_level(BUSY) == 0` to detect idle (reference)
- Our code uses `== 0` to wait while busy (opposite meaning, same code pattern)
### Clear Screen (White)
- Writes `0xFF` to **both** old (0x10) and new (0x13) data layers
- `0xFF` = White, `0x00` = Black
### Display Image
- Writes `0x00` to old data layer (0x10) — assumes previous state was black
- Writes actual image data to new data layer (0x13)
### Sleep Sequence
1. `0x50` with `0xF7` — VCOM and data interval setting before sleep
2. `0x02` — Power Off
3. Wait for BUSY idle
4. `0x07` + `0xA5` — Deep Sleep
### Init Sequence (Full Refresh)
1. Hardware reset (RST low 10ms, high 10ms)
2. `0x01` — Power Setting: VGH=20V, VGL=-20V, VDH=15V, VDL=-15V, VDHR=4.2V
3. `0x06` — Booster Soft Start: 0x17, 0x17, 0x28, 0x17
4. `0x04` — Power On + 100ms delay + wait busy
5. `0x00` — Panel Setting: `0x1F` (KW B/W mode)
6. `0x61` — Resolution: 800×480
7. `0x15` — DUSPI disabled
8. `0x50` — VCOM: 0x10, 0x07
9. `0x60` — TCON: 0x22
10. `0xE3` — PWS: 0x22
### Fast Refresh
- `0xE0``0x02` (enable fast mode)
- `0xE5``0x5A` (fast refresh timing)
### Partial Update
- Uses `0x91` (partial in) / `0x92` (partial out) + `0x90` (resolution setting)
- Writes `~data` (inverted) to old layer to force transitions
- Sets `0x50``0x21` (N2OCP disabled) for partial mode
### 4-Level Grayscale
- Requires different booster settings: `0x27, 0x27, 0x18, 0x17`
- `0xE5``0x5F` for grayscale timing
- Data encoding: 2 bits per pixel (0xC0=white, 0x00=black, 0x80=gray1, 0x40=gray2)
- Old layer and new layer encode different bit planes, both inverted (`~temp3`)
+10 -1
View File
@@ -1,4 +1,12 @@
dependencies:
epd:
dependencies:
- name: idf
version: '>=5.0.0'
source:
path: C:\Dev\Classified\Calendink\components\epd
type: local
version: 1.0.0
espressif/ethernet_init:
component_hash: 9f7d29acf5fe32315579ddb6247388291cda555aa529409108c0ada0aa7cd99d
dependencies:
@@ -164,11 +172,12 @@ dependencies:
type: local
version: 1.0.0
direct_dependencies:
- epd
- espressif/mdns
- http_client
- idf
- led
- network
manifest_hash: 097f2b35eb7bfe4a05687f2391f9fd078cab6437b8459fd420c47d1fa7a3c3d4
manifest_hash: 534458d93ffd9c5d8b40be759ddfb47940a38560cb0565b9d0ba18f8ec7510b7
target: esp32c6
version: 2.0.0
+1
View File
@@ -2,4 +2,5 @@ idf_component_register(SRCS "main.cpp" "provider.cpp"
PRIV_REQUIRES driver nvs_flash
esp_event esp_timer
led network http_client mdns
epd
INCLUDE_DIRS ".")
+2
View File
@@ -9,3 +9,5 @@ dependencies:
path: "../../components/led"
http_client:
path: "../../components/http_client"
epd:
path: "../../components/epd"
+43 -32
View File
@@ -1,3 +1,4 @@
#include <cassert>
#include <cstdio>
#include "esp_event.h"
@@ -9,6 +10,7 @@
#include "nvs_flash.h"
#include "sdkconfig.h"
#include "epd.hpp"
#include "led.hpp"
#include "network.hpp"
#include "provider.hpp"
@@ -33,45 +35,54 @@ extern "C" void app_main()
setup_led();
// Connect to WiFi
ESP_LOGI(TAG, "Initializing WiFi connection");
initialize_network();
esp_err_t err = connect_wifi(CONFIG_CALENDINK_WIFI_SSID,
CONFIG_CALENDINK_WIFI_PASSWORD, false);
if (err == ESP_OK)
if (false)
{
uint8_t retries = 1;
do
ESP_LOGI(TAG, "Initializing WiFi connection");
initialize_network();
esp_err_t err = connect_wifi(CONFIG_CALENDINK_WIFI_SSID,
CONFIG_CALENDINK_WIFI_PASSWORD, false);
if (err == ESP_OK)
{
err = check_wifi_connection(retries);
if (err != ESP_OK)
uint8_t retries = 1;
do
{
ESP_LOGW(TAG, "WiFi connection check timeout, retrying... (%d)",
retries);
led_blink_number(3, 255, 0, 0);
}
retries++;
} while (err == ESP_ERR_TIMEOUT &&
retries <= CONFIG_CALENDINK_WIFI_RETRIES);
}
err = check_wifi_connection(retries);
if (err != ESP_OK)
{
ESP_LOGW(TAG, "WiFi connection check timeout, retrying... (%d)",
retries);
led_blink_number(3, 255, 0, 0);
}
retries++;
} while (err == ESP_ERR_TIMEOUT &&
retries <= CONFIG_CALENDINK_WIFI_RETRIES);
}
if (err == ESP_OK)
{
ESP_LOGI(TAG, "Successfully connected to WiFi!");
test_provider_communication();
}
else
{
ESP_LOGE(TAG, "Failed to connect to WiFi.");
if (err == ESP_OK)
{
ESP_LOGI(TAG, "Successfully connected to WiFi!");
test_provider_communication();
}
else
{
ESP_LOGE(TAG, "Failed to connect to WiFi.");
}
}
turn_off_led();
while (true)
{
vTaskDelay(pdMS_TO_TICKS(1000));
}
ESP_LOGI(TAG, "Initializing EPD");
epd_init();
epd_init_display();
epd_clear(epd_color_t::WHITE);
epd_refresh();
epd_shutdown_display();
shutdown_network();
if (false)
{
disconnect_wifi();
shutdown_network();
}
}
File diff suppressed because it is too large Load Diff
+3
View File
@@ -0,0 +1,3 @@
idf_component_register(SRCS "epd.cpp"
INCLUDE_DIRS "." "../shared"
PRIV_REQUIRES driver)
+45
View File
@@ -0,0 +1,45 @@
menu "EPD Configuration"
config CALENDINK_EPD_SCLK
int "EPD SPI SCLK GPIO"
default 19
help
GPIO pin for SPI SCLK (D8 on XIAO C6)
config CALENDINK_EPD_MISO
int "EPD SPI MISO GPIO"
default 20
help
GPIO pin for SPI MISO (D9 on XIAO C6)
config CALENDINK_EPD_MOSI
int "EPD SPI MOSI GPIO"
default 18
help
GPIO pin for SPI MOSI (D10 on XIAO C6)
config CALENDINK_EPD_CS
int "EPD SPI CS GPIO"
default 1
help
GPIO pin for SPI CS (D1 on XIAO C6)
config CALENDINK_EPD_DC
int "EPD Data/Command GPIO"
default 21
help
GPIO pin for Data/Command selection (D3 on XIAO C6)
config CALENDINK_EPD_BUSY
int "EPD Busy GPIO"
default 2
help
GPIO pin for Busy signal (D2 on XIAO C6)
config CALENDINK_EPD_RST
int "EPD Reset GPIO"
default 0
help
GPIO pin for Reset signal (D0 on XIAO C6)
endmenu
+283
View File
@@ -0,0 +1,283 @@
#include "epd.hpp"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <assert.h>
#include <string.h>
internal const char *kTagEPD = "EPD";
internal spi_device_handle_t g_spi_handle;
internal bool g_is_asleep = true;
internal void epd_spi_init(void)
{
// 1. Initialize the SPI Bus
spi_bus_config_t buscfg = {};
buscfg.miso_io_num = TFT_MISO; // Initialize MISO as input, matching `spi.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, -1)`
buscfg.mosi_io_num = TFT_MOSI;
buscfg.sclk_io_num = TFT_SCLK;
buscfg.quadwp_io_num = -1;
buscfg.quadhd_io_num = -1;
buscfg.max_transfer_sz = 4096;
// SPI2_HOST is the general-purpose SPI host on ESP32-S3
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
// 2. Add the EPD device to the bus
spi_device_interface_config_t devcfg = {};
devcfg.clock_speed_hz = SPI_FREQUENCY;
devcfg.mode = 0; // Standard EPD SPI mode
devcfg.spics_io_num = TFT_CS; // The driver handles CS automatically
devcfg.queue_size = 7;
devcfg.flags = 0;
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &devcfg, &g_spi_handle));
}
internal void epd_gpio_init()
{
gpio_reset_pin((gpio_num_t)TFT_BUSY);
gpio_set_direction((gpio_num_t)TFT_BUSY, GPIO_MODE_INPUT);
gpio_reset_pin((gpio_num_t)TFT_RST);
gpio_set_direction((gpio_num_t)TFT_RST, GPIO_MODE_OUTPUT);
gpio_set_level((gpio_num_t)TFT_RST,
1); // Set high, do not share pin with another SPI device
gpio_reset_pin((gpio_num_t)TFT_DC);
gpio_set_direction((gpio_num_t)TFT_DC, GPIO_MODE_OUTPUT);
gpio_set_level((gpio_num_t)TFT_DC, 1); // Data/Command high = data mode
gpio_reset_pin((gpio_num_t)TFT_CS);
gpio_set_direction((gpio_num_t)TFT_CS, GPIO_MODE_OUTPUT);
gpio_set_level((gpio_num_t)TFT_CS, 1); // Chip select high (inactive)
}
internal void epd_writecommand(unsigned char command)
{
assert(!g_is_asleep);
// Pull DC Low for Command
gpio_set_level((gpio_num_t)TFT_DC, GPIO_LOW);
spi_transaction_t t = {};
t.length = 8; // length in bits
t.tx_buffer = &command;
spi_device_transmit(g_spi_handle, &t);
}
internal void epd_write_buffer(const uint8 *data, size_t len)
{
assert(!g_is_asleep);
if (len == 0)
return;
// Pull DC High for Data
gpio_set_level((gpio_num_t)TFT_DC, GPIO_HIGH);
while (len > 0)
{
// max_transfer_sz is typically 4096 which is the limit for a single SPI
// transaction
size_t chunk = (len > 4096) ? 4096 : len;
spi_transaction_t t = {};
t.length = chunk * 8; // length in bits
t.tx_buffer = data;
spi_device_transmit(g_spi_handle, &t);
data += chunk;
len -= chunk;
}
}
void epd_writedata(unsigned char data) { epd_write_buffer(&data, 1); }
internal void epd_wait_until_idle()
{
// BUSY pin on this board: LOW = busy, HIGH = idle
// (opposite of GDEY075T7 reference driver)
while (gpio_get_level((gpio_num_t)TFT_BUSY) == 0)
{
vTaskDelay(pdMS_TO_TICKS(5));
}
}
void epd_init(void)
{
ESP_LOGI(kTagEPD, "Initializing EPaper Driver");
epd_gpio_init();
epd_spi_init();
ESP_LOGI(kTagEPD, "EPaper Driver initialized successfully");
}
void epd_shutdown(void)
{
spi_bus_remove_device(g_spi_handle);
spi_bus_free(SPI2_HOST);
}
internal void epd_seeed_init_fast()
{
epd_writecommand(0x01); // POWER SETTING
epd_writedata(0x07);
epd_writedata(0x07); // VGH=20V,VGL=-20V
epd_writedata(0x3f); // VDH=15V
epd_writedata(0x3f); // VDL=-15V
epd_writecommand(0x06); // Booster Soft Start
epd_writedata(0x17);
epd_writedata(0x17);
epd_writedata(0x28);
epd_writedata(0x17);
epd_writecommand(0x04); // POWER ON
vTaskDelay(pdMS_TO_TICKS(100));
epd_wait_until_idle();
epd_writecommand(0X00); // PANEL SETTING
epd_writedata(0x1F); // KW-3f KWR-2F BWROTP 0f BWOTP 1f
epd_writecommand(0x61); // TRES
epd_writedata(EPD_WIDTH >> 8);
epd_writedata(EPD_WIDTH & 0xFF);
epd_writedata(EPD_HEIGHT >> 8);
epd_writedata(EPD_HEIGHT & 0xFF);
epd_writecommand(0x50); // VCOM AND DATA INTERVAL SETTING
epd_writedata(0x10);
epd_writedata(0x07);
epd_writecommand(0xE0); // Active Temperature
epd_writedata(0x02);
epd_writecommand(0xE5); // Input Temperature
epd_writedata(0x55);
}
internal void epd_wakeup()
{
gpio_set_level((gpio_num_t)TFT_RST, 0);
vTaskDelay(pdMS_TO_TICKS(10));
gpio_set_level((gpio_num_t)TFT_RST, 1);
vTaskDelay(pdMS_TO_TICKS(10));
epd_wait_until_idle();
epd_seeed_init_fast();
}
void epd_init_display()
{
g_is_asleep = false;
// 1. From initFromSleep() - Put SPI bus in known state for TFT with CS tied low
epd_writecommand(0x00);
gpio_set_level((gpio_num_t)TFT_RST, 1);
vTaskDelay(pdMS_TO_TICKS(5));
gpio_set_level((gpio_num_t)TFT_RST, 0);
vTaskDelay(pdMS_TO_TICKS(20));
gpio_set_level((gpio_num_t)TFT_RST, 1);
vTaskDelay(pdMS_TO_TICKS(150)); // Wait for reset to complete
// 2. From init() -> UC8179_Init.h
epd_writecommand(0x01); // POWER SETTING
epd_writedata(0x07);
epd_writedata(0x07);
epd_writedata(0x3f);
epd_writedata(0x3f);
epd_writecommand(0x06); // Booster Soft Start
epd_writedata(0x17);
epd_writedata(0x17);
epd_writedata(0x28);
epd_writedata(0x17);
epd_writecommand(0x04); // POWER ON
vTaskDelay(pdMS_TO_TICKS(100));
epd_wait_until_idle();
epd_writecommand(0X00); // PANEL SETTING
epd_writedata(0x1F);
epd_writecommand(0x61); // TRES
epd_writedata(EPD_WIDTH >> 8);
epd_writedata(EPD_WIDTH & 0xFF);
epd_writedata(EPD_HEIGHT >> 8);
epd_writedata(EPD_HEIGHT & 0xFF);
epd_writecommand(0x15);
epd_writedata(0x00);
epd_writecommand(0x50); // VCOM AND DATA INTERVAL SETTING
epd_writedata(0x10);
epd_writedata(0x07);
epd_writecommand(0x60); // TCON SETTING
epd_writedata(0x22);
// 3. EPaper::begin(0) then correctly calls EPD_WAKEUP()
epd_wakeup();
}
void epd_shutdown_display(void)
{
assert(!g_is_asleep);
ESP_LOGI(kTagEPD, "Shutting down display (Power Off)");
epd_writecommand(0x50); // VCOM AND DATA INTERVAL SETTING (pre-sleep)
epd_writedata(0xF7);
epd_writecommand(0x02); // POWER OFF
epd_wait_until_idle();
epd_writecommand(0x07); // DEEP SLEEP
epd_writedata(0xA5); // Deep sleep check code
vTaskDelay(pdMS_TO_TICKS(10));
g_is_asleep = true;
}
void epd_refresh(void)
{
assert(!g_is_asleep);
ESP_LOGI(kTagEPD, "Refreshing display...");
epd_writecommand(0x12); // REFRESH
vTaskDelay(pdMS_TO_TICKS(1));
epd_wait_until_idle();
}
bool epd_is_asleep(void) { return g_is_asleep; }
void epd_clear(epd_color_t level)
{
assert(!g_is_asleep);
uint8 color_byte = static_cast<uint8>(level);
ESP_LOGI(kTagEPD, "Clearing display (byte=0x%02X)", color_byte);
constexpr size_t total_bytes = (EPD_WIDTH * EPD_HEIGHT) / 8;
uint8 chunk[256];
memset(chunk, color_byte, sizeof(chunk));
auto write_layer = [&](uint8 cmd)
{
epd_writecommand(cmd);
size_t remaining = total_bytes;
int chunk_count = 0;
while (remaining > 0)
{
size_t to_write = (remaining > sizeof(chunk)) ? sizeof(chunk) : remaining;
epd_write_buffer(chunk, to_write);
remaining -= to_write;
// Yield every 16 chunks (~4KB) to prevent task watchdog timeout
if (++chunk_count % 16 == 0)
vTaskDelay(1);
}
};
write_layer(0x10); // Old data layer
write_layer(0x13); // New data layer
ESP_LOGI(kTagEPD, "Data transmission complete (Refresh required)");
}
+34
View File
@@ -0,0 +1,34 @@
// DRIVER FOR UC8179
#pragma once
#include "sdkconfig.h"
#include "types.hpp"
// EPD Pin Definitions - Defaulting to CONFIG_ values defined in Kconfig
#define TFT_SCLK CONFIG_CALENDINK_EPD_SCLK
#define TFT_MISO CONFIG_CALENDINK_EPD_MISO
#define TFT_MOSI CONFIG_CALENDINK_EPD_MOSI
#define TFT_CS CONFIG_CALENDINK_EPD_CS
#define TFT_DC CONFIG_CALENDINK_EPD_DC
#define TFT_BUSY CONFIG_CALENDINK_EPD_BUSY
#define TFT_RST CONFIG_CALENDINK_EPD_RST
#define SPI_FREQUENCY 10000000
#define SPI_READ_FREQUENCY 4000000
#define EPD_WIDTH 800
#define EPD_HEIGHT 480
enum class epd_color_t : uint8
{
BLACK = 0x00,
WHITE = 0xFF
};
void epd_init(void);
void epd_shutdown(void);
void epd_init_display();
void epd_shutdown_display(void);
void epd_refresh(void);
void epd_clear(epd_color_t level);
bool epd_is_asleep(void);
+6
View File
@@ -0,0 +1,6 @@
version: "1.0.0"
description: "Calendink EPD Component"
dependencies:
idf:
version: '>=5.0.0'
+1 -1
View File
@@ -48,7 +48,7 @@ internal bool s_ethernet_connected = false;
#endif
void initialize_network() { ESP_ERROR_CHECK(esp_netif_init()); }
void shutdown_network() { ESP_ERROR_CHECK(esp_netif_deinit()); }
void shutdown_network() { esp_netif_deinit(); }
void ethernet_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
+4 -1
View File
@@ -12,4 +12,7 @@ using int16 = int16_t;
using int32 = int32_t;
using int64 = int64_t;
#define internal static
#define internal static
#define GPIO_HIGH 1
#define GPIO_LOW 0