2 `adafruit_blinka` - Runtime utility objects for re-implementation of CircuitPython API
3 ======================================================================================
10 Object supporting CircuitPython-style of static symbols
11 as seen with Direction.OUTPUT, Pull.UP
16 Assumes instance will be found as attribute of own class.
17 Returns dot-subscripted path to instance
18 (assuming absolute import of containing package)
22 if getattr(cls, key) is self:
23 return "{}.{}.{}".format(cls.__module__, cls.__qualname__, key)
29 Inspects attributes of the class for instances of the class
30 and returns as key,value pairs mirroring dict#iteritems
33 val = getattr(cls, key)
34 if isinstance(cls, val):
39 """An object that automatically deinitializes hardware with a context manager."""
43 def __exit__(self, exc_type, exc_value, traceback):
46 # pylint: disable=no-self-use
48 """Free any hardware used by the object."""
50 # pylint: enable=no-self-use
53 class Lockable(ContextManaged):
54 """An object that must be locked to prevent collisions on a microcontroller resource."""
58 """Attempt to grab the lock. Return True on success, False if the lock is already taken."""
65 """Release the lock so others may use the resource."""
69 raise ValueError("Not locked")
72 """Patch modules that may be different due to the platform."""
74 from adafruit_blinka.agnostic import time
75 sys.modules['time'] = time