Camera & Imaging¶
DVP camera interface, ISP, and hardware MJPEG encoding and decoding.
| Header | Functions | Description |
|---|---|---|
hal_cam.h |
4 | Camera capture driver without the ISP: DVP or SPI camera input written to memory, with output crop, frame-rate control and ping-pong buffers. |
hal_isp.h |
9 | Image signal processor (ISP) driver: camera or memory input, global crop, two scaler output channels plus an extended channel, frame-rate control, digital zoom and ping-pong output buffers. |
hal_mjpeg.h |
17 | Hardware JPEG encoder driver: encode YUV 4:2:2, YUV 4:2:0 or grey-scale frames to baseline JPEG in software-triggered or hardware auto mode. |
hal_mjdec.h |
6 | Hardware JPEG decoder driver: decode a baseline JPEG into semi-planar YUV or grey-scale frames. |
hal_cam.h¶
#include "hal_cam.h" (Source)
Camera capture driver without the ISP: DVP or SPI camera input written to memory, with output crop, frame-rate control and ping-pong buffers.
The driver feeds the camera input (DVP_AS or SPI2DVP) directly to the DVP-to-AXI writers, without the image signal processor. Use hal_isp.h instead when scaling, colour conversion or several output channels are needed.
Typical sequence: configure the sensor, fill a cam_hal_cfg_t, cam_init(), then cam_start(). Each written frame is reported through cam_hal_cfg_t::out_callback from the capture interrupt. cam_deinit() removes the callback.
cam_init¶
Initialize camera capture.
Configures the input path and the DVP-to-AXI writers and installs the capture interrupt. Capture starts with cam_start().
| Parameter | Description |
|---|---|
cam_hal_cfg |
Configuration. cam_hal_out_t::pp_num is clamped in place to 1 to CAM_MAX_BUFFER_NUM. |
Returns: Always 0. An invalid crop window (reported on the console) is replaced by no cropping, and an invalid frame-rate setting by the full frame rate.
cam_start¶
Enable the configured input source so that frames are received.
Returns: Always 0.
cam_deinit¶
Disable the capture interrupt and remove the frame callback.
The input source and the writers are not disabled.
Returns: Always 0.
cam_fps_cfg¶
Change the output frame rate at run time.
| Parameter | Description |
|---|---|
frc |
Frame-rate setting; dst_fps = 0 drops every frame. |
| Return value | Description |
|---|---|
0 |
Applied. |
1 |
Invalid setting (src_fps is 0 or dst_fps exceeds src_fps); the current rate is kept. |
cam_hal_src_e¶
Camera input source.
| Name | Value | Description |
|---|---|---|
CAM_HAL_SRC_SPI2DVP |
0 |
SPI camera through the SPI-to-DVP bridge. |
CAM_HAL_SRC_DVP_AS |
1 |
Parallel DVP camera. |
cam_hal_out_format_e¶
Output format.
| Name | Value | Description |
|---|---|---|
CAM_HAL_OUT_FMT_YUYV |
YUYV interleaved, one plane. | |
CAM_HAL_OUT_FMT_YUV422SP |
YUV 4:2:2 semi-planar: the Y plane at the output address, followed by the interleaved UV plane. | |
CAM_HAL_OUT_FMT_Y_ONLY |
Y (luminance) only. |
Anonymous enum¶
Events reported in cam_out_frame_info_t::event.
| Name | Value | Description |
|---|---|---|
CAM_HAL_INT_NORMAL |
A frame has been written. | |
CAM_HAL_INT_FIFO_OVERWRITE |
FIFO overwrite; the writer is restarted. | |
CAM_HAL_INT_VSYNC_CNT_ERROR |
The number of valid lines per frame did not match the input height. | |
CAM_HAL_INT_HSYNC_CNT_ERROR |
The number of valid pixels per line did not match the input width. | |
CAM_HAL_INT_ALL |
Number of event codes. |
cam_hal_spi2dvp_data_order_e¶
SPI2DVP data order.
| Name | Value | Description |
|---|---|---|
CAM_HAL_SPI2DVP_ORDER_UV_FIRST |
The first input byte is a chroma (UV) byte. | |
CAM_HAL_SPI2DVP_ORDER_Y_FIRST |
The first input byte is a luma (Y) byte. |
cam_hal_spi2dvp_data_format_e¶
SPI2DVP input format.
| Name | Value | Description |
|---|---|---|
CAM_HAL_SPI2DVP_FORMAT_YUV422 |
YUV 4:2:2 interleaved input. | |
CAM_HAL_SPI2DVP_FORMAT_Y_ONLY |
Y-only input. |
cam_hal_spi2dvp_mode_e¶
SPI2DVP SPI mode (clock phase and polarity).
| Name | Value | Description |
|---|---|---|
CAM_HAL_SPI2DVP_MODE_0 |
SPI mode 0: phase 0, polarity 0. | |
CAM_HAL_SPI2DVP_MODE_1 |
SPI mode 1: phase 1, polarity 0. | |
CAM_HAL_SPI2DVP_MODE_2 |
SPI mode 2: phase 0, polarity 1. | |
CAM_HAL_SPI2DVP_MODE_3 |
SPI mode 3: phase 1, polarity 1. |
cam_hal_spi2dvp_data_endian_e¶
SPI2DVP bit order.
| Name | Value | Description |
|---|---|---|
CAM_HAL_SPI2DVP_ENDIAN_LSB |
LSB first. | |
CAM_HAL_SPI2DVP_ENDIAN_MSB |
MSB first. |
cam_hal_dvp_active_type_e¶
DVP HSYNC/VSYNC active level.
| Name | Value | Description |
|---|---|---|
CAM_HAL_DVP_ACTIVE_HIGH |
Active high. | |
CAM_HAL_DVP_ACTIVE_LOW |
Active low. |
cam_hal_dvp_data_byte_t¶
DVP input byte order.
| Name | Value | Description |
|---|---|---|
CAM_HAL_DATA_BYTE_LOWER |
The first byte is the lower byte. | |
CAM_HAL_DATA_BYTE_HIGHER |
The first byte is the higher byte. |
cam_hal_spi2dvp_input_t¶
SPI2DVP input configuration.
| Field | Type | Description |
|---|---|---|
order |
cam_hal_spi2dvp_data_order_e |
Data order: Y first or UV first. |
format |
cam_hal_spi2dvp_data_format_e |
Input format: YUYV or Y only. |
mode |
cam_hal_spi2dvp_mode_e |
SPI mode (clock phase and polarity). |
endian |
cam_hal_spi2dvp_data_endian_e |
Bit order: LSB or MSB first. |
cam_hal_dvp_input_t¶
DVP input configuration.
| Field | Type | Description |
|---|---|---|
hsync |
cam_hal_dvp_active_type_e |
HSYNC active level. |
vsync |
cam_hal_dvp_active_type_e |
VSYNC active level. |
order |
cam_hal_dvp_data_byte_t |
Byte order: lower or higher byte first. |
pclk |
uint32_t |
Sensor pixel clock in Hz. |
totalHPixels |
uint16_t |
Sensor line length including horizontal blanking, in pixels. |
cam_hal_src_cfg_t¶
Source-specific input configuration; the member is selected by cam_hal_cfg_t::cam_src.
| Field | Type | Description |
|---|---|---|
spi2dvp_input |
cam_hal_spi2dvp_input_t |
Used with CAM_HAL_SRC_SPI2DVP. |
dvp_input |
cam_hal_dvp_input_t |
Used with CAM_HAL_SRC_DVP_AS. |
cam_hal_size_t¶
Image size.
| Field | Type | Description |
|---|---|---|
width |
uint16_t |
Width in pixels. |
height |
uint16_t |
Height in lines. |
cam_hal_crop_t¶
Crop window.
| Field | Type | Description |
|---|---|---|
start_x |
uint16_t |
Left edge in pixels; must be even. |
start_y |
uint16_t |
Top edge in lines. |
width |
uint16_t |
Width in pixels; must be even. |
height |
uint16_t |
Height in lines. |
cam_hal_frame_rate_t¶
Output frame-rate control.
Of every src_fps input frames, dst_fps are written; for example 30/15 writes every other frame.
| Field | Type | Description |
|---|---|---|
src_fps |
uint8_t |
Input frame rate; must be at least 1. |
dst_fps |
uint8_t |
Output frame rate, at most src_fps; 0 drops every frame. |
cam_out_frame_info_t¶
Frame information passed to cam_hal_cfg_t::out_callback.
| Field | Type | Description |
|---|---|---|
event |
uint32_t |
Event, one of the CAM_HAL_INT_* values. |
out_addr |
uint32_t |
Address of the frame just written. |
out_size |
uint32_t |
Size of the frame in bytes (Y and UV planes together for CAM_HAL_OUT_FMT_YUV422SP). |
cam_hal_out_t¶
Output configuration.
| Field | Type | Description |
|---|---|---|
format |
cam_hal_out_format_e |
Output format. |
ring_line |
uint16_t |
Lines of the output line ring, or 0 to write whole frames. A ring is typically read by the JPEG encoder; when non-zero, pp_num is forced to 1. |
pp_num |
uint8_t |
Number of ping-pong buffers, 1 to CAM_MAX_BUFFER_NUM; 0 is treated as 1. |
addr |
uint32_t[CAM_MAX_BUFFER_NUM] |
Output buffer addresses; writing starts at addr[0]. |
fr_ctrl |
cam_hal_frame_rate_t |
Frame-rate control; an invalid setting writes every frame. |
out_crop |
cam_hal_crop_t |
Output crop within the input image; an invalid window disables cropping. |
cam_hal_cfg_t¶
Complete camera configuration for cam_init().
| Field | Type | Description |
|---|---|---|
cam_src |
cam_hal_src_e |
Input source. |
in_size |
cam_hal_size_t |
Input image size. |
src_cfg |
cam_hal_src_cfg_t |
Source-specific input configuration. |
output_cfg |
cam_hal_out_t |
Output configuration. |
out_callback |
void(*)(cam_out_frame_info_t info) |
Frame callback, called from the capture interrupt; may be NULL. |
Macros¶
| Name | Value | Description |
|---|---|---|
CAM_MAX_BUFFER_NUM |
(2) |
Maximum number of ping-pong output buffers (see cam_hal_out_t::pp_num). |
hal_isp.h¶
#include "hal_isp.h" (Source)
Image signal processor (ISP) driver: camera or memory input, global crop, two scaler output channels plus an extended channel, frame-rate control, digital zoom and ping-pong output buffers.
The ISP takes its input from a DVP camera, an SPI camera or a test source that reads frames from memory. Output channel 0 writes YUV or Y-only images, output channel 1 writes RGB or ARGB images, and the extended channel taps the image at a selectable point of the pipeline.
Typical sequence: configure the sensor, fill an isp_hal_cfg_t, isp_init(), then isp_start(). Each written frame is reported through isp_hal_cfg_t::out_callback from the capture interrupt. Zoom, frame rate and channel settings can be changed while running. isp_deinit() removes the callbacks and disables the input.
isp_init¶
Initialize the ISP.
Configures the input path, the global crop, the YUV adjustment stage and every enabled output channel, and installs the capture interrupts. Processing starts with isp_start(). If the extended channel cannot be used because of the channel 0 format, it is skipped with a console message.
| Parameter | Description |
|---|---|
isp_hal_cfg |
Configuration. The pp_num of each channel is clamped in place to 1 to ISP_MAX_BUFFER_NUM, and an invalid global crop is corrected in place. |
| Return value | Description |
|---|---|
0 |
Success. |
1 |
The input width exceeds ISP_MAX_IN_WIDTH. |
isp_start¶
Enable the configured input source so that frames are processed.
Returns: Always 0.
isp_deinit¶
Remove the channel callbacks and interrupts and disable the input source.
Returns: Always 0.
isp_tsrc_trigger¶
Make the test source send one frame.
Use with ISP_HAL_SRC_TSRC when isp_hal_tsrc_input_t::tsrc_conti is false.
Returns: Always 0.
isp_zoom_cfg¶
Change the digital zoom (scaler input window) of a channel at run time.
The new window is applied when the ISP next reaches the middle line of a frame.
| Parameter | Description |
|---|---|
channel |
ISP_CHANNEL_0 or ISP_CHANNEL_1. |
scaler_in |
Scaler input window; start_x and width must be even and the window must lie inside the scaler input image. |
| Return value | Description |
|---|---|
0 |
Accepted. |
1 |
Invalid channel or window. |
2 |
The channel is not enabled. |
isp_fps_cfg¶
Change the output frame rate of a channel at run time.
| Parameter | Description |
|---|---|
channel |
ISP_CHANNEL_0, ISP_CHANNEL_1 or ISP_CHANNEL_EXT. |
frc |
Frame-rate setting; dst_fps = 0 drops every frame. |
| Return value | Description |
|---|---|
0 |
Applied. |
1 |
Invalid channel, or invalid setting (src_fps is 0 or dst_fps exceeds src_fps). |
2 |
The channel is not enabled. |
isp_update_chn0_cfg¶
Change the configuration of output channel 0 at run time.
Reprograms the channel's scaler and writers and enables its interrupt if needed. Call it shortly after the start of a frame so that the change does not land in the middle of a frame. With enable set to 0 the channel is only marked as disabled; its hardware is not stopped.
| Parameter | Description |
|---|---|
chn0_cfg |
New channel 0 configuration. |
Returns: Always 0.
isp_update_chn1_cfg¶
Change the configuration of output channel 1 at run time.
Reprograms the channel's scaler and writer and enables its interrupt if needed. Call it shortly after the start of a frame so that the change does not land in the middle of a frame. With enable set to 0 the channel is only marked as disabled; its hardware is not stopped.
| Parameter | Description |
|---|---|
chn1_cfg |
New channel 1 configuration. |
Returns: Always 0.
isp_get_input_resolution¶
Get the input image size passed to the last successful isp_init().
| Parameter | Description |
|---|---|
width |
Receives the input width in pixels. |
height |
Receives the input height in lines. |
Anonymous enum¶
ISP output channel index.
| Name | Value | Description |
|---|---|---|
ISP_CHANNEL_0 |
Scaler output channel 0 (YUV and Y-only formats). | |
ISP_CHANNEL_1 |
Scaler output channel 1 (RGB and ARGB formats). | |
ISP_CHANNEL_EXT |
Extended output channel. | |
ISP_CHANNEL_MAX_NUM |
Number of output channels. |
isp_hal_src_e¶
ISP input source.
| Name | Value | Description |
|---|---|---|
ISP_HAL_SRC_SPI2DVP |
0 |
SPI camera through the SPI-to-DVP bridge. |
ISP_HAL_SRC_DVP_AS |
1 |
Parallel DVP camera. |
ISP_HAL_SRC_TSRC |
9 |
Test source: frames read from memory. |
isp_hal_out_format0_e¶
Output formats of channel 0.
| Name | Value | Description |
|---|---|---|
ISP_HAL_OUT_FMT0_YUYV |
YUYV interleaved, one plane. | |
ISP_HAL_OUT_FMT0_YUV422SP |
YUV 4:2:2 semi-planar (Y plane, then UV plane). | |
ISP_HAL_OUT_FMT0_NV12 |
YUV 4:2:0 semi-planar (Y plane, then UV plane). | |
ISP_HAL_OUT_FMT0_Y_ONLY |
Y (luminance) only. |
isp_hal_out_format1_e¶
Output formats of channel 1.
| Name | Value | Description |
|---|---|---|
ISP_HAL_OUT_FMT1_RGB |
RGB. | |
ISP_HAL_OUT_FMT1_ARGB |
ARGB. |
isp_hal_ext_src_e¶
Tap point of the extended channel.
| Name | Value | Description |
|---|---|---|
ISP_HAL_EXT_SRC_RAW |
The raw ISP input image. | |
ISP_HAL_EXT_SRC_ISP_OUT |
The ISP output, before the scalers. | |
ISP_HAL_EXT_SRC_OUT_CHN0_IN |
Scaler output channel 0; channel 0 must be enabled. | |
ISP_HAL_EXT_SRC_OUT_CHN1_IN |
Scaler output channel 1; channel 1 must be enabled. |
isp_hal_out_format_ext_e¶
Output formats of the extended channel.
| Name | Value | Description |
|---|---|---|
ISP_HAL_OUT_FMT_EXT_YUYV |
YUYV; available for every tap point. | |
ISP_HAL_OUT_FMT_EXT_Y_ONLY |
Y only; available for every tap point. | |
ISP_HAL_OUT_FMT_EXT_RGB |
RGB; only with ISP_HAL_EXT_SRC_OUT_CHN1_IN. |
|
ISP_HAL_OUT_FMT_EXT_ARGB |
ARGB; only with ISP_HAL_EXT_SRC_OUT_CHN1_IN. |
Anonymous enum¶
Events reported in isp_out_frame_info_t::event.
| Name | Value | Description |
|---|---|---|
ISP_HAL_INT_NORMAL |
A frame has been written. | |
ISP_HAL_INT_FIFO_OVERWRITE |
FIFO overwrite. | |
ISP_HAL_INT_VSYNC_CNT_ERROR |
The number of valid lines per frame did not match the expected height. | |
ISP_HAL_INT_HSYNC_CNT_ERROR |
The number of valid pixels per line did not match the expected width. | |
ISP_HAL_INT_ALL |
Number of event codes. |
isp_hal_spi2dvp_sel_e¶
SPI port used by the SPI-to-DVP bridge.
| Name | Value | Description |
|---|---|---|
ISP_HAL_SPI2DVP_SEL_SPI_0 |
SPI port 0. | |
ISP_HAL_SPI2DVP_SEL_SPI_1 |
SPI port 1. |
isp_hal_spi2dvp_data_order_e¶
SPI2DVP data order.
| Name | Value | Description |
|---|---|---|
ISP_HAL_SPI2DVP_ORDER_UV_FIRST |
The first input byte is a chroma (UV) byte. | |
ISP_HAL_SPI2DVP_ORDER_Y_FIRST |
The first input byte is a luma (Y) byte. |
isp_hal_spi2dvp_data_format_e¶
SPI2DVP input format.
| Name | Value | Description |
|---|---|---|
ISP_HAL_SPI2DVP_FORMAT_YUV422 |
YUV 4:2:2 interleaved input. | |
ISP_HAL_SPI2DVP_FORMAT_Y_ONLY |
Y-only input. |
isp_hal_spi2dvp_mode_e¶
SPI2DVP SPI mode (clock phase and polarity).
| Name | Value | Description |
|---|---|---|
ISP_HAL_SPI2DVP_MODE_0 |
SPI mode 0: phase 0, polarity 0. | |
ISP_HAL_SPI2DVP_MODE_1 |
SPI mode 1: phase 1, polarity 0. | |
ISP_HAL_SPI2DVP_MODE_2 |
SPI mode 2: phase 0, polarity 1. | |
ISP_HAL_SPI2DVP_MODE_3 |
SPI mode 3: phase 1, polarity 1. |
isp_hal_spi2dvp_data_endian_e¶
SPI2DVP bit order.
| Name | Value | Description |
|---|---|---|
ISP_HAL_SPI2DVP_ENDIAN_LSB |
LSB first. | |
ISP_HAL_SPI2DVP_ENDIAN_MSB |
MSB first. |
isp_hal_dvp_active_type_e¶
DVP HSYNC/VSYNC active level.
| Name | Value | Description |
|---|---|---|
ISP_HAL_DVP_ACTIVE_HIGH |
Active high. | |
ISP_HAL_DVP_ACTIVE_LOW |
Active low. |
isp_hal_dvp_data_byte_t¶
DVP input byte order.
| Name | Value | Description |
|---|---|---|
ISP_HAL_DATA_BYTE_LOWER |
The first byte is the lower byte. | |
ISP_HAL_DATA_BYTE_HIGHER |
The first byte is the higher byte. |
isp_hal_spi2dvp_input_t¶
SPI2DVP input configuration.
| Field | Type | Description |
|---|---|---|
order |
isp_hal_spi2dvp_data_order_e |
Data order: Y first or UV first. |
format |
isp_hal_spi2dvp_data_format_e |
Input format: YUYV or Y only. |
mode |
isp_hal_spi2dvp_mode_e |
SPI mode (clock phase and polarity). |
endian |
isp_hal_spi2dvp_data_endian_e |
Bit order: LSB or MSB first. |
spi_sel |
isp_hal_spi2dvp_sel_e |
SPI port: SPI 0 or SPI 1. |
isp_hal_dvp_input_t¶
DVP input configuration.
| Field | Type | Description |
|---|---|---|
hsync |
isp_hal_dvp_active_type_e |
HSYNC active level. |
vsync |
isp_hal_dvp_active_type_e |
VSYNC active level. |
order |
isp_hal_dvp_data_byte_t |
Byte order: lower or higher byte first. |
pclk |
uint32_t |
Sensor pixel clock in Hz. |
totalHPixels |
uint16_t |
Sensor line length including horizontal blanking, in pixels. |
isp_hal_tsrc_input_t¶
Test-source (memory input) configuration.
| Field | Type | Description |
|---|---|---|
input_addr |
uint32_t |
Address of the input frame (YUV 4:2:2, 16 bits per pixel). |
tsrc_conti |
bool |
true: read frames continuously; false: read one frame per isp_tsrc_trigger() |
isp_hal_src_cfg_t¶
Source-specific input configuration; the member is selected by isp_hal_cfg_t::isp_src.
| Field | Type | Description |
|---|---|---|
spi2dvp_input |
isp_hal_spi2dvp_input_t |
Used with ISP_HAL_SRC_SPI2DVP. |
dvp_input |
isp_hal_dvp_input_t |
Used with ISP_HAL_SRC_DVP_AS. |
tsrc_input |
isp_hal_tsrc_input_t |
Used with ISP_HAL_SRC_TSRC. |
isp_hal_size_t¶
Image size.
| Field | Type | Description |
|---|---|---|
width |
uint16_t |
Width in pixels. |
height |
uint16_t |
Height in lines. |
isp_hal_crop_t¶
Crop window.
| Field | Type | Description |
|---|---|---|
start_x |
uint16_t |
Left edge in pixels; must be even. |
start_y |
uint16_t |
Top edge in lines. |
width |
uint16_t |
Width in pixels; must be even. |
height |
uint16_t |
Height in lines. |
isp_hal_scaler_cfg_t¶
Scaler input and output of an output channel.
| Field | Type | Description |
|---|---|---|
in |
isp_hal_crop_t |
Scaler input window; a window smaller than the image gives a digital zoom. |
out |
isp_hal_size_t |
Scaler output size, at most ISP_MAX_OUT_WIDTH x ISP_MAX_OUT_HEIGHT. |
isp_hal_frame_rate_t¶
Output-channel frame-rate control.
Of every src_fps input frames, dst_fps are written; for example 30/15 writes every other frame.
| Field | Type | Description |
|---|---|---|
src_fps |
uint8_t |
Input frame rate; must be at least 1. |
dst_fps |
uint8_t |
Output frame rate, at most src_fps; 0 drops every frame. |
isp_out_frame_info_t¶
Frame information passed to isp_hal_cfg_t::out_callback.
| Field | Type | Description |
|---|---|---|
event |
uint32_t |
Event, one of the ISP_HAL_INT_* values. |
out_port |
uint32_t |
Output channel: ISP_CHANNEL_0, ISP_CHANNEL_1 or ISP_CHANNEL_EXT. |
out_addr |
uint32_t |
Address of the frame just written. |
out_size |
uint32_t |
Size of the frame in bytes. |
isp_hal_out_chn_comm_t¶
Settings common to all output channels.
| Field | Type | Description |
|---|---|---|
pp_num |
uint8_t |
Number of ping-pong buffers, 1 to ISP_MAX_BUFFER_NUM; 0 is treated as 1. |
addr |
uint32_t[ISP_MAX_BUFFER_NUM] |
Output buffer addresses; writing starts at addr[0]. |
fr_ctrl |
isp_hal_frame_rate_t |
Frame-rate control. |
out_crop |
isp_hal_crop_t |
Final crop of the channel output. |
isp_hal_out_chnl_0_t¶
Output channel 0 configuration.
| Field | Type | Description |
|---|---|---|
enable |
uint8_t |
Non-zero enables the channel. |
scaler_cfg |
isp_hal_scaler_cfg_t |
Scaler input and output. |
format |
isp_hal_out_format0_e |
Output format. |
ring_line |
uint16_t |
Lines of the output line ring, or 0 to write whole frames. A ring is typically read by the JPEG encoder; when non-zero, pp_num is forced to 1. |
chn_common |
isp_hal_out_chn_comm_t |
Common output settings. |
isp_hal_out_chnl_1_t¶
Output channel 1 configuration.
| Field | Type | Description |
|---|---|---|
enable |
uint8_t |
Non-zero enables the channel. |
scaler_cfg |
isp_hal_scaler_cfg_t |
Scaler input and output. |
format |
isp_hal_out_format1_e |
Output format. |
chn_common |
isp_hal_out_chn_comm_t |
Common output settings. |
isp_hal_out_chnl_ext_t¶
Extended output channel configuration.
| Field | Type | Description |
|---|---|---|
enable |
uint8_t |
Non-zero enables the channel. |
ext_src |
isp_hal_ext_src_e |
Tap point. |
format |
isp_hal_out_format_ext_e |
Output format. |
chn_common |
isp_hal_out_chn_comm_t |
Common output settings. |
isp_hal_cfg_t¶
Complete ISP configuration for isp_init().
| Field | Type | Description |
|---|---|---|
isp_src |
isp_hal_src_e |
Input source. |
in_size |
isp_hal_size_t |
Input image size; the width must not exceed ISP_MAX_IN_WIDTH. |
src_cfg |
isp_hal_src_cfg_t |
Source-specific input configuration. |
glb_crop |
isp_hal_crop_t |
Global crop applied to the ISP output before the scalers. |
yuv_adj_en |
uint8_t |
Non-zero enables the YUV adjustment stage. |
out_ch_0 |
isp_hal_out_chnl_0_t |
Output channel 0; its buffers may be in OCRAM or PSRAM. |
out_ch_1 |
isp_hal_out_chnl_1_t |
Output channel 1; its buffers must be in PSRAM. |
out_ch_ext |
isp_hal_out_chnl_ext_t |
Extended output channel; its buffers may be in OCRAM or PSRAM. Not available when channel 0 is enabled with the YUV422SP or NV12 format. |
out_callback |
void(*)(isp_out_frame_info_t info) |
Frame callback for all channels, called from the capture interrupt; may be NULL. |
Macros¶
| Name | Value | Description |
|---|---|---|
ISP_MAX_IN_WIDTH |
(1280) |
Maximum input width in pixels; isp_init() rejects wider inputs. |
ISP_MAX_IN_HEIGHT |
(720) |
Maximum input height in lines. |
ISP_MAX_OUT_WIDTH |
(1920) |
Maximum scaler output width in pixels. |
ISP_MAX_OUT_HEIGHT |
(1080) |
Maximum scaler output height in lines. |
ISP_MAX_BUFFER_NUM |
(2) |
Maximum number of ping-pong output buffers per channel (see isp_hal_out_chn_comm_t::pp_num). |
hal_mjpeg.h¶
#include "hal_mjpeg.h" (Source)
Hardware JPEG encoder driver: encode YUV 4:2:2, YUV 4:2:0 or grey-scale frames to baseline JPEG in software-triggered or hardware auto mode.
The encoder shares the JPEG hardware block with the decoder (hal_mjdec.h); only one of them can be initialized at a time. Encoded frames are kept in a queue: mjpeg_get_one_frame() returns the oldest one and mjpeg_drop_one_frame() releases it.
Software-triggered sequence: mjpeg_init(); build a header with mjpeg_headerCreate() and load it with mjpeg_fill_header_tail(); for each frame, clean the data cache over the input, set the input planes with mjpeg_set_input_addr(), then for the first frame call mjpeg_set_mode(1, 1, 1) and mjpeg_start(1), and for later frames mjpeg_sw_run_next(); wait for MJENC_HAL_INT_NORMAL in the callback, fetch the frame, invalidate the data cache over it, use it and drop it. Finish with mjpeg_stop() and mjpeg_deinit().
In hardware auto mode (mjpeg_start(0)) the encoder reads the frames that the camera or ISP writes into the input buffer (a full frame or a ring of mjpeg_hal_cfg_t::rows lines) and encodes them continuously.
mjpeg_init¶
Initialize the encoder.
Claims the JPEG hardware for encoding, programs the format, image size, buffers and quantization tables, and installs and enables the encoder interrupt. The frame-done and error events stay masked until mjpeg_start(); the swap event is enabled when swap mode is selected.
| Parameter | Description |
|---|---|
mjpeg_hal_cfg |
Encoder configuration. |
| Return value | Description |
|---|---|
0 |
Success. |
-1 |
The JPEG hardware is initialized for decoding. |
mjpeg_deinit¶
Release the JPEG hardware from encoding.
| Return value | Description |
|---|---|
0 |
Released (or not initialized). |
-1 |
The JPEG hardware is initialized for decoding. |
mjpeg_start¶
Start encoding.
Enables the frame-done and error events, then either triggers a software-mode run as configured by mjpeg_set_mode() or starts hardware auto mode.
| Parameter | Description |
|---|---|
is_sw_mode |
Non-zero: software-triggered mode. 0: hardware auto mode. |
mjpeg_stop¶
Disable the encoder.
mjpeg_get_one_frame¶
Get the oldest encoded frame without removing it.
The frame (header included) stays valid until mjpeg_drop_one_frame() is called. Invalidate the data cache over it before reading it.
| Parameter | Description |
|---|---|
addr |
Start address of the JPEG frame. |
len |
Frame length in bytes. |
| Return value | Description |
|---|---|
0 |
A frame is available. |
1 |
No frame is available. |
mjpeg_drop_one_frame¶
Release the oldest encoded frame so that its space can be reused.
mjpeg_fill_header_tail¶
Load the JPEG header that the encoder writes in front of each frame.
| Parameter | Description |
|---|---|
header |
Header bytes, for example built by mjpeg_headerCreate(). |
header_len |
Header length in bytes. |
mjpeg_headerCreate¶
Build a baseline JPEG header.
Writes the start-of-image marker, the luminance and chrominance quantization tables for quality q, the frame header, the standard Huffman tables and the start-of-scan header.
| Parameter | Description |
|---|---|
type |
Header type: YUV_MODE_400, YUV_MODE_420 or YUV_MODE_422. |
q |
JPEG quality, 1 to 100; use the value of mjpeg_hal_cfg_t::quality. |
width |
Image width in pixels. |
height |
Image height in pixels. |
out |
Destination buffer, at least 605 bytes. |
Returns: Header length in bytes: 605 for YUV_MODE_420 and YUV_MODE_422, 595 for YUV_MODE_400.
mjpeg_set_mode¶
Configure software-triggered mode.
| Parameter | Description |
|---|---|
is_sw_mode |
Non-zero to configure software mode; 0 does nothing. |
is_frame_mode |
Non-zero: frame mode (whole frames per run). 0: kick mode (block rows per mjpeg_sw_kick()). |
frm_cnt |
Number of frames encoded per run. |
mjpeg_sw_run_next¶
Trigger the next software-mode run.
mjpeg_sw_run_abort¶
Abort the current software-mode run.
mjpeg_sw_kick_block¶
Set the number of block rows encoded per kick in software kick mode.
| Parameter | Description |
|---|---|
kick_count |
Number of block rows per mjpeg_sw_kick() (13-bit value). |
mjpeg_sw_kick_stop¶
Leave software kick mode.
mjpeg_sw_kick¶
Encode the next group of block rows in software kick mode.
mjpeg_set_input_addr¶
Set an input plane address.
| Parameter | Description |
|---|---|
type |
MJPEG_HAL_SET_ADDR_Y or MJPEG_HAL_SET_ADDR_UV; other values are ignored. |
addr |
Plane address. |
mjpeg_get_swap_occur_cnt¶
Get the number of swap events in the current frame.
Counts MJENC_HAL_INT_SWAP events since mjpeg_init(), restarting from 0 when a swap event marks the end of a frame.
Returns: Number of swap events.
mjpeg_free_swap_memory¶
In swap mode, mark the output buffer halves as consumed so that the encoder can reuse them.
Anonymous enum¶
Input formats for mjpeg_hal_cfg_t::format.
| Name | Value | Description |
|---|---|---|
MJPEG_HAL_FORMAT_YUV422_YUYV |
0 |
YUV 4:2:2 interleaved, byte order Y0 U Y1 V. |
MJPEG_HAL_FORMAT_YUV422_YVYU |
1 |
YUV 4:2:2 interleaved, byte order Y0 V Y1 U. |
MJPEG_HAL_FORMAT_YUV422_UYVY |
2 |
YUV 4:2:2 interleaved, byte order U Y0 V Y1. |
MJPEG_HAL_FORMAT_YUV422_VYUY |
3 |
YUV 4:2:2 interleaved, byte order V Y0 U Y1. |
MJPEG_HAL_FORMAT_YUV422SP_NV16 |
4 |
YUV 4:2:2 semi-planar, UV plane U first. |
MJPEG_HAL_FORMAT_YUV422SP_NV61 |
5 |
YUV 4:2:2 semi-planar, UV plane V first. |
MJPEG_HAL_FORMAT_YUV420SP_NV12 |
6 |
YUV 4:2:0 semi-planar, UV plane U first. |
MJPEG_HAL_FORMAT_YUV420SP_NV21 |
7 |
YUV 4:2:0 semi-planar, UV plane V first. |
MJPEG_HAL_FORMAT_GRAY |
8 |
Grey scale (Y plane only). |
Anonymous enum¶
Events passed to mjpeg_hal_cfg_t::callback.
| Name | Value | Description |
|---|---|---|
MJENC_HAL_INT_NORMAL |
0 |
A frame has been encoded. |
MJENC_HAL_INT_IDLE |
The encoder entered idle. | |
MJENC_HAL_INT_SWAP |
Swap mode: one half of the output buffer is full. | |
MJENC_HAL_INT_ERR_CAM_OVERWRITE |
An input frame was overwritten before it was encoded. | |
MJENC_HAL_INT_ERR_MEM_OVERWRITE |
The output buffer is full. | |
MJENC_HAL_INT_ERR_FRAME_OVERWRITE |
The frame-information queue is full; the record of a new frame was lost. |
Anonymous enum¶
Input plane selector for mjpeg_set_input_addr().
| Name | Value | Description |
|---|---|---|
MJPEG_HAL_SET_ADDR_Y |
0 |
Y plane, or the whole frame for interleaved and grey formats. |
MJPEG_HAL_SET_ADDR_UV |
UV plane of semi-planar formats. |
mjpeg_hal_cfg_t¶
Encoder configuration for mjpeg_init().
| Field | Type | Description |
|---|---|---|
format |
uint8_t |
Input format, one of the MJPEG_HAL_FORMAT_* values. |
quality |
uint8_t |
JPEG quality, 1 to 100 (0 is treated as 1). Pass the same value to mjpeg_headerCreate(). |
rows |
uint16_t |
Number of input lines held in the input buffer: the frame height for a full-frame buffer, or the ring height for a line ring. Use a multiple of 8 (16 for 4:2:0 formats). |
resolution_x |
uint16_t |
Image width in pixels. |
resolution_y |
uint16_t |
Image height in pixels. |
input_bufaddr0 |
uint32_t |
Address of the Y plane, or of the whole frame for interleaved and grey formats. |
input_bufaddr1 |
uint32_t |
Address of the UV plane (semi-planar formats). |
output_bufaddr |
uint32_t |
Output (bitstream) buffer address, 4-byte aligned. |
output_bufsize |
uint32_t |
Output buffer size in bytes; rounded down to a multiple of 128. |
input_yy_table |
uint16_t * |
Not used; the driver uses its built-in luminance quantization table. |
input_uv_table |
uint16_t * |
Not used; the driver uses its built-in chrominance quantization table. |
output_swap_mode_en |
uint8_t |
0: frame mode. 1: swap mode; the output buffer is split into two halves used as ping-pong buffers, with MJENC_HAL_INT_SWAP each time a half is full. |
hw_mode_swen_en |
uint8_t |
Hardware auto mode: 1 starts encoding without waiting for the first frame-done of the input source. |
hw_mode_sshot_en |
uint8_t |
Hardware auto mode: 1 encodes a single frame and does not restart the encoder after it. |
callback |
void(*)(uint32_t event) |
Event callback, called from the JPEG encoder interrupt with an MJENC_HAL_INT_* value. Must not be NULL. |
Macros¶
| Name | Value | Description |
|---|---|---|
_MJPEG_SW_OUT_PING_PONG_MODE_ |
Defined on IPRO7. In hardware auto mode without output swap mode, the driver splits the output buffer into two halves that it uses alternately, and stops and restarts the encoder after every frame. This avoids an encoder stall after 255 frames when the input is a line ring. mjpeg_get_one_frame() and mjpeg_drop_one_frame() then operate on this two-entry queue. |
|
YUV_MODE_400 |
1 |
Header type for mjpeg_headerCreate(): grey scale. |
YUV_MODE_420 |
2 |
Header type for mjpeg_headerCreate(): YUV 4:2:0. |
YUV_MODE_422 |
3 |
Header type for mjpeg_headerCreate(): YUV 4:2:2. |
MJPEG_DEFAULT_QUALITY |
50 |
Default JPEG quality (1 to 100). |
hal_mjdec.h¶
#include "hal_mjdec.h" (Source)
Hardware JPEG decoder driver: decode a baseline JPEG into semi-planar YUV or grey-scale frames.
The decoder shares the JPEG hardware block with the encoder (hal_mjpeg.h); only one of them can be initialized at a time. Typical sequence: mjdec_init(), mjdec_set_callback(), clean the data cache over the JPEG data, then mjdec_start_decoder(). Decoding runs in the background; the callback reports the decoded frame from the decoder interrupt, after which the decoder is disabled. Invalidate the data cache over the output planes before reading them, and call mjdec_deinit() to hand the hardware back.
mjdec_init¶
Initialize the decoder.
Claims the JPEG hardware for decoding, parses the JPEG header when mjdec_config_t::is_skip_header is 1, programs the output format and buffers, and installs and enables the decoder interrupt.
| Parameter | Description |
|---|---|
config |
Decoder configuration. |
| Return value | Description |
|---|---|
0 |
Success. |
-1 |
The JPEG hardware is initialized for encoding, the header could not be parsed, or its dimensions do not match width and height. |
mjdec_deinit¶
Release the JPEG hardware from decoding.
| Return value | Description |
|---|---|
0 |
Released (or not initialized). |
-1 |
The JPEG hardware is initialized for encoding. |
mjdec_disable¶
Disable the decoder.
mjdec_start_decoder¶
Start decoding one JPEG frame.
Enables the decoder and queues the JPEG data; returns without waiting. Clean the data cache over the JPEG data first.
| Parameter | Description |
|---|---|
jpeg_buf_addr |
JPEG data; must be 8-byte aligned, otherwise it is not queued. |
Returns: Always 0.
mjdec_set_callback¶
Install the frame callback.
| Parameter | Description |
|---|---|
frame_cb |
Callback, or NULL to remove it. |
usrdata |
Pointer passed back to the callback. |
Returns: Always 0.
mjdec_irq_handler¶
Decoder interrupt handler.
Installed by mjdec_init(); applications do not call it.
Anonymous enum¶
Interrupt types reported in mjdec_frame_desc_t::ucIntType.
| Name | Value | Description |
|---|---|---|
MJDEC_HAL_INT_NORMAL |
0 |
A frame has been decoded. |
MJDEC_HAL_INT_BACK_IDLE |
The decoder returned to idle (not reported to the callback). | |
MJDEC_HAL_INT_ALL |
Number of interrupt types. |
Anonymous enum¶
Output formats for mjdec_config_t::yuv_mode.
| Name | Value | Description |
|---|---|---|
MJDEC_HAL_FORMAT_YUV420_SP |
0 |
YUV 4:2:0 semi-planar: a Y plane and an interleaved UV plane of half height (NV12/NV21). |
MJDEC_HAL_FORMAT_YUV400 |
1 |
Grey scale: Y plane only. |
MJDEC_HAL_FORMAT_YUV422_SP |
2 |
YUV 4:2:2 semi-planar: a Y plane and an interleaved UV plane of full height (NV16/NV61). |
mjdec_config_t¶
Decoder configuration for mjdec_init().
| Field | Type | Description |
|---|---|---|
width |
uint16_t |
Image width in pixels; must match the JPEG header when is_skip_header is 1. |
height |
uint16_t |
Image height in pixels; must match the JPEG header when is_skip_header is 1. |
input_buf_addr |
uint8_t * |
JPEG data used to parse the header at init. |
output_buf_addr_yy |
uint8_t * |
Y-plane output buffer. The driver rounds the address up to a multiple of 8 bytes; a 32-byte-aligned buffer is recommended for cache maintenance. |
output_buf_addr_uv |
uint8_t * |
UV-plane output buffer (not used for MJDEC_HAL_FORMAT_YUV400); same alignment rules. |
yuv_mode |
uint8_t |
Output format, one of the MJDEC_HAL_FORMAT_* values. |
is_skip_header |
uint8_t |
1: the data starts with a JPEG header; mjdec_init() parses it (searching the first 714, 599 or 605 bytes for YUV420, YUV400 and YUV422 respectively), loads its tables and the decoder skips it. 0: the data has no header. |
out_u_order_even |
uint8_t |
1: U samples at even and V samples at odd byte offsets of the UV plane; 0: the reverse order |
mjdec_frame_desc_t¶
Decoded frame description passed to the frame callback.
| Field | Type | Description |
|---|---|---|
frame_start_addr_yy |
uint8_t * |
Start of the Y plane. |
frame_start_addr_uv |
uint8_t * |
Start of the UV plane. |
frame_size_yy |
uint32_t |
Y-plane size in bytes as reported by the driver. The current driver reports width x 8 here, not the full plane size; compute the plane size from the image dimensions. |
frame_size_uv |
uint32_t |
UV-plane size in bytes: width x height for YUV422, width x height / 2 for YUV420, 0 for YUV400. |
ucIntType |
uint8_t |
Interrupt type, MJDEC_HAL_INT_NORMAL. |
Typedefs¶
| Name | Definition | Description |
|---|---|---|
mjdec_frame_cb |
typedef int(*) mjdec_frame_cb(void *usrdata, mjdec_frame_desc_t *frame_desc) |
Frame callback. Called from the decoder interrupt when a frame has been decoded. Use only interrupt-safe calls. |