libyggdrasil  v1.0.0
gpio.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 
31 namespace bsp::drv {
32 
36  enum class Active {
37  Low,
38  High
39  };
40 
47  template<auto Context, template<auto> typename GPIOImpl>
48  struct GPIOPort {
49  GPIOPort() = delete;
50  GPIOPort(const GPIOPort&) = delete;
51  GPIOPort(GPIOPort &&) = delete;
52 
53  using Impl = GPIOImpl<Context>;
54 
61  static auto init(auto ... args) {
62  return Impl::init(args...);
63  }
64 
71  static auto deinit(auto ... args) {
72  return Impl::deinit(args...);
73  }
74 
80  template<u8 Number, Active LogicActive = Active::High>
81  static inline auto& Pin = Impl::template Pin<Number, LogicActive>;
82 
88  template<u8 From, u8 To>
89  static inline auto& In = Impl::template In<From, To>;
90 
96  template<u8 From, u8 To>
97  static inline auto& Out = Impl::template Out<From, To>;
98  };
99 
100 }
bsp::drv::GPIOPort::GPIOPort
GPIOPort()=delete
bsp::drv::GPIOPort::GPIOPort
GPIOPort(GPIOPort &&)=delete
bsp::drv::Active
Active
GPIO pin logical on state.
Definition: gpio.hpp:36
bsp::drv::GPIOPort::GPIOPort
GPIOPort(const GPIOPort &)=delete
bsp::drv::GPIOPort
Base class for GPIO port abstraction.
Definition: gpio.hpp:48
bsp::drv::Active::Low
@ Low
registers.hpp
Zero-cost abstraction for accessing registers and bits/bitfields within them.
bsp::drv::GPIOPort::init
static auto init(auto ... args)
GPIO Port initialization.
Definition: gpio.hpp:61
bsp::drv::Active::High
@ High
attributes.hpp
Commonly used C++ and GNU attributes.
bsp::drv::GPIOPort::deinit
static auto deinit(auto ... args)
GPIO Port deinitialization.
Definition: gpio.hpp:71
bsp::drv
Definition: display.hpp:37
bsp::drv::GPIOPort::Out
static auto & Out
Output bitfield.
Definition: gpio.hpp:97
bsp::drv::GPIOPort::In
static auto & In
Input bitfield.
Definition: gpio.hpp:89
bsp::drv::GPIOPort::Pin
static auto & Pin
GPIO Pin.
Definition: gpio.hpp:81
bsp::drv::GPIOPort::Impl
GPIOImpl< Context > Impl
Definition: gpio.hpp:53