Skip to content
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
21 changes: 11 additions & 10 deletions drivers/display/display_co5300.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
uint16_t panel_height;
uint16_t channel;
uint16_t num_of_lanes;
uint16_t frame_pitch_align; /* Pitch alignment requirement, in bytes. */
};

struct co5300_data {
Expand All @@ -46,7 +47,7 @@
struct k_sem tear_effect_sem;
/* Pointer to framebuffer */
uint8_t *frame_ptr;
uint32_t frame_pitch;
uint32_t frame_pitch; /* Pitch in bytes. */
};

/* Organized as MIPI_CMD | SIZE OF MIPI PARAM | MIPI PARAM */
Expand Down Expand Up @@ -108,12 +109,12 @@

/* Copy the update area to the framebuffer */
src = buf;
dst = data->frame_ptr + (y * data->frame_pitch * data->bytes_per_pixel)
dst = data->frame_ptr + (y * data->frame_pitch)
+ (x * data->bytes_per_pixel);
for (uint16_t row = 0; row < desc->height; row++) {
memcpy(dst, src, desc->width * data->bytes_per_pixel);
src += desc->pitch * data->bytes_per_pixel;
dst += data->frame_pitch * data->bytes_per_pixel;
src += desc->pitch;
dst += data->frame_pitch;
}

/*
Expand All @@ -139,7 +140,7 @@
local_desc->height = ROUND_UP(local_desc->height, 2U);
local_desc->pitch = data->frame_pitch;
local_desc->frame_incomplete = desc->frame_incomplete;
local_desc->buf_size = local_desc->width * local_desc->height * data->bytes_per_pixel;
local_desc->buf_size = local_desc->pitch * local_desc->height;
}

static int co5300_write(const struct device *dev,
Expand Down Expand Up @@ -222,7 +223,7 @@

/* Start memory write. */
/* The address and the total pixel size of the updated area. */
src = data->frame_ptr + (local_y * data->frame_pitch * data->bytes_per_pixel)
src = data->frame_ptr + (local_y * data->frame_pitch)
+ (local_x * data->bytes_per_pixel);
tx_size = local_desc.buf_size;

Expand All @@ -246,11 +247,11 @@
}

/* Advance source pointer and decrement remaining */
if (local_desc.pitch > local_desc.width) {
if (local_desc.pitch > local_desc.width * data->bytes_per_pixel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

local_desc.pitch > (local_desc.width * data->bytes_per_pixel)?

total_bytes_sent += bytes_written;
src += bytes_written + total_bytes_sent /
(local_desc.width * data->bytes_per_pixel) *
((local_desc.pitch - local_desc.width) * data->bytes_per_pixel);
(local_desc.pitch - local_desc.width * data->bytes_per_pixel);
} else {
src += bytes_written;
}
Expand Down Expand Up @@ -342,6 +343,7 @@
/* Update the format in the device data after DCS command succeeds. */
data->bytes_per_pixel = bytes_per_pixel;
data->pixel_format = mipi_pixel_format;
data->frame_pitch = ROUND_UP(config->panel_width * bytes_per_pixel, config->frame_pitch_align);

Check warning on line 346 in drivers/display/display_co5300.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

drivers/display/display_co5300.c:346 line length of 103 exceeds 100 columns

Check warning on line 346 in drivers/display/display_co5300.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

drivers/display/display_co5300.c:346 line length of 103 exceeds 100 columns

return 0;
}
Expand Down Expand Up @@ -552,13 +554,12 @@
.tear_effect_gpios = GPIO_DT_SPEC_INST_GET_OR(node_id, tear_effect_gpios, {0}), \
.panel_width = DT_INST_PROP(node_id, width), \
.panel_height = DT_INST_PROP(node_id, height), \
.frame_pitch_align = DT_INST_PROP_OR(node_id, pitch_align, 1), \
}; \
CO5300_FRAMEBUFFER_DECL(node_id); \
static struct co5300_data co5300_data_##node_id = { \
.pixel_format = DT_INST_PROP(node_id, pixel_format), \
.frame_ptr = CO5300_FRAMEBUFFER(node_id), \
.frame_pitch = ROUND_UP(DT_INST_PROP(node_id, width), \
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not delete this, frame pitch needs a initial value after system init

DT_INST_PROP(node_id, pitch_align)), \
}; \
DEVICE_DT_INST_DEFINE(node_id, \
&co5300_init, \
Expand Down
14 changes: 8 additions & 6 deletions drivers/display/display_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ static int dummy_display_write(const struct device *dev, const uint16_t x,
const void *buf)
{
const struct dummy_display_config *config = dev->config;
struct dummy_display_data *disp_data = dev->data;
uint8_t bytes_per_pixel;

bytes_per_pixel = DISPLAY_BITS_PER_PIXEL(disp_data->current_pixel_format) / 8;

__ASSERT(desc->width <= desc->pitch, "Pitch is smaller than width");
__ASSERT(desc->pitch <= config->width,
"Pitch in descriptor is larger than screen size");
__ASSERT(desc->width * bytes_per_pixel <= desc->pitch, "Pitch is smaller than width");
__ASSERT(desc->height <= config->height,
"Height in descriptor is larger than screen size");
__ASSERT(x + desc->pitch <= config->width,
__ASSERT(x + desc->width <= config->width,
"Writing outside screen boundaries in horizontal direction");
__ASSERT(y + desc->height <= config->height,
"Writing outside screen boundaries in vertical direction");

if (desc->width > desc->pitch ||
x + desc->pitch > config->width ||
if (desc->width * bytes_per_pixel > desc->pitch ||
x + desc->width > config->width ||
y + desc->height > config->height) {
return -EINVAL;
}
Expand Down
10 changes: 5 additions & 5 deletions drivers/display/display_gc9x01x.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ static int gc9x01x_write(const struct device *dev, const uint16_t x, const uint1
uint16_t nbr_of_writes;
uint16_t write_h;

__ASSERT(desc->width <= desc->pitch, "Pitch is smaller than width");
__ASSERT((desc->pitch * data->bytes_per_pixel * desc->height) <= desc->buf_size,
__ASSERT(desc->width * data->bytes_per_pixel <= desc->pitch, "Pitch is smaller than width");
__ASSERT((desc->pitch * desc->height) <= desc->buf_size,
"Input buffer too small");

LOG_DBG("Writing %dx%d (w,h) @ %dx%d (x,y)", desc->width, desc->height, x, y);
Expand All @@ -526,7 +526,7 @@ static int gc9x01x_write(const struct device *dev, const uint16_t x, const uint1
return ret;
}

if (desc->pitch > desc->width) {
if (desc->pitch > desc->width * data->bytes_per_pixel) {
write_h = 1U;
nbr_of_writes = desc->height;
mipi_desc.height = 1;
Expand All @@ -540,7 +540,7 @@ static int gc9x01x_write(const struct device *dev, const uint16_t x, const uint1

mipi_desc.width = desc->width;
/* Per MIPI API, pitch must always match width */
mipi_desc.pitch = desc->width;
mipi_desc.pitch = desc->width * data->bytes_per_pixel;
mipi_desc.frame_incomplete = desc->frame_incomplete;

ret = gc9x01x_transmit(dev, GC9X01X_CMD_MEMWR, NULL, 0);
Expand All @@ -558,7 +558,7 @@ static int gc9x01x_write(const struct device *dev, const uint16_t x, const uint1
return ret;
}

write_data_start += desc->pitch * data->bytes_per_pixel;
write_data_start += desc->pitch;
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions drivers/display/display_hub12.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int hub12_write(const struct device *dev, const uint16_t x, const uint16_
return -EINVAL;
}

if (desc->pitch != desc->width) {
if (desc->pitch != (desc->width / HUB12_PIXELS_PER_BYTE)) {
LOG_ERR("Unsupported pitch");
return -ENOTSUP;
}
Expand All @@ -173,7 +173,7 @@ static int hub12_write(const struct device *dev, const uint16_t x, const uint16_
memcpy(data->framebuffer, src, fb_size);
} else {
/* Partial update */
size_t src_pitch_bytes = desc->pitch / HUB12_PIXELS_PER_BYTE;
size_t src_pitch_bytes = desc->pitch;
size_t dest_pitch_bytes = config->width / HUB12_PIXELS_PER_BYTE;

for (uint16_t j = 0; j < desc->height; j++) {
Expand Down
20 changes: 9 additions & 11 deletions drivers/display/display_ili9xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ static int ili9xxx_write(const struct device *dev, const uint16_t x,
uint16_t nbr_of_writes;
uint16_t write_h;

__ASSERT(desc->width <= desc->pitch, "Pitch is smaller than width");
__ASSERT((desc->pitch * data->bytes_per_pixel * desc->height) <=
desc->buf_size,
__ASSERT(desc->width * data->bytes_per_pixel <= desc->pitch, "Pitch is smaller than width");
__ASSERT((desc->pitch * desc->height) <= desc->buf_size,
"Input buffer too small");

LOG_DBG("Writing %dx%d (w,h) @ %dx%d (x,y)", desc->width, desc->height,
Expand All @@ -148,11 +147,11 @@ static int ili9xxx_write(const struct device *dev, const uint16_t x,
return r;
}

if (desc->pitch > desc->width) {
if (desc->pitch > desc->width * data->bytes_per_pixel) {
write_h = 1U;
nbr_of_writes = desc->height;
mipi_desc.height = 1;
mipi_desc.buf_size = desc->pitch * data->bytes_per_pixel;
mipi_desc.buf_size = desc->pitch;
} else {
write_h = desc->height;
mipi_desc.height = desc->height;
Expand All @@ -162,7 +161,7 @@ static int ili9xxx_write(const struct device *dev, const uint16_t x,

mipi_desc.width = desc->width;
/* Per MIPI API, pitch must always match width */
mipi_desc.pitch = desc->width;
mipi_desc.pitch = desc->width * data->bytes_per_pixel;
mipi_desc.frame_incomplete = desc->frame_incomplete;

r = ili9xxx_transmit(dev, ILI9XXX_RAMWR, NULL, 0);
Expand All @@ -180,7 +179,7 @@ static int ili9xxx_write(const struct device *dev, const uint16_t x,
return r;
}

write_data_start += desc->pitch * data->bytes_per_pixel;
write_data_start += desc->pitch;
}

return 0;
Expand All @@ -204,9 +203,8 @@ static int ili9xxx_read(const struct device *dev, const uint16_t x,
return -ENOTSUP;
}

__ASSERT(desc->width <= desc->pitch, "Pitch is smaller than width");
__ASSERT((desc->pitch * data->bytes_per_pixel * desc->height) <=
desc->buf_size,
__ASSERT(desc->width * data->bytes_per_pixel <= desc->pitch, "Pitch is smaller than width");
__ASSERT((desc->pitch * desc->height) <= desc->buf_size,
"Output buffer too small");

LOG_DBG("Reading %dx%d (w,h) @ %dx%d (x,y)", desc->width, desc->height,
Expand Down Expand Up @@ -235,7 +233,7 @@ static int ili9xxx_read(const struct device *dev, const uint16_t x,
mipi_desc.width = 1;
mipi_desc.height = 1;
/* Per MIPI API, pitch must always match width */
mipi_desc.pitch = 1;
mipi_desc.pitch = 1 * data->bytes_per_pixel;

nbr_of_reads = desc->width * desc->height;

Expand Down
6 changes: 3 additions & 3 deletions drivers/display/display_intel_multibootfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct framebuf_dev_config {

struct framebuf_dev_data {
void *buffer;
uint32_t pitch;
uint32_t pitch; /* In Bytes. */
};

static int framebuf_set_pixel_format(const struct device *dev,
Expand Down Expand Up @@ -135,12 +135,12 @@ static int multiboot_framebuf_init(const struct device *dev)

adj_x = info->fb_width - config->width;
adj_y = info->fb_height - config->height;
data->pitch = (info->fb_pitch / 4) + adj_x;
data->pitch = info->fb_pitch + adj_x * sizeof(uint32_t);
adj_x /= 2U;
adj_y /= 2U;
buffer = (uint32_t *) (uintptr_t) info->fb_addr_lo;
buffer += adj_x;
buffer += adj_y * data->pitch;
buffer += adj_y * (data->pitch / sizeof(uint32_t));
data->buffer = buffer;
return 0;
} else {
Expand Down
17 changes: 10 additions & 7 deletions drivers/display/display_led_strip_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@
static inline int check_descriptor(const struct led_strip_matrix_config *config, const uint16_t x,
const uint16_t y, const struct display_buffer_descriptor *desc)
{
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller than width");
__ASSERT(desc->pitch <= config->width, "Pitch in descriptor is larger than screen size");
const uint16_t bytes_per_pixel = (config->pixel_format == PIXEL_FORMAT_ARGB_8888 ? 4 : 3);
const uint16_t width_bytes = desc->width * bytes_per_pixel;

Check warning on line 92 in drivers/display/display_led_strip_matrix.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

unused variable 'width_bytes'

See more on https://sonarcloud.io/project/issues?id=zephyrproject-rtos_zephyr&issues=AZsDkNXQiCMsu6sWc8Sp&open=AZsDkNXQiCMsu6sWc8Sp&pullRequest=100749

Check warning on line 92 in drivers/display/display_led_strip_matrix.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'width_bytes' during its initialization is never read

See more on https://sonarcloud.io/project/issues?id=zephyrproject-rtos_zephyr&issues=AZsDkNXQiCMsu6sWc8Sq&open=AZsDkNXQiCMsu6sWc8Sq&pullRequest=100749

__ASSERT(width_bytes <= desc->pitch, "Pitch is smaller than width");
__ASSERT(desc->pitch <= config->width * bytes_per_pixel, "Pitch in descriptor is larger than screen size");

Check warning on line 95 in drivers/display/display_led_strip_matrix.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE_STRING

drivers/display/display_led_strip_matrix.c:95 line length of 115 exceeds 100 columns

Check warning on line 95 in drivers/display/display_led_strip_matrix.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE_STRING

drivers/display/display_led_strip_matrix.c:95 line length of 115 exceeds 100 columns
__ASSERT(desc->height <= config->height, "Height in descriptor is larger than screen size");
__ASSERT(x + desc->pitch <= config->width,
__ASSERT(x + desc->width <= config->width,
"Writing outside screen boundaries in horizontal direction");
__ASSERT(y + desc->height <= config->height,
"Writing outside screen boundaries in vertical direction");
Expand All @@ -109,6 +112,7 @@
{
const struct led_strip_matrix_config *config = dev->config;
const uint8_t *buf_ptr = buf;
const uint16_t bytes_per_pixel = (config->pixel_format == PIXEL_FORMAT_ARGB_8888 ? 4 : 3);
int rc;

rc = check_descriptor(config, x, y, desc);
Expand Down Expand Up @@ -138,8 +142,7 @@
buf_ptr++;
}
}
buf_ptr += (desc->pitch - desc->width) *
(config->pixel_format == PIXEL_FORMAT_ARGB_8888 ? 4 : 3);
buf_ptr += desc->pitch - (desc->width * bytes_per_pixel);
}

for (size_t i = 0; i < config->num_of_strips; i++) {
Expand All @@ -158,6 +161,7 @@
{
const struct led_strip_matrix_config *config = dev->config;
uint8_t *buf_ptr = buf;
const uint16_t bytes_per_pixel = (config->pixel_format == PIXEL_FORMAT_ARGB_8888 ? 4 : 3);
int rc;

rc = check_descriptor(config, x, y, desc);
Expand All @@ -183,8 +187,7 @@
buf_ptr++;
}
}
buf_ptr += (desc->pitch - desc->width) *
(config->pixel_format == PIXEL_FORMAT_ARGB_8888 ? 4 : 3);
buf_ptr += desc->pitch - (desc->width * bytes_per_pixel);
}

return 0;
Expand Down
12 changes: 6 additions & 6 deletions drivers/display/display_max7219.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ static int max7219_write(const struct device *dev, const uint16_t x, const uint1
/*
* MAX7219 only supports PIXEL_FORMAT_MONO01. 1 bit stands for 1 pixel.
*/
__ASSERT((desc->pitch * desc->height) <= (desc->buf_size * 8U), "Input buffer too small");
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller than width");
__ASSERT(desc->pitch <= max_width, "Pitch in descriptor is larger than screen size");
__ASSERT((desc->pitch * desc->height) <= desc->buf_size, "Input buffer too small");
__ASSERT((desc->width + 7U) / 8U <= desc->pitch, "Pitch is smaller than width");
__ASSERT(desc->pitch * 8U <= max_width, "Pitch in descriptor is larger than screen size");
__ASSERT(desc->height <= max_height, "Height in descriptor is larger than screen size");
__ASSERT(x + desc->pitch <= max_width,
__ASSERT(x + desc->pitch * 8U <= max_width,
"Writing outside screen boundaries in horizontal direction");
__ASSERT(y + desc->height <= max_height,
"Writing outside screen boundaries in vertical direction");
Expand All @@ -164,7 +164,7 @@ static int max7219_write(const struct device *dev, const uint16_t x, const uint1
return -EINVAL;
}

if ((x + desc->pitch) > max_width || (y + desc->height) > max_height) {
if ((x + desc->pitch * 8U) > max_width || (y + desc->height) > max_height) {
return -EINVAL;
}

Expand Down Expand Up @@ -311,7 +311,7 @@ static int max7219_init(const struct device *dev)
.buf_size = dev_config->num_cascading * MAX7219_DIGITS_PER_DEVICE,
.height = dev_config->num_cascading * MAX7219_DIGITS_PER_DEVICE,
.width = MAX7219_DIGITS_PER_DEVICE,
.pitch = MAX7219_DIGITS_PER_DEVICE,
.pitch = (MAX7219_DIGITS_PER_DEVICE + 7U) / 8U,
};

ret = max7219_write(dev, 0, 0, &desc, dev_data->digit_buf);
Expand Down
6 changes: 3 additions & 3 deletions drivers/display/display_mcux_dcnano_lcdif.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ static int mcux_dcnano_lcdif_write(const struct device *dev, const uint16_t x,
const uint8_t *src;
uint8_t *dst;

__ASSERT((data->pixel_bytes * desc->pitch * desc->height) <=
__ASSERT((desc->pitch * desc->height) <=
desc->buf_size, "Input buffer too small");

LOG_DBG("W=%d, H=%d @%d,%d", desc->width, desc->height, x, y);

if ((x == 0) && (y == 0) &&
(desc->width == config->dpi_config.panelWidth) &&
(desc->height == config->dpi_config.panelHeight) &&
(desc->pitch == desc->width)) {
(desc->pitch == (desc->width * data->pixel_bytes))) {
/* We can use the display buffer directly, without copying */
LOG_DBG("Setting FB from %p->%p",
(void *)data->active_fb, (void *)buf);
Expand All @@ -87,7 +87,7 @@ static int mcux_dcnano_lcdif_write(const struct device *dev, const uint16_t x,

for (h_idx = 0; h_idx < desc->height; h_idx++) {
memcpy(dst, src, data->pixel_bytes * desc->width);
src += data->pixel_bytes * desc->pitch;
src += desc->pitch;
dst += data->pixel_bytes * config->dpi_config.panelWidth;
}
LOG_DBG("Setting FB from %p->%p", (void *) data->active_fb,
Expand Down
Loading
Loading