improve devlib/util.py

This commit is contained in:
Ta-Shun Su
2019-05-24 16:35:25 +08:00
parent d9039070ad
commit 2ee3abf193
2 changed files with 11 additions and 4 deletions
+2 -2
View File
@@ -16,5 +16,5 @@ STI_PARAMETER = {
'STI_NUM': 10,
}
print_instruction(STI_INSTRUCTION['GLOBAL'], STI_PARAMETER)
print_instruction(STI_INSTRUCTION['LOCAL'], STI_PARAMETER)
print_instruction(STI_INSTRUCTION['GLOBAL'], STI_PARAMETER, c_style_uint8_array='buf')
print_instruction(STI_INSTRUCTION['LOCAL'], STI_PARAMETER, c_style_uint8_array='buf')
+9 -2
View File
@@ -569,7 +569,10 @@ def eval_instruction(expr: str, context: Dict[str, Any], buffer: Optional[List[i
return buffer
def print_instruction(expr: str, context: Dict[str, Any], append_ris_type: bool = True):
def print_instruction(expr: str,
context: Dict[str, Any],
append_ris_type: bool = True,
c_style_uint8_array: Optional[str] = None):
buffer = []
eval_instruction(expr, context, buffer)
@@ -579,4 +582,8 @@ def print_instruction(expr: str, context: Dict[str, Any], append_ris_type: bool
buffer.insert(0, 0x30)
buffer.insert(1, length)
print(hex_line(buffer))
if c_style_uint8_array is None:
print(hex_line(buffer))
else:
for i, v in enumerate(buffer):
print(c_style_uint8_array, '[%d]' % i, ' = ', '0x%02X' % v, ';', sep='')