SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
gpio.hpp
Go to the documentation of this file.
1/*
2 * SatNOGS-COMMS control library
3 *
4 * Copyright (C) 2022-2024, Libre Space Foundation <http://libre.space>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GNU General Public License v3.0 or later
20 */
21#pragma once
22
23#include <cstdint>
25{
37class gpio
38{
39public:
40 enum class direction : uint8_t
41 {
42 INPUT = 0,
43 OUTPUT = 1
44 };
45
53
59 virtual void
60 toggle() = 0;
61
70 virtual bool
71 get() = 0;
72
80 virtual bool
81 get_raw() = 0;
82
92 virtual void
93 set(bool s) = 0;
94
102 virtual void
103 set_raw(bool s) = 0;
104
110 virtual void
112};
113
118class dummy_gpio : public gpio
119{
120public:
121 dummy_gpio() : m_state(false) {};
122
123 void
125 {
126 m_state = !m_state;
127 }
128
129 bool
131 {
132 return m_state;
133 }
134
135 bool
137 {
138 return m_state;
139 }
140
141 void
142 set(bool s)
143 {
144 m_state = s;
145 }
146
147 void
148 set_raw(bool s)
149 {
150 m_state = s;
151 }
152
153 void
155 {
156 }
157
158private:
159 bool m_state;
160};
161
162} // namespace satnogs::comms::lib::bsp
void set_direction(direction dir)
Set the direction of the GPIO.
Definition gpio.hpp:154
void toggle()
Toggles the GPIO pin if it is configured as output. Has no effect if it is conigured as input.
Definition gpio.hpp:124
void set(bool s)
Sets the logical output of the pin. For example, if the pin has been configured as active low,...
Definition gpio.hpp:142
void set_raw(bool s)
Sets the physical output of the pin.
Definition gpio.hpp:148
bool get()
Gets the logical level of the GPIO pin. For example, if the pin has been configured as active low,...
Definition gpio.hpp:130
bool get_raw()
Gets the physical level of the GPIO pin. For example, if the input level is 0V, this method will retu...
Definition gpio.hpp:136
virtual void toggle()=0
Toggles the GPIO pin if it is configured as output. Has no effect if it is conigured as input.
virtual void set_raw(bool s)=0
Sets the physical output of the pin.
virtual void set(bool s)=0
Sets the logical output of the pin. For example, if the pin has been configured as active low,...
virtual bool get_raw()=0
Gets the physical level of the GPIO pin. For example, if the input level is 0V, this method will retu...
virtual bool get()=0
Gets the logical level of the GPIO pin. For example, if the pin has been configured as active low,...
gpio(direction dir=direction::INPUT)
Construct a new GPIO object.
Definition gpio.hpp:52
@ OUTPUT
GPIO pin is configured as output.
Definition gpio.hpp:43
@ INPUT
GPIO pin is configured as input.
Definition gpio.hpp:42
virtual void set_direction(direction dir)=0
Set the direction of the GPIO.