48#ifndef _FREERTOS_DRIVERS_TI_CC3200GPIO_HXX_
49#define _FREERTOS_DRIVERS_TI_CC3200GPIO_HXX_
52#include "inc/hw_types.h"
53#include "inc/hw_ints.h"
54#include "driverlib/gpio.h"
55#include "driverlib/prcm.h"
56#include "inc/hw_memmap.h"
57#include "driverlib/rom_map.h"
63#define DECL_PIN(NAME, PORT, NUM) \
64 static const auto NAME##_PERIPH = PRCM_GPIO##PORT; \
65 static const auto NAME##_BASE = GPIO##PORT##_BASE; \
66 static const auto NAME##_PIN = GPIO_PIN_##NUM; \
67 static const auto NAME##_INT = INT_GPIO##PORT
74template <
unsigned GPIO_BASE,
unsigned GPIO_PIN>
class CC3200Gpio :
public Gpio
87 __asm__
volatile(
"dsb" : : :
"memory");
94 __asm__
volatile(
"dsb" : : :
"memory");
101 __asm__
volatile(
"dsb" : : :
"memory");
111 if (dir == Direction::DOUTPUT)
113 MAP_GPIODirModeSet(GPIO_BASE,
GPIO_PIN, GPIO_DIR_MODE_OUT);
117 MAP_GPIODirModeSet(GPIO_BASE,
GPIO_PIN, GPIO_DIR_MODE_IN);
123 uint32_t mode = GPIODirModeGet(GPIO_BASE,
GPIO_PIN);
128 case GPIO_DIR_MODE_IN:
129 return Direction::DINPUT;
130 case GPIO_DIR_MODE_OUT:
131 return Direction::DOUTPUT;
136 template <
class Defs,
bool SAFE_VALUE>
friend struct GpioOutputPin;
152 return reinterpret_cast<volatile uint8_t *
>(
153 GPIO_BASE + (((unsigned)
GPIO_PIN) << 2));
158template <
unsigned GPIO_BASE,
unsigned GPIO_PIN>
168template <
class Defs,
bool SAFE_VALUE>
struct GpioOutputPin :
public Defs
171 using Defs::GPIO_PERIPH;
172 using Defs::GPIO_BASE;
173 using Defs::GPIO_PIN;
177 MAP_PRCMPeripheralClkEnable(GPIO_PERIPH, PRCM_RUN_MODE_CLK);
178 MAP_GPIODirModeSet(GPIO_BASE,
GPIO_PIN, GPIO_DIR_MODE_OUT);
188 static void __attribute__((always_inline))
set(
bool value)
190 volatile uint8_t *ptr =
reinterpret_cast<uint8_t *
>(
191 GPIO_BASE + (((unsigned)
GPIO_PIN) << 2));
192 *ptr = value ? 0xff : 0;
194 __asm__
volatile(
"dsb" : : :
"memory");
197 static bool __attribute__((always_inline))
get()
199 const volatile uint8_t *ptr =
reinterpret_cast<const uint8_t *
>(
200 GPIO_BASE + (((unsigned)
GPIO_PIN) << 2));
204 static void __attribute__((always_inline))
toggle()
255#define GPIO_PIN(NAME, BaseClass, PORT, NUM) \
258 DECL_PIN(GPIO, PORT, NUM); \
260 typedef BaseClass<NAME##Defs> NAME##_Pin
266 using Defs::GPIO_PERIPH;
267 using Defs::GPIO_BASE;
268 using Defs::GPIO_PIN;
272 MAP_PRCMPeripheralClkEnable(GPIO_PERIPH, PRCM_RUN_MODE_CLK);
273 MAP_GPIODirModeSet(GPIO_BASE,
GPIO_PIN, GPIO_DIR_MODE_IN);
283 const volatile uint8_t *ptr =
reinterpret_cast<const uint8_t *
>(
284 GPIO_BASE + (((unsigned)
GPIO_PIN) << 2));
303 using Defs::GPIO_PERIPH;
304 using Defs::GPIO_BASE;
305 using Defs::GPIO_PIN;
309 MAP_PRCMPeripheralClkEnable(GPIO_PERIPH, PRCM_RUN_MODE_CLK);
310 MAP_GPIODirModeSet(GPIO_BASE,
GPIO_PIN, GPIO_DIR_MODE_IN);
319 static void __attribute__((always_inline))
set(
bool value)
321 volatile uint8_t *ptr =
reinterpret_cast<uint8_t *
>(
322 GPIO_BASE + (((unsigned)
GPIO_PIN) << 2));
323 *ptr = value ? 0xff : 0;
325 __asm__
volatile(
"dsb" : : :
"memory");
328 static bool __attribute__((always_inline))
get()
330 const volatile uint8_t *ptr =
reinterpret_cast<const uint8_t *
>(
331 GPIO_BASE + (((unsigned)
GPIO_PIN) << 2));
335 static void __attribute__((always_inline))
toggle()
350 MAP_GPIODirModeSet(GPIO_BASE,
GPIO_PIN,
351 direction == Gpio::Direction::DINPUT ?
352 GPIO_DIR_MODE_IN : GPIO_DIR_MODE_OUT);
358 return (MAP_GPIODirModeGet(GPIO_BASE,
GPIO_PIN) == GPIO_DIR_MODE_OUT);
#define GPIO_PIN(NAME, BaseClass, PORT, NUM)
Helper macro for defining GPIO pins on the CC3200 microcontrollers.
#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.
Generic GPIO class implementation.
Direction direction() const OVERRIDE
Gets the GPIO direction.
static const CC3200Gpio instance_
Static instance variable that can be used for libraries expectiong a generic Gpio pointer.
void write(Value new_state) const OVERRIDE
Writes a GPIO output pin (set or clear to a specific state).
void clr() const OVERRIDE
Clears the GPIO output pin to low.
void set() const OVERRIDE
Sets the GPIO output pin to high.
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 set_direction(Direction dir) const OVERRIDE
Sets the GPIO direction.
constexpr CC3200Gpio()
This constructor is constexpr which ensures that the object can be initialized in the data section.
OS-independent abstraction for GPIO.
Value
Defines the options for GPIO level.
Direction
Defines the options for GPIO direction.
#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.
Parametric GPIO output class.
static constexpr const Gpio * instance()
static void toggle()
Changes the value of an output pin.
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 output 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.