Skip to content

Commit

Permalink
samples: modules: u8g2: add u8x8 samples for u8g2 module
Browse files Browse the repository at this point in the history
Add sample for u8g2 module.

hello_u8x8 sample show how to use u8x8 mode.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
  • Loading branch information
soburi committed Aug 16, 2023
1 parent 9627315 commit 2a1fee3
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
8 changes: 8 additions & 0 deletions samples/modules/u8g2/hello_u8x8/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions samples/modules/u8g2/hello_u8x8/README.rst
Original file line number Diff line number Diff line change
@@ -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:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SDL_DISPLAY_DEFAULT_PIXEL_FORMAT_MONO10=y
4 changes: 4 additions & 0 deletions samples/modules/u8g2/hello_u8x8/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_LOG=y
CONFIG_DISPLAY=y
CONFIG_U8G2=y
7 changes: 7 additions & 0 deletions samples/modules/u8g2/hello_u8x8/sample.yaml
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions samples/modules/u8g2/hello_u8x8/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2023 TOKITA Hiroshi
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <u8g2.h>
#include <u8g2_zephyr.h>

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/display.h>

#ifdef CONFIG_ARCH_POSIX
#include "posix_board_if.h"
#endif

#include <zephyr/logging/log.h>
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;
}

0 comments on commit 2a1fee3

Please sign in to comment.