-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <tokita.hiroshi@gmail.com>
- Loading branch information
Showing
6 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_SDL_DISPLAY_DEFAULT_PIXEL_FORMAT_MONO10=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |