Added buffering to output

This commit is contained in:
Dreaded_X 2020-12-30 21:04:37 +01:00
parent bec3721e46
commit 827bcdb386
2 changed files with 37 additions and 6 deletions

View File

@ -3,6 +3,10 @@
#include <stdint.h> #include <stdint.h>
// SCHEMATIC
// #define KEYBOARD_CLK 2
// #define KEYBOARD_DATA 3
#define KEYBOARD_CLK 2 #define KEYBOARD_CLK 2
#define KEYBOARD_DATA 7 #define KEYBOARD_DATA 7

View File

@ -5,9 +5,18 @@
#include "scancode.h" #include "scancode.h"
#include "keyboard.h" #include "keyboard.h"
#include "fifo.h"
// SCHEMATIC
/* #define CLK 4 */
/* #define DATA 5 */
/* #define RDY 6 */
/* #define WAIT 7 */
#define RDY 3
#define CLK 4 #define CLK 4
#define DATA 5 #define DATA 5
#define WAIT 6
// Clock the value to 74164 // Clock the value to 74164
void write_value(uint8_t value) { void write_value(uint8_t value) {
@ -16,24 +25,34 @@ void write_value(uint8_t value) {
PORTD |= (1<<CLK) | (bit<<DATA); PORTD |= (1<<CLK) | (bit<<DATA);
PORTD &= ~((1<<CLK) | (bit<<DATA)); PORTD &= ~((1<<CLK) | (bit<<DATA));
} }
// Indicate that a byte is waiting
PORTD &= ~(1<<RDY);
PORTD |= (1<<RDY);
}
volatile struct FIFO buffer;
void add_to_queue(uint8_t c) {
FIFO_push(&buffer, c);
} }
ISR(PCINT2_vect) { ISR(PCINT2_vect) {
keyboard_interrupt(write_value); keyboard_interrupt(add_to_queue);
} }
int main() { int main() {
// Configure pins as output // Configure pins as output
DDRD |= (1<<CLK) | (1<<DATA); DDRD |= (1<<RDY) | (1<<CLK) | (1<<DATA);
PORTD |= (1<<RDY);
DDRD &= ~((1<<KEYBOARD_CLK) | (1<<KEYBOARD_DATA)); // Configure pins as input
DDRD &= ~((1<<KEYBOARD_CLK) | (1<<KEYBOARD_DATA) | (1<<WAIT));
// interrupt // interrupt
PCMSK2 |= (1<<PCINT18); PCMSK2 |= (1<<PCINT18);
PCICR |= (1<<PCIE2); PCICR |= (1<<PCIE2);
write_value(0);
sei(); sei();
// Wait for the keyboard to be ready // Wait for the keyboard to be ready
@ -45,9 +64,17 @@ int main() {
// Set the keyboard repeat rate (and delay) // Set the keyboard repeat rate (and delay)
send_keyboard_cmd(0xF3); send_keyboard_cmd(0xF3);
send_keyboard_cmd(0x00 | (1<<5) | (1<<4)); send_keyboard_cmd(0x00 | (0<<5) | (0<<4));
for (;;) { for (;;) {
send_keyboard_cmd_queue(); send_keyboard_cmd_queue();
if (FIFO_size(&buffer) && !(PIND>>WAIT & 1)) {
// We currently need this to make sure that RDY gets set
// However that is possibly because of the button
// And might not be a problem on actual hardware
_delay_ms(1);
write_value(FIFO_pop(&buffer));
}
} }
} }