embkernel
 All Classes Functions Variables Typedefs Groups Pages
DrvSpi.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_SPI_HPP_
7 #define DRV_SPI_HPP_
8 
9 #include "DrvTypes.hpp"
10 #include "DrvGpio.hpp"
11 #include "RtosSemaphore.hpp"
12 
13 class DrvSpi {
14  friend class RtosInterrupt;
15 
16 private:
17  SPI_TypeDef* mSpi;
18  DrvGpio* mCs;
19  RtosSemaphore mSema;
20  static DrvSpi* sInstances[];
21  uint16_t mDr;
22  inline void onInterrupt();
23 public:
24  DrvSpi();
25 
26  void init(DrvTypes::SPI port, DrvGpio* cs, int baudrate, bool invertPhase = false, bool invertPolarity = false);
27  void setBaudrate(int baudrate);
28  void select();
29  void deselect();
30  uint8_t readWrite(const uint8_t value);
31  void readWrite(const uint8_t* src, int srcLen, uint8_t* dst, int dstLen);
32 
33 };
34 
35 #endif /* DRV_SPI_HPP_ */