From 9690546c18259f2c6c2acd19c23cac8d13dfdb73 Mon Sep 17 00:00:00 2001 From: Jonathan Georgino Date: Sat, 16 Nov 2019 14:03:25 -0800 Subject: [PATCH 01/14] Added support for Binho Nova Multi-Protocol USB Host Adapter --- adafruit_platformdetect/board.py | 9 +++++++++ adafruit_platformdetect/chip.py | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index d528873d..f8b5e3c9 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -65,6 +65,7 @@ DRAGONBOARD_410C = "DRAGONBOARD_410C" SIFIVE_UNLEASHED = "SIFIVE_UNLEASHED" +BINHO_NOVA = "BINHO" # pylint: enable=bad-whitespace @@ -333,6 +334,8 @@ def id(self): board_id = self._tegra_id() elif chip_id == ap_chip.HFU540: board_id = self._sifive_id() + elif chip_id == ap_chip.BINHO: + board_id = BINHO_NOVA return board_id # pylint: enable=invalid-name @@ -492,6 +495,12 @@ def ftdi_ft232h(self): """Check whether the current board is an FTDI FT232H.""" return self.id == FTDI_FT232H + @property + def binho_nova(self): + """Check whether the current board is an BINHO NOVA.""" + return self.id == BINHO_NOVA + + def __getattr__(self, attr): """ Detect whether the given attribute is the currently-detected board. See list diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 2ef85695..623511ee 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -20,6 +20,7 @@ GENERIC_X86 = "GENERIC_X86" FT232H = "FT232H" HFU540 = "HFU540" +BINHO = "BINHO" class Chip: """Attempt detection of current chip / CPU.""" @@ -46,7 +47,24 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s raise RuntimeError('BLINKA_FT232H environment variable' + \ 'set, but no FT232H device found') return FT232H - except KeyError: # no FT232H environment var + + elif os.environ['BLINKA_BINHO']: + # import the Binho libraries + + from binhoHostAdapter import binhoHostAdapter + from binhoHostAdapter import binhoUtilities + + utilities = binhoUtilities.binhoUtilities() + devices = utilities.listAvailableDevices() + + count = len(devices) + + if count == 0: + raise RuntimeError('BLINKA_BINHO environment variable' + \ + 'set, but no Binho host adapter found.') + return BINHO + + except KeyError: # no relevant environment var pass platform = sys.platform From e6925ab25765487293e24d50aefe4ede6ddd971d Mon Sep 17 00:00:00 2001 From: Francis G Date: Sat, 16 Nov 2019 20:49:25 -0800 Subject: [PATCH 02/14] Have Binho use its own try block --- adafruit_platformdetect/chip.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 623511ee..937c4106 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -48,7 +48,12 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s 'set, but no FT232H device found') return FT232H - elif os.environ['BLINKA_BINHO']: + except KeyError: # no relevant environment var + pass + + # Another special case, if we have an environment var set for BINHO + try: + if os.environ['BLINKA_BINHO']: # import the Binho libraries from binhoHostAdapter import binhoHostAdapter From 2f3ffabd9feace657474285e1e2ff0f4151e6559 Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Sat, 16 Nov 2019 21:04:49 -0800 Subject: [PATCH 03/14] Use BLINKA_NOVA as env variable instead --- adafruit_platformdetect/chip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 937c4106..595b0cdd 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -53,7 +53,7 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s # Another special case, if we have an environment var set for BINHO try: - if os.environ['BLINKA_BINHO']: + if os.environ['BLINKA_NOVA']: # import the Binho libraries from binhoHostAdapter import binhoHostAdapter From 903fc7851d790246ec23a8365ab2f91ae240102e Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Sun, 17 Nov 2019 22:27:20 -0800 Subject: [PATCH 04/14] change board id to NOVA and fix issue with autodetect being called multiple times after there's already a binho object --- adafruit_platformdetect/board.py | 2 +- adafruit_platformdetect/chip.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index f8b5e3c9..685f60d3 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -65,7 +65,7 @@ DRAGONBOARD_410C = "DRAGONBOARD_410C" SIFIVE_UNLEASHED = "SIFIVE_UNLEASHED" -BINHO_NOVA = "BINHO" +BINHO_NOVA = "NOVA" # pylint: enable=bad-whitespace diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 595b0cdd..ed8062d4 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -26,6 +26,7 @@ class Chip: """Attempt detection of current chip / CPU.""" def __init__(self, detector): self.detector = detector + self._binho = None @property def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements @@ -54,8 +55,11 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s # Another special case, if we have an environment var set for BINHO try: if os.environ['BLINKA_NOVA']: - # import the Binho libraries + # Check if we already have a binho instance + if self._binho is not None and self._binho == BINHO: + return self._binho + # import the Binho libraries from binhoHostAdapter import binhoHostAdapter from binhoHostAdapter import binhoUtilities @@ -65,8 +69,10 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s count = len(devices) if count == 0: + self._binho = None raise RuntimeError('BLINKA_BINHO environment variable' + \ 'set, but no Binho host adapter found.') + self._binho = BINHO return BINHO except KeyError: # no relevant environment var From 95e159f32dbb0a165fbff0e074223d98118b1dc0 Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Tue, 19 Nov 2019 18:04:27 -0800 Subject: [PATCH 05/14] set _binho only if BLINKA_NOVA env variable exists --- adafruit_platformdetect/chip.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index ed8062d4..7632caa8 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -26,7 +26,11 @@ class Chip: """Attempt detection of current chip / CPU.""" def __init__(self, detector): self.detector = detector - self._binho = None + try: + if os.environ['BLINKA_NOVA']: + self._binho = None + except KeyError: # no relevant environment var + pass @property def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements @@ -70,7 +74,7 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s if count == 0: self._binho = None - raise RuntimeError('BLINKA_BINHO environment variable' + \ + raise RuntimeError('BLINKA_NOVA environment variable' + \ 'set, but no Binho host adapter found.') self._binho = BINHO return BINHO From d09621e52146804b4ad47802cad25bd09be17451 Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Sat, 23 Nov 2019 14:37:07 -0800 Subject: [PATCH 06/14] Use binho connection singleton --- adafruit_platformdetect/chip.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 7632caa8..c4e2c347 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -64,18 +64,8 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s return self._binho # import the Binho libraries - from binhoHostAdapter import binhoHostAdapter - from binhoHostAdapter import binhoUtilities - - utilities = binhoUtilities.binhoUtilities() - devices = utilities.listAvailableDevices() - - count = len(devices) - - if count == 0: - self._binho = None - raise RuntimeError('BLINKA_NOVA environment variable' + \ - 'set, but no Binho host adapter found.') + from adafruit_blinka.microcontroller.nova import Connection + self._binho = Connection.getInstance() self._binho = BINHO return BINHO From 0d67ae6fe4b8541ff7b1fc642ca7e092c38120df Mon Sep 17 00:00:00 2001 From: Jonathan Georgino Date: Sat, 16 Nov 2019 14:03:25 -0800 Subject: [PATCH 07/14] Added support for Binho Nova Multi-Protocol USB Host Adapter --- adafruit_platformdetect/board.py | 9 +++++++++ adafruit_platformdetect/chip.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index 3f7c5b16..3da1472f 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -68,6 +68,8 @@ MICROCHIP_MCP2221 = "MICROCHIP_MCP2221" +BINHO_NOVA = "BINHO" + # pylint: enable=bad-whitespace #OrangePI @@ -339,6 +341,8 @@ def id(self): board_id = self._sifive_id() elif chip_id == ap_chip.MCP2221: board_id = MICROCHIP_MCP2221 + elif chip_id == ap_chip.BINHO: + board_id = BINHO_NOVA return board_id # pylint: enable=invalid-name @@ -503,6 +507,11 @@ def microchip_mcp2221(self): """Check whether the current board is a Microchip MCP2221.""" return self.id == MICROCHIP_MCP2221 + @property + def binho_nova(self): + """Check whether the current board is an BINHO NOVA.""" + return self.id == BINHO_NOVA + def __getattr__(self, attr): """ Detect whether the given attribute is the currently-detected board. See list diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index b92b5f8f..8b8d926a 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -21,6 +21,7 @@ FT232H = "FT232H" HFU540 = "HFU540" MCP2221 = "MCP2221" +BINHO = "BINHO" class Chip: """Attempt detection of current chip / CPU.""" @@ -54,6 +55,20 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s return MCP2221 raise RuntimeError('BLINKA_MCP2221 environment variable ' + \ 'set, but no MCP2221 device found') + if os.environ.get('BLINKA_BINHO'): + # import the Binho libraries + from binhoHostAdapter import binhoHostAdapter + from binhoHostAdapter import binhoUtilities + + utilities = binhoUtilities.binhoUtilities() + devices = utilities.listAvailableDevices() + + count = len(devices) + + if count == 0: + raise RuntimeError('BLINKA_BINHO environment variable' + \ + 'set, but no Binho host adapter found.') + return BINHO platform = sys.platform if platform == "linux" or platform == "linux2": From 86c99316dc92f06bb02e9e04c7b5fbbe785713d7 Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Sat, 16 Nov 2019 21:04:49 -0800 Subject: [PATCH 08/14] Use BLINKA_NOVA as env variable instead --- adafruit_platformdetect/chip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 8b8d926a..e70036db 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -55,7 +55,7 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s return MCP2221 raise RuntimeError('BLINKA_MCP2221 environment variable ' + \ 'set, but no MCP2221 device found') - if os.environ.get('BLINKA_BINHO'): + if os.environ.get('BLINKA_NOVA'): # import the Binho libraries from binhoHostAdapter import binhoHostAdapter from binhoHostAdapter import binhoUtilities From bf78cc67776b5876983e8eb32b37126fa8d18a88 Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Sun, 17 Nov 2019 22:27:20 -0800 Subject: [PATCH 09/14] change board id to NOVA and fix issue with autodetect being called multiple times after there's already a binho object --- adafruit_platformdetect/board.py | 2 +- adafruit_platformdetect/chip.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index 3da1472f..91ac873b 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -68,7 +68,7 @@ MICROCHIP_MCP2221 = "MICROCHIP_MCP2221" -BINHO_NOVA = "BINHO" +BINHO_NOVA = "NOVA" # pylint: enable=bad-whitespace diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index e70036db..d134b46b 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -27,6 +27,7 @@ class Chip: """Attempt detection of current chip / CPU.""" def __init__(self, detector): self.detector = detector + self._binho = None @property def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements @@ -56,6 +57,10 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s raise RuntimeError('BLINKA_MCP2221 environment variable ' + \ 'set, but no MCP2221 device found') if os.environ.get('BLINKA_NOVA'): + # Check if we already have a binho instance + if self._binho is not None and self._binho == BINHO: + return self._binho + # import the Binho libraries from binhoHostAdapter import binhoHostAdapter from binhoHostAdapter import binhoUtilities @@ -66,8 +71,10 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s count = len(devices) if count == 0: + self._binho = None raise RuntimeError('BLINKA_BINHO environment variable' + \ 'set, but no Binho host adapter found.') + self._binho = BINHO return BINHO platform = sys.platform From 9c684461c2c65ed7f7cde2941d7dc0f522f14899 Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Tue, 19 Nov 2019 18:04:27 -0800 Subject: [PATCH 10/14] set _binho only if BLINKA_NOVA env variable exists --- adafruit_platformdetect/chip.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index d134b46b..68be8c5c 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -27,7 +27,11 @@ class Chip: """Attempt detection of current chip / CPU.""" def __init__(self, detector): self.detector = detector - self._binho = None + try: + os.environ.get('BLINKA_NOVA'): + self._binho = None + except KeyError: # no relevant environment var + pass @property def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements From 50840337b7e3b2c0438f4b61ef438c550b76daab Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Sat, 23 Nov 2019 14:37:07 -0800 Subject: [PATCH 11/14] Use binho connection singleton --- adafruit_platformdetect/chip.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 68be8c5c..2f76058b 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -27,11 +27,6 @@ class Chip: """Attempt detection of current chip / CPU.""" def __init__(self, detector): self.detector = detector - try: - os.environ.get('BLINKA_NOVA'): - self._binho = None - except KeyError: # no relevant environment var - pass @property def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements @@ -61,24 +56,12 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s raise RuntimeError('BLINKA_MCP2221 environment variable ' + \ 'set, but no MCP2221 device found') if os.environ.get('BLINKA_NOVA'): - # Check if we already have a binho instance - if self._binho is not None and self._binho == BINHO: - return self._binho - - # import the Binho libraries - from binhoHostAdapter import binhoHostAdapter - from binhoHostAdapter import binhoUtilities - - utilities = binhoUtilities.binhoUtilities() - devices = utilities.listAvailableDevices() - - count = len(devices) - - if count == 0: - self._binho = None - raise RuntimeError('BLINKA_BINHO environment variable' + \ - 'set, but no Binho host adapter found.') - self._binho = BINHO + # Check for Nova connection + from adafruit_blinka.microcontroller.nova import Connection + binho = Connection.getInstance() + if binho == None: + raise RuntimeError('BLINKA_NOVA environment variable ' + \ + 'set, but no NOVA device found') return BINHO platform = sys.platform From 0a1c8ff2c78b678c2285fa9cb734af94e2e13bdd Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Mon, 2 Dec 2019 15:52:54 -0800 Subject: [PATCH 12/14] Clean up and remove unused code --- adafruit_platformdetect/chip.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index bbe2c7a1..2f76058b 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -27,11 +27,6 @@ class Chip: """Attempt detection of current chip / CPU.""" def __init__(self, detector): self.detector = detector - try: - if os.environ['BLINKA_NOVA']: - self._binho = None - except KeyError: # no relevant environment var - pass @property def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements From ea802ab728c9fa9871078abc4f6fabf80b3f72d7 Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Mon, 2 Dec 2019 16:43:10 -0800 Subject: [PATCH 13/14] Fix Comparison expr is None check from pylint --- adafruit_platformdetect/chip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index 2f76058b..3dbd1a66 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -59,7 +59,7 @@ def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-s # Check for Nova connection from adafruit_blinka.microcontroller.nova import Connection binho = Connection.getInstance() - if binho == None: + if binho is None: raise RuntimeError('BLINKA_NOVA environment variable ' + \ 'set, but no NOVA device found') return BINHO From 6f7af39447e8a585c50c8cc05bdd69e27530c3a7 Mon Sep 17 00:00:00 2001 From: Francis Guevarra Date: Mon, 2 Dec 2019 17:39:33 -0800 Subject: [PATCH 14/14] Rename board to BINHO_NOVA --- adafruit_platformdetect/board.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index 91ac873b..2d92a8bf 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -68,7 +68,7 @@ MICROCHIP_MCP2221 = "MICROCHIP_MCP2221" -BINHO_NOVA = "NOVA" +BINHO_NOVA = "BINHO_NOVA" # pylint: enable=bad-whitespace