[feat] add shell color demo
This commit is contained in:
parent
cd3c5062f7
commit
6f60661cca
11
example/shell/shell_color/CMakeLists.txt
Normal file
11
example/shell/shell_color/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
include(proj.conf)
|
||||
|
||||
project(${EXAMPLE_NAME} VERSION 0.1)
|
||||
add_executable(${EXAMPLE_NAME}.elf main.c)
|
||||
|
||||
include_directories(.)
|
||||
|
||||
add_subdirectory(${SDK_BASE_DIR} sdk)
|
||||
target_link_libraries(${EXAMPLE_NAME}.elf sdk)
|
||||
18
example/shell/shell_color/Makefile
Normal file
18
example/shell/shell_color/Makefile
Normal 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
|
||||
35
example/shell/shell_color/main.c
Normal file
35
example/shell/shell_color/main.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include "resets.h"
|
||||
#include "gpio.h"
|
||||
#include "uart.h"
|
||||
#include "timer.h"
|
||||
#include "stdio.h"
|
||||
#include "mem.h"
|
||||
#include "shell.h"
|
||||
|
||||
extern struct shell _shell;
|
||||
struct shell *shell = &_shell;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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("shell color example\r\n");
|
||||
|
||||
kmem_init((void *)0x20030000, 64 * 1024);
|
||||
shell_init();
|
||||
printf("shell = %p\r\n", shell);
|
||||
printf("printf = %p\r\n", shell->shell_printf);
|
||||
while(1) {
|
||||
static uint32_t count = 0;
|
||||
SHELL_CMD("cmd: hello world, %lu\r\n", count++);
|
||||
SHELL_PRINTF("printf: hello world, %lu\r\n", count++);
|
||||
SHELL_DGB("dbg: hello world, %lu\r\n", count++);
|
||||
SHELL_PROMPT("prompt: hello world, %lu\r\n", count++);
|
||||
SHELL_E("e: hello world, %lu\r\n", count++);
|
||||
timer_delay_ms(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
example/shell/shell_color/proj.conf
Normal file
1
example/shell/shell_color/proj.conf
Normal file
@ -0,0 +1 @@
|
||||
set(CONFIG_SHELL 1)
|
||||
@ -1,14 +1,12 @@
|
||||
#include "resets.h"
|
||||
#include "timer.h"
|
||||
#include "gpio.h"
|
||||
#include "uart.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "mem.h"
|
||||
#include "shell.h"
|
||||
|
||||
#define LED_PIN (25)
|
||||
#define LED_TIME (500 * 1000) /* 500ms */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@ -20,6 +18,7 @@ int main(void)
|
||||
|
||||
kmem_init((void *)0x20030000, 64 * 1024);
|
||||
shell_init();
|
||||
gpio_init(LED_PIN, GPIO_FUNC_NULL | GPIO_OVER_OUT_LOW | GPIO_OVER_OE_ENABLE | GPIO_PULL_DOWN | GPIO_DRIVE_4MA); /* LED pin */
|
||||
while(1) {
|
||||
int c = uart_get_char(uart0_hw);
|
||||
if (c >= 0) {
|
||||
@ -30,13 +29,29 @@ int main(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int shell_test(int argc, char **argv)
|
||||
void shell_test(int argc, char **argv)
|
||||
{
|
||||
printf("shell test, argc=%d:\r\n", argc);
|
||||
for (int i = 0; i < argc; i++) {
|
||||
printf("argv[%d] = %s\r\n", i, argv[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
return 0;
|
||||
}
|
||||
SHELL_CMD_EXPORT_ALIAS(shell_test, test, shell test.);
|
||||
|
||||
void shell_led(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("Usage: led on/off\r\n");
|
||||
return;
|
||||
}
|
||||
if (strlen(argv[1]) == 3 && argv[1][0] == 'o' && argv[1][1] == 'f' && argv[1][2] == 'f') {
|
||||
gpio_clear(LED_PIN);
|
||||
} else if (strlen(argv[1]) == 2 && argv[1][0] == 'o' && argv[1][1] == 'n') {
|
||||
gpio_set(LED_PIN);
|
||||
} else {
|
||||
printf("Usage: led on/off\r\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
SHELL_CMD_EXPORT_ALIAS(shell_led, led, shell led.);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user