Skip to main content

Module sim

Module sim 

Source
Expand description

A part that is not there, answering from a register map.

script plays one exact conversation: these transfers, in this order, and anything else is refused. That is what proves a driver follows a datasheet, and it is a lot to write out before a driver has been run even once.

This is the other half. An I2cPart is a register map with an address on the front of it: a write puts bytes at a register and the ones after it, a read takes them back, and the part does not mind what order any of that happens in. Give it a chip id and whatever a driver reads, and the driver runs against it with nothing plugged in and no transfer sequence written down.

Parts come in three shapes, and there is one for each:

  • I2cPart, registers a byte wide, as Bosch’s BME280 and BMP280 have.
  • WordPart, registers sixteen bits wide, as Texas Instruments’ parts have, with bits the part sets for itself marked read-only.
  • CommandPart (feature alloc), commands and the replies they leave, as Sensirion’s parts take.

A simulated bus holds any of them as a Part, and gives each back as its own kind.

Which to reach for:

  • A part here, when the question is what a driver does with what it reads, or when you are writing a driver and want to run it before the hardware arrives.
  • A script, when the question is whether the exact transfers a datasheet prescribes went out, in order and no others.

Almost every I2C part addresses its registers with one byte and moves through them as it is read, so a map of 256 registers holds one whole part and needs no allocator.

Structs§

CommandPart
A part on an I2C bus that takes commands rather than register addresses, answering each with the reply it was given for that command.
I2cPart
A part on an I2C bus, answering from its registers.
Rules
The rules a part with byte-wide registers keeps beyond plain memory: which writes it takes, what a read returns, and where its register pointer moves.
WordPart
A part on an I2C bus whose registers are sixteen bits wide, answering from them.

Enums§

Part
A simulated part of any of the three kinds, as a simulated bus holds it.
PartError
What a simulated part refuses.

Constants§

REGISTERS
How many registers a part holds, which is every address one byte reaches.

Traits§

FromPart
A kind of simulated part, taken back out of a Part.