EVShield  v1.3
EVShield Library Reference by mindsensors.com
SoftI2cMaster.h
1 /* Arduino SoftI2cMaster Library
2  * Copyright (C) 2009 by William Greiman
3  * Modified by: Teja Chiluvuri
4 
5  * This file is part of the Arduino SoftI2cMaster Library
6  *
7  * This Library is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This Library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with the Arduino SoftI2cMaster Library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 #ifndef SOFT_I2C_MASTER
22 #define SOFT_I2C_MASTER
23 #if defined(ARDUINO) && ARDUINO >= 100
24 #include "Arduino.h"
25 #else
26 #include "WProgram.h"
27 #endif
28 #include <stddef.h>
29 
30 // delay used to tweek signals
31 #define I2C_DELAY_USEC 30
32 
33 // R/W direction bit to OR with address for start or restart
34 #define I2C_READ 1
35 #define I2C_WRITE 0
36 
41 
42  bool initialized;
43 private:
44  uint8_t sclPin_;
45  uint8_t sdaPin_;
46  uint8_t deviceAddr;
47  uint8_t _error_code; // Error code
48 
49 public:
51  uint8_t* _so_buffer;
52 
54  uint8_t start(uint8_t addressRW);
55 
57  void stop(void);
58 
60  uint8_t restart(uint8_t addressRW);
61 
63  uint8_t write(uint8_t b);
64 
66  uint8_t read(uint8_t last);
67 
69  SoftI2cMaster(uint8_t devAddr);
70 
72  void initProtocol(uint8_t sclPin = (uint8_t)NULL, uint8_t sdaPin = (uint8_t)NULL);
73 
75  uint8_t* readRegisters(uint8_t startRegister, uint8_t bytes, uint8_t* buf = NULL);
76 
78  bool writeRegistersWithLocation(int bytes, uint8_t* buf);
79 
81  bool writeRegisters (uint8_t location, uint8_t bytes_to_write,
82  uint8_t* buffer = 0);
83 
85  bool writeByte (uint8_t location, uint8_t data);
86 
88  bool writeInteger(uint8_t location, uint16_t data);
89 
91  bool writeLong (uint8_t location, uint32_t data);
92 
94  char* readString(uint8_t startRegister, uint8_t bytes, uint8_t* buf = NULL, uint8_t len=0);
95 
97  uint8_t readByte (uint8_t location);
98 
100  int16_t readInteger (uint8_t location);
101 
103  uint32_t readLong (uint8_t location);
104 
106  char* getFirmwareVersion();
107 
109  char* getVendorID();
110 
112  char* getDeviceID();
113 
115  uint8_t getWriteErrorCode();
116 
117  bool checkAddress();
118 
122  bool setAddress(uint8_t address);
123 };
124 #endif //SOFT_I2C_MASTER
This class implements software i2c interface used by EVShield/NXShield on Arduino.
Definition: SoftI2cMaster.h:40
void stop(void)
Definition: SoftI2cMaster.cpp:119
char * readString(uint8_t startRegister, uint8_t bytes, uint8_t *buf=NULL, uint8_t len=0)
Definition: SoftI2cMaster.cpp:241
uint8_t restart(uint8_t addressRW)
Definition: SoftI2cMaster.cpp:95
bool writeByte(uint8_t location, uint8_t data)
Definition: SoftI2cMaster.cpp:211
int16_t readInteger(uint8_t location)
Definition: SoftI2cMaster.cpp:262
uint8_t write(uint8_t b)
Definition: SoftI2cMaster.cpp:128
char * getFirmwareVersion()
Definition: SoftI2cMaster.cpp:297
uint8_t readByte(uint8_t location)
Definition: SoftI2cMaster.cpp:253
char * getDeviceID()
Definition: SoftI2cMaster.cpp:307
uint8_t read(uint8_t last)
Definition: SoftI2cMaster.cpp:69
bool checkAddress()
Definition: SoftI2cMaster.cpp:314
bool writeRegisters(uint8_t location, uint8_t bytes_to_write, uint8_t *buffer=0)
Definition: SoftI2cMaster.cpp:197
bool setAddress(uint8_t address)
Definition: SoftI2cMaster.cpp:324
bool writeRegistersWithLocation(int bytes, uint8_t *buf)
Definition: SoftI2cMaster.cpp:186
uint32_t readLong(uint8_t location)
Definition: SoftI2cMaster.cpp:272
void initProtocol(uint8_t sclPin=(uint8_t) NULL, uint8_t sdaPin=(uint8_t) NULL)
Definition: SoftI2cMaster.cpp:34
uint8_t * readRegisters(uint8_t startRegister, uint8_t bytes, uint8_t *buf=NULL)
Definition: SoftI2cMaster.cpp:154
uint8_t * _so_buffer
Definition: SoftI2cMaster.h:51
uint8_t getWriteErrorCode()
Definition: SoftI2cMaster.cpp:290
bool writeInteger(uint8_t location, uint16_t data)
Definition: SoftI2cMaster.cpp:218
uint8_t start(uint8_t addressRW)
Definition: SoftI2cMaster.cpp:110
bool writeLong(uint8_t location, uint32_t data)
Definition: SoftI2cMaster.cpp:228
char * getVendorID()
Definition: SoftI2cMaster.cpp:302
SoftI2cMaster(uint8_t devAddr)
Definition: SoftI2cMaster.cpp:27