Skip to content

Commit

Permalink
fb: cfb: Fix print of ASCII chars from 128 to 255
Browse files Browse the repository at this point in the history
Change the "c" variable type from char to uint8_t in get_glyph_ptr() and
draw_char_vtmono() to fix issues with the range check of the "c" value.

The easiest way to print localized text with Zephyr is
to ask GCC for compile-time conversion:

  INCLUDE(${ZEPHYR_BASE}/cmake/cfb.cmake NO_POLICY_SCOPE)
    GENERATE_CFB_FONT_FOR_TARGET(app
    "${CMAKE_CURRENT_SOURCE_DIR}/fonts/koi8-u.png"
    "${ZEPHYR_BINARY_DIR}/include/generated/cfb_font_dice.h"
    8 16 --first 0 --last 255)

  TARGET_COMPILE_OPTIONS(app PRIVATE
    -finput-charset=UTF-8
    -fexec-charset=KOI8-U)

Signed-off-by: Oleh Kravchenko <[email protected]>
  • Loading branch information
Oleh-Kravchenko committed Jan 27, 2025
1 parent f0d0264 commit ae9b964
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions subsys/fb/cfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct char_framebuffer {

static struct char_framebuffer char_fb;

static inline uint8_t *get_glyph_ptr(const struct cfb_font *fptr, char c)
static inline uint8_t *get_glyph_ptr(const struct cfb_font *fptr, uint8_t c)
{
return (uint8_t *)fptr->data +
(c - fptr->first_char) *
Expand All @@ -92,7 +92,7 @@ static inline uint8_t get_glyph_byte(uint8_t *glyph_ptr, const struct cfb_font *
* a byte is interpreted as 8 pixels ordered vertically among each other.
*/
static uint8_t draw_char_vtmono(const struct char_framebuffer *fb,
char c, uint16_t x, uint16_t y,
uint8_t c, uint16_t x, uint16_t y,
bool draw_bg)
{
const struct cfb_font *fptr = &(fb->fonts[fb->font_idx]);
Expand Down

0 comments on commit ae9b964

Please sign in to comment.