Add support for GPIO pulldown control

Note that it does nothing on the AVR, which doesn't support it.
This commit is contained in:
Doug Brown 2023-08-06 20:35:29 -07:00 committed by Doug Brown
parent 7e5639c792
commit a4e6cf4809
3 changed files with 33 additions and 2 deletions

View File

@ -75,6 +75,18 @@ void GPIO_SetPullup(GPIOPin pin, bool pullup)
GPIO_Set(pin, pullup);
}
/**
* @brief Sets whether an input GPIO pin is pulled down
* @param pin The pin
* @param pulldown True if it should be pulled down, false if not
*/
void GPIO_SetPulldown(GPIOPin pin, bool pulldown)
{
(void)pin;
(void)pulldown;
// The AVR doesn't support pulldowns
}
/** Turns a GPIO pin on (sets it high)
*
* @param pin The pin

View File

@ -43,6 +43,7 @@ typedef struct GPIOPin
void GPIO_SetDirection(GPIOPin pin, bool output);
void GPIO_SetPullup(GPIOPin pin, bool pullup);
void GPIO_SetPulldown(GPIOPin pin, bool pulldown);
void GPIO_SetOn(GPIOPin pin);
void GPIO_SetOff(GPIOPin pin);
void GPIO_Toggle(GPIOPin pin);

View File

@ -64,13 +64,31 @@ void GPIO_SetPullup(GPIOPin pin, bool pullup)
if (pullup)
{
uint32_t tmp = gpioRegs[pin.port]->PUSEL;
tmp &= ~(2UL << 2*pin.pin);
tmp |= (1UL << 2*pin.pin);
gpioRegs[pin.port]->PUSEL = tmp;
}
else
{
gpioRegs[pin.port]->PUSEL &= ~(3UL << 2*pin.pin);
gpioRegs[pin.port]->PUSEL &= ~(1UL << 2*pin.pin);
}
}
/** Sets whether an input GPIO pin is pulled down
*
* @param pin The pin
* @param pulldown True if it should be pulled down, false if not
*/
void GPIO_SetPulldown(GPIOPin pin, bool pulldown)
{
if (pulldown)
{
uint32_t tmp = gpioRegs[pin.port]->PUSEL;
tmp |= (2UL << 2*pin.pin);
gpioRegs[pin.port]->PUSEL = tmp;
}
else
{
gpioRegs[pin.port]->PUSEL &= ~(2UL << 2*pin.pin);
}
}