Skip to content
Snippets Groups Projects
Commit 8f04526d authored by Jevgeni Kiski's avatar Jevgeni Kiski
Browse files

Orange PI: PIN providing mode (BCM, BOARD, MODE_SOC)

parent ecb32e2e
Branches
Tags
No related merge requests found
...@@ -21,6 +21,7 @@ gpio_modules: ...@@ -21,6 +21,7 @@ gpio_modules:
- name: orangepi - name: orangepi
module: orangepi module: orangepi
board: zero board: zero
mode: board
sensor_modules: sensor_modules:
- name: lm75 - name: lm75
... ...
......
...@@ -4,6 +4,7 @@ ALLOWED_BOARDS = [ ...@@ -4,6 +4,7 @@ ALLOWED_BOARDS = [
'zero', 'r1', 'zeroplus', 'zeroplus2h5', 'zeroplus2h3', 'zero', 'r1', 'zeroplus', 'zeroplus2h5', 'zeroplus2h3',
'pcpcplus', 'one', 'lite', 'plus2e', 'pc2', 'prime' 'pcpcplus', 'one', 'lite', 'plus2e', 'pc2', 'prime'
] ]
ALLOWED_MODES = ['bcm', 'board', 'mode_soc']
REQUIREMENTS = ("OrangePi.GPIO",) REQUIREMENTS = ("OrangePi.GPIO",)
CONFIG_SCHEMA = { CONFIG_SCHEMA = {
"board": { "board": {
...@@ -11,6 +12,12 @@ CONFIG_SCHEMA = { ...@@ -11,6 +12,12 @@ CONFIG_SCHEMA = {
"required": True, "required": True,
"empty": False, "empty": False,
"allowed": ALLOWED_BOARDS + list(map(str.upper, ALLOWED_BOARDS)) "allowed": ALLOWED_BOARDS + list(map(str.upper, ALLOWED_BOARDS))
},
"mode": {
"type": "string",
"required": False,
"empty": False,
"allowed": ALLOWED_MODES + list(map(str.upper, ALLOWED_MODES))
} }
} }
...@@ -37,10 +44,11 @@ class GPIO(GenericGPIO): ...@@ -37,10 +44,11 @@ class GPIO(GenericGPIO):
} }
board = config["board"].upper() board = config["board"].upper()
mode = config.get("mode", "bcm").upper()
if not hasattr(gpio, board): if not hasattr(gpio, board):
raise AssertionError("%s board not found" % board) raise AssertionError("%s board not found" % board)
gpio.setboard(getattr(gpio, board)) gpio.setboard(getattr(gpio, board))
gpio.setmode(gpio.BCM) gpio.setmode(getattr(gpio, mode))
def setup_pin(self, pin, direction, pullup, pin_config): def setup_pin(self, pin, direction, pullup, pin_config):
direction = DIRECTIONS[direction] direction = DIRECTIONS[direction]
...@@ -51,7 +59,10 @@ class GPIO(GenericGPIO): ...@@ -51,7 +59,10 @@ class GPIO(GenericGPIO):
pullup = PULLUPS[pullup] pullup = PULLUPS[pullup]
initial = {None: -1, "low": 0, "high": 1}[pin_config.get("initial")] initial = {None: -1, "low": 0, "high": 1}[pin_config.get("initial")]
try:
self.io.setup(pin, direction, pull_up_down=pullup, initial=initial) self.io.setup(pin, direction, pull_up_down=pullup, initial=initial)
except ValueError as e:
raise IOError("channel %d setup failed" % pin) from e
def set_pin(self, pin, value): def set_pin(self, pin, value):
self.io.output(pin, value) self.io.output(pin, value)
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment