libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
spiMultislave.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_SPI_MULTISLAVE_H
3#define DSY_SPI_MULTISLAVE_H
4
5#include "daisy_core.h"
6#include "spi.h"
7#include "gpio.h"
8
9namespace daisy
10{
21{
22 public:
23 static constexpr size_t max_num_devices_ = 4;
42
45
48
50 const Config& GetConfig() const { return config_; }
51
60 size_t size,
61 uint32_t timeout = 100);
62
73 uint32_t timeout = 100);
74
85 size_t size,
86 uint32_t timeout = 100);
87
98 DmaTransmit(size_t device_index,
100 size_t size,
103 void* callback_context);
104
115 DmaReceive(size_t device_index,
116 uint8_t* buff,
117 size_t size,
120 void* callback_context);
121
133 DmaTransmitAndReceive(size_t device_index,
136 size_t size,
139 void* callback_context);
140
143
144 private:
146 {
147 return *this;
148 };
149
150 void EnableDevice(size_t device_index);
151 void DisableDevice(size_t device_index);
152 static void DmaStartCallback(void* context);
153 static void DmaEndCallback(void* context, SpiHandle::Result result);
154
155 Config config_;
156 SpiHandle spiHandle_;
157 GPIO nss_pins[max_num_devices_];
158
159 struct DmaTransfer
160 {
161 int8_t device_index;
164 void* callback_context;
165
166 void Invalidate() { device_index = -1; }
167 bool IsValid() const { return device_index >= 0; }
168 } current_dma_transfer_;
169};
170
172} // namespace daisy
173
174#endif // ifndef DSY_SPI_MULTISLAVE_H
General Purpose I/O control.
Definition gpio.h:22
Definition leddriver.h:33
Definition spiMultislave.h:21
MultiSlaveSpiHandle()
Definition spiMultislave.h:43
SpiHandle::Result BlockingReceive(size_t device_index, uint8_t *buff, uint16_t size, uint32_t timeout=100)
SpiHandle::Result Init(const Config &config)
static constexpr size_t max_num_devices_
Definition spiMultislave.h:23
SpiHandle::Result BlockingTransmit(size_t device_index, uint8_t *buff, size_t size, uint32_t timeout=100)
SpiHandle::Result BlockingTransmitAndReceive(size_t device_index, uint8_t *tx_buff, uint8_t *rx_buff, size_t size, uint32_t timeout=100)
const Config & GetConfig() const
Definition spiMultislave.h:50
MultiSlaveSpiHandle(const MultiSlaveSpiHandle &other)=delete
SpiHandle::Result DmaReceive(size_t device_index, uint8_t *buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
SpiHandle::Result DmaTransmit(size_t device_index, uint8_t *buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
SpiHandle::Result DmaTransmitAndReceive(size_t device_index, uint8_t *tx_buff, uint8_t *rx_buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
Definition spi.h:24
void(* EndCallbackFunctionPtr)(void *context, Result result)
Definition spi.h:137
void(* StartCallbackFunctionPtr)(void *context)
Definition spi.h:135
Result
Definition spi.h:116
Hardware defines and helpers for daisy field platform.
Definition index.h:2
Definition spiMultislave.h:25
SpiHandle::Config::Direction direction
Definition spiMultislave.h:35
SpiHandle::Config::ClockPhase clock_phase
Definition spiMultislave.h:38
size_t num_devices
Definition spiMultislave.h:40
Pin sclk
Definition spiMultislave.h:28
Pin mosi
Definition spiMultislave.h:30
struct daisy::MultiSlaveSpiHandle::Config::@19 pin_config
SpiHandle::Config::Peripheral periph
Definition spiMultislave.h:34
SpiHandle::Config::ClockPolarity clock_polarity
Definition spiMultislave.h:37
SpiHandle::Config::BaudPrescaler baud_prescaler
Definition spiMultislave.h:39
Pin nss[max_num_devices_]
Definition spiMultislave.h:31
Pin miso
Definition spiMultislave.h:29
unsigned long datasize
Definition spiMultislave.h:36
representation of hardware port/pin combination
Definition daisy_core.h:193
BaudPrescaler
Definition spi.h:72
ClockPolarity
Definition spi.h:53
Direction
Definition spi.h:45
ClockPhase
Definition spi.h:59
Peripheral
Definition spi.h:29