blob: bbb3be0c47c4644a571b3bb74a04c9e596928eb3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*
* Copyright 2020 Daniel Friesel
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#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;
|