Skip to navigation

hololink::emulation::sensors::TestSensor

View as Markdown

I2C-controlled test sensor for validation and development.

Register map (16-bit big-endian address, same transaction format as Vb1940Emulator):

#include <hololink/emulation/sensors/test_sensor.hpp>

Inherits from: hololink::emulation::I2CPeripheral (public)


Constructors

TestSensor

hololink::emulation::sensors::TestSensor::TestSensor()

Destructor

~TestSensor

hololink::emulation::sensors::TestSensor::~TestSensor()

Methods

reset

void hololink::emulation::sensors::TestSensor::reset()

attach_to_i2c

void hololink::emulation::sensors::TestSensor::attach_to_i2c(
I2CController &i2c_controller,
uint8_t bus_address
) override

python:

def attach_to_i2c(self: hemu.I2CPeripheral, i2c_controller: hemu.I2CController, bus_address: int)

attach the peripheral to the I2C controller. This should be called by client code before start() is called.

Parameters

i2c_controller
I2CController &

The I2C controller to attach to. Retrieved from HSBEmulator with get_i2c(controller_address).

bus_address
uint8_t

The bus address of the peripheral.

i2c_transaction

I2CStatus hololink::emulation::sensors::TestSensor::i2c_transaction(
uint16_t peripheral_address,
const uint8_t *write_bytes,
uint16_t write_size,
uint8_t *read_bytes,
uint16_t read_size
) override

python:

def i2c_transaction(self: hemu.I2CPeripheral, peripheral_address: int, write_bytes: bytes, write_size: int, read_bytes: bytearray, read_size: int) -> hemu.I2CStatus

perform an I2C transaction. This will be called by the I2CController when a transaction is requested.

write_bytes and read_bytes may alias (the I2C controller hands the same data buffer for both), so consume the write bytes before producing the read bytes.

Python override: write_bytes arrives as an immutable bytes copy of length write_size; read_bytes is a bytearray of length read_size to fill, e.g. read_bytes[0:2] = bytes([0x12, 0x34]); it is copied into the controller’s buffer when the override returns, so it must keep its length. An exception from the override fails the transaction (I2C_STATUS_FATAL_ERROR) and is reported through sys.unraisablehook. Calling i2c_transaction on a peripheral from Python takes (peripheral_address, write_bytes, read_bytes=None, write_size=None, read_size=None) where write_bytes is any byte buffer and read_bytes a writable byte buffer (e.g. bytearray(n)).

Returns: I2CStatus The status of the transaction.

Parameters

peripheral_address
uint16_t

The peripheral address to communicate with.

write_bytes
const uint8_t *

The bytes to write to the peripheral.

write_size
uint16_t

The size of the write bytes.

read_bytes
uint8_t *

Buffer the peripheral fills with the bytes read. The caller provides read_size bytes of storage; the peripheral overwrites them with its reply.

read_size
uint16_t

The number of bytes requested by the host.

is_streaming

bool hololink::emulation::sensors::TestSensor::is_streaming() const

get_frame_size

uint32_t hololink::emulation::sensors::TestSensor::get_frame_size() const

get_frame_rate_hz

uint32_t hololink::emulation::sensors::TestSensor::get_frame_rate_hz() const

get_pattern_mode

TestPatternMode hololink::emulation::sensors::TestSensor::get_pattern_mode() const

get_constant_byte

uint8_t hololink::emulation::sensors::TestSensor::get_constant_byte() const

fill_frame

void hololink::emulation::sensors::TestSensor::fill_frame(
uint8_t *data,
uint64_t frame_index
) const

Fill a frame buffer according to the current pattern configuration.

Parameters

data
uint8_t *

Destination buffer (must be at least get_frame_size() bytes).

frame_index
uint64_t

Frame sequence number used by the incrementing pattern.

start

virtual void hololink::emulation::sensors::TestSensor::start()

start the peripheral.

This will be called when I2CController itself starts and should not be done by the client code.

stop

virtual void hololink::emulation::sensors::TestSensor::stop()

stop the peripheral.

This will be called when the I2CController is stopped and should not be done by the client code.

Peripheral should release all resources in case a subsequent start() is called.

streaming_reg

I2CStatus hololink::emulation::sensors::TestSensor::streaming_reg(
const uint8_t *write_bytes,
uint16_t write_size,
uint8_t *read_bytes,
uint16_t read_size
)

Member variables

NameTypeDescription
DEVICE_ID_REG static constexpruint16_t
FRAME_SIZE_REG static constexpruint16_t
PATTERN_MODE_REG static constexpruint16_t
CONSTANT_BYTE_REG static constexpruint16_t
FRAME_RATE_REG static constexpruint16_t
STREAMING_REG static constexpruint16_t
STATUS_REG static constexpruint16_t
memory_uint8_t