From 02de7b066b2b457c56c484b13d57592678f55de9 Mon Sep 17 00:00:00 2001 From: Sergey Shchelkanov Date: Tue, 25 Apr 2023 17:10:30 +0300 Subject: [PATCH] use python 3.8 typing syntax --- mik32_eeprom.py | 10 +++++----- mik32_parsers.py | 15 ++++++++------- mik32_spifi.py | 11 ++++++----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mik32_eeprom.py b/mik32_eeprom.py index 417388b..e8d1f7a 100644 --- a/mik32_eeprom.py +++ b/mik32_eeprom.py @@ -1,4 +1,4 @@ - +from typing import List import time from .tclrpc import TclException from .tclrpc import OpenOcdTclRpc @@ -139,7 +139,7 @@ def eeprom_write_word(openocd: OpenOcdTclRpc, address:int, word:int): openocd.write_word(EEPROM_REGS_EECON, (1 << EEPROM_EX_S) | (1 << EEPROM_BWE_S) | (EEPROM_OP_PR << EEPROM_OP_S)) time.sleep(0.001) -def eeprom_write_page(openocd: OpenOcdTclRpc, address:int, data:list[int]): +def eeprom_write_page(openocd: OpenOcdTclRpc, address:int, data:List[int]): openocd.write_word(EEPROM_REGS_EECON, 1 << EEPROM_BWE_S) openocd.write_word(EEPROM_REGS_EEA, address) page_address = address & EEPROM_PAGE_MASK @@ -152,7 +152,7 @@ def eeprom_write_page(openocd: OpenOcdTclRpc, address:int, data:list[int]): openocd.write_word(EEPROM_REGS_EECON, (1 << EEPROM_EX_S) | (1 << EEPROM_BWE_S) | (EEPROM_OP_PR << EEPROM_OP_S)) time.sleep(0.001) -def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: list[int]) -> int: +def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: List[int]) -> int: print("EEPROM check through APB...") openocd.write_word(EEPROM_REGS_EEA, 0x00000000) word_num = 0 @@ -172,7 +172,7 @@ def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: list[int]) -> int: print("EEPROM check through APB done!") return 0 -def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: list[int]) -> int: +def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: List[int]) -> int: print("EEPROM check through AHB-Lite...") mem_array = openocd.read_memory(0x01000000, 32, len(words)) if len(words) != len(mem_array): @@ -193,7 +193,7 @@ def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: list[int]) -> int: return 0 -def write_words(words: list[int], write_by_word = False, read_through_apb = False, is_resume=True) -> int: +def write_words(words: List[int], write_by_word = False, read_through_apb = False, is_resume=True) -> int: """ Write words in MIK32 EEPROM through APB bus diff --git a/mik32_parsers.py b/mik32_parsers.py index 772fea7..03491ea 100644 --- a/mik32_parsers.py +++ b/mik32_parsers.py @@ -1,5 +1,6 @@ +from typing import List, Dict -def parse_hex(file: str) -> dict: +def parse_hex(file: str) -> Dict: """ TODO: Implement support for more record types """ @@ -30,7 +31,7 @@ def parse_hex(file: str) -> dict: reclen = int(line[1:3], base=16) # Record length load_offset = int(line[3:7], base=16) # Initial address of data byte rectype = int(line[7:9], base=16) # Record type - data_bytes: list[str] = [] + data_bytes: List[str] = [] data_bytes_line = line[9:reclen*2 + 9] for i in range(reclen): @@ -95,15 +96,15 @@ def parse_hex(file: str) -> dict: return memory_blocks -def parse_bin(filename: str) -> list[int]: - arr: list[int] = [] +def parse_bin(filename: str) -> List[int]: + arr: List[int] = [] with open(filename, "rb") as f: while byte := f.read(1): arr.append(byte[0]) return arr -def bytes2words(arr: list[int]) -> list[int]: +def bytes2words(arr: List[int]) -> List[int]: word = [] words = [] for byte in arr: @@ -113,8 +114,8 @@ def bytes2words(arr: list[int]) -> list[int]: word = [] return words -def get_content(filename: str) -> list[int]: - content: list[int] = [] +def get_content(filename: str) -> List[int]: + content: List[int] = [] if filename.endswith(".bin"): content = parse_bin(filename) diff --git a/mik32_spifi.py b/mik32_spifi.py index d89e672..f334894 100644 --- a/mik32_spifi.py +++ b/mik32_spifi.py @@ -1,3 +1,4 @@ +from typing import List import time from .tclrpc import TclException from .tclrpc import OpenOcdTclRpc @@ -333,9 +334,9 @@ def spifi_chip_erase(openocd: OpenOcdTclRpc): spifi_wait_intrq_timeout(openocd, "Timeout executing chip erase command") -def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: list[int]): +def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: List[int]): print("read data") - read_data: list[int] = [] + read_data: List[int] = [] openocd.write_word(SPIFI_CONFIG_ADDR, address) """ @@ -375,7 +376,7 @@ def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_d print(f"DATA[{i+address}] = {read_data[i]:#0x} - ошибка") -def spifi_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: list[int], byte_count: int): +def spifi_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: List[int], byte_count: int): if byte_count > 256: raise Exception("Byte count more than 256") @@ -409,7 +410,7 @@ def spifi_erase(openocd): spifi_wait_busy(openocd) -def spifi_write(openocd: OpenOcdTclRpc, address: int, data: list[int], data_len: int): +def spifi_write(openocd: OpenOcdTclRpc, address: int, data: List[int], data_len: int): if data_len > 256: raise Exception("Byte count more than 256") @@ -420,7 +421,7 @@ def spifi_write(openocd: OpenOcdTclRpc, address: int, data: list[int], data_len: print("written") -def spifi_write_file(bytes: list[int], is_resume=True): +def spifi_write_file(bytes: List[int], is_resume=True): """ Write bytes in MIK32 External SPIFI Flash memory