Changed some pins and added I2C support
This commit is contained in:
45
src/main.c
45
src/main.c
@@ -7,16 +7,13 @@
|
||||
#include "keyboard.h"
|
||||
#include "fifo.h"
|
||||
|
||||
// SCHEMATIC
|
||||
/* #define CLK 4 */
|
||||
/* #define DATA 5 */
|
||||
/* #define RDY 6 */
|
||||
/* #define WAIT 7 */
|
||||
#include "I2CSlave.h"
|
||||
|
||||
#define RDY 3
|
||||
// SCHEMATIC
|
||||
#define CLK 4
|
||||
#define DATA 5
|
||||
#define WAIT 6
|
||||
#define RDY 6
|
||||
#define WAIT 7
|
||||
|
||||
// Clock the value to 74164
|
||||
void write_value(uint8_t value) {
|
||||
@@ -41,6 +38,24 @@ ISR(PCINT2_vect) {
|
||||
keyboard_interrupt(add_to_queue);
|
||||
}
|
||||
|
||||
void I2C_received(uint8_t value) {
|
||||
// Reset to bootloader
|
||||
if (value == 0xFF) {
|
||||
cli();
|
||||
WDTCSR = 0x18;
|
||||
WDTCSR = 0x08;
|
||||
while (1);
|
||||
} else if (value == 0x01) {
|
||||
return;
|
||||
}
|
||||
|
||||
FIFO_push(&buffer, value);
|
||||
}
|
||||
|
||||
void I2C_requested() {
|
||||
I2C_transmitByte(0x00);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Configure pins as output
|
||||
DDRD |= (1<<RDY) | (1<<CLK) | (1<<DATA);
|
||||
@@ -53,14 +68,14 @@ int main() {
|
||||
PCMSK2 |= (1<<PCINT18);
|
||||
PCICR |= (1<<PCIE2);
|
||||
|
||||
// Setup I2C
|
||||
I2C_setCallbacks(I2C_received, I2C_requested);
|
||||
I2C_init(0x29);
|
||||
|
||||
sei();
|
||||
|
||||
// Wait for the keyboard to be ready
|
||||
_delay_ms(1000);
|
||||
// Reset the keyboard
|
||||
send_keyboard_cmd(0xFF);
|
||||
|
||||
_delay_ms(1000);
|
||||
/* // Wait for the keyboard to be ready */
|
||||
_delay_ms(500);
|
||||
|
||||
// Set the keyboard repeat rate (and delay)
|
||||
send_keyboard_cmd(0xF3);
|
||||
@@ -70,10 +85,6 @@ int main() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user