Skip to content

Commit

Permalink
zephyr: Fix sys_io.cc to respect Kconfig
Browse files Browse the repository at this point in the history
Functions like console_init, console_getchar, and console_putchar all
depend on CONFIG_CONSOLE_GETCHAR Kconfig. We shouldn't assume it'll
always be there.

BUG: b/380001331
Change-Id: Ice6e93c244134c51ef9110ed3cb24a7835e6f07f

Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/263834
Lint: Lint 🤖 <[email protected]>
Docs-Not-Needed: Yuval Peress <[email protected]>
Reviewed-by: Ted Pudlik <[email protected]>
Pigweed-Auto-Submit: Yuval Peress <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
  • Loading branch information
yperess authored and CQ Bot Account committed Feb 1, 2025
1 parent 471eba4 commit 05504be
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pw_sys_io_zephyr/sys_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
#include <zephyr/usb/usb_device.h>

static int sys_io_init(void) {
int err;
int err = 0;

if (IS_ENABLED(CONFIG_PIGWEED_SYS_IO_USB)) {
err = usb_enable(nullptr);
if (err) {
return err;
}
}
err = console_init();
if (IS_ENABLED(CONFIG_CONSOLE_GETCHAR)) {
err = console_init();
}
return err;
}

Expand All @@ -48,6 +50,9 @@ Status ReadByte(std::byte* dest) {
}

Status TryReadByte(std::byte* dest) {
if (!IS_ENABLED(CONFIG_CONSOLE_GETCHAR)) {
return Status::Unimplemented();
}
if (dest == nullptr) {
return Status::InvalidArgument();
}
Expand All @@ -64,6 +69,9 @@ Status TryReadByte(std::byte* dest) {
}

Status WriteByte(std::byte b) {
if (!IS_ENABLED(CONFIG_CONSOLE_GETCHAR)) {
return Status::Unimplemented();
}
return console_putchar(static_cast<char>(b)) < 0
? Status::FailedPrecondition()
: OkStatus();
Expand Down

0 comments on commit 05504be

Please sign in to comment.