si5340: implement paged register writes #65

Merged
sb10q merged 1 commits from fsagbuya/nix-servo:fix_i2cwrite into master 2024-07-31 17:32:09 +08:00
1 changed files with 12 additions and 3 deletions

View File

@ -35,6 +35,15 @@ STATUS_LOSREF = 0x04
STATUS_LOL = 0x08 STATUS_LOL = 0x08
def write_register(bus, address, value):
page = address >> 8
register = address & 0xFF
bus.write_byte_data(IC_ADDR, 0x01, page)
try:
bus.write_byte_data(IC_ADDR, register, value)
except Exception as e:
raise Exception(f"Write failed 0x{value:02X} at 0x{address:04X}: {e}")
def write_preamble(bus): def write_preamble(bus):
preamble = [ preamble = [
(0x0B24, 0xC0), (0x0B24, 0xC0),
@ -45,7 +54,7 @@ def write_preamble(bus):
(0x0B4E, 0x1A), (0x0B4E, 0x1A),
] ]
for address, value in preamble: for address, value in preamble:
bus.write_byte_data(IC_ADDR, address, value) write_register(bus, address, value)
def write_postamble(bus): def write_postamble(bus):
postamble = [ postamble = [
@ -54,7 +63,7 @@ def write_postamble(bus):
(0x0B25, 0x02), (0x0B25, 0x02),
] ]
for address, value in postamble: for address, value in postamble:
bus.write_byte_data(IC_ADDR, address, value) write_register(bus, address, value)
def wait_device_ready(bus): def wait_device_ready(bus):
for _ in range(15): for _ in range(15):
@ -244,7 +253,7 @@ def configure_si5340():
print("Writing main configuration...") print("Writing main configuration...")
for address, value in main_config: for address, value in main_config:
bus.write_byte_data(IC_ADDR, address, value) write_register(bus, address, value)
print("Main configuration written") print("Main configuration written")
write_postamble(bus) write_postamble(bus)