36#ifndef _FREERTOS_DRIVERS_TI_TIVAGPIO_HXX_
37#define _FREERTOS_DRIVERS_TI_TIVAGPIO_HXX_
40#include "driverlib/gpio.h"
41#include "driverlib/pin_map.h"
42#include "driverlib/sysctl.h"
43#include "inc/hw_types.h"
44#include "inc/hw_memmap.h"
45#include "inc/hw_gpio.h"
46#include "driverlib/rom_map.h"
51#define DECL_PIN(NAME, PORT, NUM) \
52 static const auto NAME##_PERIPH = SYSCTL_PERIPH_GPIO##PORT; \
53 static const auto NAME##_BASE = GPIO_PORT##PORT##_BASE; \
54 static const auto NAME##_PIN = GPIO_PIN_##NUM; \
60#define DECL_HWPIN(NAME, PORT, NUM, CONFIG, Type) \
61 DECL_PIN(NAME, PORT, NUM); \
62 static void NAME##_SetPinType() \
64 MAP_GPIOPinType##Type(NAME##_BASE, NAME##_PIN); \
66 static const auto NAME##_CONFIG = GPIO_P##PORT##NUM##_##CONFIG
69template <
class Defs, u
int32_t GPIO_PULL>
struct GpioInputPin;
72template <
unsigned GPIO_BASE,
unsigned GPIO_PIN>
class TivaGpio :
public Gpio
103 if (dir == Direction::DOUTPUT)
105 GPIOPinTypeGPIOOutput(GPIO_BASE,
GPIO_PIN);
109 GPIOPinTypeGPIOInput(GPIO_BASE,
GPIO_PIN);
115 uint32_t mode = GPIODirModeGet(GPIO_BASE,
GPIO_PIN);
120 case GPIO_DIR_MODE_IN:
121 return Direction::DINPUT;
122 case GPIO_DIR_MODE_OUT:
123 return Direction::DOUTPUT;
128 template <
class Defs>
friend struct GpioShared;
144 return reinterpret_cast<volatile uint8_t *
>(
145 GPIO_BASE + (((unsigned)
GPIO_PIN) << 2));
150template <
unsigned GPIO_BASE,
unsigned GPIO_PIN>
157 using Defs::GPIO_PERIPH;
158 using Defs::GPIO_BASE;
159 using Defs::GPIO_PIN;
164 MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
166 HWREG(GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
167 HWREG(GPIO_BASE + GPIO_O_CR) |=
GPIO_PIN;
168 HWREG(GPIO_BASE + GPIO_O_LOCK) = 0;
173 MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
174 HWREG(GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
175 HWREG(GPIO_BASE + GPIO_O_CR) &= ~GPIO_PIN;
176 HWREG(GPIO_BASE + GPIO_O_LOCK) = 0;
181 static void set(
bool value)
199 return GPIO_BASE + (((unsigned)
GPIO_PIN) << 2);
216template <
class Defs,
bool SAFE_VALUE>
220 using Defs::GPIO_PERIPH;
221 using Defs::GPIO_BASE;
222 using Defs::GPIO_PIN;
227 MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
228 MAP_GPIOPinTypeGPIOOutput(GPIO_BASE,
GPIO_PIN);
267 using Defs::GPIO_PERIPH;
268 using Defs::GPIO_BASE;
269 using Defs::GPIO_PIN;
274 MAP_GPIOPadConfigSet(
275 GPIO_BASE,
GPIO_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
300 using Defs::GPIO_PERIPH;
301 using Defs::GPIO_BASE;
302 using Defs::GPIO_PIN;
307 MAP_GPIOPadConfigSet(
308 GPIO_BASE,
GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD);
329#define GPIO_PIN(NAME, BaseClass, PORT, NUM) \
332 DECL_PIN(GPIO, PORT, NUM); \
334 typedef BaseClass<NAME##Defs> NAME##_Pin
337template <
class Defs, u
int32_t GPIO_PULL>
341 using Defs::GPIO_PERIPH;
342 using Defs::GPIO_BASE;
343 using Defs::GPIO_PIN;
347 MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
348 MAP_GPIOPinTypeGPIOInput(GPIO_BASE,
GPIO_PIN);
349 MAP_GPIOPadConfigSet(GPIO_BASE,
GPIO_PIN, GPIO_STRENGTH_2MA, GPIO_PULL);
391 using Defs::GPIO_PERIPH;
392 using Defs::GPIO_BASE;
393 using Defs::GPIO_PIN;
397 MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
398 MAP_GPIOPinTypeGPIOInput(GPIO_BASE,
GPIO_PIN);
399 MAP_GPIOPadConfigSet(GPIO_BASE,
GPIO_PIN, GPIO_STRENGTH_2MA,
411 MAP_GPIODirModeSet(GPIO_BASE,
GPIO_PIN,
412 direction == Gpio::Direction::DINPUT ?
413 GPIO_DIR_MODE_IN : GPIO_DIR_MODE_OUT);
418 return (MAP_GPIODirModeGet(GPIO_BASE,
GPIO_PIN) == GPIO_DIR_MODE_OUT);
429 using Defs::GPIO_PERIPH;
430 using Defs::GPIO_BASE;
431 using Defs::GPIO_PIN;
435 MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
436 MAP_GPIODirModeSet(GPIO_BASE,
GPIO_PIN, GPIO_DIR_MODE_HW);
437 MAP_GPIOPadConfigSet(
438 GPIO_BASE,
GPIO_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG);
456 using Defs::GPIO_PERIPH;
457 using Defs::GPIO_BASE;
458 using Defs::GPIO_PIN;
462 MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
463 MAP_GPIOPinTypeUSBAnalog(GPIO_BASE,
GPIO_PIN);
481 using Defs::GPIO_PERIPH;
482 using Defs::GPIO_BASE;
483 using Defs::GPIO_PIN;
484 using Defs::GPIO_CONFIG;
485 using Defs::GPIO_SetPinType;
490 MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
491 MAP_GPIOPinConfigure(GPIO_CONFIG);
507 Defs::GPIO_SetPinType();
514 MAP_GPIOPinTypeGPIOOutput(GPIO_BASE,
GPIO_PIN);
515 MAP_GPIOPadConfigSet(
516 GPIO_BASE,
GPIO_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
525 static void set_input(uint32_t drive_type = GPIO_PIN_TYPE_STD)
527 MAP_GPIOPinTypeGPIOInput(GPIO_BASE,
GPIO_PIN);
528 MAP_GPIOPadConfigSet(
529 GPIO_BASE,
GPIO_PIN, GPIO_STRENGTH_2MA, drive_type);
552#define GPIO_HWPIN(NAME, BaseClass, PORT, NUM, CONFIG, TYPE) \
555 DECL_HWPIN(GPIO, PORT, NUM, CONFIG, TYPE); \
557 typedef BaseClass<NAME##Defs> NAME##_Pin
#define GPIO_PIN(NAME, BaseClass, NUM)
Helper macro for defining GPIO pins with Arduino.
#define GPIO_PIN(NAME, BaseClass, NUM)
Helper macro for defining GPIO pins on Linux-based microcontrollers (like the Raspberry Pi or Bagle B...
#define GPIO_PIN(NAME, BaseClass, PORT, NUM)
Helper macro for defining GPIO pins on the Tiva microcontrollers.
OS-independent abstraction for GPIO.
Value
Defines the options for GPIO level.
Direction
Defines the options for GPIO direction.
Generic GPIO class implementation.
constexpr TivaGpio()
This constructor is constexpr which ensures that the object can be initialized in the data section.
void set_direction(Direction dir) const OVERRIDE
Sets the GPIO direction.
void clr() const OVERRIDE
Clears the GPIO output pin to low.
constexpr volatile uint8_t * pin_address() const
Computes the memory address where the bit referring to this pin can be accessed.
Value read() const OVERRIDE
Retrieves the current Value of a GPIO input pin.
void write(Value new_state) const OVERRIDE
Writes a GPIO output pin (set or clear to a specific state).
static const TivaGpio instance_
Static instance variable that can be used for libraries expectiong a generic Gpio pointer.
Direction direction() const OVERRIDE
Gets the GPIO direction.
void set() const OVERRIDE
Sets the GPIO output pin to high.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
GPIO Input pin in ADC configuration (analog).
static void hw_init()
Implements hw_init functionality for this pin only.
static void hw_set_to_safe()
Implements hw_set_to_safe functionality for this pin only.
GPIO pin in a hardware configuration (via pinmux: UART, I2C, CAN, etc).
static void set_input(uint32_t drive_type=GPIO_PIN_TYPE_STD)
Switches the GPIO pin to an input pin.
static void set_output()
Switches the GPIO pin to an output pin.
static void set_hw()
Switches the GPIO pin to the hardware peripheral.
static void hw_init()
Implements hw_init functionality for this pin only.
static void hw_set_to_safe()
Implements hw_set_to_safe functionality for this pin only.
Defines a GPIO output pin with high-current drive and a defined initialization level.
static void hw_init()
Initializes the hardware pin.
Parametric GPIO output class.
static void hw_init()
Initializes the hardware pin.
static void set(bool value)
Sets the output pinm.
static void hw_set_to_safe()
Sets the hardware pin to a safe value.
Defines a GPIO output pin, initialized to be an output pin with high level.
Defines a GPIO output pin, initialized to be an output pin with low level.
Shared class that defines static functions used by both GpioInputPin, GpioOutputPin and GpioHwPin.
static void lock()
Used to lock special consideration pins such as JTAG or NMI pins.
static constexpr uint32_t ptr_address()
static void unlock()
Used to unlock special consideration pins such as JTAG or NMI pins.
static constexpr const Gpio * instance()
static void toggle()
Changes the value of an output pin.
static void set(bool value)
Sets the output pin to a specified value;.
static void hw_set_to_safe()
Sets the hardware pin to a safe state.
static void hw_init()
Initializes the hardware pin.
Defines a GPIO output pin with high-current drive and low initialization level.
static void hw_init()
Initialized the hardware pin.