NIBObee Library 1.4
|
00001 /* BSD-License: 00002 00003 Copyright (c) 2007 by Nils Springob, nicai-systems, Germany 00004 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, 00008 are permitted provided that the following conditions are met: 00009 00010 * Redistributions of source code must retain the above copyright notice, 00011 this list of conditions and the following disclaimer. 00012 * Redistributions in binary form must reproduce the above copyright notice, 00013 this list of conditions and the following disclaimer in the documentation 00014 and/or other materials provided with the distribution. 00015 * Neither the name nicai-systems nor the names of its contributors may be 00016 used to endorse or promote products derived from this software without 00017 specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00023 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00024 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00025 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 00031 */ 00032 00039 #ifndef NIBOBEE_I2CMASTER_H_ 00040 #define NIBOBEE_I2CMASTER_H_ 00041 00042 #include <stdint.h> 00043 00044 #ifdef __cplusplus 00045 extern "C" { 00046 #endif 00047 00048 #define I2C_BUF_SIZE 0x25 00049 #define NIBO_I2C_TXRX 1 00050 #define I2C_TWBR_INIT 100 00051 00052 00053 #ifdef NIBO_I2C_TXRX 00054 00058 extern volatile uint8_t i2c_tx_size; 00059 00063 extern volatile uint8_t i2c_rx_size; 00064 00065 #else 00066 00070 extern volatile uint8_t i2c_size; 00071 00072 #endif 00073 00074 00078 extern uint8_t i2c_buf[I2C_BUF_SIZE]; 00079 00083 enum { 00084 I2C_BUSY, 00085 I2C_IDLE, 00086 I2C_SUCCESS, 00087 I2C_ERROR=0x10 00088 }; 00089 00093 void i2c_init(void); 00094 00098 uint8_t i2c_start_transmission(void); 00099 00103 uint8_t i2c_status(void); 00104 00105 extern volatile uint8_t i2c_last_TWSR; 00106 extern volatile uint8_t i2c_pos; 00107 00111 uint8_t i2c_wait_transmission(void); 00112 00113 #define I2C_TX(ADDR) ((ADDR)<<1) 00114 #define I2C_RX(ADDR) (((ADDR)<<1)+1) 00115 00116 #ifdef __cplusplus 00117 } // extern "C" 00118 #endif 00119 00120 #endif // NIBOBEE_I2CMASTER_H_