From 021a901bc19f55a26062439885f6f9ea8b875524 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Wed, 4 Aug 2021 18:33:40 -0400 Subject: some I2C work --- watch-library/watch/watch.c | 55 ++++++++++++++++++++++++++++++++++++++++----- watch-library/watch/watch.h | 10 +++++++-- 2 files changed, 58 insertions(+), 7 deletions(-) (limited to 'watch-library') diff --git a/watch-library/watch/watch.c b/watch-library/watch/watch.c index 484cfada..b569c13d 100644 --- a/watch-library/watch/watch.c +++ b/watch-library/watch/watch.c @@ -24,7 +24,7 @@ static const uint8_t Character_Set[] = 0b00000000, // 0b00000000, // ! 0b00100010, // " - 0b00000000, // # + 0b01100011, // # (degree symbol, hash mark doesn't fit) 0b00000000, // $ 0b00000000, // % 0b01000100, // & @@ -33,9 +33,9 @@ static const uint8_t Character_Set[] = 0b00000000, // ) 0b00000000, // * 0b11000000, // + - 0b00010000, // , + 0b00000100, // , 0b01000000, // - - 0b00000100, // . + 0b01000000, // . 0b00010010, // / 0b00111111, // 0 0b00000110, // 1 @@ -138,7 +138,7 @@ void watch_enable_display() { slcd_sync_enable(&SEGMENT_LCD_0); } -void watch_display_pixel(uint8_t com, uint8_t seg) { +void watch_set_pixel(uint8_t com, uint8_t seg) { slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_SEGID(com, seg)); } @@ -283,7 +283,7 @@ static void tick_callback(struct calendar_dev *const dev) { tick_user_callback(); } -void watch_enable_tick_callback(ext_irq_cb_t callback) { +void watch_register_tick_callback(ext_irq_cb_t callback) { tick_user_callback = callback; _prescaler_register_callback(&CALENDAR_0.device, &tick_callback); } @@ -367,6 +367,51 @@ void watch_i2c_receive(int16_t addr, uint8_t *buf, uint16_t length) { io_read(I2C_0_io, buf, length); } +void watch_i2c_write8(int16_t addr, uint8_t reg, uint8_t data) { + uint8_t buf[2]; + buf[0] = reg; + buf[1] = data; + + watch_i2c_send(addr, (uint8_t *)&buf, 2); +} + +uint8_t watch_i2c_read8(int16_t addr, uint8_t reg) { + uint8_t data; + + watch_i2c_send(addr, (uint8_t *)®, 1); + watch_i2c_receive(addr, (uint8_t *)&data, 1); + + return data; +} + +uint16_t watch_i2c_read16(int16_t addr, uint8_t reg) { + uint16_t data; + + watch_i2c_send(addr, (uint8_t *)®, 1); + watch_i2c_receive(addr, (uint8_t *)&data, 2); + + return data; +} + +uint32_t watch_i2c_read24(int16_t addr, uint8_t reg) { + uint32_t data; + data = 0; + + watch_i2c_send(addr, (uint8_t *)®, 1); + watch_i2c_receive(addr, (uint8_t *)&data, 3); + + return data << 8; +} + +uint32_t watch_i2c_read32(int16_t addr, uint8_t reg) { + uint32_t data; + + watch_i2c_send(addr, (uint8_t *)®, 1); + watch_i2c_receive(addr, (uint8_t *)&data, 4); + + return data; +} + ////////////////////////////////////////////////////////////////////////////////////////// // Deep Sleep diff --git a/watch-library/watch/watch.h b/watch-library/watch/watch.h index ece87eed..04f1e486 100644 --- a/watch-library/watch/watch.h +++ b/watch-library/watch/watch.h @@ -8,7 +8,8 @@ void watch_init(); void watch_enable_display(); -void watch_display_pixel(uint8_t com, uint8_t seg); +void watch_set_pixel(uint8_t com, uint8_t seg); +void watch_clear_pixel(uint8_t com, uint8_t seg); void watch_display_string(char *string, uint8_t position); void watch_enable_led(bool pwm); @@ -23,7 +24,7 @@ bool watch_rtc_is_enabled(); void watch_set_date_time(struct calendar_date_time date_time); void watch_get_date_time(struct calendar_date_time *date_time); -void watch_enable_tick_callback(ext_irq_cb_t callback); +void watch_register_tick_callback(ext_irq_cb_t callback); void watch_enable_analog(const uint8_t pin); @@ -44,6 +45,11 @@ struct io_descriptor *I2C_0_io; void watch_enable_i2c(); void watch_i2c_send(int16_t addr, uint8_t *buf, uint16_t length); void watch_i2c_receive(int16_t addr, uint8_t *buf, uint16_t length); +void watch_i2c_write8(int16_t addr, uint8_t reg, uint8_t data); +uint8_t watch_i2c_read8(int16_t addr, uint8_t reg); +uint16_t watch_i2c_read16(int16_t addr, uint8_t reg); +uint32_t watch_i2c_read24(int16_t addr, uint8_t reg); +uint32_t watch_i2c_read32(int16_t addr, uint8_t reg); void watch_store_backup_data(uint32_t data, uint8_t reg); uint32_t watch_get_backup_data(uint8_t reg); -- cgit v1.2.3