distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
STM32-SPIv1-SpiPeripheral.hpp
Go to the documentation of this file.
1 
12 #ifndef SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_STM32_SPIV1_SPIPERIPHERAL_HPP_
13 #define SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_STM32_SPIV1_SPIPERIPHERAL_HPP_
14 
16 
17 namespace distortos
18 {
19 
20 namespace chip
21 {
22 
25 {
26 public:
27 
34  constexpr explicit SpiPeripheral(const uintptr_t spiBase) :
35  spiBase_{spiBase},
37  {
38 
39  }
40 
45  uintptr_t getDrAddress() const
46  {
47  return reinterpret_cast<uintptr_t>(&getSpi().DR);
48  }
49 
54  uint32_t getPeripheralFrequency() const
55  {
56  return peripheralFrequency_;
57  }
58 
63  uint32_t readCr1() const
64  {
65  return getSpi().CR1;
66  }
67 
72  uint32_t readCr2() const
73  {
74  return getSpi().CR2;
75  }
76 
81  uint32_t readDr() const
82  {
83  return getSpi().DR;
84  }
85 
90  uint32_t readSr() const
91  {
92  return getSpi().SR;
93  }
94 
101  void writeCr1(const uint32_t cr1) const
102  {
103  getSpi().CR1 = cr1;
104  }
105 
112  void writeCr2(const uint32_t cr2) const
113  {
114  getSpi().CR2 = cr2;
115  }
116 
123  void writeDr(const uint32_t dr) const
124  {
125  getSpi().DR = dr;
126  }
127 
134  void writeSr(const uint32_t sr) const
135  {
136  getSpi().SR = sr;
137  }
138 
139 private:
140 
145  SPI_TypeDef& getSpi() const
146  {
147  return *reinterpret_cast<SPI_TypeDef*>(spiBase_);
148  }
149 
151  uintptr_t spiBase_;
152 
155 };
156 
157 } // namespace chip
158 
159 } // namespace distortos
160 
161 #endif // SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_STM32_SPIV1_SPIPERIPHERAL_HPP_
uint32_t readCr1() const
Definition: STM32-SPIv1-SpiPeripheral.hpp:63
constexpr SpiPeripheral(const uintptr_t spiBase)
SpiPeripheral's constructor.
Definition: STM32-SPIv1-SpiPeripheral.hpp:34
void writeCr1(const uint32_t cr1) const
Writes value to CR1 register.
Definition: STM32-SPIv1-SpiPeripheral.hpp:101
void writeDr(const uint32_t dr) const
Writes value to DR register.
Definition: STM32-SPIv1-SpiPeripheral.hpp:123
SPI_TypeDef & getSpi() const
Definition: STM32-SPIv1-SpiPeripheral.hpp:145
constexpr uint32_t getBusFrequency(const uintptr_t peripheralBase)
Returns frequency of the bus to which given peripheral is connected.
Definition: getBusFrequency.hpp:32
uint32_t peripheralFrequency_
peripheral clock frequency, Hz
Definition: STM32-SPIv1-SpiPeripheral.hpp:154
uint32_t readSr() const
Definition: STM32-SPIv1-SpiPeripheral.hpp:90
uint32_t getPeripheralFrequency() const
Definition: STM32-SPIv1-SpiPeripheral.hpp:54
SpiPeripheral class is a raw SPI peripheral for SPIv1 in STM32.
Definition: STM32-SPIv1-SpiPeripheral.hpp:24
void writeSr(const uint32_t sr) const
Writes value to SR register.
Definition: STM32-SPIv1-SpiPeripheral.hpp:134
uintptr_t getDrAddress() const
Definition: STM32-SPIv1-SpiPeripheral.hpp:45
Top-level namespace of distortos project.
Definition: buttons.hpp:33
uint32_t readCr2() const
Definition: STM32-SPIv1-SpiPeripheral.hpp:72
uintptr_t spiBase_
base address of SPI peripheral
Definition: STM32-SPIv1-SpiPeripheral.hpp:151
void writeCr2(const uint32_t cr2) const
Writes value to CR2 register.
Definition: STM32-SPIv1-SpiPeripheral.hpp:112
uint32_t readDr() const
Definition: STM32-SPIv1-SpiPeripheral.hpp:81
getBusFrequency() definition for STM32F4