From c1c9774db77bfdf45e86df70235cccc0f52f676d Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Thu, 7 Jan 2021 03:44:13 +0100 Subject: [PATCH] Changed some pins and added I2C support --- .gitmodules | 3 +++ Makefile | 13 ++++++++----- blink.bin | Bin 0 -> 922 bytes include/keyboard.h | 5 +---- include/scancode.h | 3 +-- libs/avr-i2c-slave | 1 + src/main.c | 45 ++++++++++++++++++++++++++++----------------- 7 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 .gitmodules create mode 100644 blink.bin create mode 160000 libs/avr-i2c-slave 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 0000000000000000000000000000000000000000..edf537e88e9119d01511372d25d0ef9f8d270735 GIT binary patch literal 922 zcmbu7Pe>F|9LL|=oy`$sN25cA+pNyypR{If(WRAc)uF3_2k8)=r08G?!W&y*>9X_Y z&6Z-gdI;O>t;!qiX-FB#nx3?Vn30I|6r$ajH zNGfy}zO}2ZZim|AID^K^$9jvuAq4#%Iz- z*2o!_VH+F9u2DCl<}+{!4#MQ;SEtK;l|Hx6%M7>PZoJz#(>Q$YX1^A}k%hf>`tn$r zukbFPs-~iM=+yD~wnE#=kuq1|T&|~9*LU>|-PSEVr)TxF&SykJFoY+9(IP7(LDD2k za>ODCLpDW-O%Y~Oa8ShnN>ma~of-HZ%n>I5BEqT&t0Jt5aPaThgGxl$MhM#oVH+Vl zv~Uh*aT+JEf(2bz7IaZRn(5qKL`Fcf zp#g+7Fu`sCd3leJUx64EK$7JOjPiai&uGlgjrrvD2ITbygoZt8HdcVAE7{jo5~rkT zN2e)aT0DSTR{|X!Ku=MV*u-gHQJcLxByE-G8>-Q$c^yQ}4*>n4`2G34DATNK@0)e| E7mRps#Q*>R literal 0 HcmV?d00001 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)); } }