From 91ed81bfcd12753866eb5f97fcb04a7e45cf4f74 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Mon, 16 Oct 2023 20:12:55 +0300 Subject: [PATCH] Add Linxdot RK3566 hardware defs --- hm_pyhelper/hardware_definitions.py | 19 +++++++++++---- hm_pyhelper/sbc.py | 10 +++++++- .../tests/test_hardware_definitions.py | 24 +++++++++++++++++-- 3 files changed, 45 insertions(+), 8 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 9626ef5..f4fabd3 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 } @@ -178,10 +182,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..2cc40b6 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" @@ -178,3 +179,22 @@ def test_is_bobcat_rk3566(self): # which will not exist on test environment. with 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 self.assertRaises(FileNotFoundError): + self.assertFalse(is_linxdot_rk3566())