From de68e083d624ba9c2c0a13dba9b7d30e2e5eb4fc Mon Sep 17 00:00:00 2001 From: SamulKyull Date: Wed, 5 Jun 2024 22:04:19 +0800 Subject: [PATCH] [driver] gpio add drv --- include/drivers/sys-gpio.h | 14 +++++++++++++- src/drivers/sys-gpio.c | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/drivers/sys-gpio.h b/include/drivers/sys-gpio.h index c10f52dc6..77f09fe99 100644 --- a/include/drivers/sys-gpio.h +++ b/include/drivers/sys-gpio.h @@ -53,7 +53,9 @@ enum gpio_pull_t { GPIO_PULL_NONE = 2, }; +typedef uint32_t gpio_drv_t; typedef uint32_t gpio_t; + #define PIO_NUM_IO_BITS 5 #define GPIO_PIN(x, y) (((uint32_t) (x << PIO_NUM_IO_BITS)) | y) @@ -95,8 +97,18 @@ int sunxi_gpio_read(gpio_t pin); */ void sunxi_gpio_set_pull(gpio_t pin, enum gpio_pull_t pull); +/** + * @brief Sets the drive strength of a Sunxi GPIO pin. + * + * This function sets the drive strength for the specified GPIO pin. + * + * @param pin The GPIO pin to set the drive strength for. + * @param drv The drive strength value to set (GPIO_DRV_LOW, GPIO_DRV_MEDIUM, or GPIO_DRV_HIGH). + */ +void sunxi_gpio_set_drv(gpio_t pin, gpio_drv_t drv); + #ifdef __cplusplus } -#endif // __cplusplus +#endif// __cplusplus #endif// __SYS_GPIO_H__ \ No newline at end of file diff --git a/src/drivers/sys-gpio.c b/src/drivers/sys-gpio.c index f4c224e48..175eab7f0 100644 --- a/src/drivers/sys-gpio.c +++ b/src/drivers/sys-gpio.c @@ -193,3 +193,27 @@ void sunxi_gpio_set_pull(gpio_t pin, enum gpio_pull_t pull) { printk_trace("GPIO: PULL pin = %d, addr = 0x%08x, val = 0x%08x, set pull = %d\n", pin_num, addr, read32(addr), v); } + +/** + * @brief Sets the drive strength of a Sunxi GPIO pin. + * + * This function sets the drive strength for the specified GPIO pin. + * + * @param pin The GPIO pin to set the drive strength for. + * @param drv The drive strength value to set (GPIO_DRV_LOW, GPIO_DRV_MEDIUM, or GPIO_DRV_HIGH). + */ +void sunxi_gpio_set_drv(gpio_t pin, gpio_drv_t drv) { + uint32_t port_addr = _port_base_get(pin); + uint32_t pin_num = _pin_num(pin); + uint32_t addr; + uint32_t val; + + addr = port_addr + GPIO_PUL0 + ((pin_num >> 4) << 2); + val = read32(addr); + val &= ~(0x3 << ((pin_num & 0xf) << 1)); + val |= (drv << ((pin_num & 0xf) << 1)); + write32(addr, val); + + printk_trace("GPIO: DRV pin = %d, addr = 0x%08x, val = 0x%08x, set drv = %d\n", + pin_num, addr, read32(addr), drv); +}