6#ifndef ARDUCAM_IMX500_SDK_H_
7#define ARDUCAM_IMX500_SDK_H_
10#include "common_regs.h"
16#define VALID_DATA_OFFSET 0
17#define IMX500_HEADER_LEN 12
18#define MAX_DETECT_ITEM_NUM 10
19#define IMX500_FW_TYPE_LOADER 0
20#define IMX500_FW_TYPE_MAIN 1
21#define IMX500_FW_TYPE_NETWORK_WEIGHTS 2
39#define SC_DNN_MAX_NETWORK_ID_DEC (999999)
40#define SC_DNN_MAX_NETWORK_ID (0x999999)
41#define MAX_DNN_HEADER_SIZE (4096)
42#define MAX_NUM_OF_NETWORKS (3)
43#define MAX_OUTPUT_TENSOR_NUM (30)
45#define IMX500_MAX_NETWORKS MAX_NUM_OF_NETWORKS
46#define IMX500_MAX_TENSOR_DIMS 8
47#define IMX500_MAX_INPUT_TENSORS 8
48#define IMX500_MAX_OUTPUT_TENSORS MAX_OUTPUT_TENSOR_NUM
371 uint32_t source_height,
372 uint32_t target_width,
373 uint32_t target_height,
452int _preprocess_nn_input_data(uint8_t *src, uint32_t src_size);
458int _convert_injected_data(
const uint8_t *img,
459 uint32_t img_width, uint32_t img_height, uint32_t img_channels,
460 uint8_t *dst, uint32_t dst_size,
461 uint32_t input_height, uint32_t input_width, uint32_t channel_num,
462 const uint8_t transpose_order[3], uint32_t align_base);
bool abort_i2c_payload_operation(void)
Abort any active I2C payload import session and wait until it returns to idle.
#define MAX_OUTPUT_TENSOR_NUM
bool probe_imx500_module(uint32_t *device_id, uint32_t *boot_status)
Probe the module and read device ID plus boot status.
bool write_model_to_cam_flash_i2c(const uint8_t *model, uint32_t model_size)
Stream a model blob to module flash over PiVariety I2C payload.
bool load_model_to_cam_memory_i2c(const uint8_t *model, uint32_t model_size)
Load a model blob into module memory over the I2C payload path.
bool write_nn_info_to_cam_flash(const uint8_t *nn_info, uint32_t nn_info_size)
Stream a network-info blob to module flash over SPI.
int get_sensor_device_id(char *out, size_t out_size)
Read the sensor device ID used by imx500_dump_basic_info().
int sensor_i2c_write_16_32(uint16_t reg_addr, uint32_t data)
Write one 32-bit sensor register addressed by a 16-bit register address.
#define IMX500_MAX_OUTPUT_TENSORS
@ MODULE_I2C_LOAD_NN_BOOT
@ MODULE_RPI_PRIVATE_PROTOCOL_LOAD_NN_BOOT
@ MODULE_SPI_LOAD_NN_BOOT
bool reset_imx500_module(void)
Reset the IMX500 module and wait until loader/main firmware is ready.
bool load_nn_info_to_cam_memory_i2c(const uint8_t *nn_info, uint32_t nn_info_size)
Load a network-info blob into module memory over the I2C payload path.
int sensor_i2c_write_16_16(uint16_t reg_addr, uint16_t data)
Write one 16-bit sensor register addressed by a 16-bit register address.
int imx500_calculate_center_crop_xyxy(uint32_t source_width, uint32_t source_height, uint32_t target_width, uint32_t target_height, imx500_crop_rect_t *crop)
Calculate a centered crop rectangle that matches a target output aspect ratio.
uint32_t get_metadata_size(void)
Read the size of the next metadata payload exposed by the module.
bool write_model_to_cam_flash(const uint8_t *model, uint32_t model_size)
Stream a model blob to module flash over SPI.
int imx500_apply_white_balance_config(void)
Apply the staged white balance configuration to the sensor.
#define IMX500_MAX_INPUT_TENSORS
spi_data_format_t
SPI metadata layout requested from imx500_open.
@ SPI_METADATA_NONE
Disable SPI metadata output; supported.
@ SPI_METADATA_INPUT_TENSOR_OUTPUT_TENSOR
Reserved; not currently enabled.
@ SPI_METADATA_INPUT_TENSOR
Reserved; not currently enabled.
@ SPI_METADATA_OUTPUT_TENSOR
Output tensors only; supported.
@ SPI_METADATA_JPEG_INPUT_TENSOR_OUTPUT_TENSOR
JPEG/input data plus output tensors; supported.
@ SPI_METADATA_JPEG_INPUT_TENSOR
Reserved; not currently enabled.
int imx500_set_white_balance_config(const imx500_white_balance_config_t *config)
Stage a new white balance configuration in the sensor control block.
void do_data_injection(const uint8_t *data, uint32_t size, bool first_time)
Inject one complete input buffer directly.
int sensor_i2c_read_16_16(uint16_t reg_addr, uint16_t *data)
Read one 16-bit sensor register addressed by a 16-bit register address.
void unpack_imx500_output_header(const uint8_t *data, IMX500OutputHeader *header)
Decode a raw IMX500 metadata header into a typed structure.
bool write_nn_info_to_cam_flash_i2c(const uint8_t *nn_info, uint32_t nn_info_size)
Stream a network-info blob to module flash over PiVariety I2C payload.
void do_data_injection_stream(data_provider_t provider, uint32_t total_size, bool first_time)
Inject input data through a pull-based provider callback.
void get_pid(uint32_t *v)
Read the module product/device ID register.
void stream_on(void)
Start inference/video streaming after imx500_open succeeds.
imx500_white_balance_preset_t
bool parse_metadata(const uint8_t *data, uint32_t data_len, spi_data_format_t spi_format, IMX500ParsedMetadata *parsed_metadata)
Parse one raw SPI metadata buffer using the selected SPI metadata layout.
mipi_data_format_t
MIPI output layout requested from imx500_open.
@ MIPI_DATA_METADATA_INPUT_TENSOR_OUTPUT_TENSOR
Metadata and tensors without image data.
@ MIPI_DATA_IMAGE
Image stream only.
@ MIPI_DATA_IMAGE_METADATA_INPUT_TENSOR_OUTPUT_TENSOR
Image, metadata, and tensors.
@ MIPI_DATA_NONE
Disable MIPI output.
int32_t read_metadata(uint8_t *rx_buf, uint32_t buf_size)
Read one metadata frame over SPI.
spi_data_forwarding_mode_t
SPI bridge forwarding path selected inside the module.
@ SPI_MASTER_FROM_IMX500_MSPI
@ SPI_SLAVE_TO_IMX500_SSPI
@ SPI_LOAD_NN_INFO_TO_MEMORY
@ SPI_SLAVE_FROM_IMX500_MSPI
@ SPI_SLAVE_WRITE_MODEL_TO_FLASH
@ SPI_SLAVE_WRITE_NN_INFO_TO_FLASH
@ SPI_DATA_FORWARDING_NONE
@ SPI_FORWORDING_MODE_SWITCHING
@ SPI_MASTER_FROM_IMX500_SSPI
@ SPI_SLAVE_FROM_IMX500_SSPI
uint32_t bbox_coordinate_y_scale_map(float y, uint32_t s_h, uint32_t t_h)
Scale a Y coordinate from source height to target height.
bool switch_spi_data_forward_mode(spi_data_forwarding_mode_t m)
Switch the module SPI bridge to a different data forwarding mode.
int sensor_i2c_read_16_8(uint16_t reg_addr, uint8_t *data)
Read one 8-bit sensor register addressed by a 16-bit register address.
int imx500_set_ae_config(const imx500_ae_config_t *config)
Stage a new auto-exposure configuration in the sensor control block.
void imx500_get_default_white_balance_config(imx500_white_balance_config_t *config)
Fill a white balance config structure with SDK defaults.
int sensor_i2c_read_16_32(uint16_t reg_addr, uint32_t *data)
Read one 32-bit sensor register addressed by a 16-bit register address.
bool get_spi_flash_status(spi_flash_status_t *status)
Read the current flash write progress from module firmware.
@ SPI_FLASH_OP_WAIT_HEADER
bool imx500_open(const uint8_t *nn_fw, uint32_t nn_fw_size, const uint8_t *nn_info, uint32_t nn_info_size, mipi_data_format_t mipi_format, spi_data_format_t spi_format, uint32_t fps)
Reset the module, load the model, and configure stream formats.
int dnn_crop_xyxy_absolute(uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax)
Apply a crop rectangle in absolute sensor coordinates.
bool load_nn_info_to_cam_memory(const uint8_t *nn_info, uint32_t nn_info_size)
Load a network-info blob directly into module memory.
void dump_network_info_list(void)
Print the cached network list through the registered logger.
uint32_t bbox_coordinate_x_scale_map(float x, uint32_t s_w, uint32_t t_w)
Scale an X coordinate from source width to target width.
@ DNN_INPUT_FORMAT_BAYER_RGB
imx500_white_balance_mode_t
@ IMX500_WB_MODE_ONE_PUSH
@ SPI_FLASH_RESULT_PARSE_FAIL
@ SPI_FLASH_RESULT_TIMEOUT
@ SPI_FLASH_RESULT_BAD_SIZE
@ SPI_FLASH_RESULT_CRC_MISMATCH
@ SPI_FLASH_RESULT_NOT_SUPPORTED
@ SPI_FLASH_RESULT_BAD_HEADER
@ SPI_FLASH_RESULT_FLASH_BLOB_MISSING
@ SPI_FLASH_RESULT_BAD_OPERATION
@ SPI_FLASH_RESULT_NO_MEMORY
@ SPI_FLASH_RESULT_WRITE_FAIL
@ SPI_FLASH_RESULT_IMX500_DOWNLOAD_FAIL
int load_imx500_fw(const uint8_t *fw, uint32_t size, uint32_t fw_type)
Transfer one firmware blob to the module.
int load_nn_info_to_sdk_cache(const uint8_t *cfg, size_t cfg_len)
Parse and cache a network-info blob in the SDK host-side cache.
int apply_dnn_input_tensor_mapping(uint32_t width, uint32_t height)
Apply the DNN input-tensor mapping to the current IMX500 12MP active area.
int imx500_apply_ae_config(void)
Apply the staged auto-exposure configuration to the sensor.
int sensor_i2c_write_16_8(uint16_t reg_addr, uint8_t data)
Write one 8-bit sensor register addressed by a 16-bit register address.
void get_fw_ver(uint32_t *v)
Read the module firmware version register.
#define IMX500_MAX_TENSOR_DIMS
void imx500_get_default_ae_config(imx500_ae_config_t *config)
Fill an AE config structure with SDK defaults.
uint32_t(* data_provider_t)(uint8_t *buf, uint32_t max_len, uint32_t offset)
Callback used by do_data_injection_stream to stream image bytes lazily.
#define MAX_NUM_OF_NETWORKS
void stop_data_injection(void)
Exit data injection mode.
#define IMX500_MAX_NETWORKS
Host-side driver registration hooks used by the IMX500 MCU SDK.
Detection bounding box in absolute image coordinates.
Parsed network description including input and output tensors.
uint8_t input_tensor_count
IMX500ParsedTensor input_tensors[IMX500_MAX_INPUT_TENSORS]
uint8_t output_tensor_count
IMX500ParsedTensor output_tensors[IMX500_MAX_OUTPUT_TENSORS]
Parsed tensor descriptor plus bound tensor payload pointer.
uint32_t aligned_data_bytes
IMX500TensorDimension dimensions[IMX500_MAX_TENSOR_DIMS]
uint16_t serialization_index
Auto-exposure configuration to be applied to the sensor.
uint16_t max_exposure_time_100us
Crop rectangle in absolute sensor coordinates, using [xmin, xmax) and [ymin, ymax).
White balance configuration to be applied to the sensor.
imx500_white_balance_preset_t preset
imx500_white_balance_mode_t mode
sc_output_tensor_size_info_t * p_outputTensorSizeInfo
uint16_t inputTensorWidth
uint32_t inputTensorWidthStride
uint32_t inputTensorHeightStride
sc_input_tensor_rgb_norm_info_t rgbNorm[BAYER_CH_MAX]
uint16_t inputTensorHeight
uint8_t outputTensorPadding[MAX_OUTPUT_TENSOR_NUM]
uint32_t outputTensorDimSize[MAX_OUTPUT_TENSOR_NUM]
uint8_t outputTensorBytesPerElement[MAX_OUTPUT_TENSOR_NUM]
uint32_t inputTensorFormat
Summary of a model or network-info flash write request.