Holy shit, it fucking works
This commit is contained in:
parent
904bf866a6
commit
6fa31cccd8
2 changed files with 42 additions and 22 deletions
|
@ -15,7 +15,7 @@ OBJCOPY = $(CROSS)objcopy
|
||||||
OBJCOPY_FLAGS = -S
|
OBJCOPY_FLAGS = -S
|
||||||
|
|
||||||
AVRDUDE = avrdude
|
AVRDUDE = avrdude
|
||||||
AVRDUDE_DEVICE = /dev/ttyACM0
|
AVRDUDE_DEVICE = /dev/cu.usbmodem1411
|
||||||
AVRDUDE_FLAGS = -c arduino -p atmega328p -b 115200 -D -P $(AVRDUDE_DEVICE)
|
AVRDUDE_FLAGS = -c arduino -p atmega328p -b 115200 -D -P $(AVRDUDE_DEVICE)
|
||||||
|
|
||||||
HEADERS_LOCAL =
|
HEADERS_LOCAL =
|
||||||
|
|
62
avr/send.c
62
avr/send.c
|
@ -23,7 +23,7 @@ static uint8_t device = 0x00,
|
||||||
* So like, we're abusing pins here. So badly, it's beyond. So here's what's
|
* So like, we're abusing pins here. So badly, it's beyond. So here's what's
|
||||||
* going down: We want to retain the same physical I/O connections between
|
* going down: We want to retain the same physical I/O connections between
|
||||||
* both the sending and receiving flavors of the whole Game Boy Printer
|
* both the sending and receiving flavors of the whole Game Boy Printer
|
||||||
* endeavor, and that means that we must absolutely bit bang MOSI and MISO
|
* endeavor, and that mean/s that we must absolutely bit bang MOSI and MISO
|
||||||
* opposite from their ordinary roles. The reason being: There is no notion
|
* opposite from their ordinary roles. The reason being: There is no notion
|
||||||
* of MISO or MOSI from the Game Boy's (nor its peripherals') point of view.
|
* of MISO or MOSI from the Game Boy's (nor its peripherals') point of view.
|
||||||
* The SI and SO pins over a link cable are crossed over, so SI on one end
|
* The SI and SO pins over a link cable are crossed over, so SI on one end
|
||||||
|
@ -31,27 +31,37 @@ static uint8_t device = 0x00,
|
||||||
*/
|
*/
|
||||||
static void spi_init() {
|
static void spi_init() {
|
||||||
/*
|
/*
|
||||||
* Configure MISO as output...Oddly, alongside SCK as an output
|
* Set SC to output
|
||||||
*/
|
*/
|
||||||
DDRB |= ((1 << DDB5) | (1 << DDB4));
|
DDRB |= (1 << DDB5);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configure MOSI as input...Also oddly
|
* Configure SO as output
|
||||||
*/
|
*/
|
||||||
DDRB &= ~(1 << DDB3);
|
DDRB |= (1 << DDB4);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set output pins clear by default
|
* Configure SI as input with pullup
|
||||||
*/
|
*/
|
||||||
PORTB &= ~((1 << PORTB5) | (1 << PORTB4));
|
DDRB &= ~(1 << DDB3);
|
||||||
|
PORTB |= (1 << DDB3);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set SO clear
|
||||||
|
*/
|
||||||
|
PORTB &= ~(1 << PORTB4);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set SC high
|
||||||
|
*/
|
||||||
|
PORTB |= (1 << PORTB5);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t spi_send_byte(uint8_t value) {
|
static uint8_t spi_send_byte(uint8_t value) {
|
||||||
uint8_t ret = 0,
|
uint8_t i, ret = 0;
|
||||||
i = 0;
|
|
||||||
|
|
||||||
for (i=0; i<8; i++) {
|
for (i=0; i<8; i++) {
|
||||||
PORTB |= (1 << PORTB5);
|
PORTB &= ~(1 << PORTB5);
|
||||||
|
|
||||||
if (value & 0x80) {
|
if (value & 0x80) {
|
||||||
PORTB |= (1 << PORTB4);
|
PORTB |= (1 << PORTB4);
|
||||||
|
@ -59,21 +69,22 @@ static uint8_t spi_send_byte(uint8_t value) {
|
||||||
PORTB &= ~(1 << PORTB4);
|
PORTB &= ~(1 << PORTB4);
|
||||||
}
|
}
|
||||||
|
|
||||||
_delay_us(140);
|
value <<= 1;
|
||||||
|
ret <<= 1;
|
||||||
|
|
||||||
ret <<= 1;
|
_delay_us(60);
|
||||||
|
|
||||||
|
PORTB |= (1 << PORTB5);
|
||||||
|
|
||||||
if (PINB & (1 << PINB3)) {
|
if (PINB & (1 << PINB3)) {
|
||||||
ret |= 1;
|
ret |= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PORTB &= ~(1 << PORTB5);
|
_delay_us(60);
|
||||||
|
|
||||||
_delay_us(140);
|
|
||||||
|
|
||||||
value <<= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_delay_us(270);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,10 +102,10 @@ static void spi_send_packet() {
|
||||||
(void)spi_send_byte( sum & 0x00ff);
|
(void)spi_send_byte( sum & 0x00ff);
|
||||||
(void)spi_send_byte((sum & 0xff00) >> 8);
|
(void)spi_send_byte((sum & 0xff00) >> 8);
|
||||||
|
|
||||||
_delay_us(1200);
|
|
||||||
|
|
||||||
device = spi_send_byte(0);
|
device = spi_send_byte(0);
|
||||||
status = spi_send_byte(0);
|
status = spi_send_byte(0);
|
||||||
|
|
||||||
|
_delay_us(270);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t checksum() {
|
static uint16_t checksum() {
|
||||||
|
@ -113,8 +124,7 @@ static uint16_t checksum() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
uint16_t sum = 0,
|
uint16_t i = 0,
|
||||||
i = 0,
|
|
||||||
b = 0,
|
b = 0,
|
||||||
c;
|
c;
|
||||||
|
|
||||||
|
@ -123,6 +133,16 @@ int main() {
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
uart_putchar('O', NULL);
|
||||||
|
|
||||||
|
c = uart_getchar(NULL);
|
||||||
|
|
||||||
|
if (c == 'K') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
c = uart_getchar(NULL);
|
c = uart_getchar(NULL);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue