Arduino gameboy cart reader software, using https://github.com/insidegadgets/GBCartRead
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
649 B
32 lines
649 B
#include "spi.h"
|
|
|
|
#include <stdint.h>
|
|
#include <avr/io.h>
|
|
|
|
#include "utils.h"
|
|
#include "pins.h"
|
|
|
|
void spi_init(const enum spi_divider divider)
|
|
{
|
|
DDRB |= pin(PIN_SPI_SS) | pin(PIN_SPI_MOSI) | pin(PIN_SPI_SCK); // Outputs
|
|
DDRB &= ~pin(PIN_SPI_MISO); // Inputs
|
|
PORTB |= pin(PIN_SPI_MISO); // Pull it up
|
|
|
|
// Configure SPI as master
|
|
SPCR = _BV(SPE) | _BV(MSTR) | (divider & 3);
|
|
SPSR = (divider & 4) >> 2;
|
|
}
|
|
|
|
void spi_off(void)
|
|
{
|
|
SPCR = 0;
|
|
SPSR = 1;
|
|
}
|
|
|
|
uint8_t spi_transfer(const uint8_t data)
|
|
{
|
|
SPDR = data;
|
|
__asm__ volatile ("nop");
|
|
while (!(SPSR & _BV(SPIF))) __asm__ volatile ("nop");
|
|
return SPDR;
|
|
}
|
|
|