- Main Page
- Related Pages
- Data Structures
- Files

# twi.h

Go to the documentation of this file.

    00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
    00017 /* Copyright (C) 2006-2008, Atmel Corporation All rights reserved.
    00018  *
    00019  * Redistribution and use in source and binary forms, with or without
    00020  * modification, are permitted provided that the following conditions are met:
    00021  *
    00022  * 1. Redistributions of source code must retain the above copyright notice,
    00023  * this list of conditions and the following disclaimer.
    00024  *
    00025  * 2. Redistributions in binary form must reproduce the above copyright notice,
    00026  * this list of conditions and the following disclaimer in the documentation
    00027  * and/or other materials provided with the distribution.
    00028  *
    00029  * 3. The name of ATMEL may not be used to endorse or promote products derived
    00030  * from this software without specific prior written permission.
    00031  *
    00032  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
    00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00034  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
    00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00042  */
    00043
    00044
    00045 #ifndef _TWI_H_
    00046 #define _TWI_H_
    00047
    00048 #include <avr32/io.h>
    00049
    00050 #include "compiler.h"
    00051
    00054
    00055 #define TWI_SUCCESS              0
    00056 #define TWI_INVALID_ARGUMENT    -1
    00057 #define TWI_ARBITRATION_LOST    -2
    00058 #define TWI_NO_CHIP_FOUND       -3
    00059 #define TWI_RECEIVE_OVERRUN     -4
    00060 #define TWI_RECEIVE_NACK        -5
    00061 #define TWI_SEND_OVERRUN        -6
    00062 #define TWI_SEND_NACK           -7
    00064
    00065
    00069 typedef struct
    00070 {
    00072   unsigned long pba_hz;
    00074   unsigned long speed;
    00076   char chip;
    00077 } twi_options_t;
    00078
    00082 typedef struct
    00083 {
    00085   char chip;
    00087   unsigned int addr;
    00089   int addr_length;
    00091   void *buffer;
    00093   unsigned int length;
    00094 } twi_package_t;
    00095
    00096 #ifndef AVR32_TWI_180_H_INCLUDED
    00097
    00101 typedef struct
    00102 {
    00104   void (*rx)(U8);
    00106   U8 (*tx)(void);
    00108   void (*stop)(void);
    00109 } twi_slave_fct_t;
    00110
    00111 #endif
    00112
    00113
    00121 extern int twi_master_init(volatile avr32_twi_t *twi, const twi_options_t *opt);
    00122
    00123 #ifndef AVR32_TWI_180_H_INCLUDED
    00124
    00133 extern int twi_slave_init(volatile avr32_twi_t *twi, const twi_options_t *opt, const twi_slave_fct_t *slave_fct);
    00134
    00135 #endif
    00136
    00144 extern int twi_probe(volatile avr32_twi_t *twi, char chip_addr);
    00145
    00152 extern void twi_disable_interrupt(volatile avr32_twi_t *twi);
    00153
    00162 extern int twi_master_read(volatile avr32_twi_t *twi, const twi_package_t *package);
    00163
    00172 extern int twi_master_write(volatile avr32_twi_t *twi, const twi_package_t *package);
    00173
    00174
    00175 #endif  // _TWI_H_