Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 3453ec6
Author: Fabio Battaglia <tabaglio@posteo.net>
Date:   Mon Aug 12 18:47:34 2024 +0200

    changes required to use dupicolib 0.4.0
  • Loading branch information
hkzlab committed Aug 12, 2024
1 parent 3c84d11 commit d8a557b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"austin.mode": "Wall time"
"austin.mode": "Wall time",
"python.analysis.typeCheckingMode": "basic"
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
Changelog for the dpdumper utility

## [0.3.0] - 2024-08-12
## Changed
- Depends on dupicolib 0.4.0

## [0.2.1] - 2024-08-12
### Changed
- Require dupicolib 0.3.2
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "dpdumper"
version = "0.2.1"
version = "0.3.0"
description = "Tool to use the dupico as a dumping device"
authors = [
{ name = "Fabio Battaglia", email = "hkzlabnet@gmail.com" }
Expand All @@ -18,7 +18,7 @@ classifiers = [
requires-python = ">=3.12"
dependencies = [
"pyserial ~= 3.5",
"dupicolib >= 0.3.2"
"dupicolib >= 0.4.0"
]

[project.scripts]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pyserial>=3.5
setuptools==72.1.0
build==1.2.1
pytest==8.3.2
dupicolib>=0.3.2
mypy==1.11.1
dupicolib>=0.4.0
14 changes: 7 additions & 7 deletions src/dpdumper/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from enum import Enum

from dupicolib.board_commands import BoardCommands
from dupicolib.hardware_board_commands import HardwareBoardCommands
from dupicolib.board_command_class_factory import BoardCommandClassFactory
from dupicolib.board_utilities import BoardUtilities
from dupicolib.board_fw_version import FwVersionTools, FWVersionDict
Expand Down Expand Up @@ -111,7 +111,7 @@ def print_note(note: str, delay: int = 5) -> None:
time.sleep(1)
print(' ' * 80, end='\r')

def test_command(ser: serial.Serial, cmd_class: BoardCommands) -> None:
def test_command(ser: serial.Serial, cmd_class: type[HardwareBoardCommands]) -> None:
delay: int = 5

print('Make sure the ZIF socket is empty before starting the test!')
Expand All @@ -128,7 +128,7 @@ def test_command(ser: serial.Serial, cmd_class: BoardCommands) -> None:
else:
print(f'Test result is {"OK" if test_result else "BAD"}!')

def read_command(ser: serial.Serial, cmd_class: BoardCommands, ic_definition: ICDefinition, outf: str, outfb: str | None = None, check_hiz: bool = False, hiz_high: bool = False, skip_note: bool = False) -> None:
def read_command(ser: serial.Serial, cmd_class: type[HardwareBoardCommands], ic_definition: ICDefinition, outf: str, outfb: str | None = None, check_hiz: bool = False, hiz_high: bool = False, skip_note: bool = False) -> None:
_LOGGER.debug(f'Read command with definition {ic_definition.name}, output table {outf}, output binary {outfb}, check hi-z {check_hiz}, treat hi-z as high {hiz_high}')

print(f'Reading from IC {ic_definition.name}')
Expand Down Expand Up @@ -158,7 +158,7 @@ def read_command(ser: serial.Serial, cmd_class: BoardCommands, ic_definition: IC

return

def write_command(ser: serial.Serial, cmd_class: BoardCommands, ic_definition: ICDefinition, inf: str, skip_note: bool = False) -> None:
def write_command(ser: serial.Serial, cmd_class: type[HardwareBoardCommands], ic_definition: ICDefinition, inf: str, skip_note: bool = False) -> None:
_LOGGER.debug(f'Write command with definition {ic_definition.name} and input file {inf}')

print('⚠️ Writing is untested ⚠️\n')
Expand Down Expand Up @@ -206,7 +206,7 @@ def cli() -> int:
return -1

_LOGGER.info(f'Board connected @{args.port}, speed:{args.baudrate} ...')
model: int | None = BoardCommands.get_model(ser_port)
model: int | None = HardwareBoardCommands.get_model(ser_port)
if model is None:
_LOGGER.critical('Unable to retrieve model number...')
return -1
Expand All @@ -216,7 +216,7 @@ def cli() -> int:
else:
_LOGGER.info(f'Model {model} detected!')

fw_version: str | None = BoardCommands.get_version(ser_port)
fw_version: str | None = HardwareBoardCommands.get_version(ser_port)
fw_version_dict: FWVersionDict
if fw_version is None:
_LOGGER.critical('Unable to retrieve firmware version...')
Expand All @@ -226,7 +226,7 @@ def cli() -> int:
_LOGGER.info(f'Firmware version on board is "{fw_version}"')

# Now we have enough information to obtain the class that handles commands specific for this board
command_class: BoardCommands = BoardCommandClassFactory.get_command_class(model, fw_version_dict)
command_class: type[HardwareBoardCommands] = BoardCommandClassFactory.get_command_class(model, fw_version_dict) # type: ignore

# Load and check IC definition requirements
ic_definition: ICDefinition
Expand Down
32 changes: 16 additions & 16 deletions src/dpdumper/hl_board_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import math
import logging

from dupicolib.board_commands import BoardCommands
from dupicolib.hardware_board_commands import HardwareBoardCommands

from dpdumper.ic.ic_definition import ICDefinition
from dpdumper.dumper_utilities import grouped_iterator
Expand All @@ -23,7 +23,7 @@ def _print_progressBar (iteration: int, total: int, prefix: str = '', suffix: st
if iteration == total:
print()

def _read_pin_map_generator(cmd_class: BoardCommands, ic: ICDefinition, check_hiz: bool = False) -> Generator[int, None, None]:
def _read_pin_map_generator(cmd_class: type[HardwareBoardCommands], ic: ICDefinition, check_hiz: bool = False) -> Generator[int, None, None]:
addr_combs: int = 1 << len(ic.address) # Calculate the number of addresses that this IC supports

hi_pins_mapped: int = cmd_class.map_value_to_pins(ic.adapter_hi_pins, 0xFFFFFFFFFFFFFFFF)
Expand Down Expand Up @@ -58,7 +58,7 @@ class HLBoardUtilities:
_MAX_CONSECUTIVE_COMMANDS: int = 8

@classmethod
def read_ic(cls, ser: serial.Serial, cmd_class: BoardCommands, ic: ICDefinition, check_hiz: bool = False) -> list[DataElement] | None:
def read_ic(cls, ser: serial.Serial, cmd_class: type[HardwareBoardCommands], ic: ICDefinition, check_hiz: bool = False) -> list[DataElement] | None:
read_data: list[DataElement] = []
addr_combs: int = 1 << len(ic.address) # Calculate the number of addresses that this IC supports
wr_responses: list[int] = []
Expand All @@ -70,8 +70,8 @@ def read_ic(cls, ser: serial.Serial, cmd_class: BoardCommands, ic: ICDefinition,

_LOGGER.debug(f'This IC requires the following pin mask forced high: {hi_pins_mapped:0{16}X}')

cmd_class.write_pins(ser, hi_pins_mapped) # Start with these already enabled
cmd_class.set_power(ser, True)
cmd_class.write_pins(hi_pins_mapped, ser) # Start with these already enabled
cmd_class.set_power(True, ser)

tot_combs: int = addr_combs if not check_hiz else addr_combs * 2

Expand All @@ -81,7 +81,7 @@ def read_ic(cls, ser: serial.Serial, cmd_class: BoardCommands, ic: ICDefinition,
if i % 250 == 0:
_print_progressBar(i, tot_combs)

wr_addr_response: int | None = cmd_class.write_pins(ser, pin_map)
wr_addr_response: int | None = cmd_class.write_pins(pin_map, ser)

if wr_addr_response is None:
return None # Something went wrong
Expand All @@ -101,13 +101,13 @@ def read_ic(cls, ser: serial.Serial, cmd_class: BoardCommands, ic: ICDefinition,
_LOGGER.critical(exc)
finally:
print('') # Avoid writing again on the 'Testing block' string
cmd_class.set_power(ser, False)
cmd_class.write_pins(ser, 0)
cmd_class.set_power(False, ser)
cmd_class.write_pins(0, ser)

return read_data[:addr_combs]

@staticmethod
def write_ic(ser: serial.Serial, cmd_class: BoardCommands, ic: ICDefinition, data: list[int]) -> None:
def write_ic(ser: serial.Serial, cmd_class: type[HardwareBoardCommands], ic: ICDefinition, data: list[int]) -> None:
data_width: int = int(math.ceil(len(ic.data) / 8.0))
addr_combs: int = 1 << len(ic.address) # Calculate the number of addresses that this IC supports
_LOGGER.debug(f'write_ic command with definition {ic.name}, IC has {addr_combs} addresses and data width {data_width} bits.')
Expand All @@ -130,8 +130,8 @@ def write_ic(ser: serial.Serial, cmd_class: BoardCommands, ic: ICDefinition, dat

try:
# Start with the pins that must be forced high
cmd_class.write_pins(ser, hi_pins_mapped)
cmd_class.set_power(ser, True)
cmd_class.write_pins(hi_pins_mapped, ser)
cmd_class.set_power(True, ser)

for i in range(0, addr_combs):
if i % 250 == 0:
Expand All @@ -141,17 +141,17 @@ def write_ic(ser: serial.Serial, cmd_class: BoardCommands, ic: ICDefinition, dat
data_mapped: int = cmd_class.map_value_to_pins(ic.data, data[i])

# Set data and address, but with writing disabled
cmd_class.write_pins(ser, hi_pins_mapped | address_mapped | data_mapped | act_h_mapped | wr_l_mapped)
cmd_class.write_pins(hi_pins_mapped | address_mapped | data_mapped | act_h_mapped | wr_l_mapped, ser)
# Enable writing
cmd_class.write_pins(ser, hi_pins_mapped | address_mapped | data_mapped | act_h_mapped | wr_h_mapped)
cmd_class.write_pins(hi_pins_mapped | address_mapped | data_mapped | act_h_mapped | wr_h_mapped, ser)
# Disable writing before switching to the next address
cmd_class.write_pins(ser, hi_pins_mapped | address_mapped | data_mapped | act_h_mapped | wr_l_mapped)
cmd_class.write_pins(hi_pins_mapped | address_mapped | data_mapped | act_h_mapped | wr_l_mapped, ser)

_print_progressBar(addr_combs, addr_combs)
finally:
print('')
cmd_class.set_power(ser, False)
cmd_class.write_pins(ser, 0)
cmd_class.set_power(False, ser)
cmd_class.write_pins(0, ser)



0 comments on commit d8a557b

Please sign in to comment.