mirror of
https://github.com/jscrane/r65emu.git
synced 2024-05-29 03:41:36 +00:00
minor kbd changes
This commit is contained in:
parent
50110b3525
commit
f8371e10df
|
@ -7,10 +7,10 @@ public:
|
||||||
virtual void down(byte) = 0;
|
virtual void down(byte) = 0;
|
||||||
virtual void reset() = 0;
|
virtual void reset() = 0;
|
||||||
|
|
||||||
inline bool isshift(byte scan) {
|
static inline bool isshift(byte scan) {
|
||||||
return scan == 0x12 || scan == 0x59;
|
return scan == 0x12 || scan == 0x59;
|
||||||
}
|
}
|
||||||
inline bool isctrl(byte scan) {
|
static inline bool isctrl(byte scan) {
|
||||||
return scan == 0x14;
|
return scan == 0x14;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
129
ps2drv.cpp
129
ps2drv.cpp
|
@ -10,72 +10,97 @@ static uint8_t DataPin;
|
||||||
// The ISR for the external interrupt
|
// The ISR for the external interrupt
|
||||||
void ps2interrupt(void)
|
void ps2interrupt(void)
|
||||||
{
|
{
|
||||||
static uint8_t bitcount=0;
|
static uint8_t bitcount=0;
|
||||||
static uint8_t incoming=0;
|
static uint8_t incoming=0;
|
||||||
static uint32_t prev_ms=0;
|
static uint32_t prev_ms=0;
|
||||||
uint32_t now_ms;
|
uint32_t now_ms;
|
||||||
uint8_t n, val;
|
uint8_t n, val;
|
||||||
|
|
||||||
val = digitalRead(DataPin);
|
val = digitalRead(DataPin);
|
||||||
now_ms = millis();
|
now_ms = millis();
|
||||||
if (now_ms - prev_ms > 250) {
|
if (now_ms - prev_ms > 250) {
|
||||||
bitcount = 0;
|
bitcount = 0;
|
||||||
incoming = 0;
|
incoming = 0;
|
||||||
}
|
}
|
||||||
prev_ms = now_ms;
|
prev_ms = now_ms;
|
||||||
n = bitcount - 1;
|
n = bitcount - 1;
|
||||||
if (n <= 7) {
|
if (n <= 7) {
|
||||||
incoming |= (val << n);
|
incoming |= (val << n);
|
||||||
}
|
}
|
||||||
bitcount++;
|
bitcount++;
|
||||||
if (bitcount == 11) {
|
if (bitcount == 11) {
|
||||||
uint8_t i = head + 1;
|
uint8_t i = head + 1;
|
||||||
if (i == BUFFER_SIZE) i = 0;
|
if (i == BUFFER_SIZE) i = 0;
|
||||||
if (i != tail) {
|
if (i != tail) {
|
||||||
buffer[i] = incoming;
|
buffer[i] = incoming;
|
||||||
head = i;
|
head = i;
|
||||||
}
|
}
|
||||||
bitcount = 0;
|
bitcount = 0;
|
||||||
incoming = 0;
|
incoming = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PS2Driver::available() {
|
bool PS2Driver::available() {
|
||||||
if (head == tail)
|
if (head == tail)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint8_t i = tail+1;
|
uint8_t i = tail+1;
|
||||||
if (i == BUFFER_SIZE) i = 0;
|
if (i == BUFFER_SIZE) i = 0;
|
||||||
if (buffer[i] == 0xf0)
|
if (buffer[i] == 0xf0)
|
||||||
return i != head;
|
return i != head;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PS2Driver::isbreak() {
|
bool PS2Driver::isbreak() {
|
||||||
bool b = isbrk;
|
bool b = isbrk;
|
||||||
isbrk = false;
|
isbrk = false;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS2Driver::read() {
|
int PS2Driver::read() {
|
||||||
if (head == tail)
|
if (head == tail)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uint8_t i = tail+1;
|
uint8_t i = tail+1;
|
||||||
if (i == BUFFER_SIZE) i = 0;
|
if (i == BUFFER_SIZE) i = 0;
|
||||||
tail = i;
|
tail = i;
|
||||||
if (buffer[i] == 0xf0) {
|
if (buffer[i] == 0xf0) {
|
||||||
isbrk = true;
|
isbrk = true;
|
||||||
return read();
|
return read();
|
||||||
}
|
}
|
||||||
return buffer[i];
|
return buffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned PS2Driver::read2() {
|
||||||
|
if (head == tail)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint8_t i = tail+1;
|
||||||
|
if (i == BUFFER_SIZE) i = 0;
|
||||||
|
tail = i;
|
||||||
|
if (buffer[i] != 0xf0)
|
||||||
|
return buffer[i];
|
||||||
|
return 0x0100 | read2();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned PS2Driver::peek() {
|
||||||
|
if (head == tail)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint8_t i = tail+1;
|
||||||
|
if (i == BUFFER_SIZE) i = 0;
|
||||||
|
if (buffer[i] == 0xf0) {
|
||||||
|
if (++i == BUFFER_SIZE) i = 0;
|
||||||
|
return 0x0100 | buffer[i];
|
||||||
|
}
|
||||||
|
return buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void PS2Driver::begin(uint8_t data_pin, uint8_t irq_pin)
|
void PS2Driver::begin(uint8_t data_pin, uint8_t irq_pin)
|
||||||
{
|
{
|
||||||
DataPin = data_pin;
|
DataPin = data_pin;
|
||||||
pinMode(irq_pin, INPUT_PULLUP);
|
pinMode(irq_pin, INPUT_PULLUP);
|
||||||
pinMode(data_pin, INPUT_PULLUP);
|
pinMode(data_pin, INPUT_PULLUP);
|
||||||
attachInterrupt(irq_pin, ps2interrupt, FALLING);
|
attachInterrupt(irq_pin, ps2interrupt, FALLING);
|
||||||
head = tail = 0;
|
head = tail = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user