From 6cb8356eb29023ace90d2a910dbbfbf15530c501 Mon Sep 17 00:00:00 2001 From: Silke Hofstra Date: Wed, 1 Apr 2020 14:58:24 +0200 Subject: [PATCH] epd_bw_spi: add implementation for disp_dev --- drivers/epd_bw_spi/Makefile | 6 ++ drivers/epd_bw_spi/epd_bw_spi_disp_dev.c | 102 +++++++++++++++++++++++ drivers/include/epd_bw_spi.h | 8 ++ drivers/include/epd_bw_spi_disp_dev.h | 38 +++++++++ 4 files changed, 154 insertions(+) create mode 100644 drivers/epd_bw_spi/epd_bw_spi_disp_dev.c create mode 100644 drivers/include/epd_bw_spi_disp_dev.h diff --git a/drivers/epd_bw_spi/Makefile b/drivers/epd_bw_spi/Makefile index 48422e909a..e61b26311e 100644 --- a/drivers/epd_bw_spi/Makefile +++ b/drivers/epd_bw_spi/Makefile @@ -1 +1,7 @@ +SRC = epd_bw_spi.c + +ifneq (,$(filter disp_dev,$(USEMODULE))) + SRC += epd_bw_spi_disp_dev.c +endif + include $(RIOTBASE)/Makefile.base diff --git a/drivers/epd_bw_spi/epd_bw_spi_disp_dev.c b/drivers/epd_bw_spi/epd_bw_spi_disp_dev.c new file mode 100644 index 0000000000..e6037b2be2 --- /dev/null +++ b/drivers/epd_bw_spi/epd_bw_spi_disp_dev.c @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2022 Silke Hofstra + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_epd_bw_spi + * @{ + * + * @file + * @brief Driver adaption to disp_dev generic interface + * + * @author Silke Hofstra + * @} + */ + +#include +#include + +#include "epd_bw_spi.h" +#include "epd_bw_spi_disp_dev.h" + +#ifndef EPD_BW_SPI_DISP_COLOR_DEPTH +#define EPD_BW_SPI_DISP_COLOR_DEPTH (1U) +#endif + +#define ENABLE_DEBUG 0 +#include "debug.h" + +static void _epd_bw_spi_map(const disp_dev_t *disp_dev, const disp_dev_area_t *area, + const uint16_t *color) +{ + /* Convert the area to non-inclusive coordinates */ + uint8_t x1 = area->x1; + uint8_t x2 = area->x2 + 1; + uint16_t y1 = area->y1; + uint16_t y2 = area->y2 + 1; + + epd_bw_spi_t *dev = (epd_bw_spi_t *)disp_dev; + uint16_t size = ((x2 - x1) >> 3) * (y2 - y1); + + DEBUG("[epd_bw_spi] map: (%d,%d)-(%d,%d) (%u bytes) count %d\n", + x1, y1, x2, y2, size, dev->partial_refresh_count); + + /* Wake the device from sleep */ + epd_bw_spi_wake(dev); + + /* Initialize and update display */ + epd_bw_spi_init_auto(dev); + epd_bw_spi_activate(dev); + epd_bw_spi_set_area(dev, x1, x2, y1, y2); + epd_bw_spi_write_buffer(dev, (uint8_t *)color, size); + epd_bw_spi_update_auto(dev); + + /* Put the display to sleep */ + epd_bw_spi_deactivate(dev); + if (gpio_is_valid(dev->params.rst_pin)) { + epd_bw_spi_sleep(dev); + } +} + +static uint16_t _epd_bw_spi_height(const disp_dev_t *disp_dev) +{ + epd_bw_spi_t *dev = (epd_bw_spi_t *)disp_dev; + + assert(dev); + + return dev->params.size_y; +} + +static uint16_t _epd_bw_spi_width(const disp_dev_t *disp_dev) +{ + const epd_bw_spi_t *dev = (epd_bw_spi_t *)disp_dev; + + assert(dev); + + return dev->params.size_x; +} + +static uint8_t _epd_bw_spi_color_depth(const disp_dev_t *disp_dev) +{ + (void)disp_dev; + return EPD_BW_SPI_DISP_COLOR_DEPTH; +} + +/* This function does nothing, as it is not supported by this kind of display */ +static void _epd_bw_spi_set_invert(const disp_dev_t *disp_dev, bool invert) +{ + (void)disp_dev; + (void)invert; +} + +const disp_dev_driver_t epd_bw_spi_disp_dev_driver = { + .map = _epd_bw_spi_map, + .height = _epd_bw_spi_height, + .width = _epd_bw_spi_width, + .color_depth = _epd_bw_spi_color_depth, + .set_invert = _epd_bw_spi_set_invert, +}; diff --git a/drivers/include/epd_bw_spi.h b/drivers/include/epd_bw_spi.h index e66b7bc3e2..2911dfae8d 100644 --- a/drivers/include/epd_bw_spi.h +++ b/drivers/include/epd_bw_spi.h @@ -20,6 +20,7 @@ * See epd_bw_spi_params_t and @ref epd_bw_spi_params.h for more details on the parameters. * Note that while the reset and busy pins are optional, using them is highly recommended. * + * This driver has @ref drivers_disp_dev support. * * @{ * @file @@ -34,6 +35,10 @@ #include "periph/spi.h" #include "periph/gpio.h" +#ifdef MODULE_DISP_DEV +#include "disp_dev.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -99,6 +104,9 @@ typedef struct { * @brief Device initialisation parameters. */ typedef struct { + #ifdef MODULE_DISP_DEV + disp_dev_t *dev; /**< pointer to the generic display device */ + #endif epd_bw_spi_params_t params; /**< SPI display parameters */ uint16_t partial_refresh_count; /**< number of partial refreshes since the last full refresh */ diff --git a/drivers/include/epd_bw_spi_disp_dev.h b/drivers/include/epd_bw_spi_disp_dev.h new file mode 100644 index 0000000000..e9aa47a4f2 --- /dev/null +++ b/drivers/include/epd_bw_spi_disp_dev.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2020 Silke Hofstra + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_epd_bw_spi + * @{ + * + * @file + * @brief Definition of the driver for the disp_dev generic interface + * + * @author Silke Hofstra + */ + +#ifndef EPD_BW_SPI_DISP_DEV_H +#define EPD_BW_SPI_DISP_DEV_H + +#include "disp_dev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Reference to the display device driver struct + */ +extern const disp_dev_driver_t epd_bw_spi_disp_dev_driver; + +#ifdef __cplusplus +} +#endif + +#endif /* EPD_BW_SPI_DISP_DEV_H */ +/** @} */