From 3eb20ea675fc9100d494473154a82ba9604de653 Mon Sep 17 00:00:00 2001 From: Rafael Zurita Date: Mon, 3 Aug 2020 10:24:52 -0300 Subject: [PATCH] gpio --- apps/shell/xsh_gpio.c | 40 ++++++++++++++++++++++++++++++++++++++ lib/{gpio.c => avr_gpio.c} | 0 main/xsh_gpio.c | 6 +++--- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 apps/shell/xsh_gpio.c rename lib/{gpio.c => avr_gpio.c} (100%) diff --git a/apps/shell/xsh_gpio.c b/apps/shell/xsh_gpio.c new file mode 100644 index 0000000..d51dfcb --- /dev/null +++ b/apps/shell/xsh_gpio.c @@ -0,0 +1,40 @@ +/* xsh_gpio.c - xsh_gpio */ + +#include +#include + +/*------------------------------------------------------------------------ + * xsh_gpio - write a value v in port p + *------------------------------------------------------------------------ + * + * Two modes: + * Normal mode. Example: gpio b 32 # arduino pin 13 high + * Extra Arduino mode. Example: gpio 13 1 # arduino pin 13 high + */ +shellcmd xsh_gpio(int nargs, char *args[]) +{ + char p; + unsigned char v; + + char pin; + unsigned char val; + + + /* Normal mode. Example: gpio b 32 # arduino pin 13 high */ + + p = *args[1]; + v = number(args[2]); + + if ((p == 'b') | (p == 'c') | (p == 'd')) { + gpio_write(p, v); + return 0; + } + + /* Extra arduino mode. Example: gpio 13 1 # arduino pin 13 high */ + + pin = number(args[1]); + gpio_arduino_write(pin, v); + + return 0; +} + diff --git a/lib/gpio.c b/lib/avr_gpio.c similarity index 100% rename from lib/gpio.c rename to lib/avr_gpio.c diff --git a/main/xsh_gpio.c b/main/xsh_gpio.c index 9660430..d51dfcb 100644 --- a/main/xsh_gpio.c +++ b/main/xsh_gpio.c @@ -7,8 +7,9 @@ * xsh_gpio - write a value v in port p *------------------------------------------------------------------------ * - * Extra Arduino mode. Example: - * gpio 13 1 # arduino pin 13 high + * Two modes: + * Normal mode. Example: gpio b 32 # arduino pin 13 high + * Extra Arduino mode. Example: gpio 13 1 # arduino pin 13 high */ shellcmd xsh_gpio(int nargs, char *args[]) { @@ -37,4 +38,3 @@ shellcmd xsh_gpio(int nargs, char *args[]) return 0; } -