diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ad806a4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libs/avr-i2c-slave"] + path = libs/avr-i2c-slave + url = https://github.com/thegouger/avr-i2c-slave diff --git a/Makefile b/Makefile index 0bcdd2e..eb0d6bc 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,23 @@ OBJCOPY = avr-objcopy CC = avr-gcc BUILD = .build -TARGET = main - +TARGET = keyboard OPT = s -CFLAGS = -Wall -Wextra -std=c18 -O$(OPT) -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega328p -DF_CPU=16000000L -Iinclude + +CFLAGS = -Wall -Wextra -std=c18 -O$(OPT) -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects -mmcu=atmega328p -DF_CPU=16000000L -Iinclude -Ilibs/avr-i2c-slave LDFLAGS = -Wall -Wextra -O$(OPT) -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p SRC = \ src/main.c \ src/keyboard.c \ src/fifo.c \ -src/scancode.c +src/scancode.c \ +libs/avr-i2c-slave/I2CSlave.c OBJ = $(addprefix $(BUILD)/, $(notdir $(SRC:.c=.o))) -vpath %.c $(sort $(dir $(SRC))) +# We can't use this as it will use the wrong main +# vpath %.c $(sort $(dir $(SRC))) +vpath %.c $(dir $(SRC)) .PHONY: all clean diff --git a/blink.bin b/blink.bin new file mode 100644 index 0000000..edf537e Binary files /dev/null and b/blink.bin differ diff --git a/include/keyboard.h b/include/keyboard.h index 2322987..7ae4570 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -4,11 +4,8 @@ #include // SCHEMATIC -// #define KEYBOARD_CLK 2 -// #define KEYBOARD_DATA 3 - #define KEYBOARD_CLK 2 -#define KEYBOARD_DATA 7 +#define KEYBOARD_DATA 3 void send_keyboard_cmd(uint8_t value); void queue_keyboard_cmd(uint8_t value); diff --git a/include/scancode.h b/include/scancode.h index 656b6e3..4bdf82b 100644 --- a/include/scancode.h +++ b/include/scancode.h @@ -3,7 +3,6 @@ #include -void setup_scancode(); -// uint8_t convert_scancode(uint8_t shift, uint8_t code); +uint8_t convert_scancode(uint8_t shift, uint8_t code); #endif diff --git a/libs/avr-i2c-slave b/libs/avr-i2c-slave new file mode 160000 index 0000000..ae740b0 --- /dev/null +++ b/libs/avr-i2c-slave @@ -0,0 +1 @@ +Subproject commit ae740b0954a0760431db5c3f49d55de8ed74dd7c diff --git a/src/main.c b/src/main.c index 0466743..62d4350 100644 --- a/src/main.c +++ b/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<>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)); } }