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

index 693341a17bd6f08e67269d943fa5a0bb1aa82cf4..784d51bad430185ef6f60558bf5686b49b54627f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -67,6 +67,7 @@ SRCS += \
   ./watch-library/simulator/watch/watch_deepsleep.c \
   ./watch-library/simulator/watch/watch_extint.c \
   ./watch-library/simulator/watch/watch_gpio.c \
+  ./watch-library/simulator/watch/watch_i2c.c \
   ./watch-library/simulator/watch/watch_private.c \
   ./watch-library/simulator/watch/watch_rtc.c \
   ./watch-library/simulator/watch/watch_slcd.c \
@@ -86,6 +87,7 @@ SRCS += \
   ./watch-library/hardware/watch/watch_deepsleep.c \
   ./watch-library/hardware/watch/watch_extint.c \
   ./watch-library/hardware/watch/watch_gpio.c \
+  ./watch-library/hardware/watch/watch_i2c.c \
   ./watch-library/hardware/watch/watch_private.c \
   ./watch-library/hardware/watch/watch_rtc.c \
   ./watch-library/hardware/watch/watch_slcd.c \
index ff20afc6d459037fbb14c5da1f0e5be50817d1f8..05833304204672ef359d7e736f9afd130a8a820a 100644 (file)
  */
 
 #include "watch_i2c.h"
-
-struct io_descriptor *I2C_0_io;
+#include "i2c.h"
 
 void watch_enable_i2c(void) {
-    I2C_0_init();
-    i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io);
-    i2c_m_sync_enable(&I2C_0);
+    // NOTE: I2C sensors are not supported on Sensor Watch Lite, so there are no SDA/SCL pin definitions.
+    // This ifdef is here to prevent the build from failing.
+#ifdef I2C_SERCOM
+    HAL_GPIO_SDA_pmuxen(HAL_GPIO_PMUX_SERCOM);
+    HAL_GPIO_SCL_pmuxen(HAL_GPIO_PMUX_SERCOM);
+#endif
+    i2c_init();
+    i2c_enable();
 }
 
 void watch_disable_i2c(void) {
-    i2c_m_sync_disable(&I2C_0);
-       hri_mclk_clear_APBCMASK_SERCOM1_bit(MCLK);
+    i2c_disable();
 }
 
 void watch_i2c_send(int16_t addr, uint8_t *buf, uint16_t length) {
-    i2c_m_sync_set_periphaddr(&I2C_0, addr, I2C_M_SEVEN);
-    io_write(I2C_0_io, buf, length);
+    i2c_write(addr, buf, length);
 }
 
 void watch_i2c_receive(int16_t addr, uint8_t *buf, uint16_t length) {
-    i2c_m_sync_set_periphaddr(&I2C_0, addr, I2C_M_SEVEN);
-    io_read(I2C_0_io, buf, length);
+    i2c_read(addr, buf, length);
 }
 
 void watch_i2c_write8(int16_t addr, uint8_t reg, uint8_t data) {
index 12d583df051b9dc54acbeb5ac7d4afbb7a58fb6a..c6a81dd3ca28404bdc2f1d6d02ebb7e7d9675e95 100644 (file)
@@ -67,7 +67,7 @@ typedef void (*watch_cb_t)(void);
 #include "watch_tcc.h"
 #include "watch_adc.h"
 #include "watch_gpio.h"
-// #include "watch_i2c.h"
+#include "watch_i2c.h"
 #include "watch_spi.h"
 #include "watch_uart.h"
 #include "watch_storage.h"