Mbed for ESIMEos / Mbed 2 deprecated FRDM-KL46Z_LCD_I2C_demo

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Wire.h Source File

Wire.h

00001 /*
00002   TwoWire.h - TWI/I2C library for Arduino & Wiring
00003   Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
00004   This library is free software; you can redistribute it and/or
00005   modify it under the terms of the GNU Lesser General Public
00006   License as published by the Free Software Foundation; either
00007   version 2.1 of the License, or (at your option) any later version.
00008   This library is distributed in the hope that it will be useful,
00009   but WITHOUT ANY WARRANTY; without even the implied warranty of
00010   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011   Lesser General Public License for more details.
00012   You should have received a copy of the GNU Lesser General Public
00013   License along with this library; if not, write to the Free Software
00014   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00015   Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
00016 */
00017 
00018 #ifndef TwoWire_h
00019 #define TwoWire_h
00020 
00021 #if defined(__arm__) && defined(TEENSYDUINO)
00022 #include "WireKinetis.h"
00023 
00024 #elif defined(__AVR__)
00025 
00026 #include <inttypes.h>
00027 #include "Arduino.h"
00028 
00029 #define BUFFER_LENGTH 32
00030 #define WIRE_HAS_END 1
00031 
00032 class TwoWire : public Stream
00033 {
00034   private:
00035     static uint8_t rxBuffer[];
00036     static uint8_t rxBufferIndex;
00037     static uint8_t rxBufferLength;
00038 
00039     static uint8_t txAddress;
00040     static uint8_t txBuffer[];
00041     static uint8_t txBufferIndex;
00042     static uint8_t txBufferLength;
00043 
00044     static uint8_t transmitting;
00045     static void onRequestService(void);
00046     static void onReceiveService(uint8_t*, int);
00047     static void (*user_onRequest)(void);
00048     static void (*user_onReceive)(int);
00049     static void sda_rising_isr(void);
00050   public:
00051     TwoWire();
00052     void begin();
00053     void begin(uint8_t);
00054     void begin(int);
00055     void end();
00056     void setClock(uint32_t);
00057     void setSDA(uint8_t);
00058     void setSCL(uint8_t);
00059     void beginTransmission(uint8_t);
00060     void beginTransmission(int);
00061     uint8_t endTransmission(void);
00062     uint8_t endTransmission(uint8_t);
00063     uint8_t requestFrom(uint8_t, uint8_t);
00064     uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
00065     uint8_t requestFrom(int, int);
00066     uint8_t requestFrom(int, int, int);
00067     virtual size_t write(uint8_t);
00068     virtual size_t write(const uint8_t *, size_t);
00069     virtual int available(void);
00070     virtual int read(void);
00071     virtual int peek(void);
00072     virtual void flush(void);
00073     void onReceive( void (*)(int) );
00074     void onRequest( void (*)(void) );
00075   
00076 #ifdef CORE_TEENSY
00077     // added by Teensyduino installer, for compatibility
00078     // with pre-1.0 sketches and libraries
00079     void send(uint8_t b)               { write(b); }
00080     void send(uint8_t *s, uint8_t n)   { write(s, n); }
00081     void send(int n)                   { write((uint8_t)n); }
00082     void send(char *s)                 { write(s); }
00083     uint8_t receive(void) {
00084         int c = read();
00085         if (c < 0) return 0;
00086         return c;
00087     }
00088 #endif
00089     inline size_t write(unsigned long n) { return write((uint8_t)n); }
00090     inline size_t write(long n) { return write((uint8_t)n); }
00091     inline size_t write(unsigned int n) { return write((uint8_t)n); }
00092     inline size_t write(int n) { return write((uint8_t)n); }
00093     using Print::write;
00094 };
00095 
00096 extern TwoWire Wire;
00097 
00098 #endif
00099 #endif