Pigweed
 
Loading...
Searching...
No Matches
sys_io.h
1// Copyright 2019 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16// This module defines a simple and unoptimized interface for byte-by-byte
17// input/output. This can be done over a logging system, stdio, UART, via a
18// photodiode and modulated kazoo, or basically any way to get data in and out
19// of an application.
20//
21// This facade doesn't dictate any policies on input and output data encoding,
22// format, or transmission protocol. It only requires that backends return a
23// OkStatus() if the operation succeeds. Backends may provide useful error
24// Status types, but depending on the implementation-specific Status values is
25// NOT recommended. Since this facade provides a very vague I/O interface, it
26// does NOT provide tests. Backends are expected to provide their own testing to
27// validate correctness.
28//
29// The intent of this module for simplifying bringup or otherwise getting data
30// in/out of a CPU in a way that is platform-agnostic. The interface is designed
31// to be easy to understand. There's no initialization as part of this
32// interface, there's no configuration, and the interface is no-frills WYSIWYG
33// byte-by-byte i/o.
34//
35//
36// PLEASE DON'T BUILD PROJECTS ON TOP OF THIS INTERFACE.
37
38#include <cstddef>
39#include <cstring>
40#include <string_view>
41
42#include "pw_bytes/span.h"
43#include "pw_status/status.h"
44#include "pw_status/status_with_size.h"
45
46namespace pw::sys_io {
47
65Status ReadByte(std::byte* dest);
66
84Status TryReadByte(std::byte* dest);
85
100Status WriteByte(std::byte b);
101
123StatusWithSize WriteLine(std::string_view s);
124
143StatusWithSize ReadBytes(ByteSpan dest);
144
163StatusWithSize WriteBytes(ConstByteSpan src);
164
165} // namespace pw::sys_io