[feat] add gpio_init_simple function

This commit is contained in:
zhji 2025-03-15 16:15:00 +08:00
parent 3dd65364f2
commit b1cf958fd2
2 changed files with 22 additions and 0 deletions

View File

@ -106,6 +106,7 @@ void gpio_over_in_set(uint8_t pin, uint8_t over);
void gpio_over_irq_set(uint8_t pin, uint8_t over);
void gpio_init(struct gpio_cfg_s *cfg);
void gpio_init_simple(uint8_t pin, uint8_t func, uint8_t pulldown, uint8_t pullup);
uint8_t gpio_irq_get_raw_status(uint8_t pin, uint8_t irq);
void gpio_irq_raw_status_clear(uint8_t pin, uint8_t irq);

View File

@ -207,6 +207,27 @@ void gpio_init(struct gpio_cfg_s *cfg)
putreg32(val, addr + offset);
}
void gpio_init_simple(uint8_t pin, uint8_t func, uint8_t pulldown, uint8_t pullup)
{
struct gpio_cfg_s cfg = {
.pin = pin,
.sio_dir = GPIO_SIO_DIR_IN,
.funcsel = func,
.over_out = GPIO_OVER_OUT_PERIPHERAL,
.over_oe = GPIO_OVER_OE_PERIPHERAL,
.over_in = GPIO_OVER_IN_PERIPHERAL,
.over_irq = GPIO_OVER_IRQ_NORMAL,
.slew_rate = GPIO_PADS_SLEW_RATE_SLOW, /* slew rate control, slow or fast */
.schmitt = ENABLE, /* enable or disable schmitt */
.pull_down = pulldown, /* enable or disable pull down */
.pull_up = pullup, /* enable or disable pull up */
.drive = GPIO_PADS_DRIVE_STRENGTH_4MA, /* drive strength */
.ie = DISABLE, /* enable or disable input */
.od = DISABLE, /* output disable, has priority over output enable from peripherals */
};
gpio_init(&cfg);
}
uint8_t gpio_irq_get_raw_status(uint8_t pin, uint8_t irq)
{
uint32_t addr;