Skip to content

Commit

Permalink
Add an input/output GPIO type. This helps support bit banged I2C. (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerstu authored Dec 3, 2023
1 parent 4c28fe3 commit 7317c34
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/freertos_drivers/ti/TivaGPIO.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,41 @@ struct GpioInputNP : public GpioInputPin<Defs, GPIO_PIN_TYPE_STD>
{
};

/// Common class for GPIO input/output pins.
template <class Defs> struct GpioInputOutputPin : public GpioShared<Defs>
{
public:
using Defs::GPIO_PERIPH;
using Defs::GPIO_BASE;
using Defs::GPIO_PIN;
/// Initializes the hardware pin.
static void hw_init()
{
MAP_SysCtlPeripheralEnable(GPIO_PERIPH);
MAP_GPIOPinTypeGPIOInput(GPIO_BASE, GPIO_PIN);
MAP_GPIOPadConfigSet(GPIO_BASE, GPIO_PIN, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD);
}
/// Sets the hardware pin to a safe state.
static void hw_set_to_safe()
{
hw_init();
}
/// Sets the direction of the I/O pin.
/// @param direction direction to set pin to
static void set_direction(Gpio::Direction direction)
{
MAP_GPIODirModeSet(GPIO_BASE, GPIO_PIN,
direction == Gpio::Direction::DINPUT ?
GPIO_DIR_MODE_IN : GPIO_DIR_MODE_OUT);
}
/// @return true if the pin is set to an output.
static bool is_output()
{
return (MAP_GPIODirModeGet(GPIO_BASE, GPIO_PIN) == GPIO_DIR_MODE_OUT);
}
};

/// GPIO Input pin in ADC configuration (analog).
///
/// This pin cannot be read or written directly (will fail compilation).
Expand Down

0 comments on commit 7317c34

Please sign in to comment.