From e625328d58619d0a16288fe7beea1a252eb6f13a Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Sun, 24 Jul 2022 20:19:23 +0200 Subject: [PATCH] Started to add some SPI commands --- app/nano_shell_command.c | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/app/nano_shell_command.c b/app/nano_shell_command.c index dec1ee4..cf0176a 100644 --- a/app/nano_shell_command.c +++ b/app/nano_shell_command.c @@ -7,6 +7,7 @@ #include "task.h" #include "lwip/netif.h" #include "common.h" +#include "wm_gpio_afsel.h" extern int shell_printf(const char *format, ...); extern int wm_printf(const char *fmt,...); @@ -129,6 +130,66 @@ int _reset(const shell_cmd_t *pcmd, int argc, char *const argv[]) return 0; } +int _bus(const shell_cmd_t *pcmd, int argc, char *const argv[]) +{ + if(argc > 1) + { + if(strcmp(argv[1], "spi_init") == 0) + { + //Let's set the IO's up + wm_spi_cs_config(WM_IO_PB_14); + wm_spi_ck_config(WM_IO_PB_15); + wm_spi_di_config(WM_IO_PB_16); + wm_spi_do_config(WM_IO_PB_17); + + shell_printf("SPI init : %d"NEW_LINE, tls_spi_setup(SPI_DEFAULT_MODE, SPI_CS_ACTIVE_MODE, SPI_DEFAULT_SPEED)); + } + else if(strcmp(argv[1], "spi_w") == 0) + { + + } + else if(strcmp(argv[1], "spi_r") == 0) + { + + } + else if(strcmp(argv[1], "spi_wr") == 0) + { + char spi_recv_buff[32] = ""; + /*shell_printf("Writing [%s](len : %d) to SPI"NEW_LINE, argv[2], strlen(argv[2])); + if(tls_spi_write((u8*)argv[2], strlen(argv[2])) != TLS_SPI_STATUS_OK) + { + shell_printf("Failed to write to SPI"NEW_LINE); + return 0; + } + + tls_os_time_delay(1000);*/ + + /*if(tls_spi_read((u8*)spi_recv_buff, sizeof(spi_recv_buff) - 1) != TLS_SPI_STATUS_OK) + { + shell_printf("Failed to read from SPI"NEW_LINE); + return 0; + }*/ + + if(tls_spi_read_with_cmd((u8 *) argv[2], strlen(argv[2]), (u8 *) spi_recv_buff, sizeof(spi_recv_buff) - 1) != TLS_SPI_STATUS_OK) + { + shell_printf("Failed to write & read combo using SPI"NEW_LINE); + return 0; + } + shell_printf("Writing [%s](len : %d) to SPI"NEW_LINE, argv[2], strlen(argv[2])); + shell_printf("Received [%s](len : %d) from SPI"NEW_LINE, spi_recv_buff, strlen(spi_recv_buff)); + } + else + { + shell_printf("Unknown %s action"NEW_LINE, argv[0]); + } + } + else + { + shell_printf("List of %s actions :"NEW_LINE"spi_init"NEW_LINE"spi_w"NEW_LINE"spi_r"NEW_LINE"spi_wr"NEW_LINE, argv[0]); + } + return 0; +} + int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[]) { if(argc > 1) @@ -513,6 +574,10 @@ int _exit_remote_access(const shell_cmd_t *pcmd, int argc, char *const argv[]) return 0; } +NANO_SHELL_ADD_CMD(bus, + _bus, + "Command to interact with the SPI bus", + " Use this command to send/receive data from the SPI bus"NEW_LINE); NANO_SHELL_ADD_CMD(system, _system, "Query system information",