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
77 void Init();
78
82 void Init(const Config &cfg);
83
89 void Init(Pin p, const Config &cfg);
90
97 void Init(Pin p,
101
103 void DeInit();
104
108 bool Read();
109
113 void Write(bool state);
114
118 void Toggle();
119
121 Config &GetConfig() { return cfg_; }
122
123 private:
132 uint32_t *GetGPIOBaseRegister();
133
135 Config cfg_;
136
138 uint32_t *port_base_addr_;
139};
140
141} // namespace daisy
142
143#endif
144#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:121
void Init()
Initialize the GPIO using the internal Config struct.
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
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:193