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