MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / DigitalInOut

Class DigitalInOut

cpython/kbdFeatherWing/lib/bbq10keyboard.py:108–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106
107
108class DigitalInOut:
109 def __init__(self, pin, kbd):
110 if pin < 0 or pin > 7:
111 raise ValueError('Only pins 0-7 supported right now')
112
113 self._pin = pin
114 self._kbd = kbd
115
116 def switch_to_output(self, value=False):
117 self.direction = digitalio.Direction.OUTPUT
118 self.value = value
119
120 def switch_to_input(self, pull=None):
121 self.direction = digitalio.Direction.INPUT
122 self.pull = pull
123
124 @property
125 def value(self):
126 return self._kbd._get_register_bit(_REG_GIO, self._pin)
127
128 @value.setter
129 def value(self, value):
130 self._kbd._update_register_bit(_REG_GIO, self._pin, value)
131
132 @property
133 def direction(self):
134 if self._kbd._get_register_bit(_REG_DIR, self._pin) == DIR_INPUT:
135 return digitalio.Direction.INPUT
136
137 return digitalio.Direction.OUTPUT
138
139 @direction.setter
140 def direction(self, value):
141 self._kbd._update_register_bit(_REG_DIR, self._pin, value == digitalio.Direction.INPUT)
142
143 @property
144 def pull(self):
145 if self.direction == digitalio.Direction.OUTPUT:
146 raise AttributeError('Pull not used when direction is output')
147
148 if self._kbd._get_register_bit(_REG_PUE, self._pin):
149 if self._kbd._get_register_bit(_REG_PUD, self._pin) == PUD_UP:
150 return digitalio.Pull.UP
151
152 return digitalio.Pull.DOWN
153
154 return None
155
156 @pull.setter
157 def pull(self, value):
158 if self.direction == digitalio.Direction.OUTPUT:
159 raise AttributeError('Pull not used when direction is output')
160
161 if value is None:
162 self._kbd._update_register_bit(_REG_PUE, self._pin, False)
163 else:
164 self._kbd._update_register_bit(_REG_PUD, self._pin, value == digitalio.Pull.UP)
165 self._kbd._update_register_bit(_REG_PUE, self._pin, True)

Callers 4

blinkFunction · 0.85
get_pinMethod · 0.85
connectMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected