// ----------------------------------------------------------------------------------------
//
//  avr/device/spi.h
//    
//  Bob Cook Development, Robotics Library
//  http://www.bobcookdev.com/rl/
//    
//  This file provides the interface for the SPI library.
//
//  Copyright (C) 2007 Bob Cook
//
//      This program is free software; you can redistribute it and/or modify it
//      under the terms of the GNU General Public License as published by the
//      Free Software Foundation; either version 2 of the License, or (at your
//      option) any later version.
//    
//      This program is distributed in the hope that it will be useful, but 
//      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
//      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
//      for more details.
//    
//      You should have received a copy of the GNU General Public License along
//      with this program; if not, write to the Free Software Foundation, Inc., 
//      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
// ----------------------------------------------------------------------------------------


#if !defined( BCDRL_AVR_DEVICE_SPI_H )
#define BCDRL_AVR_DEVICE_SPI_H


#include <stdint.h>


// ----------------------------------------------------------------------------------------
//  definitions from "project_defs.h"
//
//  enable the SPI support with one (and only one) of:
//  
//      + PRJ_SPI_ENABLE_MASTER
//      + PRJ_SPI_ENABLE_SLAVE
//
//  specify the bus mode using one (and only one) of:
//
//      + PRJ_SPI_BUS_MODE_0
//      + PRJ_SPI_BUS_MODE_1
//      + PRJ_SPI_BUS_MODE_2
//      + PRJ_SPI_BUS_MODE_3
//
//  specify the data direction using one (and only one) of:
//
//      + PRJ_SPI_DATA_DIRECTION_MSB
//      + PRJ_SPI_DATA_DIRECTION_LSB
//
//  specify the clock rate using one (and only one) of:
//
//      + PRJ_SPI_CLOCK_FACTOR_DIV_2
//      + PRJ_SPI_CLOCK_FACTOR_DIV_4
//      + PRJ_SPI_CLOCK_FACTOR_DIV_8
//      + PRJ_SPI_CLOCK_FACTOR_DIV_16
//      + PRJ_SPI_CLOCK_FACTOR_DIV_32
//      + PRJ_SPI_CLOCK_FACTOR_DIV_64
//      + PRJ_SPI_CLOCK_FACTOR_DIV_128
//
//  optionally define:
//
//      + PRJ_SPI_USE_SLAVE_SELECT
//
// ----------------------------------------------------------------------------------------


// ----------------------------------------------------------------------------------------
//  spi_init
//
//      Initialize and configure the Serial Peripheral Interface hardware according to
//      the project_defs.h specification.
//

void spi_init();


// ----------------------------------------------------------------------------------------
//  spi_stop
//
//      Disable the SPI h/w.
//

void spi_stop();

    
// ----------------------------------------------------------------------------------------
//  spi_read
//
//      Read a byte from the SPI h/w register. Blocks until a byte is available.
//

uint8_t spi_read();


// ----------------------------------------------------------------------------------------
//  spi_write
//
//      Write a byte to the SPI h/w register. Blocks until the write is complete.
//

void spi_write( uint8_t data );


#endif  // #if !defined( BCDRL_AVR_DEVICE_SPI_H )
// ----------------------------------------------------------------------------------------
//  end of spi.h
// ----------------------------------------------------------------------------------------

