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/arch/esp8266/driver/stdin.cc | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/arch/esp8266/driver/stdin.cc (limited to 'src/arch/esp8266/driver/stdin.cc') 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; -- cgit v1.2.3