-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: driver: Add auxdisplay sample
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
Showing
3 changed files
with
88 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 @@ | ||
# 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) |
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,2 @@ | ||
CONFIG_AUXDISPLAY=y | ||
CONFIG_LOG=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,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 | ||
} |