I2Cdev.h
Go to the documentation of this file.
00001 // I2Cdev library collection - Main I2C device class header file
00002 // Abstracts bit and byte I2C R/W functions into a convenient class
00003 // 6/9/2012 by Jeff Rowberg <jeff@rowberg.net>
00004 //
00005 // Changelog:
00006 //     2012-06-09 - fix major issue with reading > 32 bytes at a time with Arduino Wire
00007 //                - add compiler warnings when using outdated or IDE or limited I2Cdev implementation
00008 //     2011-11-01 - fix write*Bits mask calculation (thanks sasquatch @ Arduino forums)
00009 //     2011-10-03 - added automatic Arduino version detection for ease of use
00010 //     2011-10-02 - added Gene Knight's NBWire TwoWire class implementation with small modifications
00011 //     2011-08-31 - added support for Arduino 1.0 Wire library (methods are different from 0.x)
00012 //     2011-08-03 - added optional timeout parameter to read* methods to easily change from default
00013 //     2011-08-02 - added support for 16-bit registers
00014 //                - fixed incorrect Doxygen comments on some methods
00015 //                - added timeout value for read operations (thanks mem @ Arduino forums)
00016 //     2011-07-30 - changed read/write function structures to return success or byte counts
00017 //                - made all methods static for multi-device memory savings
00018 //     2011-07-28 - initial release
00019 
00020 /* ============================================
00021 I2Cdev device library code is placed under the MIT license
00022 Copyright (c) 2012 Jeff Rowberg
00023 
00024 Permission is hereby granted, free of charge, to any person obtaining a copy
00025 of this software and associated documentation files (the "Software"), to deal
00026 in the Software without restriction, including without limitation the rights
00027 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00028 copies of the Software, and to permit persons to whom the Software is
00029 furnished to do so, subject to the following conditions:
00030 
00031 The above copyright notice and this permission notice shall be included in
00032 all copies or substantial portions of the Software.
00033 
00034 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00035 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00036 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00037 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00038 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00039 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00040 THE SOFTWARE.
00041 ===============================================
00042 */
00043 
00044 #ifndef _I2CDEV_H_
00045 #define _I2CDEV_H_
00046 
00047 // -----------------------------------------------------------------------------
00048 // I2C interface implementation setting
00049 // -----------------------------------------------------------------------------
00050 #define I2CDEV_IMPLEMENTATION       I2CDEV_ARDUINO_WIRE
00051 
00052 // comment this out if you are using a non-optimal IDE/implementation setting
00053 // but want the compiler to shut up about it
00054 #define I2CDEV_IMPLEMENTATION_WARNINGS
00055 
00056 // -----------------------------------------------------------------------------
00057 // I2C interface implementation options
00058 // -----------------------------------------------------------------------------
00059 #define I2CDEV_ARDUINO_WIRE         1 // Wire object from Arduino
00060 
00061 // -----------------------------------------------------------------------------
00062 // Arduino-style "Serial.print" debug constant (uncomment to enable)
00063 // -----------------------------------------------------------------------------
00064 //#define I2CDEV_SERIAL_DEBUG
00065 
00066 #include "Arduino.h"
00067 #include <Wire.h>
00068 
00069 // 1000ms default read timeout (modify with "I2Cdev::readTimeout = [ms];")
00070 #define I2CDEV_DEFAULT_READ_TIMEOUT     1000
00071 
00072 class I2Cdev {
00073     public:
00074         I2Cdev();
00075         
00076         static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
00077         //static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
00078         static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
00079         //static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
00080         static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
00081         //static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
00082         static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
00083         //static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
00084 
00085         static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data);
00086         //static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
00087         static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data);
00088         //static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
00089         static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data);
00090         static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
00091         static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data);
00092         static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data);
00093 
00094         static uint16_t readTimeout;
00095 };
00096 
00097 #endif /* _I2CDEV_H_ */


segbot_firmware
Author(s): Jose Bigio, Jack O'Quin, Tim Eckel (NewPing library)
autogenerated on Fri Aug 28 2015 13:02:53