Skip to content

Commit

Permalink
Add register write command
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Nov 4, 2023
1 parent d4d14e5 commit a31d5f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bk7231tools/serial/cmd_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
BkReadRegResp,
BkRebootCmnd,
BkSetBaudRateCmnd,
BkWriteRegCmnd,
)
from .protocol import CHIP_BY_CRC, PROTOCOLS, BK7231Protocol, ProtocolType
from .utils import fix_addr
Expand Down Expand Up @@ -99,6 +100,10 @@ def register_read(self, address: int) -> int:
response: BkReadRegResp = self.command(command)
return response.value

def register_write(self, address: int, value: int) -> None:
command = BkWriteRegCmnd(address, value)
self.command(command)

def read_flash_range_crc(self, start: int, end: int) -> int:
start = fix_addr(start)
end = fix_addr(end)
Expand Down
11 changes: 11 additions & 0 deletions bk7231tools/serial/packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class BkLinkCheckResp(Packet):

@dataclass
class BkWriteRegCmnd(Packet):
CODE = 0x01 # CMD_WriteReg
FORMAT = "<II"
HAS_RESP_OTHER = True
HAS_RESP_SAME = slice(0, 8)
address: int
value: int


@dataclass
class BkWriteRegResp(Packet):
CODE = 0x01 # CMD_WriteReg
FORMAT = "<II"
address: int
Expand Down Expand Up @@ -277,6 +287,7 @@ def deserialize(cls, data: bytes) -> "Packet":
RESPONSE_TABLE: Dict[Type[Packet], Type[Packet]] = {
# short commands
BkLinkCheckCmnd: BkLinkCheckResp, # 0x00 / CMD_LinkCheck
BkWriteRegCmnd: BkWriteRegResp, # 0x01 / CMD_WriteReg
BkReadRegCmnd: BkReadRegResp, # 0x03 / CMD_ReadReg
BkCheckCrcCmnd: BkCheckCrcResp, # 0x10 / CMD_CheckCRC
BkBootVersionCmnd: BkBootVersionResp, # 0x11 / CMD_ReadBootVersion
Expand Down

0 comments on commit a31d5f6

Please sign in to comment.