Skip to content

Commit

Permalink
Update TwoWire class to support multiple instances (#2405)
Browse files Browse the repository at this point in the history
This PR revises the `TwoWire` class so that multiple instances work as expected.

The code from `twi.h` and `si2c.cpp` has been ported is no longer required by the framework, although there may be libraries which make use of them so have been left.
  • Loading branch information
mikee47 authored Oct 27, 2021
1 parent 12061b3 commit cc99648
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 172 deletions.
3 changes: 3 additions & 0 deletions Sming/Arch/Esp32/Core/twi_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
#define SCL_LOW() gpio_ll_output_enable(&GPIO, gpio_num_t(twi_scl))
#define SCL_HIGH() gpio_ll_output_disable(&GPIO, gpio_num_t(twi_scl))
#define SCL_READ() (gpio_ll_get_level(&GPIO, gpio_num_t(twi_scl)) != 0)

#define DEFAULT_SDA_PIN 21
#define DEFAULT_SCL_PIN 22
3 changes: 3 additions & 0 deletions Sming/Arch/Esp8266/Core/twi_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
#define SCL_LOW() (GPES = (1 << twi_scl))
#define SCL_HIGH() (GPEC = (1 << twi_scl))
#define SCL_READ() ((GPI & (1 << twi_scl)) != 0)

#define DEFAULT_SDA_PIN 2
#define DEFAULT_SCL_PIN 0
3 changes: 3 additions & 0 deletions Sming/Arch/Host/Core/twi_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
#define SCL_LOW()
#define SCL_HIGH()
#define SCL_READ() 1

#define DEFAULT_SDA_PIN 255
#define DEFAULT_SCL_PIN 255
4 changes: 4 additions & 0 deletions Sming/Arch/Rp2040/Core/twi_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <hardware/gpio.h>
#include <pico.h>

//Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low)
#define SDA_LOW() gpio_set_dir(twi_sda, true)
Expand All @@ -17,3 +18,6 @@
#define SCL_LOW() gpio_set_dir(twi_scl, true)
#define SCL_HIGH() gpio_set_dir(twi_scl, false)
#define SCL_READ() gpio_get(twi_scl)

#define DEFAULT_SDA_PIN PICO_DEFAULT_I2C_SDA_PIN
#define DEFAULT_SCL_PIN PICO_DEFAULT_I2C_SCL_PIN
Loading

0 comments on commit cc99648

Please sign in to comment.