23
23
0x6C : "Pixels"
24
24
}
25
25
26
- class I2CHelper :
26
+ class _I2CHelper :
27
27
"""
28
28
A helper class for interacting with I2C devices on supported boards.
29
29
"""
@@ -54,15 +54,15 @@ def reset_bus(i2c_bus):
54
54
55
55
# This is a workaround to get the SCL and SDA pins from a given bus object.
56
56
# 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 )
58
58
59
59
scl_pin = Pin (scl_pin_number , Pin .IN ) # Detach pin from I2C
60
60
sda_pin = Pin (sda_pin_number , Pin .IN ) # Detach pin from I2C
61
61
62
62
scl_pin = Pin (scl_pin_number , Pin .OUT )
63
63
sda_pin = Pin (sda_pin_number , Pin .OUT )
64
64
65
- period = 1 / I2CHelper .frequency
65
+ period = 1 / _I2CHelper .frequency
66
66
sda_pin .value (1 )
67
67
for _ in range (0 , 20 ):
68
68
scl_pin .value (1 )
@@ -72,17 +72,17 @@ def reset_bus(i2c_bus):
72
72
73
73
# Need to re-initialize the bus after resetting it
74
74
# otherwise it gets stuck.
75
- return I2C (interface , freq = I2CHelper .frequency )
75
+ return I2C (interface , freq = _I2CHelper .frequency )
76
76
77
77
@staticmethod
78
78
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
83
83
84
84
@staticmethod
85
- def find_interface () -> I2C :
85
+ def _find_interface () -> I2C :
86
86
"""
87
87
Returns an instance of the I2C interface for the current board.
88
88
@@ -99,11 +99,11 @@ def find_interface() -> I2C:
99
99
raise RuntimeError (f"I2C interface couldn't be determined automatically for '{ board_name } '." )
100
100
101
101
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 )
103
103
104
104
if interface_info .type == "sw" :
105
105
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 )
107
107
108
108
class Modulino :
109
109
default_addresses = []
@@ -112,7 +112,7 @@ class Modulino:
112
112
113
113
def __init__ (self , i2c_bus = None , address = None , name = None ):
114
114
if i2c_bus is None :
115
- self .i2c_bus = I2CHelper .get_interface ()
115
+ self .i2c_bus = _I2CHelper .get_interface ()
116
116
else :
117
117
self .i2c_bus = i2c_bus
118
118
@@ -252,7 +252,7 @@ def available_devices():
252
252
Returns:
253
253
list: A list of Modulino objects.
254
254
"""
255
- bus = I2CHelper .get_interface ()
255
+ bus = _I2CHelper .get_interface ()
256
256
device_addresses = bus .scan ()
257
257
devices = []
258
258
for address in device_addresses :
@@ -270,4 +270,4 @@ def reset_bus(i2c_bus):
270
270
Returns:
271
271
I2C: A new i2c bus object after resetting the bus.
272
272
"""
273
- return I2CHelper .reset_bus (i2c_bus )
273
+ return _I2CHelper .reset_bus (i2c_bus )
0 commit comments