embkernel
 All Classes Functions Variables Typedefs Groups Pages
DrvI2cMaster.hpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #ifndef DRV_I2C_MASTER_HPP_
7 #define DRV_I2C_MASTER_HPP_
8 
9 #include "DrvCfg.hpp"
10 #include "DrvTypes.hpp"
11 #include "RtosSemaphore.hpp"
12 #include "RtosInterrupt.hpp"
13 
14 class DrvI2cMaster {
15  friend class RtosInterrupt;
16 private:
17  static DrvI2cMaster* sInstances[];
18  RtosSemaphore mSema;
19  I2C_TypeDef* mI2c;
20  uint16_t mSlaveAddr;
21  const uint8_t* mSrc;
22  int mSrcLen;
23  uint8_t* mDst;
24  int mDstLen;
25  bool mResult;
26  void onEvent();
27  void onError();
28 public:
29  DrvI2cMaster();
30  void init(DrvTypes::I2C port);
31  void setSlaveAddr(uint16_t slaveAddr);
32  bool readWrite(const uint8_t* src, int srcLen, uint8_t* dst, int dstLen);
33 };
34 
35 #endif /* DRV_I2C_MASTER_HPP_ */