2323 0x6C : "Pixels"
2424}
2525
26- class I2CHelper :
26+ class _I2CHelper :
2727 """
2828 A helper class for interacting with I2C devices on supported boards.
2929 """
@@ -54,15 +54,15 @@ def reset_bus(i2c_bus):
5454
5555 # This is a workaround to get the SCL and SDA pins from a given bus object.
5656 # Unfortunately the I2C class does not expose those attributes directly.
57- interface , scl_pin_number , sda_pin_number = I2CHelper .extract_i2c_info (i2c_bus )
57+ interface , scl_pin_number , sda_pin_number = _I2CHelper .extract_i2c_info (i2c_bus )
5858
5959 scl_pin = Pin (scl_pin_number , Pin .IN ) # Detach pin from I2C
6060 sda_pin = Pin (sda_pin_number , Pin .IN ) # Detach pin from I2C
6161
6262 scl_pin = Pin (scl_pin_number , Pin .OUT )
6363 sda_pin = Pin (sda_pin_number , Pin .OUT )
6464
65- period = 1 / I2CHelper .frequency
65+ period = 1 / _I2CHelper .frequency
6666 sda_pin .value (1 )
6767 for _ in range (0 , 20 ):
6868 scl_pin .value (1 )
@@ -72,17 +72,17 @@ def reset_bus(i2c_bus):
7272
7373 # Need to re-initialize the bus after resetting it
7474 # otherwise it gets stuck.
75- return I2C (interface , freq = I2CHelper .frequency )
75+ return I2C (interface , freq = _I2CHelper .frequency )
7676
7777 @staticmethod
7878 def get_interface () -> I2C :
79- if (I2CHelper .i2c_bus is None ):
80- I2CHelper .i2c_bus = I2CHelper . find_interface ()
81- I2CHelper .i2c_bus = I2CHelper .reset_bus (I2CHelper .i2c_bus )
82- return I2CHelper .i2c_bus
79+ if (_I2CHelper .i2c_bus is None ):
80+ _I2CHelper .i2c_bus = _I2CHelper . _find_interface ()
81+ _I2CHelper .i2c_bus = _I2CHelper .reset_bus (_I2CHelper .i2c_bus )
82+ return _I2CHelper .i2c_bus
8383
8484 @staticmethod
85- def find_interface () -> I2C :
85+ def _find_interface () -> I2C :
8686 """
8787 Returns an instance of the I2C interface for the current board.
8888
@@ -99,11 +99,11 @@ def find_interface() -> I2C:
9999 raise RuntimeError (f"I2C interface couldn't be determined automatically for '{ board_name } '." )
100100
101101 if interface_info .type == "hw" :
102- return I2C (interface_info .bus_number , freq = I2CHelper .frequency )
102+ return I2C (interface_info .bus_number , freq = _I2CHelper .frequency )
103103
104104 if interface_info .type == "sw" :
105105 from machine import SoftI2C , Pin
106- return SoftI2C (scl = Pin (interface_info .scl ) , sda = Pin (interface_info .sda ), freq = I2CHelper .frequency )
106+ return SoftI2C (scl = Pin (interface_info .scl ) , sda = Pin (interface_info .sda ), freq = _I2CHelper .frequency )
107107
108108class Modulino :
109109 default_addresses = []
@@ -112,7 +112,7 @@ class Modulino:
112112
113113 def __init__ (self , i2c_bus = None , address = None , name = None ):
114114 if i2c_bus is None :
115- self .i2c_bus = I2CHelper .get_interface ()
115+ self .i2c_bus = _I2CHelper .get_interface ()
116116 else :
117117 self .i2c_bus = i2c_bus
118118
@@ -252,7 +252,7 @@ def available_devices():
252252 Returns:
253253 list: A list of Modulino objects.
254254 """
255- bus = I2CHelper .get_interface ()
255+ bus = _I2CHelper .get_interface ()
256256 device_addresses = bus .scan ()
257257 devices = []
258258 for address in device_addresses :
@@ -270,4 +270,4 @@ def reset_bus(i2c_bus):
270270 Returns:
271271 I2C: A new i2c bus object after resetting the bus.
272272 """
273- return I2CHelper .reset_bus (i2c_bus )
273+ return _I2CHelper .reset_bus (i2c_bus )
0 commit comments