Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
I2CDevice.h
Go to the documentation of this file.
1 /*
2  * I2C.h Created on: 17 May 2014
3  * Copyright (c) 2014 Derek Molloy (www.derekmolloy.ie)
4  * Made available for the book "Exploring BeagleBone"
5  * See: www.exploringbeaglebone.com
6  * Licensed under the EUPL V.1.1
7  *
8  * This Software is provided to You under the terms of the European
9  * Union Public License (the "EUPL") version 1.1 as published by the
10  * European Union. Any use of this Software, other than as authorized
11  * under this License is strictly prohibited (to the extent such use
12  * is covered by a right of the copyright holder of this Software).
13  *
14  * This Software is provided under the License on an "AS IS" basis and
15  * without warranties of any kind concerning the Software, including
16  * without limitation merchantability, fitness for a particular purpose,
17  * absence of defects or errors, accuracy, and non-infringement of
18  * intellectual property rights other than copyright. This disclaimer
19  * of warranty is an essential part of the License and a condition for
20  * the grant of any rights to this Software.
21  *
22  * For more details, see http://www.derekmolloy.ie/
23  */
24 
25 #ifndef I2C_H_
26 #define I2C_H_
27 #include"BusDevice.h"
28 
29 #define BBB_I2C_0 "/dev/i2c-0"
30 #define BBB_I2C_1 "/dev/i2c-1"
31 
32 namespace exploringBB{
33 
38 class I2CDevice:public BusDevice{
39 
40 public:
41  I2CDevice(unsigned int bus, unsigned int device);
42  virtual int open();
43  virtual int write(unsigned char value);
44  virtual unsigned char readRegister(unsigned int registerAddress);
45  virtual unsigned char* readRegisters(unsigned int number, unsigned int fromAddress=0);
46  virtual int writeRegister(unsigned int registerAddress, unsigned char value);
47  virtual void debugDumpRegisters(unsigned int number = 0xff);
48  virtual void close();
49  virtual ~I2CDevice();
50 };
51 
52 } /* namespace exploringBB */
53 
54 #endif /* I2C_H_ */
virtual ~I2CDevice()
Definition: I2CDevice.cpp:168
virtual void debugDumpRegisters(unsigned int number=0xff)
Definition: I2CDevice.cpp:147
virtual void close()
Definition: I2CDevice.cpp:160
virtual unsigned char * readRegisters(unsigned int number, unsigned int fromAddress=0)
Definition: I2CDevice.cpp:129
virtual int write(unsigned char value)
Definition: I2CDevice.cpp:96
unsigned int bus
Definition: BusDevice.h:39
Generic I2C Device class that can be used to connect to any type of I2C device and read or write to i...
Definition: I2CDevice.h:38
virtual unsigned char readRegister(unsigned int registerAddress)
Definition: I2CDevice.cpp:111
I2CDevice(unsigned int bus, unsigned int device)
Definition: I2CDevice.cpp:47
Definition: BusDevice.cpp:27
This class is the parent of I2C and SPI devices, so that devices that use both SPI and I2C interfaces...
Definition: BusDevice.h:37
virtual int open()
Definition: I2CDevice.cpp:56
unsigned int device
Definition: BusDevice.h:40
virtual int writeRegister(unsigned int registerAddress, unsigned char value)
Definition: I2CDevice.cpp:79