modm_data.owl.stmicro.identifier
1# Copyright 2022, Niklas Hauser 2# SPDX-License-Identifier: MPL-2.0 3 4from ..identifier import DeviceIdentifier 5 6 7def did_from_string(string) -> DeviceIdentifier: 8 string = string.lower() 9 10 if string.startswith("stm32"): 11 schema = "{platform}{family}{name}{pin}{size}{package}{temperature}{variant}" 12 if "@" in string: 13 schema += "@{core}" 14 i = DeviceIdentifier(schema) 15 i.set("platform", "stm32") 16 i.set("family", string[5:7]) 17 i.set("name", string[7:9]) 18 i.set("pin", string[9]) 19 i.set("size", string[10]) 20 i.set("package", string[11]) 21 i.set("temperature", string[12]) 22 if "@" in string: 23 string, core = string.split("@") 24 i.set("core", core) 25 if len(string) >= 14: 26 i.set("variant", string[13]) 27 else: 28 i.set("variant", "") 29 return i 30 31 raise ValueError(f"Unknown identifier '{string}'!")
8def did_from_string(string) -> DeviceIdentifier: 9 string = string.lower() 10 11 if string.startswith("stm32"): 12 schema = "{platform}{family}{name}{pin}{size}{package}{temperature}{variant}" 13 if "@" in string: 14 schema += "@{core}" 15 i = DeviceIdentifier(schema) 16 i.set("platform", "stm32") 17 i.set("family", string[5:7]) 18 i.set("name", string[7:9]) 19 i.set("pin", string[9]) 20 i.set("size", string[10]) 21 i.set("package", string[11]) 22 i.set("temperature", string[12]) 23 if "@" in string: 24 string, core = string.split("@") 25 i.set("core", core) 26 if len(string) >= 14: 27 i.set("variant", string[13]) 28 else: 29 i.set("variant", "") 30 return i 31 32 raise ValueError(f"Unknown identifier '{string}'!")