libyggdrasil  v1.0.0
uart.hpp
Go to the documentation of this file.
1  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * _____.___. .___ .__.__ *
3  * \__ | | ____ ____ __| _/___________ _____|__| | *
4  * / | |/ ___\ / ___\ / __ |\_ __ \__ \ / ___/ | | *
5  * \____ / /_/ > /_/ > /_/ | | | \// __ \_\___ \| | |__ *
6  * / ______\___ /\___ /\____ | |__| (____ /____ >__|____/ *
7  * \/ /_____//_____/ \/ \/ \/ *
8  * - Common - *
9  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10  * This software can be used by students and other personal of the *
11  * Bern University of Applied Sciences under the terms of the MIT *
12  * license. *
13  * For other persons this software is under the terms of the GNU *
14  * General Public License version 2. *
15  * *
16  * Copyright © 2021, Bern University of Applied Sciences. *
17  * All rights reserved. *
18  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26 #pragma once
27 
28 #include <cpp/common/registers.hpp>
30 #include <cpp/common/utils.hpp>
31 
32 #include <array>
33 
34 namespace bsp::drv {
35 
42  template<auto Context, template<auto> typename UARTImpl>
43  struct UART {
44  UART() = delete;
45 
46  using Impl = UARTImpl<Context>;
47 
54  static auto init(auto ... args) {
55  return Impl::init(args...);
56  }
57 
64  static auto deinit(auto ... args) {
65  return Impl::deinit(args...);
66  }
67 
73  static std::string readString() {
74  std::string data;
75  Impl::receive(data);
76 
77  return data;
78  }
79 
86  template<size_t N>
87  static std::array<u8, N> read() {
88  std::array<u8, N> data;
89  Impl::receive(data);
90 
91  return data;
92  }
93 
99  static void write(std::string_view data) {
100  Impl::transmit(data);
101  }
102 
109  template<size_t N>
110  static void write(const std::array<u8, N> &data) {
111  Impl::transmit(data);
112  }
113  };
114 }
bsp::drv::UART::write
static void write(std::string_view data)
UART write string function.
Definition: uart.hpp:99
utils.hpp
Commonly used helper functions.
bsp::drv::UART::readString
static std::string readString()
UART read string function.
Definition: uart.hpp:73
bsp::drv::UART::read
static std::array< u8, N > read()
UART read function.
Definition: uart.hpp:87
registers.hpp
Zero-cost abstraction for accessing registers and bits/bitfields within them.
bsp::drv::UART::init
static auto init(auto ... args)
UART initialization.
Definition: uart.hpp:54
attributes.hpp
Commonly used C++ and GNU attributes.
bsp::drv::UART::write
static void write(const std::array< u8, N > &data)
UART write string function.
Definition: uart.hpp:110
bsp::drv
Definition: display.hpp:37
bsp::drv::UART::deinit
static auto deinit(auto ... args)
UART initialization.
Definition: uart.hpp:64
bsp::drv::UART
Base class for UART abstraction.
Definition: uart.hpp:43
bsp::drv::UART::Impl
UARTImpl< Context > Impl
Definition: uart.hpp:46
bsp::drv::UART::UART
UART()=delete