summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--include/esp8266/driver/stdin.h24
-rw-r--r--include/msp430fr5969lp/driver/stdin.h24
-rw-r--r--src/app/bench/main.cc5
-rw-r--r--src/app/ledblink/main.cc88
-rw-r--r--src/app/shell/Makefile.inc2
-rw-r--r--src/app/shell/main.cc124
-rw-r--r--src/arch/esp8266/Makefile.inc4
-rw-r--r--src/arch/esp8266/driver/stdin.cc77
-rw-r--r--src/arch/msp430fr5969lp/Makefile.inc4
-rw-r--r--src/arch/msp430fr5969lp/arch.cc13
-rw-r--r--src/arch/msp430fr5969lp/driver/stdin.cc31
12 files changed, 305 insertions, 95 deletions
diff --git a/Makefile b/Makefile
index 0e5371a..a6f03c9 100644
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,10 @@ ifeq (${loop}, 1)
COMMON_FLAGS += -DWITH_LOOP
endif
+ifeq (${wakeup}, 1)
+ COMMON_FLAGS += -DWITH_WAKEUP
+endif
+
include src/arch/${arch}/Makefile.inc
clean: arch_clean
diff --git a/include/esp8266/driver/stdin.h b/include/esp8266/driver/stdin.h
new file mode 100644
index 0000000..6462e0c
--- /dev/null
+++ b/include/esp8266/driver/stdin.h
@@ -0,0 +1,24 @@
+#ifndef STANDARDINPUT_H
+#define STANDARDINPUT_H
+
+class StandardInput {
+ private:
+ StandardInput(const StandardInput &copy);
+ char buffer[8];
+ unsigned char write_pos, read_pos;
+
+ public:
+ StandardInput() : write_pos(0), read_pos(0) {}
+ void setup();
+ bool hasKey();
+ char getKey();
+
+ inline void addKey(char key) {
+ buffer[write_pos++] = key;
+ write_pos %= 8;
+ }
+};
+
+extern StandardInput kin;
+
+#endif
diff --git a/include/msp430fr5969lp/driver/stdin.h b/include/msp430fr5969lp/driver/stdin.h
new file mode 100644
index 0000000..6462e0c
--- /dev/null
+++ b/include/msp430fr5969lp/driver/stdin.h
@@ -0,0 +1,24 @@
+#ifndef STANDARDINPUT_H
+#define STANDARDINPUT_H
+
+class StandardInput {
+ private:
+ StandardInput(const StandardInput &copy);
+ char buffer[8];
+ unsigned char write_pos, read_pos;
+
+ public:
+ StandardInput() : write_pos(0), read_pos(0) {}
+ void setup();
+ bool hasKey();
+ char getKey();
+
+ inline void addKey(char key) {
+ buffer[write_pos++] = key;
+ write_pos %= 8;
+ }
+};
+
+extern StandardInput kin;
+
+#endif
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 <on|off|detect|gettemp> [-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 <on|off|sharp>\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 <on|off|detect|gettemp> [-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 <on|off|sharp>\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;
+}
diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc
index 69a96f1..82755ce 100644
--- a/src/arch/esp8266/Makefile.inc
+++ b/src/arch/esp8266/Makefile.inc
@@ -29,6 +29,10 @@ ifeq (${esp8266_led2}, 1)
COMMON_FLAGS += -DLED_ON_GPIO16
endif
+ifneq ($(findstring stdin,${arch_drivers}), )
+ TARGETS += src/arch/esp8266/driver/stdin.cc
+endif
+
.cc.o:
${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
${OBJCOPY} --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal $@
diff --git a/src/arch/esp8266/driver/stdin.cc b/src/arch/esp8266/driver/stdin.cc
new file mode 100644
index 0000000..7c7d2a7
--- /dev/null
+++ b/src/arch/esp8266/driver/stdin.cc
@@ -0,0 +1,77 @@
+#include "driver/stdin.h"
+#include "driver/gpio.h"
+extern "C" {
+#include "osapi.h"
+#include "user_interface.h"
+#include "gpio.h"
+#include "ets_sys.h"
+void ets_isr_attach(uint16_t idx, void func(), void *arg);
+void ets_isr_unmask(uint16_t idx);
+}
+
+#define USF *((volatile uint32_t *)(0x60000000))
+#define USIR *((volatile uint32_t *)(0x60000004))
+#define USIS *((volatile uint32_t *)(0x60000008))
+#define USIE *((volatile uint32_t *)(0x6000000c))
+#define USIC *((volatile uint32_t *)(0x60000010))
+#define USS *((volatile uint32_t *)(0x6000001c))
+#define USC1 *((volatile uint32_t *)(0x60000024))
+
+#define UIFF 0
+#define UIFE 1
+#define UIPE 2
+#define UIFR 3
+#define UIOF 4
+#define UIDSR 5
+#define UICTS 6
+#define UIBD 7
+#define UITO 8
+
+#define USRXC 0
+#define UCFFT 0
+#define UCTOT 24
+#define UCTOE 31
+
+
+#ifdef WITH_WAKEUP
+void wakeup();
+#endif
+
+void uart_isr()
+{
+ if (USIS & ((1 << UIFF) | (1 << UITO))) {
+ while ((USS >> USRXC) & 0x7f) {
+ kin.addKey(USF);
+ }
+ }
+ USIC = USIS;
+#ifdef WITH_WAKEUP
+ wakeup();
+#endif
+}
+
+void StandardInput::setup()
+{
+ //USC1 = (0x7f << UCFFT) | (0x02 << UCTOT) | (1 << UCTOE );
+ USIC = 0xffff;
+ USIE = (1 << UIFF) | (1 << UIFR) | (1 << UITO);
+ ETS_UART_INTR_ATTACH(&uart_isr, NULL);
+ ETS_UART_INTR_ENABLE();
+}
+
+bool StandardInput::hasKey()
+{
+ if (write_pos != read_pos) {
+ return true;
+ }
+ return false;
+}
+
+char StandardInput::getKey()
+{
+ char ret = buffer[read_pos++];
+ read_pos %= 8;
+ return ret;
+}
+
+StandardInput kin;
diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc
index 05fcab1..bb91973 100644
--- a/src/arch/msp430fr5969lp/Makefile.inc
+++ b/src/arch/msp430fr5969lp/Makefile.inc
@@ -24,6 +24,10 @@ TARGETS += src/arch/msp430fr5969lp/driver/gpio.cc
TARGETS += src/arch/msp430fr5969lp/driver/stdout.cc
TARGETS += src/arch/msp430fr5969lp/driver/uptime.cc
+ifneq ($(findstring stdin,${arch_drivers}), )
+ TARGETS += src/arch/msp430fr5969lp/driver/stdin.cc
+endif
+
ifneq ($(findstring i2c,${arch_drivers}), )
TARGETS += src/arch/msp430fr5969lp/driver/i2c.cc
endif
diff --git a/src/arch/msp430fr5969lp/arch.cc b/src/arch/msp430fr5969lp/arch.cc
index 44a22c6..8281e66 100644
--- a/src/arch/msp430fr5969lp/arch.cc
+++ b/src/arch/msp430fr5969lp/arch.cc
@@ -63,10 +63,19 @@ void Arch::setup(void)
//P4OUT = 0;
}
+#ifdef WITH_WAKEUP
+extern void wakeup();
+#endif
+
void Arch::idle_loop(void)
{
- __eint();
- while (1);
+ while (1) {
+ __eint();
+ __bis_SR_register(LPM0_bits);
+#ifdef WITH_WAKEUP
+ wakeup();
+#endif
+ }
}
Arch arch;
diff --git a/src/arch/msp430fr5969lp/driver/stdin.cc b/src/arch/msp430fr5969lp/driver/stdin.cc
new file mode 100644
index 0000000..cc6e586
--- /dev/null
+++ b/src/arch/msp430fr5969lp/driver/stdin.cc
@@ -0,0 +1,31 @@
+#include "driver/stdin.h"
+#include <msp430.h>
+
+void StandardInput::setup()
+{
+ UCA0IE |= UCRXIE;
+}
+
+bool StandardInput::hasKey()
+{
+ if (write_pos != read_pos) {
+ return true;
+ }
+ return false;
+}
+
+char StandardInput::getKey()
+{
+ char ret = buffer[read_pos++];
+ read_pos %= 8;
+ return ret;
+}
+
+StandardInput kin;
+
+__attribute__((interrupt(USCI_A0_VECTOR))) __attribute__((wakeup)) void handle_stdin()
+{
+ if (UCA0IFG & UCRXIFG) {
+ kin.addKey(UCA0RXBUF);
+ }
+}