Home | History | Annotate | Download | only in Wire
      1 /*
      2   TwoWire.h - TWI/I2C library for Arduino & Wiring
      3   Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
      4 
      5   This library is free software; you can redistribute it and/or
      6   modify it under the terms of the GNU Lesser General Public
      7   License as published by the Free Software Foundation; either
      8   version 2.1 of the License, or (at your option) any later version.
      9 
     10   This library is distributed in the hope that it will be useful,
     11   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13   Lesser General Public License for more details.
     14 
     15   You should have received a copy of the GNU Lesser General Public
     16   License along with this library; if not, write to the Free Software
     17   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 */
     19 
     20 #ifndef TwoWire_h
     21 #define TwoWire_h
     22 
     23 #include <inttypes.h>
     24 
     25 #define BUFFER_LENGTH 32
     26 
     27 class TwoWire
     28 {
     29   private:
     30     static uint8_t rxBuffer[];
     31     static uint8_t rxBufferIndex;
     32     static uint8_t rxBufferLength;
     33 
     34     static uint8_t txAddress;
     35     static uint8_t txBuffer[];
     36     static uint8_t txBufferIndex;
     37     static uint8_t txBufferLength;
     38 
     39     static uint8_t transmitting;
     40     static void (*user_onRequest)(void);
     41     static void (*user_onReceive)(int);
     42     static void onRequestService(void);
     43     static void onReceiveService(uint8_t*, int);
     44   public:
     45     TwoWire();
     46     void begin();
     47     void begin(uint8_t);
     48     void begin(int);
     49     void beginTransmission(uint8_t);
     50     void beginTransmission(int);
     51     uint8_t endTransmission(void);
     52     uint8_t requestFrom(uint8_t, uint8_t);
     53     uint8_t requestFrom(int, int);
     54     void send(uint8_t);
     55     void send(uint8_t*, uint8_t);
     56     void send(int);
     57     void send(char*);
     58     uint8_t available(void);
     59     uint8_t receive(void);
     60     void onReceive( void (*)(int) );
     61     void onRequest( void (*)(void) );
     62 };
     63 
     64 extern TwoWire Wire;
     65 
     66 #endif
     67 
     68