summaryrefslogtreecommitdiff
path: root/src/drivers/Spi.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-05-24 16:58:29 +0200
committerGitea <gitea@fake.local>2020-05-24 16:58:29 +0200
commit82b4ddc25b4c7913e0e6a13a209a4415dff044f1 (patch)
tree8eeafef1f4150a1cf238ee80e53c8901b0ec67af /src/drivers/Spi.cpp
parentbe1ad9b07083e656a649d223750ff4b14b781b7b (diff)
parent073717980f5c00f553ac3b58a50b792b32a14c7a (diff)
Merge branch 'nimble-ota' of JF/PineTime into develop
Diffstat (limited to 'src/drivers/Spi.cpp')
-rw-r--r--src/drivers/Spi.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/drivers/Spi.cpp b/src/drivers/Spi.cpp
new file mode 100644
index 00000000..ec3a5e94
--- /dev/null
+++ b/src/drivers/Spi.cpp
@@ -0,0 +1,34 @@
+#include <hal/nrf_gpio.h>
+#include "Spi.h"
+
+using namespace Pinetime::Drivers;
+
+Spi::Spi(SpiMaster& spiMaster, uint8_t pinCsn) :
+ spiMaster{spiMaster}, pinCsn{pinCsn} {
+ nrf_gpio_cfg_output(pinCsn);
+ nrf_gpio_pin_set(pinCsn);
+}
+
+bool Spi::Write(const uint8_t *data, size_t size) {
+ return spiMaster.Write(pinCsn, data, size);
+}
+
+bool Spi::Read(uint8_t* cmd, size_t cmdSize, uint8_t *data, size_t dataSize) {
+ return spiMaster.Read(pinCsn, cmd, cmdSize, data, dataSize);
+}
+
+void Spi::Sleep() {
+ // TODO sleep spi
+ nrf_gpio_cfg_default(pinCsn);
+}
+
+bool Spi::Init() {
+ nrf_gpio_pin_set(pinCsn); /* disable Set slave select (inactive high) */
+ return true;
+}
+
+bool Spi::WriteCmdAndBuffer(uint8_t *cmd, size_t cmdSize, uint8_t *data, size_t dataSize) {
+ return spiMaster.WriteCmdAndBuffer(pinCsn, cmd, cmdSize, data, dataSize);
+}
+
+