From ac6d0b90777ea8e666e253af60abca27133e2fd6 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 14 Jan 2020 16:12:02 +0100 Subject: [PATCH] sys: add interface for generic display device --- drivers/disp_dev/Makefile | 1 + drivers/disp_dev/disp_dev.c | 61 +++++++++++++++ drivers/include/disp_dev.h | 146 ++++++++++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 drivers/disp_dev/Makefile create mode 100644 drivers/disp_dev/disp_dev.c create mode 100644 drivers/include/disp_dev.h diff --git a/drivers/disp_dev/Makefile b/drivers/disp_dev/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/drivers/disp_dev/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/drivers/disp_dev/disp_dev.c b/drivers/disp_dev/disp_dev.c new file mode 100644 index 0000000000..ae791d374f --- /dev/null +++ b/drivers/disp_dev/disp_dev.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2020 Inria + * + * 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_disp_dev + * @{ + * + * @file + * @brief Helper functions for generic API of display device + * + * @author Alexandre Abadie + * + * @} + */ + +#include +#include + +#include "disp_dev.h" + +void disp_dev_map(disp_dev_t *dev, + uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, + const uint16_t *color) +{ + assert(dev); + + dev->driver->map(dev, x1, x2, y1, y2, color); +} + +uint16_t disp_dev_height(disp_dev_t *dev) +{ + assert(dev); + + return dev->driver->height(dev); +} + +uint16_t disp_dev_width(disp_dev_t *dev) +{ + assert(dev); + + return dev->driver->width(dev); +} + +uint8_t disp_dev_color_depth(disp_dev_t *dev) +{ + assert(dev); + + return dev->driver->color_depth(dev); +} + +void disp_dev_set_invert(disp_dev_t *dev, bool invert) +{ + assert(dev); + + dev->driver->set_invert(dev, invert); +} diff --git a/drivers/include/disp_dev.h b/drivers/include/disp_dev.h new file mode 100644 index 0000000000..7da7794ba6 --- /dev/null +++ b/drivers/include/disp_dev.h @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2020 Inria + * + * 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. + */ + +/** + * @defgroup drivers_disp_dev Display device generic API + * @ingroup drivers_display + * @brief Define the generic API of a display device + * @experimental This API is experimental and in an early state - expect + * changes! + * @{ + * + * @author Alexandre Abadie + */ + +#ifndef DISP_DEV_H +#define DISP_DEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/** + * @brief Forward declaration for display device struct + */ +typedef struct disp_dev disp_dev_t; + +/** + * @brief Generic type for a display driver + */ +typedef struct { + /** + * @brief Map an area to display on the device + * + * @param[in] dev Pointer to the display device + * @param[in] x1 Left coordinate + * @param[in] x2 Right coordinate + * @param[in] y1 Top coordinate + * @param[in] y2 Bottom coordinate + * @param[in] color Array of color to map to the display + */ + void (*map)(disp_dev_t *dev, + uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, + const uint16_t *color); + + /** + * @brief Get the height of the display device + * + * @param[in] dev Pointer to the display device + * + * @return Height in pixels + */ + uint16_t (*height)(disp_dev_t *dev); + + /** + * @brief Get the width of the display device + * + * @param[in] dev Pointer to the display device + * + * @return Width in pixels + */ + uint16_t (*width)(disp_dev_t *dev); + + /** + * @brief Get the color depth of the display device + * + * @return The color depth + */ + uint8_t (*color_depth)(disp_dev_t *dev); + + /** + * @brief Invert the display device colors + * + * @param[in] dev Network device descriptor + * @param[in] invert Invert mode (true if invert, false otherwise) + */ + void (*set_invert)(disp_dev_t *dev, bool invert); +} disp_dev_driver_t; + +/** + * @brief Generic type for a display device + */ +struct disp_dev { + const disp_dev_driver_t *driver; /**< Pointer to driver of the display device */ +}; + +/** + * @brief Map an area to display on the device + * + * @param[in] dev Pointer to the display device + * @param[in] x1 Left coordinate + * @param[in] x2 Right coordinate + * @param[in] y1 Top coordinate + * @param[in] y2 Bottom coordinate + * @param[in] color Array of color to map to the display + */ +void disp_dev_map(disp_dev_t *dev, + uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, + const uint16_t *color); + +/** + * @brief Get the height of the display device + * + * @param[in] dev Pointer to the display device + * + * @return Height in pixels + */ +uint16_t disp_dev_height(disp_dev_t *dev); + +/** + * @brief Get the width of the display device + * + * @param[in] dev Pointer to the display device + * + * @return Width in pixels + */ +uint16_t disp_dev_width(disp_dev_t *dev); + +/** + * @brief Get the color depth of the display device + * + * @return The color depth + */ +uint8_t disp_dev_color_depth(disp_dev_t *dev); + +/** + * @brief Invert the display device colors + * + * @param[in] dev Network device descriptor + * @param[in] invert Invert mode (true if invert, false otherwise) + */ +void disp_dev_set_invert(disp_dev_t *dev, bool invert); + +#ifdef __cplusplus +} +#endif + +#endif /* DISP_DEV_H */ +/** @} */