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

fb: cfb: Support memory constrainted system by partial frame transferring #72204

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions doc/hardware/peripherals/display/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BBC micro:bit Display

.. doxygengroup:: mb_display

Monochrome Character Framebuffer
================================
Compact Framebuffer APIs
========================

.. doxygengroup:: monochrome_character_framebuffer
.. doxygengroup:: compact_framebuffer_subsystem
59 changes: 59 additions & 0 deletions doc/releases/migration-guide-3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,65 @@ Flash map
one-time cost of enabling the PSA API (:kconfig:option:`CONFIG_MBEDTLS_PSA_CRYPTO_C` for devices without TF-M).
:github:`73511`

CFB
===

* Changed API to support multiple displays.

Introduced :c:struct:`cfb_display` structure to represent a display.
Therefore, use :c:func:`cfb_display_init` instead of deprecated cfb_framebuffer_init.
cfb_framebuffer_init has been deprecated.

Added :c:func:`cfb_display_get_framebuffer` to get the framebuffer associated with a display.

The following API has changed the first argument pointer of :c:struct:`device` to
pointer of :c:struct:`cfb_framebuffer`.
Use the reference obtained with :c:func:`cfb_display_get_framebuffer` above.

* :c:func:`cfb_print`
* :c:func:`cfb_draw_text`
* :c:func:`cfb_draw_point`
* :c:func:`cfb_draw_line`
* :c:func:`cfb_draw_rect`
* :c:func:`cfb_invert_area`
* :c:func:`cfb_set_kerning`
* :c:func:`cfb_clear` (renamed from `cfb_framebuffer_clear`)
* :c:func:`cfb_invert` (renamed from `cfb_framebuffer_invert`)
* :c:func:`cfb_finalize` (renamed from `cfb_framebuffer_finalize`)
* :c:func:`cfb_set_font` (renamed from `cfb_framebuffer_finalize`)

:c:func:`cfb_display_alloc` can use to migrate from `cfb_framebuffer_init`.

.. code-block:: c

const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
struct cfb_display *disp;
struct cfb_framebuffer *fb;

disp = cfb_display_alloc(dev);
fb = cfb_display_get_framebuffer(&disp);
cfb_print(fb, "Hello!", 0, 0);


Also, please see the sample in ``samples/display/cfb``.

* Remove unnecessary arguments for font-related APIs

The following API has removed the first argument pointer of :c:struct:`device`.
This argument was not used internally, so simply remove it.

* :c:func:`cfb_get_font_size`
* :c:func:`cfb_get_numof_fonts`

* Change coordinate specification to signed integer

Change the following function arguments and structure fields used to specify
coordinates to signed integers.

* :c:func:`cfb_print`
* :c:func:`cfb_invert_area`
* :c:struct:`cfb_position`

hawkBit
=======

Expand Down
1,072 changes: 963 additions & 109 deletions include/zephyr/display/cfb.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion samples/boards/reel_board/mesh_badge/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ CONFIG_SPI_ASYNC=y
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_DISPLAY=y

CONFIG_CHARACTER_FRAMEBUFFER=y
CONFIG_CFB=y

CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
Expand Down
32 changes: 21 additions & 11 deletions samples/boards/reel_board/mesh_badge/src/reel_board.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct font_info {
#define STAT_COUNT 128

static const struct device *const epd_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
static struct cfb_display *epd_disp;
static bool pressed;
static uint8_t screen_id = SCREEN_MAIN;
static struct k_work_delayable epd_work;
Expand All @@ -74,11 +75,12 @@ struct k_work_delayable led_timer;
static size_t print_line(enum font_size font_size, int row, const char *text,
size_t len, bool center)
{
struct cfb_framebuffer *fb = cfb_display_get_framebuffer(epd_disp);
uint8_t font_height, font_width;
uint8_t line[fonts[FONT_SMALL].columns + 1];
int pad;

cfb_framebuffer_set_font(epd_dev, font_size);
cfb_set_font(fb, font_size);

len = MIN(len, fonts[font_size].columns);
memcpy(line, text, len);
Expand All @@ -90,9 +92,9 @@ static size_t print_line(enum font_size font_size, int row, const char *text,
pad = 0;
}

cfb_get_font_size(epd_dev, font_size, &font_width, &font_height);
cfb_get_font_size(font_size, &font_width, &font_height);

if (cfb_print(epd_dev, line, font_width * pad, font_height * row)) {
if (cfb_print(fb, line, font_width * pad, font_height * row)) {
printk("Failed to print a string\n");
}

Expand Down Expand Up @@ -134,9 +136,10 @@ void board_blink_leds(void)

void board_show_text(const char *text, bool center, k_timeout_t duration)
{
struct cfb_framebuffer *fb = cfb_display_get_framebuffer(epd_disp);
int i;

cfb_framebuffer_clear(epd_dev, false);
cfb_clear(fb, false);

for (i = 0; i < 3; i++) {
size_t len;
Expand All @@ -156,7 +159,7 @@ void board_show_text(const char *text, bool center, k_timeout_t duration)
}
}

cfb_framebuffer_finalize(epd_dev);
cfb_finalize(fb);

if (!K_TIMEOUT_EQ(duration, K_FOREVER)) {
k_work_reschedule(&epd_work, duration);
Expand Down Expand Up @@ -267,12 +270,13 @@ void board_add_heartbeat(uint16_t addr, uint8_t hops)

static void show_statistics(void)
{
struct cfb_framebuffer *fb = cfb_display_get_framebuffer(epd_disp);
int top[4] = { -1, -1, -1, -1 };
int len, i, line = 0;
struct stat *stat;
char str[32];

cfb_framebuffer_clear(epd_dev, false);
cfb_clear(fb, false);

len = snprintk(str, sizeof(str),
"Own Address: 0x%04x", mesh_get_addr());
Expand Down Expand Up @@ -335,16 +339,17 @@ static void show_statistics(void)
}
}

cfb_framebuffer_finalize(epd_dev);
cfb_finalize(fb);
}

static void show_sensors_data(k_timeout_t interval)
{
struct cfb_framebuffer *fb = cfb_display_get_framebuffer(epd_disp);
struct sensor_value val[3];
uint8_t line = 0U;
uint16_t len = 0U;

cfb_framebuffer_clear(epd_dev, false);
cfb_clear(fb, false);

/* hdc1010 */
if (get_hdc1010_val(val)) {
Expand Down Expand Up @@ -386,7 +391,7 @@ static void show_sensors_data(k_timeout_t interval)
len = snprintf(str_buf, sizeof(str_buf), "Proximity:%d\n", val[1].val1);
print_line(FONT_SMALL, line++, str_buf, len, false);

cfb_framebuffer_finalize(epd_dev);
cfb_finalize(fb);

k_work_reschedule(&epd_work, interval);

Expand Down Expand Up @@ -584,17 +589,22 @@ void board_refresh_display(void)

int board_init(void)
{
struct cfb_framebuffer *fb;

if (!device_is_ready(epd_dev)) {
printk("%s: device not ready.\n", epd_dev->name);
return -ENODEV;
}

if (cfb_framebuffer_init(epd_dev)) {
epd_disp = cfb_display_alloc(epd_dev);
if (!epd_disp) {
printk("Framebuffer initialization failed\n");
return -EIO;
}

cfb_framebuffer_clear(epd_dev, true);
fb = cfb_display_get_framebuffer(epd_disp);

cfb_clear(fb, true);

if (configure_button()) {
printk("Failed to configure button\n");
Expand Down
16 changes: 16 additions & 0 deletions samples/subsys/display/cfb/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2024 TOKITA Hiroshi
# SPDX-License-Identifier: Apache-2.0

mainmenu "CFB Sample Application"

config CFB_SAMPLE_TRANSFER_BUFFER_SIZE
int "Buffer size for image transfer"
default 0
help
Dynamically allocate display object if set 0 to this option,

config CFB_SAMPLE_COMMAND_BUFFER_SIZE
int "Buffer size for store commands"
default 0

source "Kconfig.zephyr"
16 changes: 8 additions & 8 deletions samples/subsys/display/cfb/README.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
.. zephyr:code-sample:: character-frame-buffer
:name: Character frame buffer
:relevant-api: monochrome_character_framebuffer
.. zephyr:code-sample:: cfb-sample
:name: Compact Framebuffer subsystem sample
:relevant-api: compact_framebuffer_subsystem

Display character strings using the Character Frame Buffer (CFB).
Display character strings using the Compact Framebuffer (CFB) subsystem.

Overview
********

This sample displays character strings using the Character Frame Buffer
(CFB) subsystem framework.
This sample displays character strings using the Compact Framebuffer
(CFB) subsystem.

Requirements
************

This sample requires a supported board and CFB-supporting
display, such as the :ref:`reel_board`.
This sample requires a board that have a display,
such as the :ref:`reel_board`.

Building and Running
********************
Expand Down
3 changes: 3 additions & 0 deletions samples/subsys/display/cfb/boards/longan_nano.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_CFB_SAMPLE_TRANSFER_BUFFER_SIZE=6400
CONFIG_CFB_SAMPLE_COMMAND_BUFFER_SIZE=128
3 changes: 3 additions & 0 deletions samples/subsys/display/cfb/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_STDOUT_CONSOLE=n
CONFIG_HEAP_MEM_POOL_SIZE=1244160
Copy link
Member

Choose a reason for hiding this comment

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

sounds a bit random, maybe pick some more recognizable number?

CONFIG_SDL_DISPLAY_DEFAULT_PIXEL_FORMAT_MONO01=y
3 changes: 3 additions & 0 deletions samples/subsys/display/cfb/boards/native_sim_64.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_STDOUT_CONSOLE=n
CONFIG_HEAP_MEM_POOL_SIZE=1244160
CONFIG_SDL_DISPLAY_DEFAULT_PIXEL_FORMAT_MONO01=y
2 changes: 1 addition & 1 deletion samples/subsys/display/cfb/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ CONFIG_DISPLAY=y
CONFIG_LOG=y

CONFIG_CFB_LOG_LEVEL_DBG=y
CONFIG_CHARACTER_FRAMEBUFFER=y
CONFIG_CFB=y
2 changes: 1 addition & 1 deletion samples/subsys/display/cfb/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ common:
harness: display
tags: display
sample:
description: Character framebuffer test
description: Compact Framebuffer Subsystem test
name: cfb sample
tests:
sample.display.cfb.ssd1306:
Expand Down
Loading
Loading