1
0

add some stuff

This commit is contained in:
2026-02-15 09:17:37 +01:00
commit 311bf3e60b
2 changed files with 72 additions and 0 deletions

21
rtc.py Normal file
View File

@@ -0,0 +1,21 @@
import datetime
from protocol import I2CPCClient
def sync_rtc(p: I2CPCClient):
ADDRESS = 0x32
p.write_i2c(ADDRESS, b"\x1f\x40") # halt the clock
dtime = datetime.datetime.now()
def toBCD(val: int) -> int:
return ((val // 10) << 4) | (val % 10)
data = b"\x10"
data += toBCD(dtime.second).to_bytes(1)
data += toBCD(dtime.minute).to_bytes(1)
data += toBCD(dtime.hour).to_bytes(1)
data += toBCD(1 << dtime.weekday()).to_bytes(1)
data += toBCD(dtime.day).to_bytes(1)
data += toBCD(dtime.month).to_bytes(1)
data += toBCD((1900 + dtime.year - 26) % 100).to_bytes(1)
p.write_i2c(ADDRESS, data)
p.write_i2c(ADDRESS, b"\x1f\x00") # start the clock