-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPIClassSercom.h
More file actions
35 lines (28 loc) · 943 Bytes
/
Copy pathSPIClassSercom.h
File metadata and controls
35 lines (28 loc) · 943 Bytes
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
#pragma once
#include <wiring_private.h>
struct PinAssignment {
constexpr PinAssignment(uint32_t pin, EPioType type) :
pin(pin), type(type) {}
const uint32_t pin;
const EPioType type;
};
// Extension of the normal SPI class that correctly sets the pin perhipheral type, necessary when reconfiguring SERCOMs.
class SPIClassSercom final : public SPIClass {
public:
SPIClassSercom(SERCOM* sercom, PinAssignment miso, PinAssignment sck, PinAssignment mosi, SercomSpiTXPad txPad, SercomRXPad rxPad) :
SPIClass(sercom, miso.pin, sck.pin, mosi.pin, txPad, rxPad),
miso(miso),
sck(sck),
mosi(mosi)
{}
void begin() {
SPIClass::begin();
pinPeripheral(miso.pin, miso.type);
pinPeripheral(sck.pin, sck.type);
pinPeripheral(mosi.pin, mosi.type);
}
private:
const PinAssignment miso;
const PinAssignment sck;
const PinAssignment mosi;
};