From: ladyada Date: Sat, 1 Dec 2018 20:27:42 +0000 (-0500) Subject: orange pi GPIO led blinky X-Git-Tag: 0.4.0^2~3 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/031c39f2511a2db0913d6f0410056e3b71c47cc5 orange pi GPIO led blinky --- diff --git a/src/adafruit_blinka/agnostic/__init__.py b/src/adafruit_blinka/agnostic/__init__.py index 0327ae9..1d93e6c 100755 --- a/src/adafruit_blinka/agnostic/__init__.py +++ b/src/adafruit_blinka/agnostic/__init__.py @@ -21,16 +21,27 @@ if platform is not None: platform = "stm32" board_id = "pyboard" elif platform == "linux": - from Adafruit_GPIO import Platform - if Platform.platform_detect() == Platform.RASPBERRY_PI: - if Platform.pi_version() == 1: - board_id = "raspi_1" - elif Platform.pi_version() == 2: - board_id = "raspi_2" - elif Platform.pi_version() == 3: - board_id = "raspi_3" - elif Platform.platform_detect() == Platform.BEAGLEBONE_BLACK: - board_id = "beaglebone_black" + import re + # we're going to redo the Platform detection, this is a terrible hack + # for now. + try: + # lets see if we're an armbian board + for line in open("/etc/armbian-release", 'r'): + #print(line) + m = re.search('BOARD=(.*)', line) + if m: + board_id = m.group(1) + except: + from Adafruit_GPIO import Platform + if Platform.platform_detect() == Platform.RASPBERRY_PI: + if Platform.pi_version() == 1: + board_id = "raspi_1" + elif Platform.pi_version() == 2: + board_id = "raspi_2" + elif Platform.pi_version() == 3: + board_id = "raspi_3" + elif Platform.platform_detect() == Platform.BEAGLEBONE_BLACK: + board_id = "beaglebone_black" implementation = sys.implementation.name if implementation == "micropython": diff --git a/src/adafruit_blinka/board/orangepipc.py b/src/adafruit_blinka/board/orangepipc.py new file mode 100644 index 0000000..18bcd25 --- /dev/null +++ b/src/adafruit_blinka/board/orangepipc.py @@ -0,0 +1,33 @@ +from adafruit_blinka.microcontroller.allwinner_h3 import pin + +PA12 = pin.PA12 +SDA = pin.PA12 +PA11 = pin.PA11 +SCL = pin.PA11 +PA6 = pin.PA6 +PA1 = pin.PA1 +PA0 = pin.PA0 +PA3 = pin.PA3 +PC0 = pin.PC0 +PC1 = pin.PC1 +PC2 = pin.PC2 +PA19 = pin.PA19 +PA7 = pin.PA7 +PA8 = pin.PA8 +PA9 = pin.PA9 +PA10 = pin.PA10 +PA20 = pin.PA20 + +PA13 = pin.PA13 +PA14 = pin.PA14 +PD14 = pin.PD14 +PC4 = pin.PC4 +PC7 = pin.PC7 +PA2 = pin.PA2 +PC3 = pin.PC3 +PA21 = pin.PA21 +PA18 = pin.PA18 +PG8 = pin.PG8 +PG9 = pin.PG9 +PG6 = pin.PG6 +PG7 = pin.PG7 diff --git a/src/adafruit_blinka/microcontroller/allwinner_h3/__init__.py b/src/adafruit_blinka/microcontroller/allwinner_h3/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/adafruit_blinka/microcontroller/allwinner_h3/pin.py b/src/adafruit_blinka/microcontroller/allwinner_h3/pin.py new file mode 100644 index 0000000..15410c6 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/allwinner_h3/pin.py @@ -0,0 +1,33 @@ +from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin + +PA0 = Pin(0) +PA1 = Pin(1) +PA2 = Pin(2) +PA3 = Pin(3) +PA6 = Pin(6) +PA7 = Pin(7) +PA8 = Pin(8) +PA9 = Pin(9) +PA10 = Pin(10) +PA11 = Pin(11) +PA12 = Pin(12) +PA13 = Pin(13) +PA14 = Pin(14) +PA18 = Pin(18) +PA19 = Pin(19) +PA20 = Pin(20) +PA21 = Pin(21) + +PC0 = Pin(64) +PC1 = Pin(65) +PC2 = Pin(66) +PC3 = Pin(67) +PC4 = Pin(68) +PC7 = Pin(71) + +PD14 = Pin(110) + +PG6 = Pin(198) +PG7 = Pin(199) +PG8 = Pin(200) +PG9 = Pin(201) diff --git a/src/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py b/src/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py new file mode 100644 index 0000000..51b87f9 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py @@ -0,0 +1,74 @@ +try: + import gpiod +except ImportError: + raise ImportError("libgpiod Python bindings not found, please install and try again! See https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh") + +# Pins dont exist in CPython so...lets make our own! +class Pin: + IN = 0 + OUT = 1 + LOW = 0 + HIGH = 1 + PULL_NONE = 0 + PULL_UP = 1 + PULL_DOWN = 2 + _CONSUMER = 'adafruit_blinka' + + id = None + _value = LOW + _mode = IN + + def __init__(self, pin_number, gpiod_chipname="gpiochip0"): + self.id = int(pin_number) + # FIXME: Presumably this might vary by system: + self._chip = gpiod.Chip(gpiod_chipname, gpiod.Chip.OPEN_BY_NAME) + self._line = None + + def __repr__(self): + return str(self.id) + + def __eq__(self, other): + return self.id == other + + def init(self, mode=IN, pull=None): + if not self._line: + self._line = self._chip.get_line(int(self.id)) + print("init line: ", int(self.id), self._line) + + if mode != None: + if mode == self.IN: + flags = 0 + if pull != None: + if pull == self.PULL_UP: + flags |= gpiod.LINE_REQ_FLAG_ACTIVE_LOW + elif pull == self.PULL_DOWN: + flags |= gpiod.LINE_REQ_FLAG_ACTIVE_HIGH + else: + raise RuntimeError("Invalid pull for pin: %s" % self.id) + + self._mode = self.IN + self._line.release() + self._line.request(consumer=self._CONSUMER, + type=gpiod.LINE_REQ_DIR_IN, + flags=flags) + + elif mode == self.OUT: + if pull != None: + raise RuntimeError("Cannot set pull resistor on output") + self._mode = self.OUT + self._line.release() + self._line.request(consumer=self._CONSUMER, + type=gpiod.LINE_REQ_DIR_OUT) + + else: + raise RuntimeError("Invalid mode for pin: %s" % self.id) + + def value(self, val=None): + if val != None: + if val in (self.LOW, self.HIGH): + self._value = val + self._line.set_value(val) + else: + raise RuntimeError("Invalid value for pin") + else: + return self._line.get_value()