]> git.earman.xyz Git - sensor-watch.git/commitdiff
refactor watch SPI for gossamer
authorjoeycastillo <joeycastillo@utexas.edu>
Tue, 8 Oct 2024 21:59:01 +0000 (17:59 -0400)
committerjoeycastillo <joeycastillo@utexas.edu>
Wed, 9 Oct 2024 02:44:08 +0000 (22:44 -0400)
Makefile
watch-library/hardware/watch/watch_spi.c
watch-library/shared/watch/watch.h

index 2d87c5a25c9d09ee8671919323838a4780344188..e42cb28cd24fae20487dcdb2976c325d01bde64f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -68,6 +68,7 @@ SRCS += \
   ./watch-library/simulator/watch/watch_private.c \
   ./watch-library/simulator/watch/watch_rtc.c \
   ./watch-library/simulator/watch/watch_slcd.c \
+  ./watch-library/simulator/watch/watch_spi.c \
   ./watch-library/simulator/watch/watch_storage.c \
   ./watch-library/simulator/watch/watch_tcc.c \
   ./watch-library/simulator/watch/watch_uart.c \
@@ -86,6 +87,7 @@ SRCS += \
   ./watch-library/hardware/watch/watch_private.c \
   ./watch-library/hardware/watch/watch_rtc.c \
   ./watch-library/hardware/watch/watch_slcd.c \
+  ./watch-library/hardware/watch/watch_spi.c \
   ./watch-library/hardware/watch/watch_storage.c \
   ./watch-library/hardware/watch/watch_tcc.c \
   ./watch-library/hardware/watch/watch_uart.c \
index 8cdebb08d7a012e37764f83fa18c6962c90c6f4e..9ff10d4c7894b962261b928a53519e90a516ef0b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * MIT License
  *
- * Copyright (c) 2022 Joey Castillo
+ * Copyright (c) 2022-2024 Joey Castillo
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  */
 
 #include "watch_spi.h"
-
-struct io_descriptor *spi_io;
+#include "spi.h"
 
 void watch_enable_spi(void) {
-    SPI_0_init();
-    spi_m_sync_get_io_descriptor(&SPI_0, &spi_io);
-    spi_m_sync_enable(&SPI_0);
+    spi_init(SPI_MODE_3, 1000000);
+    spi_enable();
 }
 
 void watch_disable_spi(void) {
-    spi_m_sync_disable(&SPI_0);
-    spi_io = NULL;
+    spi_disable();
 }
 
 bool watch_spi_write(const uint8_t *buf, uint16_t length) {
-       return !!io_write(spi_io, buf, length);
+    for (uint16_t i = 0; i < length; i++) {
+        spi_transfer(buf[i]);
+    }
+
+    return true;
 }
 
 bool watch_spi_read(uint8_t *buf, uint16_t length) {
-       return !!io_read(spi_io, buf, length);
+    for (uint16_t i = 0; i < length; i++) {
+        buf[i] = spi_transfer(0);
+    }
+
+    return true;
 }
 
 bool watch_spi_transfer(const uint8_t *data_out, uint8_t *data_in, uint16_t length) {
-    struct spi_xfer xfer;
-    xfer.txbuf = (uint8_t *)data_out;
-    xfer.rxbuf = data_in;
-    xfer.size = length;
-    return !!spi_m_sync_transfer(&SPI_0, &xfer);
+    for (uint16_t i = 0; i < length; i++) {
+        data_in[i] = spi_transfer(data_out[i]);
+    }
+
+    return true;
 }
index e38ab9e03e9d9feb0e64653a1e3999e9ab88e2db..12d583df051b9dc54acbeb5ac7d4afbb7a58fb6a 100644 (file)
@@ -68,7 +68,7 @@ typedef void (*watch_cb_t)(void);
 #include "watch_adc.h"
 #include "watch_gpio.h"
 // #include "watch_i2c.h"
-// #include "watch_spi.h"
+#include "watch_spi.h"
 #include "watch_uart.h"
 #include "watch_storage.h"
 #include "watch_deepsleep.h"