Changed some pins and added I2C support
This commit is contained in:
parent
827bcdb386
commit
c1c9774db7
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "libs/avr-i2c-slave"]
|
||||
path = libs/avr-i2c-slave
|
||||
url = https://github.com/thegouger/avr-i2c-slave
|
13
Makefile
13
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
|
||||
|
||||
|
|
|
@ -4,11 +4,8 @@
|
|||
#include <stdint.h>
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
void setup_scancode();
|
||||
// uint8_t convert_scancode(uint8_t shift, uint8_t code);
|
||||
uint8_t convert_scancode(uint8_t shift, uint8_t code);
|
||||
|
||||
#endif
|
||||
|
|
1
libs/avr-i2c-slave
Submodule
1
libs/avr-i2c-slave
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit ae740b0954a0760431db5c3f49d55de8ed74dd7c
|
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