*shrug* Gotta commit somethin'
This commit is contained in:
parent
e618aa68cd
commit
c679426262
5 changed files with 134 additions and 14 deletions
35
avr/Makefile
35
avr/Makefile
|
@ -1,11 +1,14 @@
|
|||
include ../mk/build.mk
|
||||
|
||||
CLOCK_SPEED = 16000000L
|
||||
|
||||
INCLUDE_PATH = ../include
|
||||
HEADER_SUBDIR = tabby
|
||||
CROSS = avr-
|
||||
|
||||
CC = $(CROSS)gcc
|
||||
CFLAGS = $(CGFLAGS) -Wall -Os -mmcu=atmega328p -I$(INCLUDE_PATH)
|
||||
CFLAGS = $(CGFLAGS) -Wall -Os -mmcu=atmega328p -I$(INCLUDE_PATH) \
|
||||
-DF_CPU=$(CLOCK_SPEED)
|
||||
LDFLAGS =
|
||||
|
||||
OBJCOPY = $(CROSS)objcopy
|
||||
|
@ -20,21 +23,33 @@ HEADERS_BUILD = $(HEADERS_LOCAL) \
|
|||
$(addprefix $(INCLUDE_PATH)/$(HEADER_SUBDIR)/,$(HEADERS))
|
||||
|
||||
HEADERS = avr/buffer.h avr/uart.h link.h
|
||||
OBJS = main.o uart.o
|
||||
OBJS = send.o recv.o uart.o
|
||||
|
||||
IMAGE_NAME = tabby
|
||||
IMAGE_ELF = $(IMAGE_NAME).elf
|
||||
IMAGE_BIN = $(IMAGE_NAME).bin
|
||||
RECV_NAME = recv
|
||||
RECV_BIN = $(RECV_NAME).bin
|
||||
RECV_ELF = $(RECV_NAME).elf
|
||||
RECV_OBJS = recv.o uart.o
|
||||
|
||||
SEND_NAME = send
|
||||
SEND_BIN = $(SEND_NAME).bin
|
||||
SEND_ELF = $(SEND_NAME).elf
|
||||
SEND_OBJS = send.o uart.o
|
||||
|
||||
IMAGES_BIN = $(RECV_BIN) $(SEND_BIN)
|
||||
IMAGES_ELF = $(RECV_ELF) $(SEND_ELF)
|
||||
|
||||
RM = /bin/rm
|
||||
|
||||
all: $(IMAGE_BIN)
|
||||
all: $(IMAGES_BIN)
|
||||
|
||||
$(IMAGE_BIN): $(IMAGE_ELF)
|
||||
$(IMAGES_BIN): %.bin: %.elf
|
||||
$(OBJCOPY) $(OBJCOPY_FLAGS) -O binary $< $@
|
||||
|
||||
$(IMAGE_ELF): $(OBJS)
|
||||
$(CC) $(CFLAGS) $(OBJS) -o $@
|
||||
$(SEND_ELF): $(SEND_OBJS)
|
||||
$(CC) $(CFLAGS) $(SEND_OBJS) -o $@
|
||||
|
||||
$(RECV_ELF): $(RECV_OBJS)
|
||||
$(CC) $(CFLAGS) $(RECV_OBJS) -o $@
|
||||
|
||||
$(OBJS): %.o: %.c $(HEADERS_BUILD)
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
@ -43,4 +58,4 @@ flash: $(IMAGE_BIN)
|
|||
$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(IMAGE_BIN):r
|
||||
|
||||
clean:
|
||||
$(RM) -f $(IMAGE_BIN) $(IMAGE_ELF) $(OBJS)
|
||||
$(RM) -f $(IMAGES_BIN) $(IMAGES_ELF) $(OBJS)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
106
avr/send.c
Normal file
106
avr/send.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include <tabby/printer.h>
|
||||
#include <tabby/avr/uart.h>
|
||||
|
||||
#define TIMER0_INTERVAL 1953
|
||||
|
||||
static volatile uint8_t bits = 0;
|
||||
static volatile uint8_t value_in = 0x00; /* Data coming in from Game Boy */
|
||||
static volatile uint8_t value_out = 0x00; /* Data going out to Game Boy */
|
||||
|
||||
static volatile tabby_printer_packet header = {
|
||||
.type = 0,
|
||||
.compression = 0,
|
||||
.size = 0
|
||||
};
|
||||
|
||||
static volatile uint16_t i = 0,
|
||||
b = 0;
|
||||
|
||||
/*
|
||||
* Internal clock source interrupt vector
|
||||
*/
|
||||
ISR(TIMER0_COMPB_vect) {
|
||||
value_in >>= 1;
|
||||
|
||||
PORTB |= (1 << PORTB5);
|
||||
|
||||
if (PORTB & (1 << PORTB4)) {
|
||||
value_in |= 0x80;
|
||||
}
|
||||
|
||||
if (value_out & 0x80) {
|
||||
PORTB |= (1 << PORTB3);
|
||||
} else {
|
||||
PORTB &= ~(1 << PORTB3);
|
||||
}
|
||||
|
||||
value_out <<= 1;
|
||||
|
||||
if (--bits == 0) {
|
||||
bits = 8;
|
||||
}
|
||||
|
||||
/*
|
||||
* Chill out for 60µsec, then ride out the rest of the time until the next
|
||||
* interrupt with a high as fuck SCK
|
||||
*/
|
||||
_delay_us(60);
|
||||
|
||||
PORTB &= ~(1 << PORTB5);
|
||||
}
|
||||
|
||||
static void clock_setup() {
|
||||
/*
|
||||
* Configure MISO as output
|
||||
*/
|
||||
DDRB |= (1 << DDB4);
|
||||
|
||||
/*
|
||||
* Configure MOSI as input
|
||||
*/
|
||||
DDRB &= ~(1 << DDB3);
|
||||
|
||||
/*
|
||||
* Configure SCK pin as output
|
||||
*/
|
||||
DDRB |= (1 << DDB5);
|
||||
|
||||
/*
|
||||
* Enable timer interrupt vector
|
||||
*/
|
||||
TIMSK0 = (1 << TOIE1);
|
||||
|
||||
/*
|
||||
* Reset timer counter to zero
|
||||
*/
|
||||
TCNT1 = 0;
|
||||
|
||||
/*
|
||||
* Set timer interval
|
||||
*/
|
||||
OCR1A = TIMER0_INTERVAL;
|
||||
|
||||
/*
|
||||
* Set timer clock divider to 1/1
|
||||
*/
|
||||
TCCR1B = (1 << CS10);
|
||||
}
|
||||
|
||||
int main() {
|
||||
uart_init();
|
||||
|
||||
clock_setup();
|
||||
|
||||
sei();
|
||||
|
||||
while (1) {
|
||||
uint8_t c = uart_getchar(NULL);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -5,8 +5,7 @@
|
|||
|
||||
#include <tabby/avr/uart.h>
|
||||
|
||||
#define F_CPU 16000000UL
|
||||
#define BAUD TABBY_AVR_UART_BAUD
|
||||
#define BAUD TABBY_AVR_UART_BAUD
|
||||
|
||||
#include <util/setbaud.h>
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef _TABBY_AVR_UART_H
|
||||
#define _TABBY_AVR_UART_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define TABBY_AVR_UART_BAUD 57600
|
||||
|
||||
void uart_init();
|
||||
|
|
Loading…
Add table
Reference in a new issue