Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Tiva input/output GPIO type. This helps support bit banged I2C. #752

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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