-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspibus.h
53 lines (48 loc) · 1.5 KB
/
spibus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef LIBESP_WIRING_H
#define LIBESP_WIRING_H
#include <etl/vector.h>
#include "error_type.h"
#include <driver/spi_master.h>
#include <freertos/semphr.h>
namespace libesp {
class SPIDevice;
// ESP32 SPI BUss
class SPIBus {
public:
typedef etl::vector<SPIDevice*,4> ATTACHED_DEVICE_TYPE;
typedef ATTACHED_DEVICE_TYPE::iterator ATTACHED_DEVICE_TYPE_IT;
public:
static ErrorType initializeBus(const spi_host_device_t &shd, const spi_bus_config_t &buscfg, int dmaChan);
static SPIBus *get(const spi_host_device_t &shd);
static ErrorType shutdown(const spi_host_device_t &shd);
public:
~SPIBus();
const spi_host_device_t &getSPIBusID() const {return SPIBusID;}
const spi_bus_config_t &getSPIBusConfig() const {return BusConfig;}
int getDMAChannel() const {return DMAChannel;}
/*
* create a master device for this SPI Bus
*/
SPIDevice *createMasterDevice(const spi_device_interface_config_t &devcfg);
SPIDevice *createMasterDevice(const spi_device_interface_config_t &devcfg, SemaphoreHandle_t spiSemaphore);
/*
* removes the device from this Bus, SPI device itself is not destroyed, device is not destoryed
*/
ErrorType removeDevice(SPIDevice *d);
/*
* remove all devices, destroy all devices, free spi bus
*/
ErrorType shutdown();
protected:
SPIBus(const spi_host_device_t &shd, const spi_bus_config_t &buscfg, int dma);
private:
//break copy ctor
SPIBus(const SPIBus &r);
private:
spi_host_device_t SPIBusID;
spi_bus_config_t BusConfig;
int DMAChannel;
ATTACHED_DEVICE_TYPE AttachedDevices;
};
}
#endif