SFBHWI2C.h

Go to the documentation of this file.
00001 /*                                              -*- mode:C++; fill-column:100 -*-
00002   SFBHWI2C.h Low-level interface for accessing I2C communications on the LPC23xx.
00003   Copyright (C) 2010 Sam Bayless.  All rights reserved.
00004   
00005   Modifications for inclusion in SFB core
00006   Copyright (C) 2010 The Regents of the University of New Mexico.  All rights reserved.
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00021   USA
00022 */
00023 #ifndef SFBHWI2C_H
00024 #define SFBHWI2C_H
00025 
00035 #include "SFBTypes.h"
00036 
00038 enum I2CStatusCodes {
00039   I2C_MODE_UNINITIALIZED = -4,   
00040   I2C_MODE_ARBITRATION_ERROR = -3, 
00041   I2C_MODE_NO_ACK = -2,          
00042   I2C_MODE_ERROR = -1,           
00043   I2C_MODE_DONE = 0,             
00044   I2C_MODE_RECEIVE = 1,          
00045   I2C_MODE_TRANSMIT = 2,         
00046   I2C_MODE_TRANSCEIVE = 3        
00047 };
00048 
00050 enum I2CInterfaceCodes {
00051   I2C_1 = 1,                     
00052   I2C_2 = 2                      
00053 };
00054 
00059 enum I2CPinSelectCode {
00060   I2C1_PINS_WEST_TX_RX = 0,     
00061   I2C1_PINS_SOUTH_D3_D2 = 1,    
00062   I2C2_PINS_EAST_TX_RX = 0      
00063 };
00064 
00072 typedef u32 (*I2CByteSource)(int offset); 
00073 
00080 typedef bool (*I2CByteSink)(u8 byte);   
00081 
00087 class SFBHWI2C {
00088 
00089 public:
00090 
00097   SFBHWI2C(u32 interface ) ;
00098 
00110   void setByteSource(I2CByteSource function) {
00111     if (!function && byteSource) msgLen = 0;  // Require a new transmit when source cleared
00112     byteSource = function;
00113   }
00114 
00127   void setByteSink(I2CByteSink function) {
00128     if (!function && byteSink) msgLen = 0;   // Require a new receive when sink cleared
00129     byteSink = function;
00130   }
00131 
00141   void transmit(u8 address, u32 length, u8 *message);
00142 
00152   void receive(u8 address, u32 length, u8 *message);
00153 
00175   void transceive(u8 address, u32 xmtLength, u8 *xmtData, u32 rcvLength, u8 *rcvData);
00176 
00186   void init(u32 pins, u32 bitRate);
00187 
00196   s8 status();
00197 
00207   void setBitRate(u32 bitRate);
00208 
00213   u32 count();
00214 
00215 private:
00216   void i2cInterrupt() ;         /* The interrupt routine */
00217   friend void I2C1Handler();    
00218   friend void I2C2Handler();    
00219   void masterReceive();
00220   void masterTransmit();
00221 
00222   I2CByteSource byteSource; 
00223 
00224   I2CByteSink byteSink;     
00225 
00226   u32 dataCount;  
00227 
00228   u32 msgLen;     
00229 
00230   u8* msg;        
00231   
00232   u32 xcvLen;     
00233 
00234   u8* xcvMsg;     
00235 
00236   const u8 i2c;   
00237 
00238   s8 mode;        
00239 
00240   u8 addr;        
00241 
00242 };
00243 
00244 #endif  /*SFBHWI2C_H */
00245 

Generated on Fri Apr 22 06:54:11 2011 for SFB by doxygen 1.5.9