Migrating to aqpxlib 0.7.0¶
In 0.7.0, the user-facing APIs for bus topology, device configuration, device state, events, GPIO, and POD no longer use the generated aqpxlib.message types. Scripts and tutorials should import frozen dataclasses and event classes from the protocol packages and from aqpxlib.event, aqpxlib.gpio, and aqpxlib.pod.
This guide covers what changed and how to update code written for 0.6.x and earlier.
Stay on 0.6.x while you migrate
Pin aqpxlib<0.7 in your project until you have updated your imports and handler signatures. The wire protocol to the exerciser has not changed. Only the Python types did.
What stayed the same¶
- Connection setup (
AqProtocolExerciser.connect, session configuration). - Bus and device lifecycle (
create_bus,attach_to_bus,detach_from_bus,atomic_update_handlebehavior). - Device operation methods on controllers and targets (I2C
writeto, I3Cdo_daa, FIFOenqueue, and so on). - Event handler registration (
on_event,add_event_handler). Pass an event class fromaqpxlib.event, such asPxI3CTargetAssignedAddressEvent. The legacy event name string is still accepted.
When you still need aqpxlib.message¶
aqpxlib.message is still there for advanced callers: replay tools, custom RPCs, and a few library internals. Typical application code should not import it.
You may still need protobuf types if you:
- Call
PxI3CBaseController.send_i3c_transactionswith low-level lists ofI3CControllerTransactionV2fromaqpxlib.message. If the controller'ssdr_write_transactionandsdr_read_transactionhelpers fit your case, use them instead. - Build or parse raw
PxProtobufMsgrequests outside the public device APIs.
For everything else in this guide, replace aqpxlib.message imports with the domain types listed in the tables.
Topology: bus handles¶
get_handle, set_handle, get_handles, and set_handles on AqProtocolExerciser now take and return Px*BusConfig dataclasses instead of PxHandle protobuf messages.
| Before (0.6.x) | After (0.7.0) |
|---|---|
px.get_handle(0) → pxmsg.PxHandle |
px.get_handle(0) → PxI3CBusConfig (or PxI2CBusConfig, …) |
PxI2CBus(px, config=wire_handle, handle_index=0) |
PxI2CBus(px, config=PxI2CBusConfig(scl=0, sda=1), handle_index=0) |
Read pins via handle.i2_c.scl |
Read pins via handle.scl on PxI2CBusConfig |
Import bus config types from the protocol module:
from aqpxlib.i2c import PxI2CBusConfig
from aqpxlib.i3c import PxI3CBusConfig
handle = px.get_handle(0)
assert isinstance(handle, PxI3CBusConfig)
updated = px.set_handle(0, PxI3CBusConfig(scl=0, sda=1, revision=handle.revision))
Each Px*BusConfig has:
revision: the compare-and-swap revision for topology writes.controllersandtargets: tuples ofPx*ControllerConfigandPx*TargetConfigdomain objects, not protobuf messages.
On a live bus object, call bus.atomic_update_handle(...) rather than writing your own get_handle, edit, set_handle sequence.
The supported bus config types are PxI2CBusConfig, PxI3CBusConfig, PxSPIBusConfig, PxUartBusConfig, PxPwmBusConfig, and PxDataGeneratorBusConfig, from aqpxlib.i2c, aqpxlib.i3c, aqpxlib.spi, aqpxlib.uart, aqpxlib.pwm, and aqpxlib.data_generator.
Devices: configuration and state¶
Reading and writing config¶
| Before (0.6.x) | After (0.7.0) |
|---|---|
device.config → betterproto.Message (for example I2CControllerConfig) |
device.config → PxI2CControllerConfig (per device class) |
device.config = pxmsg.I2CControllerConfig(...) |
device.config = PxI2CControllerConfig(...) |
| Mutate protobuf fields in place | Use dataclasses.replace on frozen configs |
Example (I3C controller timing):
from dataclasses import replace
from aqpxlib.i3c import PxI3CBaseController
from aqpxlib.i3c.device_config import PxI3CBaseControllerConfig, PxI3CControllerTimingConfig
timing = PxI3CControllerTimingConfig(i3_c_t_cas=1000)
controller.config = PxI3CBaseControllerConfig(enabled=1, timing=timing)
# Or update through the bus without replacing the whole object manually:
controller.update_config(lambda cfg: replace(cfg, enabled=1))
If a device needs a non-default configuration before attach, pass config=... to its constructor. Constructor keyword shortcuts such as static_addr= on I3C targets still work and fill in the domain config for you.
Reading state¶
| Before (0.6.x) | After (0.7.0) |
|---|---|
target.state → protobuf (for example FIFO target state message) |
target.state → PxI2CFifoTargetState, PxI3C32BitRegisterTargetState, … |
State types live in the same protocol package as the device. Each device's API reference page lists them.
Where config and state types live¶
Types are named Px<DeviceClass>Config and Px<DeviceClass>State, and each protocol package exports them from its __init__.py, for example from aqpxlib.i2c import PxI2CControllerConfig, PxI2CControllerState.
Nested enums moved along with the config types. For example, PxI3C32BitRegisterTargetSubAddressType is now in aqpxlib.i3c. Device classes may still expose a nested SubAddressType alias for backward compatibility.
Events¶
Event handlers now receive typed event dataclasses from aqpxlib.event instead of a single PxEventMsg wrapper.
Before¶
from aqpxlib.event import PxEventMsg
@i3c_target.on_event("i3_c_target_assigned_address")
def handler(event_msg: PxEventMsg):
addr = event_msg.device_event.i3_c_target_assigned_address.assigned_address
After¶
from aqpxlib.event import PxI3CTargetAssignedAddressEvent
@i3c_target.on_event(PxI3CTargetAssignedAddressEvent)
def handler(event: PxI3CTargetAssignedAddressEvent):
addr = event.assigned_address
We recommend registering with the event class. The legacy event name string still works, and in both cases the handler receives the typed event object, not PxEventMsg.
Global events such as PxGpioTriggerEvent and PxUpdatedTopologyEvent work the same way through AqProtocolExerciser.add_event_handler. PxUpdatedTopologyEvent.config is a Px*BusConfig instance (or None), not a raw handle message.
The full event class table is in Example: Event Registration and Handler Setup.
GPIO and POD¶
The GPIO and POD helpers on AqProtocolExerciser use domain types instead of protobuf.
| Area | Import from | Notes |
|---|---|---|
| GPIO levels, pin state, width trigger | aqpxlib.gpio |
GpioState, GpioPinState, GpioWidthTriggerConfig, … |
| POD IO and DC output | aqpxlib.pod |
PodIoElectricalConfig, PodDcOutputConfig, … |
aqpxlib.gpio keeps backward-compatible Px* aliases, for example PxIoState for GpioState.
| Before (0.6.x) | After (0.7.0) |
|---|---|
get_pod_io_configs() → list[pxmsg.PxPodIoElectricalConfig] |
list[PodIoElectricalConfig] |
get_pod_dc_output_config() → pxmsg.PxPodDcOutputRequest |
PodDcOutputConfig |
See GPIO read, drive, and pulse and GPIO width trigger.
Memory and FIFO helpers¶
The protocol packages re-export the operation structs some targets use under Px* names. Internally they map to wire messages.
| Protocol | Examples |
|---|---|
| I2C | PxMemoryTargetRead, PxMemoryTargetWrite, PxFifoTargetEnqueue from aqpxlib.i2c |
| I3C | FIFO and memory helpers from aqpxlib.i3c |
Where they fit, use the high-level methods (read_mem, enqueue, event handlers) instead.
Migration checklist¶
- On a branch, upgrade to
aqpxlib==0.7.0and run your test suite. - In application code, replace
from aqpxlib.message import ...with the protocolPx*ConfigandPx*Statetypes and theaqpxlib.eventtypes. - Change event handlers to take typed
Px*Eventarguments instead ofPxEventMsg. - Replace protobuf
configassignments with domain dataclasses, usingdataclasses.replaceorupdate_configfor edits. - Update
get_handleandset_handlecallers to usePx*BusConfig. - Move GPIO and POD code to
aqpxlib.gpioandaqpxlib.pod.
Other changes in 0.7.0¶
The Changelog lists the rest of the 0.7.0 changes: I3C target reset actions, the SPI FIFO target, MCTP endpoint typing, and ZMQ timeout alignment. These are additive or documented on their protocol pages.