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