diff options
author | Armando Montanez <amontanez@google.com> | 2019-11-18 15:05:53 -0800 |
---|---|---|
committer | Armando Montanez <amontanez@google.com> | 2019-11-20 18:30:11 +0000 |
commit | 759ff77d81b2954618e59c7aa97dd082454fbd2c (patch) | |
tree | 83815bdca84465951399dbca29864c2bb5fe001e /pw_dumb_io_baremetal_stm32f429 | |
parent | 88726e83f6be5f934a89b7aad48250770c347051 (diff) | |
download | pigweed-759ff77d81b2954618e59c7aa97dd082454fbd2c.tar.gz |
Add WriteLine() to pw_dumb_io
Adds WriteLine() to pw_dumb_io, and updates all function names to use
read/write.
Change-Id: I0c3358fa264f9a5e7c8b49736e960015df0e67fc
Diffstat (limited to 'pw_dumb_io_baremetal_stm32f429')
-rw-r--r-- | pw_dumb_io_baremetal_stm32f429/BUILD.gn | 1 | ||||
-rw-r--r-- | pw_dumb_io_baremetal_stm32f429/dumb_io_baremetal.cc | 20 |
2 files changed, 19 insertions, 2 deletions
diff --git a/pw_dumb_io_baremetal_stm32f429/BUILD.gn b/pw_dumb_io_baremetal_stm32f429/BUILD.gn index d467a41d1..1bc300dc6 100644 --- a/pw_dumb_io_baremetal_stm32f429/BUILD.gn +++ b/pw_dumb_io_baremetal_stm32f429/BUILD.gn @@ -30,6 +30,7 @@ source_set("pw_dumb_io_baremetal_stm32f429") { ":linker_script", ] deps = [ + "$dir_pw_dumb_io:default_putget_bytes", "$dir_pw_dumb_io:facade", "$dir_pw_preprocessor", ] diff --git a/pw_dumb_io_baremetal_stm32f429/dumb_io_baremetal.cc b/pw_dumb_io_baremetal_stm32f429/dumb_io_baremetal.cc index 110e44c19..322aebb0f 100644 --- a/pw_dumb_io_baremetal_stm32f429/dumb_io_baremetal.cc +++ b/pw_dumb_io_baremetal_stm32f429/dumb_io_baremetal.cc @@ -168,7 +168,7 @@ namespace pw::dumb_io { // Wait for a byte to read on USART1. This blocks until a byte is read. This is // extremely inefficient as it requires the target to burn CPU cycles polling to // see if a byte is ready yet. -Status GetByte(std::byte* dest) { +Status ReadByte(std::byte* dest) { while (true) { if (usart1.status & kReadDataReady) { *dest = static_cast<std::byte>(usart1.data_register); @@ -181,7 +181,7 @@ Status GetByte(std::byte* dest) { // inefficient. At the default baud rate of 115200, one byte blocks the CPU for // ~87 micro seconds. This means it takes only 10 bytes to block the CPU for // 1ms! -Status PutByte(std::byte b) { +Status WriteByte(std::byte b) { // Wait for TX buffer to be empty. When the buffer is empty, we can write // a value to be dumped out of UART. while (!(usart1.status & kTxRegisterEmpty)) { @@ -190,4 +190,20 @@ Status PutByte(std::byte b) { return Status::OK; } +// Writes a string using pw::dumb_io, and add newline characters at the end. +StatusWithSize WriteLine(const std::string_view& s) { + size_t chars_written = 0; + StatusWithSize result = WriteBytes(as_bytes(span(s))); + if (!result.ok()) { + return result; + } + chars_written += result.size(); + + // Write trailing newline ("\n\r"). + result = WriteBytes(as_bytes(span("\n\r", 2))); + chars_written += result.size(); + + return StatusWithSize(result.status(), chars_written); +} + } // namespace pw::dumb_io |