rp2040/example/peripherals/gpio/gpio_led/main.c
2025-03-23 12:59:34 +08:00

71 lines
2.1 KiB
C

#include "reset.h"
#include "clock.h"
#include "sio.h"
#include "gpio.h"
#include "uart.h"
#include "stdio.h"
#include "RP2040.h"
struct gpio_cfg_s gpio_led_cfg = {
.pin = 25,
.sio_dir = GPIO_SIO_DIR_OUT,
.funcsel = GPIO_FUNC_SIO,
.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 = DISABLE, /* enable or disable pull down */
.pull_up = DISABLE, /* 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 */
};
struct uart_cfg_s uart_cfg = {
.baudrate = 6 * 1000 * 1000,
.mode = UART_MODE_TX_RX,
.data_bits = UART_DATABITS_8,
.parity = UART_PARITY_NONE,
.stop_bits = UART_STOPBITS_1,
.fifo_enable = ENABLE,
.tx_fifo_level = UART_FIFO_LEVEL_1_2,
.rx_fifo_level = UART_FIFO_LEVEL_1_2,
};
extern volatile uint32_t tick_1ms;
void isr_uart0(void)
{
uint32_t status = uart_int_get_mask_status(UART_ID_0);
printf("sts = 0x%08lX\t\n", status);
}
int main(void)
{
reset_enable(RESET_IO_BANK0 | RESET_PADS_BANK0 | RESET_UART0);
reset_disable(RESET_IO_BANK0 | RESET_PADS_BANK0 | RESET_UART0);
gpio_init(&gpio_led_cfg);
gpio_init_simple(0, GPIO_FUNC_UART, DISABLE, ENABLE);
__enable_irq();
while (!reset_get_state(RESET_UART0));
uart_init(UART_ID_0, &uart_cfg);
uart_int_enable(UART_ID_0, UART_INT_ALL);
// NVIC_EnableIRQ(UART0_IRQ_IRQn);
while (1) {
static uint32_t tick_led = 0;
if (tick_1ms > (tick_led + 500)) {
tick_led = tick_1ms;
gpio_toggle(gpio_led_cfg.pin);
printf("tick_led = %ld\r\n", tick_led);
}
}
return 0;
}