refactor watch I2C for gossamer

This commit is contained in:
joeycastillo 2024-10-08 21:04:25 -04:00
parent d05fdf2845
commit c238511795
3 changed files with 15 additions and 12 deletions

View File

@ -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 \

View File

@ -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) {

View 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"