amiro-os / components / bus / spi / HWSPIDriver.cpp @ e2002d0e
History | View | Annotate | Download (1.079 KB)
1 |
#include <hal.h> |
---|---|
2 |
#include <amiro/bus/spi/HWSPIDriver.hpp> |
3 |
|
4 |
using namespace chibios_rt; |
5 |
|
6 |
namespace amiro {
|
7 |
|
8 |
HWSPIDriver:: |
9 |
HWSPIDriver(::SPIDriver *driver, const ::SPIConfig *config) :
|
10 |
driver(driver), |
11 |
config(config) { |
12 |
|
13 |
} |
14 |
|
15 |
HWSPIDriver:: |
16 |
~HWSPIDriver() { |
17 |
|
18 |
|
19 |
} |
20 |
|
21 |
void
|
22 |
HWSPIDriver:: |
23 |
exchange(uint8_t *readData, const uint8_t *writeData, size_t length) {
|
24 |
spiAcquireBus(this->driver);
|
25 |
spiStart(this->driver, this->config); |
26 |
spiSelect(this->driver);
|
27 |
spiExchange(this->driver, length, writeData, readData);
|
28 |
spiUnselect(this->driver);
|
29 |
spiReleaseBus(this->driver);
|
30 |
} |
31 |
|
32 |
void
|
33 |
HWSPIDriver:: |
34 |
read(uint8_t *data, size_t length) { |
35 |
spiAcquireBus(this->driver);
|
36 |
spiStart(this->driver, this->config); |
37 |
spiSelect(this->driver);
|
38 |
spiReceive(this->driver, length, data);
|
39 |
spiUnselect(this->driver);
|
40 |
spiReleaseBus(this->driver);
|
41 |
} |
42 |
|
43 |
void
|
44 |
HWSPIDriver:: |
45 |
write(const uint8_t *data, size_t length) {
|
46 |
spiAcquireBus(this->driver);
|
47 |
spiStart(this->driver, this->config); |
48 |
spiSelect(this->driver);
|
49 |
spiSend(this->driver, length, data);
|
50 |
spiUnselect(this->driver);
|
51 |
spiReleaseBus(this->driver);
|
52 |
} |
53 |
|
54 |
} /* amiro */
|