From 2a1fee34f529704039d3239d862a17b5a0f5de68 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Wed, 16 Aug 2023 11:56:49 +0900 Subject: [PATCH] samples: modules: u8g2: add u8x8 samples for u8g2 module Add sample for u8g2 module. hello_u8x8 sample show how to use u8x8 mode. Signed-off-by: TOKITA Hiroshi --- .../modules/u8g2/hello_u8x8/CMakeLists.txt | 8 +++ samples/modules/u8g2/hello_u8x8/README.rst | 26 ++++++++ .../hello_u8x8/boards/native_posix_64.conf | 1 + samples/modules/u8g2/hello_u8x8/prj.conf | 4 ++ samples/modules/u8g2/hello_u8x8/sample.yaml | 7 +++ samples/modules/u8g2/hello_u8x8/src/main.c | 60 +++++++++++++++++++ 6 files changed, 106 insertions(+) create mode 100644 samples/modules/u8g2/hello_u8x8/CMakeLists.txt create mode 100644 samples/modules/u8g2/hello_u8x8/README.rst create mode 100644 samples/modules/u8g2/hello_u8x8/boards/native_posix_64.conf create mode 100644 samples/modules/u8g2/hello_u8x8/prj.conf create mode 100644 samples/modules/u8g2/hello_u8x8/sample.yaml create mode 100644 samples/modules/u8g2/hello_u8x8/src/main.c diff --git a/samples/modules/u8g2/hello_u8x8/CMakeLists.txt b/samples/modules/u8g2/hello_u8x8/CMakeLists.txt new file mode 100644 index 00000000000000..370aeeb4df17e1 --- /dev/null +++ b/samples/modules/u8g2/hello_u8x8/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2023 TOKITA Hiroshi +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(hello_u8x8) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/modules/u8g2/hello_u8x8/README.rst b/samples/modules/u8g2/hello_u8x8/README.rst new file mode 100644 index 00000000000000..fe162ad9ca6516 --- /dev/null +++ b/samples/modules/u8g2/hello_u8x8/README.rst @@ -0,0 +1,26 @@ +.. _hello_u8x8: + +U8x8 sample +########### + +Overview +******** + +This sample is U8G2 library demo. +This sample shows how to use U8x8 mode that not use offscreen buffer mode. + +Requirements +************ + +This sample require display device. + +Building and Running +******************** + +To build and flash the sample for the :ref:`frdm_k64f`: + +.. zephyr-app-commands:: + :zephyr-app: samples/module/u8g2/hello_u8x8 + :board: frdm_k64f + :goals: build flash + :compact: diff --git a/samples/modules/u8g2/hello_u8x8/boards/native_posix_64.conf b/samples/modules/u8g2/hello_u8x8/boards/native_posix_64.conf new file mode 100644 index 00000000000000..fbfa2e6e86a3fc --- /dev/null +++ b/samples/modules/u8g2/hello_u8x8/boards/native_posix_64.conf @@ -0,0 +1 @@ +CONFIG_SDL_DISPLAY_DEFAULT_PIXEL_FORMAT_MONO10=y diff --git a/samples/modules/u8g2/hello_u8x8/prj.conf b/samples/modules/u8g2/hello_u8x8/prj.conf new file mode 100644 index 00000000000000..8997b38ce5b62b --- /dev/null +++ b/samples/modules/u8g2/hello_u8x8/prj.conf @@ -0,0 +1,4 @@ +CONFIG_HEAP_MEM_POOL_SIZE=16384 +CONFIG_LOG=y +CONFIG_DISPLAY=y +CONFIG_U8G2=y diff --git a/samples/modules/u8g2/hello_u8x8/sample.yaml b/samples/modules/u8g2/hello_u8x8/sample.yaml new file mode 100644 index 00000000000000..558b801e0b71c3 --- /dev/null +++ b/samples/modules/u8g2/hello_u8x8/sample.yaml @@ -0,0 +1,7 @@ +sample: + description: U8x8 Sample application + name: hello_u8x8 +tests: + sample.modules.u8g2.hello_u8x8.sdl: + platform_allow: native_posix_64 + tags: display diff --git a/samples/modules/u8g2/hello_u8x8/src/main.c b/samples/modules/u8g2/hello_u8x8/src/main.c new file mode 100644 index 00000000000000..497e588ba5f057 --- /dev/null +++ b/samples/modules/u8g2/hello_u8x8/src/main.c @@ -0,0 +1,60 @@ +/* + * Copyright 2023 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include +#include + +#ifdef CONFIG_ARCH_POSIX +#include "posix_board_if.h" +#endif + +#include +LOG_MODULE_REGISTER(hello_u8x8, LOG_LEVEL_INF); + +int main(void) +{ + const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)); + u8x8_t *u8x8; + + if (!device_is_ready(dev)) { + LOG_ERR("Device %s not found. Aborting sample.", dev->name); + return 0; + } + + if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO10) != 0) { + LOG_ERR("Failed to set required pixel format."); + return 0; + } + + if (display_blanking_off(dev) != 0) { + LOG_ERR("Failed to turn off display blanking."); + return 0; + } + + u8x8 = u8x8_SetupZephyr(dev); + if (!u8x8) { + LOG_ERR("Failed to allocate u8x8 instance."); + return 0; + } + + u8x8_InitDisplay(u8x8); + u8x8_ClearDisplay(u8x8); + + u8x8_SetFont(u8x8, u8x8_font_amstrad_cpc_extended_f); + u8x8_DrawString(u8x8, 0, 0, "Hello World!"); + u8x8_Draw1x2String(u8x8, 0, 1, "Hello World!"); + u8x8_Draw2x2String(u8x8, 0, 3, "Hello World!"); + +#ifdef CONFIG_ARCH_POSIX + posix_exit_main(0); +#endif + + return 0; +}