libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_GPIO_H
3#define DSY_GPIO_H
4#include "daisy_core.h"
5
6#ifdef __cplusplus
7
8namespace daisy
9{
21class GPIO
22{
23 public:
25 enum class Mode
26 {
27 INPUT,
28 OUTPUT,
30 ANALOG,
31 };
32
41 enum class Pull
42 {
43 NOPULL,
44 PULLUP,
45 PULLDOWN,
46 };
47
49 enum class Speed
50 {
51 LOW,
52 MEDIUM,
53 HIGH,
55 };
56
58 struct Config
59 {
64
70 {
71 }
72 };
73
74 GPIO() {}
75
79 void Init(const Config &cfg);
80
86 void Init(Pin p, const Config &cfg);
87
94 void Init(Pin p,
98
100 void DeInit();
101
105 bool Read();
106
110 void Write(bool state);
111
115 void Toggle();
116
118 Config &GetConfig() { return cfg_; }
119
120 private:
129 uint32_t *GetGPIOBaseRegister();
130
132 Config cfg_;
133
135 uint32_t *port_base_addr_;
136};
137
138} // namespace daisy
139
140
151extern "C"
152{
164
172
180
184 void dsy_gpio_init(const dsy_gpio *p);
185
189 void dsy_gpio_deinit(const dsy_gpio *p);
190
195 uint8_t dsy_gpio_read(const dsy_gpio *p);
196
203 void dsy_gpio_write(const dsy_gpio *p, uint8_t state);
204
208 void dsy_gpio_toggle(const dsy_gpio *p);
210}
211#endif
212
213#endif
General Purpose I/O control.
Definition gpio.h:22
void DeInit()
Deinitializes the GPIO pin.
void Init(Pin p, const Config &cfg)
Initialize the GPIO with a Configuration struct, and explicit pin.
void Write(bool state)
Changes the state of the GPIO hardware when configured as an OUTPUT.
void Init(const Config &cfg)
Initialize the GPIO from a Config struct.
GPIO()
Definition gpio.h:74
bool Read()
Reads the state of the GPIO.
Pull
Configures whether an internal Pull up or Pull down resistor is used.
Definition gpio.h:42
Speed
Output speed controls the drive strength, and slew rate of the pin.
Definition gpio.h:50
void Init(Pin p, Mode m=Mode::INPUT, Pull pu=Pull::NOPULL, Speed sp=Speed::LOW)
Explicity initialize all configuration for the GPIO.
Config & GetConfig()
Definition gpio.h:118
void Toggle()
flips the current state of the GPIO. If it was HIGH, it will go LOW, and vice versa.
Mode
Mode of operation for the specified GPIO.
Definition gpio.h:26
Definition leddriver.h:33
void dsy_gpio_write(const dsy_gpio *p, uint8_t state)
dsy_gpio_mode
Definition gpio.h:157
void dsy_gpio_deinit(const dsy_gpio *p)
void dsy_gpio_init(const dsy_gpio *p)
uint8_t dsy_gpio_read(const dsy_gpio *p)
dsy_gpio_pull
Definition gpio.h:167
void dsy_gpio_toggle(const dsy_gpio *p)
@ DSY_GPIO_MODE_INPUT
Definition gpio.h:158
@ DSY_GPIO_MODE_ANALOG
Definition gpio.h:161
@ DSY_GPIO_MODE_OUTPUT_OD
Definition gpio.h:160
@ DSY_GPIO_MODE_LAST
Definition gpio.h:162
@ DSY_GPIO_MODE_OUTPUT_PP
Definition gpio.h:159
@ DSY_GPIO_PULLDOWN
Definition gpio.h:170
@ DSY_GPIO_PULLUP
Definition gpio.h:169
@ DSY_GPIO_NOPULL
Definition gpio.h:168
Hardware defines and helpers for daisy field platform.
Definition index.h:2
Configuration for a given GPIO.
Definition gpio.h:59
Pull pull
Definition gpio.h:62
Speed speed
Definition gpio.h:63
Mode mode
Definition gpio.h:61
Config()
Definition gpio.h:68
Pin pin
Definition gpio.h:60
representation of hardware port/pin combination
Definition daisy_core.h:261
Definition daisy_core.h:205
Definition gpio.h:175
dsy_gpio_mode mode
Definition gpio.h:177
dsy_gpio_pin pin
Definition gpio.h:176
dsy_gpio_pull pull
Definition gpio.h:178