lpGBT readout with Adafruit FT323H and blinka
The snippet can be accessed without any authentication.
Authored by
Branislav Ristic
Start with a new environment and install packages
python -m venv --system-site-packages lpgbt_env
source lpgbt_env/bin/activate
pip install -U pip
pip install Adafruit-Blinka git+https://gitlab.cern.ch/lpgbt/lpgbt_control_lib.git@v4.0.0
You need to set the BLINKA_FT232H
environmental variable for the USB-I2C adapter to be detected.
I'd suggest to place it in the activate
script of the environment so it gets set automatically (you have to reactivate the environment after the next step).
cat >> lpgbt_env/bin/activate <<EOF
echo "Using FT232 for blinka"
export BLINKA_FT232H=1
EOF
You can then access registers via
import lpgbt
chip1 = lpgbt.get_lpgbt(0x70)
chip1.read_reg(chip1.CHIPID0)
# or
chip1.read_regs(chip1.CHIPID0, 4) # returns CHIPID0 and the following 3 registers as a list
chip1.pusm_get_state()
chip1.wait_pusm_state(chip1.pusm_state.READY, timeout=1) #timeout in seconds, throws exception if state not reached within timeout
Interesting states
chip1.PusmState.PAUSE_FOR_DLL_CONFIG_DONE
chip1.PusmState.READY
lpgbt.py 1.58 KiB
from functools import partial
import board
import logging
from lpgbt_control_lib import LpgbtV0, LpgbtV1
i2c = board.I2C()
def encodeReg(reg_addr):
regl = (reg_addr & 0xFF) >> 0
regh = (reg_addr) >> 8
return bytes([regl, regh])
# low level access to I2C interface
def write_lpgbt_regs_i2c(chip_addr, reg_addr, reg_vals):
outbuf = encodeReg(reg_addr) + bytes(reg_vals)
i2c.writeto(chip_addr, outbuf)
def read_lpgbt_regs_i2c(chip_addr, reg_addr, read_len):
outbuf = encodeReg(reg_addr)
inbuf = bytearray(read_len)
i2c.writeto_then_readfrom(
chip_addr,
outbuf,
inbuf )
return list(inbuf)
def get_lpgbt(chip_addr, version=1):
# get a logger for lpGBT library logging
lpgbt_logger = logging.getLogger(f"lpgbt_{hex(chip_addr)}")
# instantiate lpGBT class
chip = [LpgbtV0,LpgbtV1][version](logger=lpgbt_logger)
# register communications interface(s)
chip.register_comm_intf(
name="I2C",
write_regs = partial(write_lpgbt_regs_i2c, chip_addr=chip_addr),
read_regs = partial(read_lpgbt_regs_i2c, chip_addr=chip_addr),
default=True )
return chip
def main():
chip1 = get_lpgbt(0x70)
pusm = chip1.pusm_get_state()
print("state", chip1)
if (pusm == chip1.pusm_state.PAUSE_FOR_DLL_CONFIG_DONE):
print("fake configuring DLL")
chip1.config_done()
while True:
try:
pusm=chip1.wait_pusm_state(chip1.pusm_state.READY, 1)
except:
pass
print("READY")
if __name__ == "__main__":
main()
Please register or sign in to comment