xtensa/esp32: Enable configuration of GPIO pad's drive strength
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
parent
e98220c81a
commit
2d676f5e46
@ -163,6 +163,18 @@ static int gpio_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
* Description:
|
||||
* Configure a GPIO pin based on encoded pin attributes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pin - GPIO pin to be configured
|
||||
* attr - Attributes to be configured for the selected GPIO pin.
|
||||
* The following attributes are accepted:
|
||||
* - Direction (OUTPUT or INPUT)
|
||||
* - Pull (PULLUP, PULLDOWN or OPENDRAIN)
|
||||
* - Function (if not provided, assume function GPIO by default)
|
||||
* - Drive strength (if not provided, assume DRIVE_2 by default)
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success, or -1 (ERROR) in case of failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32_configgpio(int pin, gpio_pinattr_t attr)
|
||||
@ -281,23 +293,34 @@ int esp32_configgpio(int pin, gpio_pinattr_t attr)
|
||||
}
|
||||
}
|
||||
|
||||
/* Add drivers */
|
||||
|
||||
func |= (uint32_t)(2ul << FUN_DRV_S);
|
||||
|
||||
/* Select the pad's function. If no function was given, consider it a
|
||||
* normal input or output (i.e. function3).
|
||||
*/
|
||||
/* Configure the pad's function */
|
||||
|
||||
if ((attr & FUNCTION_MASK) != 0)
|
||||
{
|
||||
func |= (uint32_t)(((attr >> FUNCTION_SHIFT) - 1) << MCU_SEL_S);
|
||||
uint32_t val = ((attr & FUNCTION_MASK) >> FUNCTION_SHIFT) - 1;
|
||||
func |= val << MCU_SEL_S;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Function not provided, assuming function GPIO by default */
|
||||
|
||||
func |= (uint32_t)(PIN_FUNC_GPIO << MCU_SEL_S);
|
||||
}
|
||||
|
||||
/* Configure the pad's drive strength */
|
||||
|
||||
if ((attr & DRIVE_MASK) != 0)
|
||||
{
|
||||
uint32_t val = ((attr & DRIVE_MASK) >> DRIVE_SHIFT) - 1;
|
||||
func |= val << FUN_DRV_S;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Drive strength not provided, assuming strength 2 by default */
|
||||
|
||||
func |= UINT32_C(2) << FUN_DRV_S;
|
||||
}
|
||||
|
||||
if ((attr & OPEN_DRAIN) != 0)
|
||||
{
|
||||
cntrl |= (1 << GPIO_PIN_PAD_DRIVER_S);
|
||||
|
@ -56,6 +56,7 @@
|
||||
#define PULLUP (1 << 3)
|
||||
#define PULLDOWN (1 << 4)
|
||||
#define OPEN_DRAIN (1 << 5)
|
||||
|
||||
#define FUNCTION_SHIFT 6
|
||||
#define FUNCTION_MASK (7 << FUNCTION_SHIFT)
|
||||
# define FUNCTION_1 (1 << FUNCTION_SHIFT)
|
||||
@ -65,6 +66,13 @@
|
||||
# define FUNCTION_5 (5 << FUNCTION_SHIFT)
|
||||
# define FUNCTION_6 (6 << FUNCTION_SHIFT)
|
||||
|
||||
#define DRIVE_SHIFT 9
|
||||
#define DRIVE_MASK (7 << DRIVE_SHIFT)
|
||||
# define DRIVE_0 (1 << DRIVE_SHIFT)
|
||||
# define DRIVE_1 (2 << DRIVE_SHIFT)
|
||||
# define DRIVE_2 (3 << DRIVE_SHIFT)
|
||||
# define DRIVE_3 (4 << DRIVE_SHIFT)
|
||||
|
||||
#define INPUT_PULLUP (INPUT | PULLUP)
|
||||
#define INPUT_PULLDOWN (INPUT | PULLDOWN)
|
||||
#define OUTPUT_OPEN_DRAIN (OUTPUT | OPEN_DRAIN)
|
||||
@ -147,6 +155,18 @@ void esp32_gpioirqinitialize(void);
|
||||
* Description:
|
||||
* Configure a GPIO pin based on encoded pin attributes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pin - GPIO pin to be configured
|
||||
* attr - Attributes to be configured for the selected GPIO pin.
|
||||
* The following attributes are accepted:
|
||||
* - Direction (OUTPUT or INPUT)
|
||||
* - Pull (PULLUP, PULLDOWN or OPENDRAIN)
|
||||
* - Function (if not provided, assume function GPIO by default)
|
||||
* - Drive strength (if not provided, assume DRIVE_2 by default)
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success, or -1 (ERROR) in case of failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32_configgpio(int pin, gpio_pinattr_t attr);
|
||||
|
Loading…
Reference in New Issue
Block a user