From 4d10c10acaaa31502c2742392c4a5e4a7888be28 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 27 Oct 2024 09:05:46 +0200 Subject: [PATCH] Add Linxdot RK3566 hardware defs (#290) * Add Linxdot RK3566 hardware defs * Update pyproject.toml * Update test_hardware_definitions.py * Update test_hardware_definitions.py --------- Co-authored-by: Aaron Shaw --- hm_pyhelper/hardware_definitions.py | 19 +++++++--- hm_pyhelper/sbc.py | 10 ++++- .../tests/test_hardware_definitions.py | 37 ++++++++++++++++--- pyproject.toml | 2 +- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/hm_pyhelper/hardware_definitions.py b/hm_pyhelper/hardware_definitions.py index 9c54d2d..58eea6a 100644 --- a/hm_pyhelper/hardware_definitions.py +++ b/hm_pyhelper/hardware_definitions.py @@ -11,6 +11,10 @@ def is_bobcat_rk3566() -> bool: return sbc.is_sbc_type(sbc.DeviceVendorID.BOBCAT_RK3566) +def is_linxdot_rk3566() -> bool: + return sbc.is_sbc_type(sbc.DeviceVendorID.LINXDOT_RK3566) + + def is_rockpi() -> bool: return sbc.is_sbc_type(sbc.DeviceVendorID.ROCK_PI) @@ -511,19 +515,24 @@ def is_raspberry_pi() -> bool: 'CONTAINS_IC_IDS': [] }, - # Linxdot RKCM3 + # Linxdot RK3566 'linxdot-rk3566-fl1': { 'FRIENDLY': 'Linxdot RK3566 Hotspot', 'SUPPORTED_MODELS': ['Linxdot RK3566 Hotspot'], 'CPU_ARCH': 'arm64', 'BALENA_DEVICE_TYPE': ['nanopc-t4'], 'SPIBUS': 'spidev0.0', - 'SWARM_KEY_URI': ['ecc://i2c-1:96?slot=0'], - 'ONBOARDING_KEY_URI': ['ecc://i2c-1:96?slot=0'], + 'SWARM_KEY_URI': ['ecc://i2c-5:96?slot=1'], + 'ONBOARDING_KEY_URI': ['ecc://i2c-5:96?slot=1'], 'RESET': 17, 'MAC': 'wlan0', - 'STATUS': 22, - 'BUTTON': 27, + 'STATUS': None, + 'BUTTON': None, + 'BUTTON_ADC': { + 'PATH': '/sys/bus/iio/devices/iio:device0/in_voltage0_raw', + 'ACTIVE_BELOW': 500, + }, + 'STATUS_LINUX_LED': '/sys/devices/platform/leds/leds/work-led1/brightness', 'ECCOB': True, 'TYPE': 'Full', 'CELLULAR': False, diff --git a/hm_pyhelper/sbc.py b/hm_pyhelper/sbc.py index 5574cc6..f11acdc 100644 --- a/hm_pyhelper/sbc.py +++ b/hm_pyhelper/sbc.py @@ -21,6 +21,7 @@ class DeviceVendorID(Enum): RASPBERRY_PI = auto() BOBCAT_PX30 = auto() BOBCAT_RK3566 = auto() + LINXDOT_RK3566 = auto() # Pulled from @@ -42,9 +43,12 @@ class DeviceVendorID(Enum): BALENA_ENV_BOBCATRK3566_MODELS = ['rockpro64'] +BALENA_ENV_LINXDOTRK3566_MODELS = ['nanopc-t4'] + BALENA_MODELS = { DeviceVendorID.BOBCAT_PX30: BALENA_ENV_BOBCATPX30_MODELS, DeviceVendorID.BOBCAT_RK3566: BALENA_ENV_BOBCATRK3566_MODELS, + DeviceVendorID.LINXDOT_RK3566: BALENA_ENV_LINXDOTRK3566_MODELS, DeviceVendorID.ROCK_PI: BALENA_ENV_ROCKPI_MODELS, DeviceVendorID.RASPBERRY_PI: BALENA_ENV_RASPBERRY_PI_MODELS } @@ -179,10 +183,14 @@ def sbc_info() -> SBCInfo: sbc_info = SBCInfo(vendor_id=DeviceVendorID.RASPBERRY_PI, vendor_name='Raspberry Pi', model_name=dev_model) - elif dev_model.lower().find('rk3566') >= 0: + elif dev_model.lower().find('rk3566 evb2') >= 0: sbc_info = SBCInfo(vendor_id=DeviceVendorID.BOBCAT_RK3566, vendor_name='Bobcat', model_name=dev_model) + elif dev_model.lower().find('rk3566 r01') >= 0: + sbc_info = SBCInfo(vendor_id=DeviceVendorID.LINXDOT_RK3566, + vendor_name='Linxdot', + model_name=dev_model) elif dev_model.lower().find('rock') >= 0: sbc_info = SBCInfo(vendor_id=DeviceVendorID.ROCK_PI, vendor_name='Radxa Rock Pi', diff --git a/hm_pyhelper/tests/test_hardware_definitions.py b/hm_pyhelper/tests/test_hardware_definitions.py index 856344d..8b34fec 100644 --- a/hm_pyhelper/tests/test_hardware_definitions.py +++ b/hm_pyhelper/tests/test_hardware_definitions.py @@ -7,9 +7,10 @@ UnknownVariantAttributeException from hm_pyhelper.hardware_definitions import is_rockpi, variant_definitions, \ - get_variant_attribute, is_raspberry_pi, is_bobcat_px30, is_bobcat_rk3566 + get_variant_attribute, is_raspberry_pi, is_bobcat_px30, is_bobcat_rk3566, is_linxdot_rk3566 from hm_pyhelper.sbc import BALENA_ENV_RASPBERRY_PI_MODELS, \ - BALENA_ENV_ROCKPI_MODELS, BALENA_ENV_BOBCATPX30_MODELS, BALENA_ENV_BOBCATRK3566_MODELS + BALENA_ENV_ROCKPI_MODELS, BALENA_ENV_BOBCATPX30_MODELS, BALENA_ENV_BOBCATRK3566_MODELS, \ + BALENA_ENV_LINXDOTRK3566_MODELS BUILTINS_OPEN_LITERAL = "builtins.open" @@ -119,7 +120,8 @@ def test_is_raspberry_pi(self): self.assertTrue(is_raspberry_pi()) # in absence of the env, it should look for /proc/device-tree/model # which will not exist on test environment. - with self.assertRaises(FileNotFoundError): + with patch.dict(os.environ, {'BALENA_DEVICE_TYPE': "something"}): + self.assertRaises(FileNotFoundError) self.assertFalse(is_raspberry_pi()) mock_known_rock_dts_models = ["ROCK PI 4B"] @@ -138,7 +140,8 @@ def test_is_rock_pi(self): self.assertTrue(is_rockpi()) # in absence of the env, it should look for /proc/device-tree/model # which will not exist on test environment. - with self.assertRaises(FileNotFoundError): + with patch.dict(os.environ, {'BALENA_DEVICE_TYPE': "something"}): + self.assertRaises(FileNotFoundError) self.assertFalse(is_rockpi()) mock_known_bobcat_px30_dts_models = ["Bobcat PX30"] @@ -157,7 +160,8 @@ def test_is_bobcat_px30(self): self.assertTrue(is_bobcat_px30()) # in absence of the env, it should look for /proc/device-tree/model # which will not exist on test environment. - with self.assertRaises(FileNotFoundError): + with patch.dict(os.environ, {'BALENA_DEVICE_TYPE': "something"}): + self.assertRaises(FileNotFoundError) self.assertFalse(is_bobcat_px30()) mock_known_bobcat_rk3566_dts_models = ["Rockchip RK3566 EVB2 LP4X V10 Board"] @@ -176,5 +180,26 @@ def test_is_bobcat_rk3566(self): self.assertTrue(is_bobcat_rk3566()) # in absence of the env, it should look for /proc/device-tree/model # which will not exist on test environment. - with self.assertRaises(FileNotFoundError): + with patch.dict(os.environ, {'BALENA_DEVICE_TYPE': "something"}): + self.assertRaises(FileNotFoundError) self.assertFalse(is_bobcat_rk3566()) + + mock_known_linxdot_rk3566_dts_models = ["Linxdot RK3566 R01"] + + def test_is_linxdot_rk3566(self): + for model in self.mock_known_linxdot_rk3566_dts_models: + with patch(BUILTINS_OPEN_LITERAL, new_callable=mock_open, read_data=model): + self.assertTrue(is_linxdot_rk3566()) + with patch(BUILTINS_OPEN_LITERAL, new_callable=mock_open, + read_data="raspberry something"): + self.assertFalse(is_linxdot_rk3566()) + + # test balena env based detection + for model in BALENA_ENV_LINXDOTRK3566_MODELS: + with patch.dict(os.environ, {'BALENA_DEVICE_TYPE': model}): + self.assertTrue(is_linxdot_rk3566()) + # in absence of the env, it should look for /proc/device-tree/model + # which will not exist on test environment. + with patch.dict(os.environ, {'BALENA_DEVICE_TYPE': "something"}): + self.assertRaises(FileNotFoundError) + self.assertFalse(is_linxdot_rk3566()) diff --git a/pyproject.toml b/pyproject.toml index 97870c9..098e2ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "hm_pyhelper" -version = "0.14.35" +version = "0.14.36" description = "Helium Python Helper" authors = ["Nebra Ltd "] readme = "README.md"