1
0

Add scanner

This commit is contained in:
2026-02-20 21:53:52 +01:00
parent 6517709ea7
commit eece17b9db
7 changed files with 325 additions and 25 deletions

View File

@@ -1,5 +1,6 @@
from protocol import I2CPCClient, time
from tef_102_patch import *
from tef_205_patch import *
from typing import Callable, TypeVar, ParamSpec, Concatenate
from collections.abc import Callable as ABCCallable
@@ -11,25 +12,27 @@ ADDRESS = 0x64
class BaseTEF668X:
def __init__(self, p: I2CPCClient) -> None:
self.p = p
p.set_baudrate(1500000)
self.p.set_clock(400_000)
p.set_baudrate(921600)
self.p.set_clock(100_000)
def close(self):
self.p.set_baudrate(115200)
self.p.close()
def _reset(self):
self.p.write_i2c(ADDRESS, b"\x1e\x5a\x01\x5a\x5a")
def _write_firmware(self, patch: bytes | list[int], patch_lut: bytes | list[int]):
self.p.set_clock(400_000)
self.p.write_i2c(ADDRESS, b"\x1c\x00\x00")
self.p.write_i2c(ADDRESS, b"\x1c\x00\x74")
def send_patch(_patch: bytes):
for i in range(0, len(_patch), 24):
data = _patch[i:i+24]
for i in range(0, len(_patch), 64):
data = _patch[i:i+64]
if self.p.write_i2c(ADDRESS, b"\x1b" + data)[0] != 0: raise Exception
send_patch(bytes(patch))
self.p.write_i2c(ADDRESS, b"\x1c\x00\x00")
self.p.write_i2c(ADDRESS, b"\x1c\x00\x75")
send_patch(bytes(patch_lut))
self.p.write_i2c(ADDRESS, b"\x1c\x00\x00")
self.p.set_clock(100_000)
def APPL_Get_Operation_Status(self):
data = self.p.write_read_i2c(ADDRESS, b"\x40\x80\x01", 2)
@@ -55,12 +58,12 @@ class BaseTEF668X:
def APPL_Activate(self):
return b"\x40\x05\x01\x00\x01", None, None
def init(self):
def init(self, patch = tef_102_patch, patch_lut = tef_102_patch_lut, clock: int = 9216000):
self._reset()
while self.APPL_Get_Operation_Status() != 0: time.sleep(0.01)
self._write_firmware(tef_102_patch, tef_102_patch_lut)
self._write_firmware(patch, patch_lut)
self.p.write_i2c(ADDRESS, b"\x14\x00\x01")
while self.APPL_Get_Operation_Status() != 1: time.sleep(0.01)
self.APPL_Set_ReferenceClock(12000000, False)
if clock != 9216000: self.APPL_Set_ReferenceClock(clock, False)
self.APPL_Activate()
while self.APPL_Get_Operation_Status() != 2: time.sleep(0.01)