Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color depth types to disp_dev API #14054

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions drivers/disp_dev/disp_dev.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2020 Inria
* 2020 Philipp-Alexander Blum <philipp-blum@jakiku.de>
*
* 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
Expand All @@ -14,6 +15,7 @@
* @brief Helper functions for generic API of display device
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
* @author Philipp-Alexander Blum <philipp-blum@jakiku.de>
*
* @}
*/
Expand All @@ -24,13 +26,12 @@

#include "disp_dev.h"

void disp_dev_map(const disp_dev_t *dev,
uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2,
const uint16_t *color)
void disp_dev_map(disp_dev_t *dev, disp_dev_coordinates_t *coordinates,
const void *color, disp_dev_color_depth_t color_depth)
{
assert(dev);

dev->driver->map(dev, x1, x2, y1, y2, color);
dev->driver->map(dev, coordinates, color, color_depth);
}

uint16_t disp_dev_height(const disp_dev_t *dev)
Expand Down
45 changes: 26 additions & 19 deletions drivers/ili9341/ili9341.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2018 Koen Zandberg
* 2020 Philipp-Alexander Blum
*
* 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
Expand All @@ -14,6 +15,7 @@
* @brief Device driver implementation for the ili9341 display controller
*
* @author Koen Zandberg <koen@bergzand.net>
* @author Philipp-Alexander Blum <philipp-blum@jakiku.de>
*
* @}
*/
Expand Down Expand Up @@ -69,21 +71,27 @@ static void _write_cmd(const ili9341_t *dev, uint8_t cmd, const uint8_t *data,
}
}

static void _ili9341_set_area(const ili9341_t *dev, uint16_t x1, uint16_t x2,
uint16_t y1, uint16_t y2)
static void _ili9341_set_area(const ili9341_t *dev,
ili9341_coordinates_t * coordinates)
{
be_uint16_t params[2];

params[0] = byteorder_htons(x1);
params[1] = byteorder_htons(x2);
params[0] = byteorder_htons(coordinates->x1);
params[1] = byteorder_htons(coordinates->x2);
_write_cmd(dev, ILI9341_CMD_CASET, (uint8_t *)params,
sizeof(params));
params[0] = byteorder_htons(y1);
params[1] = byteorder_htons(y2);
params[0] = byteorder_htons(coordinates->y1);
params[1] = byteorder_htons(coordinates->y2);
_write_cmd(dev, ILI9341_CMD_PASET, (uint8_t *)params,
sizeof(params));
}

static uint32_t _ili9341_get_pixel_num(ili9341_coordinates_t * coordinates){
return
(coordinates->x2 - coordinates->x1 + 1) *
(coordinates->y2 - coordinates->y1 + 1);
}

int ili9341_init(ili9341_t *dev, const ili9341_params_t *params)
{
assert(params->lines >= 16 && params->lines <= 320 && !(params->lines & 0x7));
Expand Down Expand Up @@ -230,22 +238,20 @@ void ili9341_read_cmd(const ili9341_t *dev, uint8_t cmd, uint8_t *data, size_t l
}


void ili9341_fill(const ili9341_t *dev, uint16_t x1, uint16_t x2, uint16_t y1,
uint16_t y2, uint16_t color)
void ili9341_fill(const ili9341_t *dev, ili9341_coordinates_t * coordinates,
uint16_t color)
{
/* Send fill area to the display */

/* Calculate number of pixels */
int32_t num_pix = (x2 - x1 + 1) * (y2 - y1 + 1);
int32_t num_pix = _ili9341_get_pixel_num(coordinates);

DEBUG("[ili9341]: Write x1: %" PRIu16 ", x2: %" PRIu16 ", "
"y1: %" PRIu16 ", y2: %" PRIu16 ". Num pixels: %lu\n",
x1, x2, y1, y2, (unsigned long)num_pix);
coordinates->x1, coordinates->x2, coordinates->y1,
coordinates->y2, (unsigned long)num_pix);

/* Send fill area to the display */
_ili9341_spi_acquire(dev);

_ili9341_set_area(dev, x1, x2, y1, y2);
_ili9341_set_area(dev, coordinates);
/* Memory access command */
_ili9341_cmd_start(dev, ILI9341_CMD_RAMWR, true);
#if ILI9341_LE_MODE
Expand All @@ -260,19 +266,20 @@ void ili9341_fill(const ili9341_t *dev, uint16_t x1, uint16_t x2, uint16_t y1,
spi_release(dev->params->spi);
}

void ili9341_pixmap(const ili9341_t *dev, uint16_t x1, uint16_t x2,
uint16_t y1, uint16_t y2, const uint16_t *color)
void ili9341_pixmap(const ili9341_t *dev, ili9341_coordinates_t * coordinates,
const uint16_t *color)
{
size_t num_pix = (x2 - x1 + 1) * (y2 - y1 + 1);
size_t num_pix = (size_t) _ili9341_get_pixel_num(coordinates);

DEBUG("[ili9341]: Write x1: %" PRIu16 ", x2: %" PRIu16 ", "
"y1: %" PRIu16 ", y2: %" PRIu16 ". Num pixels: %lu\n",
x1, x2, y1, y2, (unsigned long)num_pix);
coordinates->x1, coordinates->x2, coordinates->y1,
coordinates->y2, (unsigned long)num_pix);

_ili9341_spi_acquire(dev);

/* Send fill area to the display */
_ili9341_set_area(dev, x1, x2, y1, y2);
_ili9341_set_area(dev, coordinates);

/* Memory access command */
_ili9341_cmd_start(dev, ILI9341_CMD_RAMWR, true);
Expand Down
8 changes: 5 additions & 3 deletions drivers/ili9341/ili9341_disp_dev.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2020 Inria
* 2020 Philipp-Alexander Blum
*
* 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
Expand All @@ -14,6 +15,7 @@
* @brief Driver adaption to disp_dev generic interface
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
* @author Philipp-Alexander Blum <philipp-blum@jakiku.de>
* @}
*/

Expand All @@ -31,11 +33,11 @@
#define ILI9341_DISP_COLOR_DEPTH (16U)
#endif

static void _ili9341_map(const disp_dev_t *dev, uint16_t x1, uint16_t x2,
uint16_t y1, uint16_t y2, const uint16_t *color)
static void _ili9341_map(disp_dev_t *dev, disp_dev_coordinates_t *coordinates,
const uint16_t *color)
{
ili9341_t *ili9341 = (ili9341_t *)dev;
ili9341_pixmap(ili9341, x1, x2, y1, y2, color);
ili9341_pixmap(ili9341, (ili9341_coordinates_t *)coordinates, color);
}

static uint16_t _ili9341_height(const disp_dev_t *disp_dev)
Expand Down
103 changes: 83 additions & 20 deletions drivers/include/disp_dev.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2020 Inria
* 2020 Philipp-Alexander Blum
*
* 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
Expand All @@ -15,6 +16,7 @@
* @{
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
* @author Philipp-Alexander Blum <philipp-blum@jakiku.de>
*/

#ifndef DISP_DEV_H
Expand Down Expand Up @@ -42,23 +44,87 @@ extern "C" {
*/
typedef struct disp_dev disp_dev_t;

/**
* @brief Type to store the update coordinates in
*/
typedef struct {
uint16_t x1; /**< Left coordinate */
uint16_t x2; /**< Right coordinate */
uint16_t y1; /**< Top coordinate */
uint16_t y2; /**< Bottom coordinate */
} disp_dev_coordinates_t;

/**
* @brief Type for color depth.
*/
typedef enum {
MONOCHROME = 0,
2_BIT_COLOR,
GRAYSCALE,
8_BIT_COLOR,
16_BIT_HIGH_COLOR,
24_BIT_TRUE_COLOR
} disp_dev_color_depth_t;

/**
* @brief Type to hold a pixel for monochrome data
*/
typedef struct {
bool color;
} disp_dev_pix_mono_t;

/**
* @brief Type to hold a pixel for 2bit color data
*/
typedef struct {
bool black;
bool color;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this though. Maybe storing it in one uint8_t is better. Or maybe two booleans is better for the compiler to optimize.

} disp_dev_pix_2bit_color_t;

/**
* @brief Type to hold a pixel for greyscale data
*/
typedef struct {
uint8_t contrast;
} disp_dev_pix_greyscale_t;

/**
* @brief Type to hold a pixel for 8bit color data
*/
typedef struct {
uint8_t rgb;
} disp_dev_pix_8bit_color_t;

/**
* @brief Type to hold a pixel for 16bit high color data
*/
typedef struct {
uint16_t rgb;
} disp_dev_pix_16bit_hc_t;

/**
* @brief Type to hold a pixel for monochrome color data
*/
typedef struct {
uint8_t r;
uint8_t g;
uint8_t b;
} disp_dev_pix_24bit_tc_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
* @param[in] dev Pointer to the display device
* @param[in] coordinates Coordinate
* @param[in] color Array of color to map to the display
* @param[in] color_depth Color depth of color
*/
void (*map)(const disp_dev_t *dev,
uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2,
const uint16_t *color);
void (*map)(disp_dev_t *dev, disp_dev_coordinates_t *coordinates,
const void *color, disp_dev_color_depth_t color_depth);

/**
* @brief Get the height of the display device
Expand All @@ -83,7 +149,7 @@ typedef struct {
*
* @return The color depth
*/
uint8_t (*color_depth)(const disp_dev_t *dev);
disp_dev_color_depth_t (*color_depth)(const disp_dev_t *dev);

/**
* @brief Invert the display device colors
Expand All @@ -104,16 +170,13 @@ struct disp_dev {
/**
* @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
* @param[in] dev Pointer to the display device
* @param[in] coordinates Coordinate
* @param[in] color Array of color to map to the display
* @param[in] color_depth Color depth of color
*/
void disp_dev_map(const disp_dev_t *dev,
uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2,
const uint16_t *color);
void disp_dev_map(disp_dev_t *dev, disp_dev_coordinates_t *coordinates,
const void *color, disp_dev_color_depth_t color_depth);

/**
* @brief Get the height of the display device
Expand All @@ -138,7 +201,7 @@ uint16_t disp_dev_width(const disp_dev_t *dev);
*
* @return The color depth
*/
uint8_t disp_dev_color_depth(const disp_dev_t *dev);
disp_dev_color_depth_t disp_dev_color_depth(const disp_dev_t *dev);

/**
* @brief Invert the display device colors
Expand Down
38 changes: 21 additions & 17 deletions drivers/include/ili9341.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ typedef struct {
uint16_t lines; /**< Number of lines, from 16 to 320 in 8 line steps */
} ili9341_params_t;

/**
* @brief Type to store the update coordinates in
*/
typedef struct {
uint16_t x1; /**< Left coordinate */
uint16_t x2; /**< Right coordinate */
uint16_t y1; /**< Top coordinate */
uint16_t y2; /**< Bottom coordinate */
} ili9341_coordinates_t;

/**
* @brief Device descriptor for a ili9341
*/
Expand All @@ -129,15 +139,12 @@ int ili9341_init(ili9341_t *dev, const ili9341_params_t *params);
* x2 being the last column of pixels to fill. similar to that, y1 is the first
* row to fill and y2 is the last row to fill.
*
* @param[in] dev device descriptor
* @param[in] x1 x coordinate of the first corner
* @param[in] x2 x coordinate of the opposite corner
* @param[in] y1 y coordinate of the first corner
* @param[in] y2 y coordinate of the opposite corner
* @param[in] color single color to fill the area with
* @param[in] dev device descriptor
* @param[in] coordinates coordinates to fill with data
* @param[in] color single color to fill the area with
*/
void ili9341_fill(const ili9341_t *dev, uint16_t x1, uint16_t x2,
uint16_t y1, uint16_t y2, uint16_t color);
void ili9341_fill(const ili9341_t *dev, ili9341_coordinates_t *coordinates,
uint16_t color);

/**
* @brief Fill a rectangular area with an array of pixels
Expand All @@ -148,15 +155,12 @@ void ili9341_fill(const ili9341_t *dev, uint16_t x1, uint16_t x2,
*
* @note @p color must have a length equal to `(x2 - x1 + 1) * (y2 - y1 + 1)`
*
* @param[in] dev device descriptor
* @param[in] x1 x coordinate of the first corner
* @param[in] x2 x coordinate of the opposite corner
* @param[in] y1 y coordinate of the first corner
* @param[in] y2 y coordinate of the opposite corner
* @param[in] color array of colors to fill the area with
*/
void ili9341_pixmap(const ili9341_t *dev, uint16_t x1, uint16_t x2, uint16_t y1,
uint16_t y2, const uint16_t *color);
* @param[in] dev device descriptor
* @param[in] coordinates coordinates to fill with data
* @param[in] color array of colors to fill the area with
*/
void ili9341_pixmap(const ili9341_t *dev, ili9341_coordinates_t *coordinates,
const uint16_t *color);

/**
* @brief Raw write command
Expand Down
5 changes: 3 additions & 2 deletions pkg/lvgl/contrib/lvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ static void _disp_map(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *col
return;
}

disp_dev_map(_dev, area->x1, area->x2, area->y1, area->y2,
(const uint16_t *)color_p);
disp_dev_coordinates_t coordinates =
{ .x1 = area->x1, .x2 = area->x2, .y1 = area->y1, .y2 = area->y1 };
disp_dev_map(_dev, &coordinates, (const uint16_t *)color_p);

LOG_DEBUG("[lvgl] flush display\n");

Expand Down
Loading