distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
SpiMasterLowLevelDmaBased.hpp
Go to the documentation of this file.
1 
12 #ifndef SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_SPIMASTERLOWLEVELDMABASED_HPP_
13 #define SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_SPIMASTERLOWLEVELDMABASED_HPP_
14 
17 
19 
20 namespace distortos
21 {
22 
23 namespace chip
24 {
25 
26 class SpiPeripheral;
27 
37 {
38 public:
39 
50  constexpr SpiMasterLowLevelDmaBased(const SpiPeripheral& spiPeripheral, DmaChannel& rxDmaChannel,
51  const uint8_t rxDmaRequest, DmaChannel& txDmaChannel, const uint8_t txDmaRequest) :
52  spiPeripheral_{spiPeripheral},
53  rxDmaChannel_{rxDmaChannel},
54  txDmaChannel_{txDmaChannel},
57  rxDmaChannelFunctor_{*this},
58  txDmaChannelFunctor_{*this},
60  rxDummyData_{},
61  txDummyData_{},
62  rxDmaRequest_{rxDmaRequest},
63  txDmaRequest_{txDmaRequest},
64  started_{},
65  wordLength_{8}
66  {
67 
68  }
69 
76  ~SpiMasterLowLevelDmaBased() override;
77 
93  void configure(devices::SpiMode mode, uint32_t clockFrequency, uint8_t wordLength, bool lsbFirst,
94  uint32_t dummyData) override;
95 
105  int start() override;
106 
127  void startTransfer(devices::SpiMasterBase& spiMasterBase, const void* writeBuffer, void* readBuffer,
128  size_t size) override;
129 
139  void stop() override;
140 
141 private:
142 
145  {
146  public:
147 
154  constexpr explicit RxDmaChannelFunctor(SpiMasterLowLevelDmaBased& owner) :
155  owner_{owner}
156  {
157 
158  }
159 
166  void transferCompleteEvent() override;
167 
176  void transferErrorEvent(size_t transactionsLeft) override;
177 
178  private:
179 
182  };
183 
186  {
187  public:
188 
195  constexpr explicit TxDmaChannelFunctor(SpiMasterLowLevelDmaBased& owner) :
196  owner_{owner}
197  {
198 
199  }
200 
209  void transferErrorEvent(size_t transactionsLeft) override;
210 
211  private:
212 
215  };
216 
223  void eventHandler(bool success);
224 
229  bool isStarted() const
230  {
231  return started_;
232  }
233 
238  bool isTransferInProgress() const
239  {
240  return spiMasterBase_ != nullptr;
241  }
242 
245 
248 
251 
254 
257 
260 
263 
266 
268  uint16_t rxDummyData_;
269 
271  uint16_t txDummyData_;
272 
274  uint8_t rxDmaRequest_;
275 
277  uint8_t txDmaRequest_;
278 
280  bool started_;
281 
283  uint8_t wordLength_;
284 };
285 
286 } // namespace chip
287 
288 } // namespace distortos
289 
290 #endif // SOURCE_CHIP_STM32_PERIPHERALS_SPIV1_INCLUDE_DISTORTOS_CHIP_SPIMASTERLOWLEVELDMABASED_HPP_
Definition: SpiMasterBase.hpp:28
DmaChannel & rxDmaChannel_
reference to DMA channel used for reception
Definition: SpiMasterLowLevelDmaBased.hpp:247
TxDmaChannelFunctor class is a DmaChannelFunctorCommon for DMA channel used for transmission.
Definition: SpiMasterLowLevelDmaBased.hpp:185
~SpiMasterLowLevelDmaBased() override
SpiMasterLowLevelDmaBased's destructor.
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:33
RxDmaChannelFunctor class is a DmaChannelFunctor for DMA channel used for reception.
Definition: SpiMasterLowLevelDmaBased.hpp:144
Definition: DmaChannelFunctorCommon.hpp:29
SpiMasterLowLevel class header.
int start() override
Starts low-level SPI master driver.
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:49
SpiMasterLowLevelDmaBased & owner_
reference to owner SpiMasterLowLevelDmaBased object
Definition: SpiMasterLowLevelDmaBased.hpp:181
void eventHandler(bool success)
"Transfer complete" and "transfer error" event handler
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:132
void configure(devices::SpiMode mode, uint32_t clockFrequency, uint8_t wordLength, bool lsbFirst, uint32_t dummyData) override
Configures parameters of low-level SPI master driver.
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:38
Definition: DmaChannel.hpp:149
const SpiPeripheral & spiPeripheral_
reference to raw SPI peripheral
Definition: SpiMasterLowLevelDmaBased.hpp:244
SpiMode
Definition: SpiMode.hpp:29
Definition: SpiMasterLowLevel.hpp:33
bool isStarted() const
Definition: SpiMasterLowLevelDmaBased.hpp:229
DmaChannelHandle class header for STM32.
DmaChannel & txDmaChannel_
reference to DMA channel used for transmission
Definition: SpiMasterLowLevelDmaBased.hpp:250
void transferErrorEvent(size_t transactionsLeft) override
"Transfer error" event
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:161
SpiPeripheral class is a raw SPI peripheral for SPIv1 in STM32.
Definition: STM32-SPIv1-SpiPeripheral.hpp:24
constexpr SpiMasterLowLevelDmaBased(const SpiPeripheral &spiPeripheral, DmaChannel &rxDmaChannel, const uint8_t rxDmaRequest, DmaChannel &txDmaChannel, const uint8_t txDmaRequest)
SpiMasterLowLevelDmaBased's constructor.
Definition: SpiMasterLowLevelDmaBased.hpp:50
void transferCompleteEvent() override
"Transfer complete" event
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:147
Definition: DmaChannelHandle.hpp:29
Top-level namespace of distortos project.
Definition: buttons.hpp:33
DmaChannelHandle rxDmaChannelHandle_
handle of DMA channel used for reception
Definition: SpiMasterLowLevelDmaBased.hpp:253
RxDmaChannelFunctor rxDmaChannelFunctor_
functor for DMA channel used for reception
Definition: SpiMasterLowLevelDmaBased.hpp:259
void startTransfer(devices::SpiMasterBase &spiMasterBase, const void *writeBuffer, void *readBuffer, size_t size) override
Starts asynchronous transfer.
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:80
void stop() override
Stops low-level SPI master driver.
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:114
bool started_
true if driver is started, false otherwise
Definition: SpiMasterLowLevelDmaBased.hpp:280
TxDmaChannelFunctor txDmaChannelFunctor_
functor for DMA channel used for transmission
Definition: SpiMasterLowLevelDmaBased.hpp:262
SpiMasterLowLevelDmaBased & owner_
reference to owner SpiMasterLowLevelDmaBased object
Definition: SpiMasterLowLevelDmaBased.hpp:214
void transferErrorEvent(size_t transactionsLeft) override
"Transfer error" event
Definition: STM32-SPIv1-SpiMasterLowLevelDmaBased.cpp:152
DmaChannelHandle txDmaChannelHandle_
handle of DMA channel used for transmission
Definition: SpiMasterLowLevelDmaBased.hpp:256
uint8_t txDmaRequest_
request identifier for DMA channel used for transmission
Definition: SpiMasterLowLevelDmaBased.hpp:277
Definition: DmaChannelFunctor.hpp:29
DmaChannelFunctorCommon class header for DMA in STM32.
constexpr TxDmaChannelFunctor(SpiMasterLowLevelDmaBased &owner)
TxDmaChannelFunctor's constructor.
Definition: SpiMasterLowLevelDmaBased.hpp:195
constexpr RxDmaChannelFunctor(SpiMasterLowLevelDmaBased &owner)
RxDmaChannelFunctor's constructor.
Definition: SpiMasterLowLevelDmaBased.hpp:154
uint16_t txDummyData_
dummy data that will be sent if write buffer of transfer is nullptr
Definition: SpiMasterLowLevelDmaBased.hpp:271
uint16_t rxDummyData_
object used as reception DMA target if read buffer of transfer is nullptr
Definition: SpiMasterLowLevelDmaBased.hpp:268
devices::SpiMasterBase *volatile spiMasterBase_
pointer to SpiMasterBase object associated with this one
Definition: SpiMasterLowLevelDmaBased.hpp:265
bool isTransferInProgress() const
Definition: SpiMasterLowLevelDmaBased.hpp:238
uint8_t wordLength_
selected word length, bits, [4; 16] or [minSpiWordLength; maxSpiWordLength]
Definition: SpiMasterLowLevelDmaBased.hpp:283
Definition: SpiMasterLowLevelDmaBased.hpp:36
uint8_t rxDmaRequest_
request identifier for DMA channel used for reception
Definition: SpiMasterLowLevelDmaBased.hpp:274