summaryrefslogtreecommitdiffstats
path: root/_log/e-reader.md
blob: 2edd5dd9edf304a9e41cd1139e8f44024187ab2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: ESP32 e-reader prototype
date: 2023-10-24
layout: post
project: true
thumbnail: thumb_sm.png
---

First project with e-paper displays and ESP32.

<video style="max-width:100%;" controls="" poster="poster.png">
  <source src="ereader.mp4" type="video/mp4">
</video>

ESP-WROOM-32, 7.5" Waveshare e-paper display, three buttons (prev/next/sleep).

No local storage—streams books over HTTP. RTC memory tracks reading progress
between sessions.

ESP32: 512KB SRAM, 4MB flash (shared with FreeRTOS, ESP-IDF). Not enough to
store books. Stream from webserver instead.

Custom EBM file format. Rasterized monochrome bitmaps, one per page (480x800).
One byte = 8 pixels. Pages on 48KB boundaries—HTTP Range requests work without
server logic. pdftoebm.py converts PDFs.

Circular buffer holds 3 pages (prev/current/next)--page table. Single-threaded
approach too slow—user input, SPI, and HTTP on one core causes lag.

Optimizations: pin the GPIO task (responding to user input and updating
display) to one core, pin the HTTP task to the other core.

Better, but system unresponsive during screen updates. Made SPI transfer async:

```
void epd_draw_async(const uint8_t *buf, size_t n)
{
    static spi_transaction_t t[3];

    memset(&t[0], 0, sizeof(t[0])); 
    t[0].length = 8;
    t[0].tx_data[0] = 0x13;
    t[0].user = (void*) 0; 
    t[0].flags = SPI_TRANS_USE_TXDATA;

    memset(&t[1], 0, sizeof(t[1])); 
    t[1].length = 8 * n;
    t[1].tx_buffer = buf;
    t[1].user = (void*) 1; 

    memset(&t[2], 0, sizeof(t[2])); 
    t[2].length = 8;
    t[2].tx_data[0] = 0x12;
    t[2].user = (void*) 0; 
    t[2].flags = SPI_TRANS_USE_TXDATA;

    for (int i = 0; i < 3; i++)
        spi_device_queue_trans(spi, &t[i], portMAX_DELAY);
}
```

Much better. Squeeze a few more cycles by moving SPI buffer to DMA. 

Can't think of anything else.

Outcome: Works but limited. Led to [Etlas](../etlas/).

Commit:
[7f691c4](https://git.asciimx.com/esp32-e-reader/commit/?id=7f691c46093933b67aab466c0ca582ace8ab73d4)