summaryrefslogtreecommitdiff
path: root/hid/lib/drivers-avr/spi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hid/lib/drivers-avr/spi.cpp')
-rw-r--r--hid/lib/drivers-avr/spi.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/hid/lib/drivers-avr/spi.cpp b/hid/lib/drivers-avr/spi.cpp
index 66061692..ae54f545 100644
--- a/hid/lib/drivers-avr/spi.cpp
+++ b/hid/lib/drivers-avr/spi.cpp
@@ -21,7 +21,8 @@
#include "spi.h"
-
+#ifdef CMD_SPI
+#include <SPI.h>
static volatile uint8_t _spi_in[8] = {0};
static volatile uint8_t _spi_in_index = 0;
@@ -29,28 +30,26 @@ static volatile uint8_t _spi_in_index = 0;
static volatile uint8_t _spi_out[8] = {0};
static volatile uint8_t _spi_out_index = 0;
+namespace DRIVERS {
+ void Spi::begin() {
+ pinMode(MISO, OUTPUT);
+ SPCR = (1 << SPE) | (1 << SPIE); // Slave, SPI En, IRQ En
+ }
-void spiBegin() {
- pinMode(MISO, OUTPUT);
- SPCR = (1 << SPE) | (1 << SPIE); // Slave, SPI En, IRQ En
-}
-
-bool spiReady() {
- return (!_spi_out[0] && _spi_in_index == 8);
-}
-
-const uint8_t *spiGet() {
- return (const uint8_t *)_spi_in;
-}
+ void Spi::periodic() {
+ if (!_spi_out[0] && _spi_in_index == 8) {
+ _data_cb((const uint8_t *)_spi_in, 8);
+ }
+ }
-void spiWrite(const uint8_t *data) {
- // Меджик в нулевом байте разрешает начать ответ
- for (int index = 7; index >= 0; --index) {
- _spi_out[index] = data[index];
+ void Spi::write(const uint8_t *data, size_t size) {
+ // Меджик в нулевом байте разрешает начать ответ
+ for (int index = 7; index >= 0; --index) {
+ _spi_out[index] = data[index];
+ }
}
}
-
ISR(SPI_STC_vect) {
uint8_t in = SPDR;
if (_spi_out[0] && _spi_out_index < 8) {
@@ -78,3 +77,4 @@ ISR(SPI_STC_vect) {
SPDR = 0;
}
}
+#endif