]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/microcontroller/_pin.py
Added pre-commit support
[Adafruit_Blinka-hackapet.git] / src / microcontroller / _pin.py
1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2 #
3 # SPDX-License-Identifier: MIT
4 from adafruit_blinka import Enum
5 import microcontroller.pin
6
7 class Pin(Enum):
8     """
9     Identifies an IO pin on the microcontroller.
10
11     They are fixed by the hardware so they cannot be constructed on demand. Instead, use board or
12     microcontroller.pin to reference the desired pin.
13     """
14
15     def __init__(self, pin_id):
16         """Identifier for pin, referencing platform-specific pin id"""
17         self.id = pin_id
18
19     def __repr__(self):
20         # pylint: disable=import-outside-toplevel, cyclic-import
21         import board
22
23         for key in dir(board):
24             if getattr(board, key) is self:
25                 return "board.{}".format(key)
26         # pylint: enable=import-outside-toplevel, cyclic-import
27
28         for key in dir(microcontroller.pin):
29             if getattr(microcontroller.pin, key) is self:
30                 return "microcontroller.pin.{}".format(key)
31         return repr(self)
32