diff --git a/example/peripherals/gpio/gpio_key/CMakeLists.txt b/example/peripherals/gpio/gpio_key/CMakeLists.txt new file mode 100644 index 0000000..e07dfed --- /dev/null +++ b/example/peripherals/gpio/gpio_key/CMakeLists.txt @@ -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) diff --git a/example/peripherals/gpio/gpio_key/Makefile b/example/peripherals/gpio/gpio_key/Makefile new file mode 100644 index 0000000..df5330b --- /dev/null +++ b/example/peripherals/gpio/gpio_key/Makefile @@ -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 diff --git a/example/peripherals/gpio/gpio_key/main.c b/example/peripherals/gpio/gpio_key/main.c new file mode 100644 index 0000000..6b80882 --- /dev/null +++ b/example/peripherals/gpio/gpio_key/main.c @@ -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; +} diff --git a/example/peripherals/gpio/gpio_key/proj.conf b/example/peripherals/gpio/gpio_key/proj.conf new file mode 100644 index 0000000..7d2ef31 --- /dev/null +++ b/example/peripherals/gpio/gpio_key/proj.conf @@ -0,0 +1 @@ +# set(CONFIG_COMPONENT1 1)