aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-07-16 11:23:34 +0100
committerFreeArtMan <dos21h@gmail.com>2017-07-16 11:23:34 +0100
commitc7449c1a905f9bffddd374016fcc7bf30e0e8ad0 (patch)
tree751204c4031c398cc7f25416f211d8f2565adc5a /cmd
parent309b670b9b8778f314076b0606d6578ab031ad16 (diff)
downloadagni-c7449c1a905f9bffddd374016fcc7bf30e0e8ad0.tar.gz
agni-c7449c1a905f9bffddd374016fcc7bf30e0e8ad0.zip
New command SPI added
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cmd_spi.c118
-rw-r--r--cmd/cmd_spi.h18
2 files changed, 136 insertions, 0 deletions
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 <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "util.h"
+#include "debug.h"
+#include "sds.h"
+
+void *cmd_spi(void *data);
+
+#endif \ No newline at end of file