From 3875f37b2ce1d020aaf5174ea2a885bfdb98db98 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 12 Jan 2018 14:40:30 +0100 Subject: add stdin for esp8266 and msp430 as well as preliminary shell app --- src/app/bench/main.cc | 5 -- src/app/ledblink/main.cc | 88 -------------------------------- src/app/shell/Makefile.inc | 2 + src/app/shell/main.cc | 124 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 93 deletions(-) create mode 100644 src/app/shell/Makefile.inc create mode 100644 src/app/shell/main.cc (limited to 'src/app') diff --git a/src/app/bench/main.cc b/src/app/bench/main.cc index cdbc00f..ee11a06 100644 --- a/src/app/bench/main.cc +++ b/src/app/bench/main.cc @@ -59,10 +59,5 @@ int main(void) arch.idle_loop(); - //uart_setup(); - //uart_puts("\n" COL_YELLOW "dOS" COL_GREEN " > " COL_RESET); - - //arch_idle_loop(); - return 0; } diff --git a/src/app/ledblink/main.cc b/src/app/ledblink/main.cc index 8b0fe87..8d2e9d4 100644 --- a/src/app/ledblink/main.cc +++ b/src/app/ledblink/main.cc @@ -7,89 +7,6 @@ #error makeflag timer_cycles=1 required #endif -/* -void check_command(unsigned char argc, char** argv) -{ - unsigned char i2c_rxbuf[16]; - unsigned char i2c_txbuf[16]; - float buf = 0; - int i; - if (!strcmp(argv[0], "i2c")) { - if (argc == 0) { - uart_puterr("Usage: i2c [-u]\n"); - return; - } - if (!strcmp(argv[1], "on")) { - if ((argc >= 2) && !strcmp(argv[2], "-u")) { - if (i2c_setup(1) < 0) - uart_puterr("Error initializing I²C: Line is busy\n"); - } else { - if (i2c_setup(0) < 0) - uart_puterr("Error initializing I²C: Line is busy\n" - "Do you have hardware pullups on SDA/SCL?\n"); - } - } else if (!strcmp(argv[1], "off")) { - uart_puterr("Error: not implemented yet\n"); - } else if (!strcmp(argv[1], "detect")) { - i2c_scan(); - } else if (!strcmp(argv[1], "tc74")) { - i2c_txbuf[0] = 0x00; - i2c_xmit(0x4d, 1, 1, i2c_txbuf, i2c_rxbuf); - uart_putint(i2c_rxbuf[0]); - uart_puts("°C\n"); - } else if (!strcmp(argv[1], "lm75")) { - i2c_txbuf[0] = 0x00; - i2c_xmit(0x48, 1, 2, i2c_txbuf, i2c_rxbuf); - uart_putfloat(i2c_rxbuf[0] + (i2c_rxbuf[1] / 256.0)); - uart_puts("°C\n"); - } - else if (!strcmp(argv[1], "eepr")) { - i2c_rxbuf[0] = 0; - i2c_txbuf[0] = 0; - i2c_txbuf[1] = argv[2][0]; - i2c_xmit(0x50, 2, 1, i2c_txbuf, i2c_rxbuf); - uart_putint(i2c_rxbuf[0]); - uart_puts("\n"); - } - else if (!strcmp(argv[1], "eepw")) { - i2c_txbuf[0] = 0; - i2c_txbuf[1] = argv[2][0]; - i2c_txbuf[2] = argv[3][0]; - i2c_txbuf[3] = argv[3][1]; - i2c_txbuf[4] = argv[3][2]; - i2c_txbuf[5] = argv[3][3]; - i2c_txbuf[6] = argv[3][4]; - i2c_txbuf[7] = argv[3][5]; - i2c_xmit(0x50, 8, 0, i2c_txbuf, i2c_rxbuf); - } - } else if (!strcmp(argv[0], "sensors")) { - for (i = 0; i < 32; i++) { - buf += adc_gettemp(); - __delay_cycles(64000); - } - uart_puts("Temperature : "); - uart_putfloat(buf / 32); - uart_puts("°C avg / "); - uart_putfloat(adc_gettemp()); - uart_puts("°C single\n Voltage : "); - uart_putfloat(adc_getvcc()); - uart_puts("V\n"); - } else if (!strcmp(argv[0], "spi")) { - if (argc == 0) { - uart_puterr("Usage: spi \n"); - return; - } - if (!strcmp(argv[1], "on")) { - spi_setup(); - } - } else if (!strcmp(argv[0], "help")) { - uart_puts("Supported commands: i2c sensors\n"); - } else { - uart_puterr("Unknown command\n"); - } -} -*/ - void loop(void) { gpio.led_toggle(1); @@ -114,10 +31,5 @@ int main(void) arch.idle_loop(); - //uart_setup(); - //uart_puts("\n" COL_YELLOW "dOS" COL_GREEN " > " COL_RESET); - - //arch_idle_loop(); - return 0; } diff --git a/src/app/shell/Makefile.inc b/src/app/shell/Makefile.inc new file mode 100644 index 0000000..66d80ec --- /dev/null +++ b/src/app/shell/Makefile.inc @@ -0,0 +1,2 @@ +arch_drivers += ,stdin +wakeup ?= 1 diff --git a/src/app/shell/main.cc b/src/app/shell/main.cc new file mode 100644 index 0000000..33896e4 --- /dev/null +++ b/src/app/shell/main.cc @@ -0,0 +1,124 @@ +#include "arch.h" +#include "driver/gpio.h" +#include "driver/stdout.h" +#include "driver/stdin.h" +#include "driver/uptime.h" + +/* +void check_command(unsigned char argc, char** argv) +{ + unsigned char i2c_rxbuf[16]; + unsigned char i2c_txbuf[16]; + float buf = 0; + int i; + if (!strcmp(argv[0], "i2c")) { + if (argc == 0) { + uart_puterr("Usage: i2c [-u]\n"); + return; + } + if (!strcmp(argv[1], "on")) { + if ((argc >= 2) && !strcmp(argv[2], "-u")) { + if (i2c_setup(1) < 0) + uart_puterr("Error initializing I²C: Line is busy\n"); + } else { + if (i2c_setup(0) < 0) + uart_puterr("Error initializing I²C: Line is busy\n" + "Do you have hardware pullups on SDA/SCL?\n"); + } + } else if (!strcmp(argv[1], "off")) { + uart_puterr("Error: not implemented yet\n"); + } else if (!strcmp(argv[1], "detect")) { + i2c_scan(); + } else if (!strcmp(argv[1], "tc74")) { + i2c_txbuf[0] = 0x00; + i2c_xmit(0x4d, 1, 1, i2c_txbuf, i2c_rxbuf); + uart_putint(i2c_rxbuf[0]); + uart_puts("°C\n"); + } else if (!strcmp(argv[1], "lm75")) { + i2c_txbuf[0] = 0x00; + i2c_xmit(0x48, 1, 2, i2c_txbuf, i2c_rxbuf); + uart_putfloat(i2c_rxbuf[0] + (i2c_rxbuf[1] / 256.0)); + uart_puts("°C\n"); + } + else if (!strcmp(argv[1], "eepr")) { + i2c_rxbuf[0] = 0; + i2c_txbuf[0] = 0; + i2c_txbuf[1] = argv[2][0]; + i2c_xmit(0x50, 2, 1, i2c_txbuf, i2c_rxbuf); + uart_putint(i2c_rxbuf[0]); + uart_puts("\n"); + } + else if (!strcmp(argv[1], "eepw")) { + i2c_txbuf[0] = 0; + i2c_txbuf[1] = argv[2][0]; + i2c_txbuf[2] = argv[3][0]; + i2c_txbuf[3] = argv[3][1]; + i2c_txbuf[4] = argv[3][2]; + i2c_txbuf[5] = argv[3][3]; + i2c_txbuf[6] = argv[3][4]; + i2c_txbuf[7] = argv[3][5]; + i2c_xmit(0x50, 8, 0, i2c_txbuf, i2c_rxbuf); + } + } else if (!strcmp(argv[0], "sensors")) { + for (i = 0; i < 32; i++) { + buf += adc_gettemp(); + __delay_cycles(64000); + } + uart_puts("Temperature : "); + uart_putfloat(buf / 32); + uart_puts("°C avg / "); + uart_putfloat(adc_gettemp()); + uart_puts("°C single\n Voltage : "); + uart_putfloat(adc_getvcc()); + uart_puts("V\n"); + } else if (!strcmp(argv[0], "spi")) { + if (argc == 0) { + uart_puterr("Usage: spi \n"); + return; + } + if (!strcmp(argv[1], "on")) { + spi_setup(); + } + } else if (!strcmp(argv[0], "help")) { + uart_puts("Supported commands: i2c sensors\n"); + } else { + uart_puterr("Unknown command\n"); + } +} +*/ + +void loop(void) +{ + gpio.led_toggle(1); +} + +void wakeup(void) +{ + char key; + while (kin.hasKey()) { + key = kin.getKey(); + if (key == '\r') { + kout.put('\n'); + } else { + kout.put(key); + } + } +} + +int main(void) +{ + arch.setup(); + gpio.setup(); + kout.setup(); + kin.setup(); + + kout << "ohai > " << endl;; + kout << "ohai > " << endl;; + kout << "ohai > " << endl;; + kout << "ohai > " << endl;; + kout << "ohai > " << endl;; + + arch.idle_loop(); + + return 0; +} -- cgit v1.2.3