From 00b1faab8358d1575e4567d462a5329201023bc2 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 27 Oct 2018 21:38:08 +0200 Subject: [PATCH] SPI wire interface (experimental) --- src/spisend.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/spisend.cpp b/src/spisend.cpp index c778a887..6d28f5a8 100644 --- a/src/spisend.cpp +++ b/src/spisend.cpp @@ -41,34 +41,32 @@ void spi_loop(void *pvParameters) { void hal_spi_init() { SPI.begin(SCK, MISO, MOSI, SS); } -void hal_spi_trx(u1_t cmd, u1_t *buf, int len, u1_t is_read) { +void hal_spi_trx(uint8_t port, uint8_t *buf, int len, uint8_t is_read) { - u1_t nss = SS; SPISettings settings(1E6, MSBFIRST, SPI_MODE0); SPI.beginTransaction(settings); + digitalWrite(SS, 0); - digitalWrite(nss, 0); + SPI.transfer(port); - SPI.transfer(cmd); - - for (u1_t i = 0; i < len; i++) { - u1_t *p = buf + i; - u1_t data = is_read ? 0x00 : *p; + for (uint8_t i = 0; i < len; i++) { + uint8_t *p = buf + i; + uint8_t data = is_read ? 0x00 : *p; data = SPI.transfer(data); if (is_read) *p = data; } - digitalWrite(nss, 1); + digitalWrite(SS, 1); SPI.endTransaction(); } -void hal_spi_write(u1_t cmd, const u1_t *buf, int len) { - hal_spi_trx(cmd, (u1_t *)buf, len, 0); +void hal_spi_write(uint8_t port, const uint8_t *buf, int len) { + hal_spi_trx(port, (uint8_t *)buf, len, 0); } -void hal_spi_read(u1_t cmd, u1_t *buf, int len) { - hal_spi_trx(cmd, buf, len, 1); +void hal_spi_read(uint8_t port, uint8_t *buf, int len) { + hal_spi_trx(port, buf, len, 1); } #endif // HAS_SPI \ No newline at end of file