[feat] add gpio_key demo

This commit is contained in:
zhji 2025-06-02 21:34:33 +08:00
parent ab88fa8455
commit 33bd91609b
4 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.10)
include(proj.conf)
project(${EXAMPLE_NAME} VERSION 0.1)
add_executable(${EXAMPLE_NAME}.elf main.c)
add_subdirectory(${SDK_BASE_DIR} sdk)
target_link_libraries(${EXAMPLE_NAME}.elf sdk)

View File

@ -0,0 +1,18 @@
EXAMPLE_BASE_DIR ?= $(shell realpath .)
EXAMPLE_NAME := $(notdir $(patsubst %/,%,$(CURDIR)))
SDK_BASE_DIR ?= $(shell realpath ./../../../..)
export SDK_BASE_DIR
export EXAMPLE_NAME
export EXAMPLE_BASE_DIR
GCC_PATH := $(shell which arm-none-eabi-gcc)
CROSS_COMPILE := $(patsubst %gcc,%,$(GCC_PATH))
ifeq ($(GCC_PATH),)
$(error arm-none-eabi-gcc not found in PATH. Please install the ARM toolchain.)
endif
# add custom cmake definition
#cmake_definition+=-Dxxx=sss
include $(SDK_BASE_DIR)/project.build

View File

@ -0,0 +1,31 @@
#include "resets.h"
#include "gpio.h"
#include "uart.h"
#include "stdio.h"
#define KEY_PIN (24)
#define LED_PIN (25)
int main(void)
{
reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_UART0);
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_key example\r\n");
gpio_init(LED_PIN, GPIO_FUNC_NULL | GPIO_OVER_OUT_HIGH | GPIO_OVER_OE_ENABLE | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* LED pin */
gpio_init(KEY_PIN, GPIO_FUNC_NULL | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* KEY pin */
while (1) {
if (gpio_read(KEY_PIN)) {
/* read pin status as 1: release key */
gpio_clear(LED_PIN); /* low level for turn off LED */
} else {
/* read pin status as 0: press key */
gpio_set(LED_PIN); /* high level for turn on LED */
}
}
return 0;
}

View File

@ -0,0 +1 @@
# set(CONFIG_COMPONENT1 1)