00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00023 /* ************************************************************************ 00024 00025 Copyright (c) 2006, Atmel Corporation All rights reserved. 00026 00027 Redistribution and use in source and binary forms, with or without 00028 modification, are permitted provided that the following conditions are met: 00029 00030 1. Redistributions of source code must retain the above copyright notice, 00031 this list of conditions and the 00032 following disclaimer. 00033 00034 2. Redistributions in binary form must reproduce the above copyright notice, 00035 this list of conditions and the following disclaimer in the documentation 00036 and/or other materials provided with the distribution. 00037 00038 3. The name of ATMEL may not be used to endorse or promote products 00039 derived from this software without specific prior written permission. 00040 00041 THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS 00042 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00043 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00044 PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY 00045 DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, 00046 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00047 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00048 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00049 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00050 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00051 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 00052 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00053 00054 POSSIBILITY OF SUCH DAMAGE. 00055 00056 ************************************************************************ */ 00057 00058 00059 #ifndef _TWI_H_ 00060 #define _TWI_H_ 00061 00062 #ifdef __GNUC__ 00063 #include <avr32/io.h> 00064 #elif __ICCAVR32__ 00065 #include <avr32/ioap7000.h> 00066 #else 00067 #error No known compiler used 00068 #endif 00069 00070 00071 #define TWI_SUCCESS 0 00072 #define TWI_INVALID_ARGUMENT -1 00073 #define TWI_ARBITRATION_LOST -2 00074 00075 #define TWI_NO_CHIP_FOUND -3 00076 #define TWI_RECEIVE_OVERRUN -4 00077 #define TWI_RECEIVE_NACK -5 00078 00079 #define TWI_SEND_OVERRUN -6 00080 #define TWI_SEND_NACK -7 00081 00082 #define TWI_TIMEOUT 5000 00083 00087 struct twi_options_t 00088 { 00090 unsigned long cpu_hz; 00091 00093 unsigned long speed; 00094 00096 unsigned char twi_addr; 00097 00098 }; 00099 00103 struct twi_package_t 00104 { 00105 00107 char chip; 00108 00110 unsigned int addr; 00111 00113 int addr_length; 00114 00116 char *buffer; 00117 00119 unsigned int length; 00120 }; 00121 00128 int twi_init(struct twi_options_t * opt); 00129 00130 00137 int twi_probe(char chip_addr); 00138 00139 00147 int twi_read(struct twi_package_t * package); 00148 00149 00150 /* 00151 * twi_write: - Write multiple bytes to an twi compatable device 00152 * 00153 * \param *package Package information and data 00154 * (see \ref twi_package_t) 00155 * \return 0 in case of success 00156 */ 00157 int twi_write(struct twi_package_t * package); 00158 00159 #endif
1.5.3