IMX500 MCU SDK
API reference for the Arducam IMX500 MCU SDK
Loading...
Searching...
No Matches
ArducamIMX500SDK.h
Go to the documentation of this file.
1
5
6#ifndef ARDUCAM_IMX500_SDK_H_
7#define ARDUCAM_IMX500_SDK_H_
8
9#include "ai_regs.h"
10#include "common_regs.h"
11#include "ai_driver.h"
12#include "stdint.h"
13#include "stdbool.h"
14#include "stdlib.h"
15
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
22
23
25typedef struct {
26 uint8_t valid_flag;
27 uint8_t frame_count;
31 uint8_t indicator;
33
34typedef struct {
35 float scale;
38
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)
44
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
49
50typedef struct {
51 uint16_t id;
52 uint16_t size;
54 uint16_t padding;
56
58typedef struct {
59 uint32_t id;
60 char name[48];
61 uint8_t format;
64 int32_t zero_point;
65 float scale;
66 uint32_t element_count;
67 uint32_t data_bytes;
69 const uint8_t *data;
72
83
106
108typedef struct {
109 float x1;
110 float y1;
111 float x2;
112 float y2;
113 float score;
115} BBox;
116
117typedef struct {
119 uint16_t valid_num;
121
128
136
137typedef struct {
138 uint16_t add;
139 uint8_t shift;
140 uint16_t clipMax;
141 uint16_t clipMin;
143
144typedef struct {
145 uint32_t tensorSize;
146 uint32_t dimSize;
147 uint8_t padding;
150
189
203
220
228
229
237
246
263
265typedef struct {
266 uint32_t status;
267 uint32_t result;
268 uint32_t bytes_done;
269 uint32_t bytes_total;
271
272typedef struct {
273 uint16_t top;
274 uint16_t left;
275 uint16_t height;
276 uint16_t width;
278
280typedef struct {
281 uint32_t xmin;
282 uint32_t ymin;
283 uint32_t xmax;
284 uint32_t ymax;
286
296
302
309
317
318#ifdef __cplusplus
319#include "ApParams.h"
320extern "C" {
321#endif
322
329
338bool parse_metadata(const uint8_t *data,
339 uint32_t data_len,
340 spi_data_format_t spi_format,
341 IMX500ParsedMetadata *parsed_metadata);
342
344
350
352uint32_t bbox_coordinate_x_scale_map(float x, uint32_t s_w, uint32_t t_w);
353
355uint32_t bbox_coordinate_y_scale_map(float y, uint32_t s_h, uint32_t t_h);
356
370int imx500_calculate_center_crop_xyxy(uint32_t source_width,
371 uint32_t source_height,
372 uint32_t target_width,
373 uint32_t target_height,
374 imx500_crop_rect_t *crop);
375
380int dnn_crop_xyxy_absolute(uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax);
381
393int apply_dnn_input_tensor_mapping(uint32_t width, uint32_t height);
394
396
402
405
408
411
414
417
420
422
428
430typedef uint32_t (*data_provider_t)(uint8_t *buf, uint32_t max_len, uint32_t offset);
431
438void do_data_injection_stream(data_provider_t provider, uint32_t total_size, bool first_time);
439
446void do_data_injection(const uint8_t *data, uint32_t size, bool first_time);
447
450
452int _preprocess_nn_input_data(uint8_t *src, uint32_t src_size);
453
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);
463
465
471
477void get_fw_ver(uint32_t* v);
478
484void get_pid(uint32_t* v);
485
495int get_sensor_device_id(char *out, size_t out_size);
496
503bool probe_imx500_module(uint32_t *device_id, uint32_t *boot_status);
504
513
529bool 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);
530
538int load_imx500_fw(const uint8_t *fw, uint32_t size, uint32_t fw_type);
539
541void stream_on(void);
542
549
555uint32_t get_metadata_size(void);
556
563int32_t read_metadata(uint8_t *rx_buf, uint32_t buf_size);
564
570void unpack_imx500_output_header(const uint8_t* data, IMX500OutputHeader* header);
571
578
584
591bool write_model_to_cam_flash(const uint8_t *model, uint32_t model_size);
592
599bool write_nn_info_to_cam_flash(const uint8_t *nn_info, uint32_t nn_info_size);
600
607bool load_nn_info_to_cam_memory(const uint8_t *nn_info, uint32_t nn_info_size);
614bool write_model_to_cam_flash_i2c(const uint8_t *model, uint32_t model_size);
615
622bool write_nn_info_to_cam_flash_i2c(const uint8_t *nn_info, uint32_t nn_info_size);
623
630bool load_nn_info_to_cam_memory_i2c(const uint8_t *nn_info, uint32_t nn_info_size);
631
638bool load_model_to_cam_memory_i2c(const uint8_t *model, uint32_t model_size);
639
641extern sc_dnn_nw_info_t network_info[MAX_NUM_OF_NETWORKS];
642
644int load_nn_info_to_sdk_cache(const uint8_t *cfg, size_t cfg_len);
645
648
650int sensor_i2c_write_16_8(uint16_t reg_addr, uint8_t data);
651
653int sensor_i2c_read_16_8(uint16_t reg_addr, uint8_t *data);
654
656int sensor_i2c_write_16_16(uint16_t reg_addr, uint16_t data);
657
659int sensor_i2c_read_16_16(uint16_t reg_addr, uint16_t *data);
660
662int sensor_i2c_write_16_32(uint16_t reg_addr, uint32_t data);
663
665int sensor_i2c_read_16_32(uint16_t reg_addr, uint32_t *data);
666
668
669#ifdef __cplusplus
670}
671#endif
672
673#endif // ARDUCAM_IMX500_SDK_H_
bool abort_i2c_payload_operation(void)
Abort any active I2C payload import session and wait until it returns to idle.
@ BAYER_CH_B
@ BAYER_CH_MAX
@ BAYER_CH_GR
@ BAYER_CH_R
@ BAYER_CH_GB
#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_boot_mode_t
@ MODULE_WAIT_BOOT
@ MODULE_I2C_LOAD_NN_BOOT
@ MODULE_RPI_PRIVATE_PROTOCOL_LOAD_NN_BOOT
@ MODULE_SELF_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
@ IMX500_WB_PRESET_3200
@ IMX500_WB_PRESET_6500
@ IMX500_WB_PRESET_5600
@ IMX500_WB_PRESET_4300
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_status_t
@ SPI_FLASH_OP_PARSING
@ SPI_FLASH_OP_SUCCESS
@ SPI_FLASH_OP_FAILED
@ SPI_FLASH_OP_WAIT_HEADER
@ SPI_FLASH_OP_RECEIVING
@ SPI_FLASH_OP_IDLE
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_t
@ DNN_INPUT_FORMAT_Y
@ DNN_INPUT_FORMAT_RGB
@ DNN_INPUT_FORMAT_BAYER_RGB
@ DNN_INPUT_FORMAT_BGR
imx500_white_balance_mode_t
@ IMX500_WB_MODE_AUTO
@ IMX500_WB_MODE_ONE_PUSH
@ IMX500_WB_MODE_PRESET
spi_flash_op_result_t
@ 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_OK
@ SPI_FLASH_RESULT_BAD_HEADER
@ SPI_FLASH_RESULT_FLASH_BLOB_MISSING
@ SPI_FLASH_RESULT_NONE
@ SPI_FLASH_RESULT_BAD_OPERATION
@ SPI_FLASH_RESULT_NO_MEMORY
@ SPI_FLASH_RESULT_WRITE_FAIL
@ SPI_FLASH_RESULT_IMX500_DOWNLOAD_FAIL
@ SPI_FLASH_RESULT_BUSY
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.
float score
Decoded 12-byte metadata header emitted by the IMX500 output stream.
Parsed metadata payload with JPEG and output tensor offsets.
IMX500ParsedNetwork networks[IMX500_MAX_NETWORKS]
const uint8_t * jpeg_data
IMX500OutputHeader output_header
IMX500OutputHeader primary_header
Parsed network description including input and output tensors.
IMX500ParsedTensor input_tensors[IMX500_MAX_INPUT_TENSORS]
IMX500ParsedTensor output_tensors[IMX500_MAX_OUTPUT_TENSORS]
Parsed tensor descriptor plus bound tensor payload pointer.
const uint8_t * data
IMX500TensorDimension dimensions[IMX500_MAX_TENSOR_DIMS]
Auto-exposure configuration to be applied to the sensor.
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
uint32_t inputTensorWidthStride
uint32_t inputTensorHeightStride
sc_input_tensor_rgb_norm_info_t rgbNorm[BAYER_CH_MAX]
uint8_t outputTensorPadding[MAX_OUTPUT_TENSOR_NUM]
uint32_t outputTensorDimSize[MAX_OUTPUT_TENSOR_NUM]
uint8_t outputTensorBytesPerElement[MAX_OUTPUT_TENSOR_NUM]
Summary of a model or network-info flash write request.