From c7449c1a905f9bffddd374016fcc7bf30e0e8ad0 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Sun, 16 Jul 2017 11:23:34 +0100 Subject: New command SPI added --- cmd/cmd_spi.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cmd/cmd_spi.h | 18 +++++++++ 2 files changed, 136 insertions(+) create mode 100644 cmd/cmd_spi.c create mode 100644 cmd/cmd_spi.h (limited to 'cmd') diff --git a/cmd/cmd_spi.c b/cmd/cmd_spi.c new file mode 100644 index 0000000..bfda27c --- /dev/null +++ b/cmd/cmd_spi.c @@ -0,0 +1,118 @@ +#include "cmd_spi.h" + +/* +SPI command shows some info about SPI protocol +HELP - shows all params +MISO,MOSI,SCK,HOLD,CS shows meaning of them +MODES - shows SPI modes avaliable +SPI - show diagram of spi +MASTER - show master connection +SLAVE - show slave connection +*/ + +//TODO multiline output =[ +char _spi_str_spi[]="""\ +--------\n\ +| MISO |\n\ +| MOSI |\n\ +| SCK |\n\ +| CS |\n\ +--------\n\ +"""; + +char _spi_str_slave[]="""\ +slave\n\ +--------\n\ +| MISO |>-\n\ +| MOSI |<-\n\ +| SCK |<-\n\ +| CS |<-\n\ +--------\n\ +"""; + +char _spi_str_master[]="""\ +master\n\ +--------\n\ +| MISO |<-\n\ +| MOSI |>-\n\ +| SCK |>-\n\ +| CS |>-\n\ +--------\n\ +"""; + +char *_spi_help_table[] = +{ + "help" ,"MODES,SPI,SLAVE,MASTER,MISO,MOSI,SCK,HOLD,CS", + "MODES" ,"QUAD(4-wires),DOUBLE(3-wires),SINGLE(2-wires)", + "SPI" ,_spi_str_spi, + "SLAVE" ,_spi_str_slave, + "MASTER",_spi_str_master, + "MISO" ,"(M)aster(I)nput(S)lave(O)utput", + "MOSI" ,"(M)aster(O)utput(S)lave(I)nput", + "SCK" ,"Serial Clockrate", + "HOLD" ,"HOLD operation for some time", + "CS" ,"(C)hip(S)elect", + NULL,NULL +}; + +char *__cmd_spi_iter(char **table, char *cmp) +{ + int iter = 0; + char *ret = NULL; + + //yea thats hack mate + iter = 0; + while (table[iter]!=NULL) + { + printf("%s\n",table[iter]); + if (strncmp(table[iter],cmp,strlen(table[iter]))==0) + { + ret = table[iter+1]; + } + iter += 2; + } + return ret; +} + +void *cmd_spi(void *data) +{ + char *ret = NULL; + char *match = NULL; + + int count=-1; + sds params; + sds *tokens=NULL; + + printf("SPI\n"); + + if (data == NULL) + { + ret = alloc_new_str("SPI protocol info!"); + } else + { + params = sdsnew(data); + tokens = sdssplitargs(params, &count); + + //maybe useless thing but who knows + if (count < 1) + { + ret = alloc_new_str("None args"); + } + + match = __cmd_spi_iter(_spi_help_table, tokens[0]); + if (match) + { + ret = alloc_new_str(match); + } else + { + ret = alloc_new_str("None such commund"); + } + + sdsfree(params); + sdsfreesplitres(tokens, count); + + } + + return ret; +} + diff --git a/cmd/cmd_spi.h b/cmd/cmd_spi.h new file mode 100644 index 0000000..818fb1a --- /dev/null +++ b/cmd/cmd_spi.h @@ -0,0 +1,18 @@ +#ifndef __CMD_SPI_H +#define __CMD_SPI_H + +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "debug.h" +#include "sds.h" + +void *cmd_spi(void *data); + +#endif \ No newline at end of file -- cgit v1.2.3