[update] update gpio_led demo
This commit is contained in:
parent
59ee3ee23f
commit
35186111b8
@ -1,68 +1,38 @@
|
|||||||
#include "reset.h"
|
#include "resets.h"
|
||||||
#include "clock.h"
|
#include "timer.h"
|
||||||
#include "sio.h"
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "RP2040.h"
|
|
||||||
|
|
||||||
struct gpio_cfg_s gpio_led_cfg = {
|
#define LED_PIN (25)
|
||||||
.pin = 25,
|
#define LED_TIME (500 * 1000) /* 500ms */
|
||||||
.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)
|
int main(void)
|
||||||
{
|
{
|
||||||
reset_enable(RESET_IO_BANK0 | RESET_PADS_BANK0 | RESET_UART0);
|
reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_UART0 | RESETS_BLOCK_TIMER);
|
||||||
reset_disable(RESET_IO_BANK0 | RESET_PADS_BANK0 | RESET_UART0);
|
gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */
|
||||||
gpio_init(&gpio_led_cfg);
|
gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */
|
||||||
gpio_init_simple(0, GPIO_FUNC_UART, DISABLE, ENABLE);
|
uart_init(uart0_hw, 6 * 1000 * 1000, UART_DATABITS_8 | UART_PARITY_NONE | UART_STOPBITS_1);
|
||||||
|
printf("gpio_led example\r\n");
|
||||||
|
|
||||||
__enable_irq();
|
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 */
|
||||||
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) {
|
while (1) {
|
||||||
static uint32_t tick_led = 0;
|
static int flag = 0;
|
||||||
|
static uint64_t tick_led = 0;
|
||||||
|
uint64_t tick_now;
|
||||||
|
|
||||||
if (tick_1ms > (tick_led + 500)) {
|
tick_now = timer_count_read();
|
||||||
tick_led = tick_1ms;
|
if (tick_now >= (tick_led + LED_TIME)) {
|
||||||
gpio_toggle(gpio_led_cfg.pin);
|
if (flag & 1) {
|
||||||
printf("tick_led = %ld\r\n", tick_led);
|
gpio_set(LED_PIN);
|
||||||
|
} else {
|
||||||
|
gpio_clear(LED_PIN);
|
||||||
|
}
|
||||||
|
flag ^= 1;
|
||||||
|
tick_led = tick_now;
|
||||||
|
printf("tick_led = %llu\r\n", tick_led);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user