mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2026-01-01 01:41:18 +01:00
Merge pull request #13262 from aabadie/pr/sys/disp_dev
sys/disp_dev: add generic interface for display drivers
This commit is contained in:
commit
b050608771
1
drivers/disp_dev/Makefile
Normal file
1
drivers/disp_dev/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
61
drivers/disp_dev/disp_dev.c
Normal file
61
drivers/disp_dev/disp_dev.c
Normal file
@ -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 <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
81
drivers/ili9341/ili9341_disp_dev.c
Normal file
81
drivers/ili9341/ili9341_disp_dev.c
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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_ili9341
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Driver adaption to disp_dev generic interface
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ili9341.h"
|
||||
#include "ili9341_disp_dev.h"
|
||||
|
||||
#ifndef ILI9341_DISP_DEV_HEIGHT
|
||||
#define ILI9341_DISP_DEV_HEIGHT (240U)
|
||||
#endif
|
||||
|
||||
#ifndef ILI9341_DISP_COLOR_DEPTH
|
||||
#define ILI9341_DISP_COLOR_DEPTH (16U)
|
||||
#endif
|
||||
|
||||
static void _ili9341_map(disp_dev_t *dev, uint16_t x1, uint16_t x2,
|
||||
uint16_t y1, uint16_t y2, const uint16_t *color)
|
||||
{
|
||||
ili9341_t *ili9341 = (ili9341_t *)dev;
|
||||
ili9341_pixmap(ili9341, x1, x2, y1, y2, color);
|
||||
}
|
||||
|
||||
static uint16_t _ili9341_height(disp_dev_t *disp_dev)
|
||||
{
|
||||
(void)disp_dev;
|
||||
return ILI9341_DISP_DEV_HEIGHT;
|
||||
}
|
||||
|
||||
static uint16_t _ili9341_width(disp_dev_t *disp_dev)
|
||||
{
|
||||
const ili9341_t *dev = (ili9341_t *)disp_dev;
|
||||
assert(dev);
|
||||
|
||||
return dev->params->lines;
|
||||
}
|
||||
|
||||
static uint8_t _ili9341_color_depth(disp_dev_t *disp_dev)
|
||||
{
|
||||
(void)disp_dev;
|
||||
return ILI9341_DISP_COLOR_DEPTH;
|
||||
}
|
||||
|
||||
static void _ili9341_set_invert(disp_dev_t *disp_dev, bool invert)
|
||||
{
|
||||
const ili9341_t *dev = (ili9341_t *)disp_dev;
|
||||
|
||||
assert(dev);
|
||||
|
||||
if (invert) {
|
||||
ili9341_invert_on(dev);
|
||||
}
|
||||
else {
|
||||
ili9341_invert_off(dev);
|
||||
}
|
||||
}
|
||||
|
||||
const disp_dev_driver_t ili9341_disp_dev_driver = {
|
||||
.map = _ili9341_map,
|
||||
.height = _ili9341_height,
|
||||
.width = _ili9341_width,
|
||||
.color_depth = _ili9341_color_depth,
|
||||
.set_invert = _ili9341_set_invert,
|
||||
};
|
||||
37
drivers/ili9341/include/ili9341_disp_dev.h
Normal file
37
drivers/ili9341/include/ili9341_disp_dev.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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_ili9341
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Definition of the driver for the disp_dev generic interface
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef ILI9341_DISP_DEV_H
|
||||
#define ILI9341_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 ili9341_disp_dev_driver;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ILI9341_DISP_DEV_H */
|
||||
146
drivers/include/disp_dev.h
Normal file
146
drivers/include/disp_dev.h
Normal file
@ -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 <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef DISP_DEV_H
|
||||
#define DISP_DEV_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
/** @} */
|
||||
@ -36,6 +36,10 @@
|
||||
#include "periph/spi.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
#ifdef MODULE_DISP_DEV
|
||||
#include "disp_dev.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -98,6 +102,9 @@ typedef struct {
|
||||
* @brief Device descriptor for a ili9341
|
||||
*/
|
||||
typedef struct {
|
||||
#ifdef MODULE_DISP_DEV
|
||||
disp_dev_t *dev; /**< Pointer to the generic display device */
|
||||
#endif
|
||||
const ili9341_params_t *params; /**< Device initialization parameters */
|
||||
} ili9341_t;
|
||||
|
||||
|
||||
9
tests/disp_dev/Makefile
Normal file
9
tests/disp_dev/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
BOARD ?= stm32f429i-disc1
|
||||
include ../Makefile.tests_common
|
||||
|
||||
DISABLE_MODULE += test_utils_interactive_sync
|
||||
|
||||
USEMODULE += ili9341
|
||||
USEMODULE += disp_dev
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
14
tests/disp_dev/Makefile.ci
Normal file
14
tests/disp_dev/Makefile.ci
Normal file
@ -0,0 +1,14 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
arduino-duemilanove \
|
||||
arduino-leonardo \
|
||||
arduino-mega2560 \
|
||||
arduino-nano \
|
||||
arduino-uno \
|
||||
atmega1284p \
|
||||
atmega328p \
|
||||
derfmega128 \
|
||||
mega-xplained \
|
||||
microduino-corerf \
|
||||
stm32f030f4-demo \
|
||||
waspmote-pro \
|
||||
#
|
||||
68
tests/disp_dev/main.c
Normal file
68
tests/disp_dev/main.c
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Generic display device test application
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "disp_dev.h"
|
||||
|
||||
#include "ili9341.h"
|
||||
#include "ili9341_params.h"
|
||||
#include "ili9341_disp_dev.h"
|
||||
|
||||
#include "riot_logo.h"
|
||||
|
||||
#include "test_utils/expect.h"
|
||||
|
||||
static ili9341_t ili9341;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#ifdef BOARD_PINETIME
|
||||
/* on PineTime, enable the backlight */
|
||||
gpio_clear(LCD_BACKLIGHT_LOW);
|
||||
#endif
|
||||
|
||||
ili9341_init(&ili9341, &ili9341_params[0]);
|
||||
|
||||
disp_dev_t *dev = (disp_dev_t *)&ili9341;
|
||||
dev->driver = &ili9341_disp_dev_driver;
|
||||
|
||||
disp_dev_set_invert(dev, true);
|
||||
|
||||
uint16_t max_width = disp_dev_width(dev);
|
||||
uint16_t max_height = disp_dev_height(dev);
|
||||
|
||||
expect(max_width == ili9341.params->lines);
|
||||
expect(max_height == 240);
|
||||
|
||||
uint16_t color = 0;
|
||||
for (uint16_t y = 0; y < max_height; ++y) {
|
||||
for (uint16_t x = 0; x < max_width; ++x) {
|
||||
disp_dev_map(dev, x, x, y, y, &color);
|
||||
}
|
||||
}
|
||||
|
||||
disp_dev_map(dev, 95, 222, 85, 153, (const uint16_t *)picture);
|
||||
|
||||
puts("SUCCESS");
|
||||
|
||||
return 0;
|
||||
}
|
||||
1058
tests/disp_dev/riot_logo.h
Normal file
1058
tests/disp_dev/riot_logo.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user