i2c2_device.hpp
Go to the documentation of this file.
1 /*
2  * SocialLedge.com - Copyright (C) 2013
3  *
4  * This file is part of free software framework for embedded processors.
5  * You can use it and/or distribute it as long as this copyright header
6  * remains unmodified. The code is free for personal use and requires
7  * permission to use in a commercial product.
8  *
9  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
10  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
12  * I SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
13  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
14  *
15  * You can reach the author of this software at :
16  * p r e e t . w i k i @ g m a i l . c o m
17  */
18 
23 #ifndef i2c2_device_HPP_
24 #define i2c2_device_HPP_
25 
26 #include "i2c2.hpp"
27 
28 
29 
40 {
41 protected:
43  i2c2_device(uint8_t addr) : mI2C(I2C2::getInstance()), mOurAddr(addr)
44  {
45  }
46 
48  inline uint8_t readReg(unsigned char reg)
49  {
50  return mI2C.readReg(mOurAddr, reg);
51  }
52 
54  inline void writeReg(unsigned char reg, unsigned char data)
55  {
56  mI2C.writeReg(mOurAddr, reg, data);
57  }
58 
60  inline bool checkDeviceResponse()
61  {
62  return mI2C.checkDeviceResponse(mOurAddr);
63  }
64 
68  uint16_t get16BitRegister(unsigned char reg)
69  {
70  uint8_t buff[2] = {0};
71  mI2C.readRegisters(mOurAddr, reg, &buff[0], sizeof(buff));
72 
73  const uint16_t MSB = buff[0];
74  const uint16_t LSB = buff[1];
75  return ((MSB << 8) | (LSB & 0xFF));
76  }
77 
78 private:
79  I2C_Base& mI2C;
80  const uint8_t mOurAddr;
81 
82  // Do not use this constructor
83  i2c2_device();
84 };
85 
86 #endif /* i2c2_device_HPP_ */
Definition: i2c2_device.hpp:39
uint16_t get16BitRegister(unsigned char reg)
Definition: i2c2_device.hpp:68
uint8_t readReg(uint8_t deviceAddress, uint8_t registerAddress)
Definition: i2c_base.cpp:48
Definition: i2c2.hpp:40
Definition: i2c_base.hpp:68
bool readRegisters(uint8_t deviceAddress, uint8_t firstReg, uint8_t *pData, uint32_t transferSize)
Definition: i2c_base.cpp:55
bool checkDeviceResponse()
Definition: i2c2_device.hpp:60
i2c2_device(uint8_t addr)
Constructor of this base class that takes addr as a parameter.
Definition: i2c2_device.hpp:43
bool writeReg(uint8_t deviceAddress, uint8_t registerAddress, uint8_t value)
Definition: i2c_base.cpp:61
bool checkDeviceResponse(uint8_t deviceAddress)
Definition: i2c_base.cpp:111
uint8_t readReg(unsigned char reg)
Definition: i2c2_device.hpp:48
void writeReg(unsigned char reg, unsigned char data)
Writes a register of this device.
Definition: i2c2_device.hpp:54
I2C2 Interrupt driven IO driver.