Instead of delay, wait for keyboard to respond

This commit is contained in:
Dreaded_X 2021-01-18 17:25:25 +01:00
parent 8e66529df3
commit befc326c7f
6 changed files with 20 additions and 14 deletions

6
include/coroutine.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#define CO_BEGIN static unsigned state = 0; switch (state) { case 0:
#define CO_YIELD do { state = __LINE__; return; case __LINE__:; } while (0)
#define CO_BREAK do { state = 0; return; } while (0)
#define CO_END } state = 0

View File

@ -1,5 +1,4 @@
#ifndef FIFO_h #pragma once
#define FIFO_h
#include <stdint.h> #include <stdint.h>
@ -16,5 +15,3 @@ void FIFO_push(volatile struct FIFO* fifo, uint8_t value);
uint8_t FIFO_pop(volatile struct FIFO* fifo); uint8_t FIFO_pop(volatile struct FIFO* fifo);
int FIFO_size(volatile struct FIFO* fifo); int FIFO_size(volatile struct FIFO* fifo);
void FIFO_clear(volatile struct FIFO* fifo); void FIFO_clear(volatile struct FIFO* fifo);
#endif

View File

@ -1,5 +1,4 @@
#ifndef KEYBOARD_h #pragma once
#define KEYBOARD_h
#include <stdint.h> #include <stdint.h>
@ -12,5 +11,3 @@ void queue_keyboard_cmd(uint8_t value);
void send_keyboard_cmd_queue(); void send_keyboard_cmd_queue();
void keyboard_interrupt(void (*callback)(uint8_t)); void keyboard_interrupt(void (*callback)(uint8_t));
#endif

View File

@ -1,8 +1,5 @@
#ifndef SCANCODE_H #pragma once
#define SCANCODE_H
#include <stdint.h> #include <stdint.h>
uint8_t convert_scancode(uint8_t shift, uint8_t code); uint8_t convert_scancode(uint8_t shift, uint8_t code);
#endif

View File

@ -4,6 +4,7 @@
#include "keyboard.h" #include "keyboard.h"
#include "scancode.h" #include "scancode.h"
#include "fifo.h" #include "fifo.h"
#include "coroutine.h"
volatile struct { volatile struct {
struct FIFO buffer; struct FIFO buffer;

View File

@ -1,5 +1,6 @@
#include <avr/io.h> #include <avr/io.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <stdint.h>
#include <util/delay.h> #include <util/delay.h>
#include <stddef.h> #include <stddef.h>
@ -57,6 +58,8 @@ void I2C_requested() {
} }
int main() { int main() {
/* FIFO_clear(&buffer); */
// Configure pins as output // Configure pins as output
DDRD |= (1<<RDY) | (1<<CLK) | (1<<DATA); DDRD |= (1<<RDY) | (1<<CLK) | (1<<DATA);
PORTD |= (1<<RDY); PORTD |= (1<<RDY);
@ -74,8 +77,13 @@ int main() {
sei(); sei();
/* // Wait for the keyboard to be ready */ send_keyboard_cmd(0xFF);
_delay_ms(500);
while(FIFO_size(&buffer)) {};
if (FIFO_pop(&buffer) != 0xFF) {
send_keyboard_cmd(0xED);
send_keyboard_cmd(0x06);
}
// Set the keyboard repeat rate (and delay) // Set the keyboard repeat rate (and delay)
send_keyboard_cmd(0xF3); send_keyboard_cmd(0xF3);