Skip to content

Commit

Permalink
Merge pull request #98 from YuzukiHD/dev
Browse files Browse the repository at this point in the history
[driver] gpio add sunxi_gpio_set_drv
  • Loading branch information
YuzukiTsuru committed Jun 5, 2024
2 parents fef9e5f + de68e08 commit ef68353
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
14 changes: 13 additions & 1 deletion include/drivers/sys-gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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__
24 changes: 24 additions & 0 deletions src/drivers/sys-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit ef68353

Please sign in to comment.