mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-28 23:29:45 +01:00
epd_bw_spi: add implementation for disp_dev
This commit is contained in:
parent
f4791a0280
commit
6cb8356eb2
@ -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
|
||||
|
102
drivers/epd_bw_spi/epd_bw_spi_disp_dev.c
Normal file
102
drivers/epd_bw_spi/epd_bw_spi_disp_dev.c
Normal file
@ -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 <silke@slxh.eu>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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,
|
||||
};
|
@ -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 */
|
||||
|
38
drivers/include/epd_bw_spi_disp_dev.h
Normal file
38
drivers/include/epd_bw_spi_disp_dev.h
Normal file
@ -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 <silke@slxh.eu>
|
||||
*/
|
||||
|
||||
#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 */
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user