drivers.Epaper.Epdconfig.Epdconfig¶
- class drivers.Epaper.Epdconfig.Epdconfig¶
Hardware abstraction over RPi.GPIO and spidev for an e-paper module.
Owns the SPI device handle and exposes thin wrappers around the GPIO and SPI calls that
drivers.Epaper.EPD.EPDneeds. The pin map and SPI parameters mirror Waveshare’s reference firmware so that any compatible panel works without modification.- Variables:
RST_PIN (
int) – BCM GPIO number for the panelRSTline (17).DC_PIN (
int) – BCM GPIO number for the data/commandDCline (25).CS_PIN (
int) – BCM GPIO number for the SPICSline (8).BUSY_PIN (
int) – BCM GPIO number for the panelBUSYline (24).GPIO (
module) – Reference to the importedRPi.GPIOmodule.SPI (
spidev.SpiDev) – Handle to/dev/spidev0.0.
Example
>>> from drivers.Epaper.Epdconfig import Epdconfig >>> cfg = Epdconfig() >>> cfg.RST_PIN, cfg.DC_PIN, cfg.CS_PIN, cfg.BUSY_PIN (17, 25, 8, 24)
Import RPi.GPIO and open the SPI device handle (bus 0, device 0).
Lazily imports
RPi.GPIOandspidevinside the constructor so that the module can be imported on non-Pi hosts without immediately failing. The SPI handle is opened but not yet configured; callmodule_init()to set the mode and clock speed.- Parameters:
None.
- Returns:
None.
- Raises:
ModuleNotFoundError – If
RPi.GPIOorspidevis not installed on the host.FileNotFoundError – If
/dev/spidev0.0does not exist (the SPI driver is disabled inraspi-config).PermissionError – If the calling user does not have access to the SPI or GPIO device nodes.
Example
>>> from drivers.Epaper.Epdconfig import Epdconfig >>> cfg = Epdconfig()
Note
One
Epdconfiginstance is shared as a class attribute ondrivers.Epaper.EPD.EPD, so creating additional instances is rarely necessary.- delay_ms(delaytime)¶
Block the current thread for a fixed number of milliseconds.
Thin wrapper around
time.sleep()that converts milliseconds to seconds.- Parameters:
delaytime (
int | float) – Delay duration in milliseconds.- Returns:
None.
- Raises:
ValueError – If
delaytimeis negative.
Example
>>> cfg = Epdconfig() >>> cfg.delay_ms(100) # sleep 100 ms
Note
Used by the EPD driver around reset pulses and between busy polls; not suitable for sub-millisecond timing.
- digital_read(pin)¶
Sample the current logic level of a GPIO pin.
- Parameters:
pin (
int) – BCM GPIO pin number. Must have been configured as an input viamodule_init().- Returns:
1if the pin is HIGH,0if LOW.- Return type:
- Raises:
RuntimeError – From
RPi.GPIOifpinis not configured as an input.
Example
>>> cfg = Epdconfig() >>> cfg.module_init() >>> level = cfg.digital_read(cfg.BUSY_PIN)
Note
On this panel the
BUSYline is active-low:0means the controller is processing a command,1means it is idle.
- digital_write(pin, value)¶
Drive a GPIO pin to a HIGH or LOW logic level.
- Parameters:
pin (
int) – BCM GPIO pin number. Must have been configured as an output viamodule_init().value (
int | bool) – Output level.1/Truedrives HIGH,0/Falsedrives LOW.
- Returns:
None.
- Raises:
RuntimeError – From
RPi.GPIOifpinis not configured as an output.
Example
>>> cfg = Epdconfig() >>> cfg.module_init() >>> cfg.digital_write(cfg.RST_PIN, 0)
Note
Used by the EPD driver to bit-bang
RST,DC, andCSaround SPI transfers.
- module_exit()¶
Close the SPI handle, force the panel idle, and run GPIO cleanup.
Logs
"spi end"at debug level and closesSPI, then drivesRST_PINandDC_PINlow (per the Waveshare reference sequence for"close 5V, Module enters 0 power consumption") and callsGPIO.cleanup().- Parameters:
None.
- Returns:
None.
- Raises:
OSError – If the spidev handle is already closed when
close()is invoked again.
Example
>>> cfg = Epdconfig() >>> cfg.module_init() >>> cfg.module_exit()
Note
After
module_exitthe panel must be re-initialized viamodule_init()(and a freshEPD.init()) before any further I/O is attempted.
- module_init()¶
Configure GPIO direction, SPI mode, and SPI clock speed.
Sets BCM pin numbering, disables
RPi.GPIOwarnings, and configuresRST_PIN,DC_PIN,CS_PINas outputs andBUSY_PINas an input. Sets the SPI bus tomax_speed_hz = 1_240_000andmode = 0b00.- Parameters:
None.
- Returns:
0on success. The signature returns an int so the EPD driver can branch on the result (seeEPD.init()).- Return type:
- Raises:
RuntimeError – From
RPi.GPIOif the host is not a Raspberry Pi or if pins are claimed by another process.
Example
>>> cfg = Epdconfig() >>> cfg.module_init() 0
Note
Always pair with
module_exit()to release peripherals. Re-runningmodule_initaftermodule_exit()is safe.
- spi_writebyte(data)¶
Transmit a list of bytes over SPI using
spidev.writebytes.- Parameters:
data (
list[int]) – Bytes to send, each in the range0..255. TheCSline is managed by the SPI peripheral.- Returns:
None.
- Raises:
Example
>>> cfg = Epdconfig() >>> cfg.module_init() >>> cfg.spi_writebyte([0x9F])
Note
writebytesis unbuffered; for large payloads preferspi_writebyte2().
- spi_writebyte2(data)¶
Transmit a list of bytes over SPI using
spidev.writebytes2.writebytes2supports arbitrarily long buffers and is faster for full-screen image transmission thanspi_writebyte().- Parameters:
data (
list[int]) – Bytes to send, each in the range0..255.- Returns:
None.
- Raises:
Example
>>> cfg = Epdconfig() >>> cfg.module_init() >>> cfg.spi_writebyte2([0xFF] * 4736) # full frame
Note
Currently not used by the EPD driver (which streams the framebuffer byte-by-byte via
send_data()), but provided for future optimization.
- BUSY_PIN = 24¶
- CS_PIN = 8¶
- DC_PIN = 25¶
- GPIO¶
- RST_PIN = 17¶
- SPI¶