
#include "spi.h"

// RFM69 chip select (SS1/PE2, active low)
void spi_rfm69_select(bool state)
{
    SET_PIN_OUT(DDRE, DDE2);
    SET_PIN_TO(PORTE, PE2, !state);
}

uint8_t spi_write(uint8_t data)
{
    SPDR1 = data; // Load data into the SPI data register
    while (!(SPSR1 & (1 << SPIF1))) { }; // Wait for transmission to complete
    return SPDR1; // Return received data
}

uint8_t spi_read(void) { return spi_write(0xFF); }
