1 """Module providing runtime utility objects to support the Micro/CircuitPython api"""
6 Object supporting CircuitPython-style of static symbols
7 as seen with Direction.OUTPUT, Pull.UP
12 Assumes instance will be found as attribute of own class.
13 Returns dot-subscripted path to instance
14 (assuming absolute import of containing package)
18 if getattr(cls, key) is self:
19 return "{}.{}.{}".format(cls.__module__, cls.__qualname__, key)
25 Inspects attributes of the class for instances of the class
26 and returns as key,value pairs mirroring dict#iteritems
29 val = getattr(cls, key)
30 if isinstance(cls, val):
35 """An object that automatically deinitializes hardware with a context manager."""
39 def __exit__(self, exc_type, exc_value, traceback):
43 """Free any hardware used by the object."""
47 class Lockable(ContextManaged):
48 """An object that must be locked to prevent collisions on a microcontroller resource."""
52 """Attempt to grab the lock. Return True on success, False if the lock is already taken."""
59 """Release the lock so others may use the resource."""
63 raise ValueError("Not locked")
66 """Patch modules that may be different due to the platform."""
68 from adafruit_blinka.agnostic import time
69 sys.modules['time'] = time