diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-01-12 14:40:30 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-01-12 14:40:30 +0100 |
commit | 3875f37b2ce1d020aaf5174ea2a885bfdb98db98 (patch) | |
tree | 8815e77b3407ea45209bb03147dd08be82b8e539 /src/arch/esp8266/driver | |
parent | c00a200c508e18c41b6c55506ee35a2f21a6fa57 (diff) |
add stdin for esp8266 and msp430 as well as preliminary shell app
Diffstat (limited to 'src/arch/esp8266/driver')
-rw-r--r-- | src/arch/esp8266/driver/stdin.cc | 77 |
1 files changed, 77 insertions, 0 deletions
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; |