Subversion Repositories idreammicro-avr

Rev

Rev 17 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/**************************************************************************//**
 * \brief TWI library
 * \author Copyright (C) 2011  Julien Le Sech - www.idreammicro.com
 * \version 1.0
 * \date 20090501
 *
 * 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 twi.h
 ******************************************************************************/


#ifndef H__IDREAMMICRO__TWI__H
#define H__IDREAMMICRO__TWI__H

#ifdef _cplusplus
extern "C"{
#endif

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


#include <stdint.h>

/******************************************************************************
 * Public type definitions.
 ******************************************************************************/


/**************************************************************************//**
 * \typedef twi__error_t
 *
 * \brief TWI errors.
 ******************************************************************************/

// TODO: more errors.
typedef enum twi__errors
{
    TWI__ERROR__NONE,
    TWI__ERROR__ERROR,
    TWI__ERROR__INVALID
} twi__error_t;

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


/**************************************************************************//**
 * \fn void twi__initialize(uint32_t frequency)
 *
 * \brief Initialize TWI.
 *
 * \param   frequency   TWI frequency (up to 400 kHz).
 ******************************************************************************/

void
twi__initialize
(
    uint32_t    frequency
);

/**************************************************************************//**
 * \fn twi__error_t twi__start(void)
 *
 * \brief
 ******************************************************************************/

twi__error_t
twi__start
(
    void
);

/**************************************************************************//**
 * \fn twi__error_t twi__repeat_start(void)
 *
 * \brief
 ******************************************************************************/

twi__error_t
twi__repeat_start
(
    void
);

/**************************************************************************//**
 * \fn twi__error_t twi__send_slar(uint8_t sla)
 *
 * \brief
 *
 * \param   sla
 ******************************************************************************/

twi__error_t
twi__send_slar
(
    uint8_t sla
);

/**************************************************************************//**
 * \fn twi__error_t twi__send_slaw(uint8_t sla)
 *
 * \brief
 *
 * \param   sla
 ******************************************************************************/

twi__error_t
twi__send_slaw
(
    uint8_t sla
);

/**************************************************************************//**
 * \fn twi__error_t twi__send_data(uint8_t data)
 *
 * \brief
 *
 * \param   data    Data to send.
 ******************************************************************************/

twi__error_t
twi__send_data
(
    uint8_t data
);

/**************************************************************************//**
 * \fn twi__error_t twi__receive_data_ack(uint8_t* p_data)
 *
 * \brief
 *
 * \param   p_data
 ******************************************************************************/

twi__error_t
twi__receive_data_ack
(
    uint8_t* p_data
);

/**************************************************************************//**
 * \fn twi__error_t twi__receive_data_nack(uint8_t* p_data)
 *
 * \brief
 *
 * \param   p_data
 ******************************************************************************/

twi__error_t
twi__receive_data_nack
(
    uint8_t* p_data
);

/**************************************************************************//**
 * \fn void twi__stop(void)
 *
 * \brief
 ******************************************************************************/

void
twi__stop
(
    void
);

#ifdef _cplusplus
}
#endif

#endif /* H__IDREAMMICRO__TWI__H */