Toying around with a 4.2 in. e-Paper module from Waveshare and the Raspberry Pi Pico. Maybe it'll become a library some day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

85 lines
2.2 KiB

/* epd0.c - Instantiate E-Paper Display 0 */
/* Includes */
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/spi.h"
#include "epd/epd.h"
#include "epd0.h"
/* Definitions */
/* Data Structures */
/* Global Variables */
epd_t epd0;
/* Function Prototypes */
static int epd0_spi_write(const uint8_t *buf, size_t len, void *udata);
static void epd0_spi_cs(bool state, void *udata);
static void epd0_gpo_rst(bool state, void *udata);
static void epd0_gpo_dc(bool state, void *udata);
static bool epd0_gpo_busy(void *udata);
static void epd0_sleep_ms(uint32_t ms, void *udata);
/* Function Definitions */
void epd0_init()
{
epd_platform_config_t epd0_cfg = {
.spi_write = epd0_spi_write,
.spi_cs = epd0_spi_cs,
.rst = epd0_gpo_rst,
.dc = epd0_gpo_dc,
.busy = epd0_gpo_busy,
.sleep_ms = epd0_sleep_ms,
.udata = NULL
};
/* SPI initialisation. This example will use SPI at 1MHz. */
spi_init(EPD0_SPI_PORT, 1000*1000);
gpio_set_function(EPD0_PIN_MISO, GPIO_FUNC_SPI);
gpio_set_function(EPD0_PIN_CS, GPIO_FUNC_SIO);
gpio_set_function(EPD0_PIN_SCK, GPIO_FUNC_SPI);
gpio_set_function(EPD0_PIN_MOSI, GPIO_FUNC_SPI);
/* initialize other display pins */
gpio_set_function(EPD0_PIN_RST, GPIO_FUNC_SIO);
gpio_set_function(EPD0_PIN_BUSY, GPIO_FUNC_SIO);
gpio_set_function(EPD0_PIN_DC, GPIO_FUNC_SIO);
gpio_set_dir(EPD0_PIN_CS, GPIO_OUT);
gpio_set_dir(EPD0_PIN_RST, GPIO_OUT);
gpio_set_dir(EPD0_PIN_BUSY, GPIO_IN);
gpio_set_dir(EPD0_PIN_DC, GPIO_OUT);
/* initialize epd0 */
epd_init(&epd0, &epd0_cfg);
}
static int epd0_spi_write(const uint8_t *buf, size_t len, void *udata)
{
return spi_write_blocking(EPD0_SPI_PORT, buf, len);
}
static void epd0_spi_cs(bool state, void *udata)
{
gpio_put(EPD0_PIN_CS, state ? 0 : 1);
}
static void epd0_gpo_rst(bool state, void *udata)
{
gpio_put(EPD0_PIN_RST, state ? 0 : 1);
}
static void epd0_gpo_dc(bool state, void *udata)
{
gpio_put(EPD0_PIN_DC, state ? 1 : 0);
}
static bool epd0_gpo_busy(void *udata)
{
return gpio_get(EPD0_PIN_BUSY);
}
static void epd0_sleep_ms(uint32_t ms, void *udata)
{
sleep_ms(ms);
}