Skip to content

Commit

Permalink
samples: driver: Add auxdisplay sample
Browse files Browse the repository at this point in the history
Adds a simple auxdisplay sample which outputs hello world and the
name of the board.

Signed-off-by: Jamie McCrae <spam@helper3000.net>
  • Loading branch information
thedjnK committed Jan 7, 2023
1 parent 61e355d commit b16e223
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions samples/drivers/auxdisplay/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
project(auxdisplay)

target_sources(app PRIVATE src/main.c)
2 changes: 2 additions & 0 deletions samples/drivers/auxdisplay/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_AUXDISPLAY=y
CONFIG_LOG=y
78 changes: 78 additions & 0 deletions samples/drivers/auxdisplay/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2023 Jamie McCrae
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <string.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/auxdisplay.h>
#include <zephyr/logging/log.h>

#ifdef CONFIG_PM_DEVICE
#include <zephyr/pm/device.h>
#endif

LOG_MODULE_REGISTER(auxdisplay_sample, LOG_LEVEL_DBG);

void main(void)
{
int rc;
const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(auxdisplay_0));
uint8_t data[64];

if (!device_is_ready(dev)) {
LOG_ERR("Auxdisplay device is not ready.");
return;
}

rc = auxdisplay_cursor_set_enabled(dev, true);

if (rc != 0) {
LOG_ERR("Failed to enable cursor: %d", rc);
}

snprintk(data, sizeof(data), "Hello world from %s", CONFIG_BOARD);
rc = auxdisplay_write(dev, data, strlen(data));

if (rc != 0) {
LOG_ERR("Failed to write data: %d", rc);
}

#ifdef CONFIG_PM_DEVICE
k_sleep(K_SECONDS(3));

snprintk(data, sizeof(data), "Suspending display in 3 seconds...");
rc = auxdisplay_clear(dev);
if (rc != 0) {
LOG_ERR("Failed to clear: %d", rc);
}

rc = auxdisplay_write(dev, data, strlen(data));
if (rc != 0) {
LOG_ERR("Failed to write data: %d", rc);
}

k_sleep(K_SECONDS(3));

pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);

k_sleep(K_SECONDS(3));

pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME);

snprintk(data, sizeof(data), "Display back online");
rc = auxdisplay_clear(dev);

if (rc != 0) {
LOG_ERR("Failed to clear: %d", rc);
}

rc = auxdisplay_write(dev, data, strlen(data));

if (rc != 0) {
LOG_ERR("Failed to write data: %d", rc);
}
#endif
}

0 comments on commit b16e223

Please sign in to comment.