]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/nova/pin.py
Update busion to avoid triggering frequency warning
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / nova / pin.py
1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2 #
3 # SPDX-License-Identifier: MIT
4 """Binho Nova pin names"""
5
6
7 class Pin:
8     """A basic Pin class for use with Binho Nova."""
9
10     IN = "DIN"
11     OUT = "DOUT"
12     AIN = "AIN"
13     AOUT = "AOUT"
14     PWM = "PWM"
15     LOW = 0
16     HIGH = 1
17
18     _nova = None
19
20     def __init__(self, pin_id=None):
21         if not Pin._nova:
22             # pylint: disable=import-outside-toplevel
23             from adafruit_blinka.microcontroller.nova import Connection
24
25             # pylint: enable=import-outside-toplevel
26
27             Pin._nova = Connection.getInstance()
28         # check if pin is valid
29         if pin_id > 4:
30             raise ValueError("Invalid pin {}.".format(pin_id))
31
32         self.id = pin_id
33
34     def init(self, mode=IN, pull=None):
35         """Initialize the Pin"""
36         if self.id is None:
37             raise RuntimeError("Can not init a None type pin.")
38         # Nova does't have configurable internal pulls for
39         if pull:
40             raise ValueError("Internal pull up/down not currently supported.")
41         Pin._nova.setIOpinMode(self.id, mode)
42
43     def value(self, val=None):
44         """Set or return the Pin Value"""
45         if self.id is None:
46             raise RuntimeError("Can not access a None type pin.")
47         # read
48         if val is None:
49             return int(Pin._nova.getIOpinValue(self.id).split("VALUE ")[1])
50         # write
51         if val in (self.LOW, self.HIGH):
52             Pin._nova.setIOpinValue(self.id, val)
53             return None
54         raise RuntimeError("Invalid value for pin")
55
56
57 # create pin instances for each pin
58 IO0 = Pin(0)
59 IO1 = Pin(1)
60 IO2 = Pin(2)
61 IO3 = Pin(3)
62 IO4 = Pin(4)
63
64 SCL = IO2
65 SDA = IO0
66 SCK = SCLK = IO3
67 MOSI = IO4
68 MISO = IO2
69 SS0 = IO0
70 SS1 = IO1
71
72 PWM0 = IO0
73 # No PWM support on IO1
74 PWM2 = IO2
75 PWM3 = IO3
76 PWM4 = IO4
77
78 # orderd as (channel, pin), id
79 pwmOuts = (((1, 0), PWM0), ((1, 2), PWM2), ((1, 3), PWM3), ((1, 4), PWM4))
80
81 UART1_TX = IO4
82 UART1_RX = IO3
83
84 # ordered as uartId, txId, rxId
85 uartPorts = ((0, UART1_TX, UART1_RX),)