2025-06-02 21:06:55 +08:00
|
|
|
#include "resets.h"
|
|
|
|
|
#include "timer.h"
|
2025-03-22 21:13:21 +08:00
|
|
|
#include "gpio.h"
|
|
|
|
|
#include "uart.h"
|
|
|
|
|
#include "stdio.h"
|
|
|
|
|
|
2025-06-02 21:06:55 +08:00
|
|
|
#define LED_PIN (25)
|
|
|
|
|
#define LED_TIME (500 * 1000) /* 500ms */
|
2025-03-22 21:13:21 +08:00
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
2025-06-02 21:06:55 +08:00
|
|
|
reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_UART0 | RESETS_BLOCK_TIMER);
|
|
|
|
|
gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */
|
|
|
|
|
gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */
|
|
|
|
|
uart_init(uart0_hw, 6 * 1000 * 1000, UART_DATABITS_8 | UART_PARITY_NONE | UART_STOPBITS_1);
|
|
|
|
|
printf("gpio_led example\r\n");
|
2025-03-22 21:13:21 +08:00
|
|
|
|
2025-06-02 21:06:55 +08:00
|
|
|
timer_count_write(0);
|
|
|
|
|
gpio_init(LED_PIN, GPIO_FUNC_NULL | GPIO_OVER_OUT_HIGH | GPIO_OVER_OE_ENABLE | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* LED pin */
|
2025-03-22 21:13:21 +08:00
|
|
|
|
|
|
|
|
while (1) {
|
2025-06-02 21:06:55 +08:00
|
|
|
static int flag = 0;
|
|
|
|
|
static uint64_t tick_led = 0;
|
|
|
|
|
uint64_t tick_now;
|
|
|
|
|
|
|
|
|
|
tick_now = timer_count_read();
|
|
|
|
|
if (tick_now >= (tick_led + LED_TIME)) {
|
|
|
|
|
if (flag & 1) {
|
|
|
|
|
gpio_set(LED_PIN);
|
|
|
|
|
} else {
|
|
|
|
|
gpio_clear(LED_PIN);
|
|
|
|
|
}
|
|
|
|
|
flag ^= 1;
|
|
|
|
|
tick_led = tick_now;
|
|
|
|
|
printf("tick_led = %llu\r\n", tick_led);
|
2025-03-22 21:13:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|