From c2385117956322a810a643e7254c701f2325b5da Mon Sep 17 00:00:00 2001 From: joeycastillo Date: Tue, 8 Oct 2024 21:04:25 -0400 Subject: [PATCH] refactor watch I2C for gossamer --- Makefile | 2 ++ watch-library/hardware/watch/watch_i2c.c | 23 ++++++++++++----------- watch-library/shared/watch/watch.h | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 693341a1..784d51ba 100644 --- 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 \ diff --git a/watch-library/hardware/watch/watch_i2c.c b/watch-library/hardware/watch/watch_i2c.c index ff20afc6..05833304 100644 --- a/watch-library/hardware/watch/watch_i2c.c +++ b/watch-library/hardware/watch/watch_i2c.c @@ -23,28 +23,29 @@ */ #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) { diff --git a/watch-library/shared/watch/watch.h b/watch-library/shared/watch/watch.h index 12d583df..c6a81dd3 100644 --- a/watch-library/shared/watch/watch.h +++ b/watch-library/shared/watch/watch.h @@ -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"