RTLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
core::stm32f4::GPIO Class Referencefinal

STM32F4xx-specific HAL implementation for GPIO pins. More...

#include <gpio.h>

Classes

struct  Config
 Configuration for GPIO. More...
 

Public Types

enum  Mode : uint8_t { Mode::kInput = 0x0, Mode::kOutput, Mode::kAF, Mode::kAnalog }
 Enumeration for different GPIO modes. More...
 
enum  Speed : uint8_t { Speed::k2MHz = 0x0, Speed::k25MHz, Speed::k50MHz, Speed::k100MHz }
 Enumeration for different GPIO output speeds. More...
 
enum  Pullup : uint8_t { Pullup::kNone = 0x0, Pullup::kPullup, Pullup::kPulldown }
 Enumeration for different internal pull-up states. More...
 
enum  DriverType : uint8_t { DriverType::kPushPull = 0x0, DriverType::kOpenDrain }
 Enumeration for GPIO output driver modes. More...
 
using AltFn = uint8_t
 Type definition for GPIO alternate function selection. More...
 

Public Member Functions

 GPIO (const Config &config)
 Conversion constructor. More...
 
 GPIO (Pinout pin, Mode mode, Pullup pullup, Speed speed=Speed::k2MHz, DriverType driver=DriverType::kPushPull, AltFn altfn=0x0)
 Constructor for internal API use. More...
 
 ~GPIO ()=default
 
 GPIO (GPIO &&other) noexcept=default
 Move constructor. More...
 
GPIOoperator= (GPIO &&other) noexcept=default
 Move assignment operator. More...
 
 GPIO (const GPIO &)=delete
 Copy constructor. More...
 
GPIOoperator= (const GPIO &)=delete
 Copy assignment operator. More...
 
bool Read () const
 Reads the current logic state of the managed GPIO. More...
 
void Set (bool state) const
 Sets new GPIO state. More...
 
void Toggle () const
 Toggles GPIO state. Logic High -> Logic Low and vice versa. More...
 
void Reset () const
 Resets the GPIO to its original configuration, i.e. when the RESET button is first pushed. More...
 

Detailed Description

STM32F4xx-specific HAL implementation for GPIO pins.

This abstraction layer provides simple Read/Write operations on GPIO pins. One GPIO object will correspond and manage one GPIO pinout from the MCU.

Member Typedef Documentation

using core::stm32f4::GPIO::AltFn = uint8_t

Type definition for GPIO alternate function selection.

See http://libopencm3.org/docs/latest/stm32f4/html/group__gpio__af__num.html.

Member Enumeration Documentation

enum core::stm32f4::GPIO::DriverType : uint8_t
strong

Enumeration for GPIO output driver modes.

This enum is intended to replace equivalent macros used in libopencm3.

See http://libopencm3.org/docs/latest/stm32f4/html/group__gpio__output__type.html.

Enumerator
kPushPull 

Drive GPIO output using push-pull (i.e. actively pushed to VCC/pulled to GND).

kOpenDrain 

Drive GPIO output using open-drain (i.e. only pull to GND).

enum core::stm32f4::GPIO::Mode : uint8_t
strong

Enumeration for different GPIO modes.

This enum is intended to replace equivalent macros used in libopencm3.

See http://libopencm3.org/docs/latest/stm32f4/html/group__gpio__mode.html.

Enumerator
kInput 

Use this GPIO as digital input.

Equivalent to libopencm3 macro GPIO_MODE_INPUT.

kOutput 

Use this GPIO as digital output.

Equivalent to libopencm3 macro GPIO_MODE_OUTPUT.

kAF 

Use this GPIO as an alternate function.

Equivalent to libopencm3 macro GPIO_MODE_AF.

kAnalog 

Use this GPIO as analog I/O.

Equivalent to libopencm3 macro GPIO_MODE_ANALOG.

enum core::stm32f4::GPIO::Pullup : uint8_t
strong

Enumeration for different internal pull-up states.

This enum is intended to replace equivalent macros used in libopencm3.

See http://libopencm3.org/docs/latest/stm32f4/html/group__gpio__pup.html.

Enumerator
kNone 

Do not use the internal pull-up/pull-down resistor (i.e. floating mode).

Equivalent to libopencm3 macro GPIO_PUPD_NONE.

kPullup 

Use the internal pull-up resistor.

Equivalent to libopencm3 macro GPIO_PUPD_PULLUP.

kPulldown 

Use the internal pull-down resistor.

Equivalent to libopencm3 macro GPIO_PUPD_PULLDOWN.

enum core::stm32f4::GPIO::Speed : uint8_t
strong

Enumeration for different GPIO output speeds.

This enum is intended to replace equivalent macros used in libopencm3.

See http://libopencm3.org/docs/latest/stm32f4/html/group__gpio__speed.html.

Enumerator
k2MHz 

Output GPIO at 2MHz.

Equivalent to libopencm3 macro GPIO_OSPEED_2MHZ.

k25MHz 

Output GPIO at 25MHz.

Equivalent to libopencm3 macro GPIO_OSPEED_25MHZ.

k50MHz 

Output GPIO at 50MHz.

Equivalent to libopencm3 macro GPIO_OSPEED_50MHZ.

k100MHz 

Output GPIO at 100MHz.

Equivalent to libopencm3 macro GPIO_OSPEED_100MHZ.

Constructor & Destructor Documentation

core::stm32f4::GPIO::GPIO ( const Config config)
explicit

Conversion constructor.

Parameters
configConfiguration for the GPIO. See GPIO::Config.
core::stm32f4::GPIO::GPIO ( Pinout  pin,
Mode  mode,
Pullup  pullup,
Speed  speed = Speed::k2MHz,
DriverType  driver = DriverType::kPushPull,
AltFn  altfn = 0x0 
)

Constructor for internal API use.

This constructor is equivalent to

GPIO::GPIO(const Config&)

. However, it is suggested to use that constructor instead for code readability.

Parameters
pinMCU pinout
modeGPIO mode
pullupInternal pull-up mode
speedGPIO Output Speed
driverGPIO Output Driver Type
altfnGPIO Alternate Function Select
core::stm32f4::GPIO::~GPIO ( )
default

Default trivial destructor.

core::stm32f4::GPIO::GPIO ( GPIO &&  other)
defaultnoexcept

Move constructor.

Parameters
otherGPIO object to move from
core::stm32f4::GPIO::GPIO ( const GPIO )
delete

Copy constructor.

This constructor is deleted because there should only be one object managing each GPIO pin, similar to std::unique_ptr.

Member Function Documentation

GPIO& core::stm32f4::GPIO::operator= ( GPIO &&  other)
defaultnoexcept

Move assignment operator.

Parameters
otherGPIO object to move from
Returns
Reference to the moved GPIO.
GPIO& core::stm32f4::GPIO::operator= ( const GPIO )
delete

Copy assignment operator.

This constructor is deleted because there should only be one object managing each GPIO pin, similar to std::unique_ptr.

bool core::stm32f4::GPIO::Read ( ) const

Reads the current logic state of the managed GPIO.

Returns
true if high value, otherwise false
void core::stm32f4::GPIO::Reset ( ) const

Resets the GPIO to its original configuration, i.e. when the RESET button is first pushed.

void core::stm32f4::GPIO::Set ( bool  state) const

Sets new GPIO state.

Parameters
stateNew state of GPIO, where true represents a high value, and false represents a low value.
void core::stm32f4::GPIO::Toggle ( ) const

Toggles GPIO state. Logic High -> Logic Low and vice versa.


The documentation for this class was generated from the following files: