Subversion Repositories idreammicro-avr

Rev

Blame | Last modification | View Log | Download | RSS feed

/**************************************************************************//**
 * \brief SPI library
 * \author Copyright (C) 2011  Julien Le Sech - www.idreammicro.com
 * \version 1.0
 * \date 20110315
 *
 * This file is part of the iDreamMicro library.
 *
 * This library is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * This library 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 Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 ******************************************************************************/


/**************************************************************************//**
 * \headerfile spi.h
 ******************************************************************************/

 
#ifndef H__IDREAMMICRO__SPI__H
#define H__IDREAMMICRO__SPI__H

#ifdef _cplusplus
extern "C"{
#endif

/******************************************************************************
 * Header file inclusions.
 ******************************************************************************/


#include <stdint.h>

/******************************************************************************
 * Public types.
 ******************************************************************************/


/**************************************************************************//**
 *
 ******************************************************************************/

typedef enum spi__clock_rates
{
    SPI__CLOCK_RATE__FOSC_OVER_2,
    SPI__CLOCK_RATE__FOSC_OVER_4,
    SPI__CLOCK_RATE__FOSC_OVER_8,
    SPI__CLOCK_RATE__FOSC_OVER_16,
    SPI__CLOCK_RATE__FOSC_OVER_32,
    SPI__CLOCK_RATE__FOSC_OVER_64,
    SPI__CLOCK_RATE__FOSC_OVER_128
} spi__clock_rate_t;

/**************************************************************************//**
 *
 ******************************************************************************/

typedef enum spi__data_modes
{
    SPI__DATA_MODE_0,
    SPI__DATA_MODE_1,
    SPI__DATA_MODE_2,
    SPI__DATA_MODE_3
} spi__data_mode_t;

/**************************************************************************//**
 *
 ******************************************************************************/

typedef enum spi__data_orders
{
    SPI__DATA_ORDER__MSB_FIRST,
    SPI__DATA_ORDER__LSB_FIRST
} spi__data_order_t;

/******************************************************************************
 * Public function prototypes.
 ******************************************************************************/


/**************************************************************************//**
 * \fn void spi_master__initialize(void)
 *
 * \brief Initialize SPI in master mode.
 ******************************************************************************/

void
spi_master__initialize
(
    void
);

/**************************************************************************//**
 * \fn void spi_master__transmit(uint8_t data)
 *
 * \brief Transmit data.
 *
 * \param   data    Data to transmit.
 ******************************************************************************/

void
spi_master__transmit
(
    uint8_t data
);

/**************************************************************************//**
 * \fn void spi_slave__initialize(void)
 *
 * \brief Initialize SPI in slave mode.
 ******************************************************************************/

void
spi_slave__initialize
(
    void
);

/**************************************************************************//**
 * \fn uint8_t spi_slave__receive(void)
 *
 * \brief Receive data.
 *
 * \return Received data.
 ******************************************************************************/

uint8_t
spi_slave__receive
(
    void
);

/**************************************************************************//**
 * \fn void spi__set_clock_rate(spi__clock_rate_t clock_rate)
 *
 * \brief Set clock rate.
 *
 * \param[in]   clock_rate  Clock rate to set.
 ******************************************************************************/

void
spi__set_clock_rate
(
    spi__clock_rate_t   clock_rate
);

/**************************************************************************//**
 * \fn void spi__set_data_mode(spi__data_mode_t mode)
 *
 * \brief Set SPI data mode.
 *
 * \param[in]   mode    Data mode to set.
 ******************************************************************************/

void
spi__set_data_mode
(
    spi__data_mode_t    data_mode
);

/**************************************************************************//**
 * \fn void spi__set_data_order(spi__data_order_t data_order)
 *
 * \brief Set SPI data order.
 *
 * \param[in]   data_order  Data order to set.
 ******************************************************************************/

void
spi__set_data_order
(
    spi__data_order_t   data_order
);

#ifdef _cplusplus
}
#endif

#endif /* H__IDREAMMICRO__SPI__H */