JPEGENC APIs

[English]

Important

The JPEGENC API v1.0 is the lastest stable JPEGENC APIs. All new applications should use JPEGENC API v1.0.

JPEGENC Interface

The JPEGENC module can work two different mode
  • 0: JPEG ENCODER mode, output jpeg data

  • 1: YUV mode, output camera sample data, yuv data

JPEGENC API Categories

Most of JPEGENC APIs can be categoried as:

  • JPEGENC APIs

    The common APIs are prefixed with bk_jpeg_enc, e.g. bk_jpeg_enc_driver_init() etc.

JPEGENC APIs:

API Reference

Header File

Functions

bk_err_t bk_jpeg_enc_driver_init(void)

Init the jpeg encode driver.

This API init the resoure common:

  • Init jpegenc driver control memory

  • register jpegenc isr

Attention

1. This API should be called before any other jpeg APIs.

2. This API will power up video when soc is bk7256XX

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_driver_deinit(void)

Deinit the jpegenc driver.

This API free all resource related to jpegenc and disable jpegenc.

Attention

1. This API will power down video when soc is bk7256XX

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_init(const jpeg_config_t *config)

Init the jpeg encode.

This API init the jpegenc

  • Configure clock and Power up the jpegenc

  • Enable Jpegenc interrupt

  • Map the jpegenc to dedicated GPIO port(MCLK and PCLK)

  • Set the jpegenc parameters

  • set and start the dma function

  • Enable jpeg encode module

Usage example:

 jpeg_config_t init_config = {
                     .rx_buf = xxx, // the address point to mem for receiving jpeg data
                     .yuv_mode = 0,
                     .sys_clk_div = 3, // jpeg_clk = 480 / (1+3) =120MHz
                     .mclk_div = 0, // MCLK=jpeg_clk/4 = 30MHz
                     .rx_buf_len = xxx, // the length of receive jpeg data
                     .node_len = xxx, // dma transfer length
                     .x_pixel = 80, // jpeg image resolution of width: 80 * 8 = 640
                     .y_pixel = 60, // jpeg image resolution of height: 60 * 8 = 480
                     .dma_rx_finish_handler = cb, // dma transfer finish callback
                 };
 BK_LOG_ON_ERR(bk_jpeg_init(&init_config);

Attention

1. only work for imaging transfer

Parameters

config – jpeg encode parameter settings

Returns

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: jpegenc config paramter is NULL

  • BK_ERR_JPEG_NOT_INIT: jpegenc driver not init

  • others: other errors.

bk_err_t bk_jpeg_enc_deinit(void)

Deinit the jpeg.

This API stop jpeg encode, dma and close jpeg gpio, power off jpeg module at last.

Attention

1. only work for imaging transfer

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_dvp_init(const jpeg_config_t *config)

Init the jpeg when use dvp.

This API init the jpeg

  • Configure clock and Power up the jpegenc clock

  • enable the JPEG encode interrupt

  • Map the jpegenc to dedicated GPIO port(MCLK and PCLK)

  • Set the jpegenc parameters

  • Enable Jpeg encode module

Attention

1. not init dma function compare with bk_jpeg_init, need user init dma

Parameters

config – jpeg parameter settings

Returns

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: jpegenc config paramter is NULL

  • BK_ERR_JPEG_NOT_INIT: jpegenc driver not init

  • others: other errors.

bk_err_t bk_jpeg_enc_dvp_deinit(void)

Deinit the jpeg when use dvp.

This API stop jpeg encode, close jpeg gpio, and power off jpeg module at last.

Attention

1. not stop dma compare with bk_jpeg_deinit

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_set_enable(uint8_t enable, uint8_t mode)

set jpegenc enable

This API will set jpegenc work enable/disable.

Attention

1. if work in jpegenc mode, this api can enable/disable jpegenc mode

2. if work in yuv mode, this api only can disable yuv_mode. The bk_jpeg_set_yuv_mode api also can set yuv mode enable/disable.

Parameters
  • enable – 0/1:jpegenc work disable/enable

  • mode – 0/1:jpeg encode mode/yuv mode

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_yuv_fmt_sel(uint32_t value)

yuv format select

This API will set yuv output format.

Attention

1. this function only used when jpeg at yuv mode

Parameters

value – 0:yuyv, 1:uyvy, 2:yyuv, 3:uvyy

Returns

  • BK_OK: succeed

  • others: other errors.

uint32_t bk_jpeg_enc_get_frame_size(void)

get a frame size output from jpegenc module, uint byte

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_register_isr(jpeg_isr_type_t type_id, jpeg_isr_t isr, void *param)

register frame end isr

This API will register jpeg encode isr function, need user defined.The isr function will execute when the isr be triggered.

.*

Attention

1. This API only effect when work yuv mode

Parameters
  • type_id – the type of the isr

    • JPEG_EOY: (eoy)when jpeg encode work in yuv mode, once a complete frame have been transfer by jpeg encode module, the isr will trigger.

    • JPEG_HEAD_OUTPUT: jpeg encode output head the isrt will be triggered, work in jpeg encode mode.

    • START_OFFRAME: (sof) when jpeg encode module start reveice a frame the isr will be triggered.

    • JPEG_EOF: (eof) when jpeg encode module receive a complete frame the isr will be triggered, this only effect in jpeg encode mode.

    • JPEG_VSYNC_NEGEDGE: (vng) when jpeg encode module receive a vsync negedge the isr will be triggered.

  • isr – isr_func

  • param – other value(default set NULL)

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_set_gpio(jpeg_gpio_mode_t mode)

set jpeg gpio function

This API will operate jpeg gpio

Parameters

mode, : – reference jpeg_gpio_mode_t

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_get_fifo_addr(uint32_t *fifo_addr)

get jpeg enc fifo addr

This API will get jpeg encode fifo addr in param

Attention

1. only work in jpeg encode mode is effective

Parameters

fifo_addr – fifo addr

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_set_auxs(uint32_t cksel, uint32_t ckdiv)

set mclk output

This API will use for camera config

1. this api only used for bk7256xx_mp chip, and when use this api, this api ‘bk_jpeg_enc_mclk_enable’ will not useful

Parameters
  • cksel – 0-3:0:DCO/1:APLL/2:320M/3:480M,use 2 or 3

  • ckdiv – 0-15, div = 1/(ckdiv+1)

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_mclk_enable(void)

set jpeg module mclk enable

This API will set jpeg mclk output for sensor

1. this api must call after bk_jpeg_enc_driver_init, and output 24MHz.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_partial_display_init(const jpeg_partial_offset_config_t *offset_config)

partial display init

This API will use for partial display configure of jpeg encode

Parameters

offset_config – x_pixel left/right offset and y_pixel left/right offset configure

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_partial_display_deinit(void)

partial display deinit

This API will use for partial display deinit

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_set_em_base_addr(uint8_t *address)

jpeg em base set

This API will use for jpeg em base address, 64KB memory align.

Parameters

address – set a mem used for jpeg encode

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_encode_config(uint8_t enable, uint16_t up_size, uint16_t low_size)

jpeg encode enable encode auto contrl

This API will use for enable/disable for auto encode size. only valid in jpeh encode mode

1. this api only called in jpeg_eof_isr function, and only bk_jpeg_enc_enable_encode_auto_ctrl have been set enable

Parameters
  • up_size – the jpeg image upper limit, unit byte

  • low_size – the jpeg image lower limit, unit byte

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_enable_vsync_hsync_reverse(uint8_t vsync_enable, uint8_t hsync_enable)

jpeg encode enable vsync vsync reverse

This API will use for enable reverse vsync or hsync singal

1. this JPEG mode work in vsync and hsync high

Parameters
  • vsync_enable – 1/0:enbale/disable reverse vsync singal

  • hsync_enable – 1/0:enbale/disable reverse hsync singal

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_jpeg_enc_dvp_switch(jpeg_config_t *config)

jpeg encode mode and yuv mode switch

This API will use for switch jpeg mode

1. this api must called in jpeg_eof isr or yuv_eof isr

Parameters

config – jpeg encode config or jpeg yuv config

Returns

  • BK_OK: succeed

  • others: other errors.

API Typedefs

Header File

Structures

struct jpegenc_desc_t

Public Members

uint8_t *rxbuf

the address of receiving jpeg data

void (*node_full_handler)(void *curptr, uint32_t newlen, uint32_t is_eof, uint32_t frame_len)

node full handler

This is a transfer jpeg data to uplayer api, when transfer node_len jpeg data finish , this function will be called

Param curptr, :

the start address of transfer data.

Param newlen, :

the transfer data length

Param is_eof, :

0/1: whether this packet data is the last packet of this frame, will called in jpeg_end_frame isr

Param frame_len, :

the complete jpeg frame size, if is_eof=1, the frame_len is the true value of jpeg frame size, is_eof=0, the frame_len=0, in other words, only when transfer really frame_len at the last packet in jpeg_end_frame isr

void (*data_end_handler)(void)

brief data_end_handler

This api use to inforamte video transfer thread to deal transfer jpegenc data

uint16_t rxbuf_len

The length of receiving jpegenc data buff

uint16_t rx_read_len

manage the node_full_handler callback function input params

uint32_t node_len

dma transfer length

uint32_t sener_cfg

The sensor config:[0-15]:image_resolution, [16-31]:image rate

uint16_t x_pixel

jpeg encoder image resolution for width

uint16_t y_pixel

jpeg encoder image resolution for height

Macros

Y_PIXEL_272

JPEGENC APIs Version 1.0.

image resolution for hight: Y * 8 = 272

Y_PIXEL_320

image resolution for hight: Y * 8 = 320

X_PIXEL_480

image resolution for width: X * 8 = 480

Y_PIXEL_480

image resolution for hight: Y * 8 = 480

X_PIXEL_640

image resolution for hight: X * 8 = 640

Y_PIXEL_240

image resolution for hight: Y * 8 = 240

X_PIXEL_320

image resolution for hight: X * 8 = 320

Y_PIXEL_600

image resolution for hight: Y * 8 = 600

X_PIXEL_800

image resolution for hight: X * 8 = 800

Y_PIXEL_720

image resolution for hight: Y * 8 = 720

X_PIXEL_1280

image resolution for hight: X * 8 = 1280

X_PIXEL_1600

image resolution for hight: X * 8 = 1600

Y_PIXEL_1200

image resolution for hight: Y * 8 = 1200

Type Definitions

typedef void (*jpeg_isr_t)(jpeg_unit_t id, void *param)

jpeg isr callback relay jpeg driver

Param id, :

only 0 useful, set 0 default

Param param, :

NULL default

Enumerations

enum jpeg_mode_t

Values:

enumerator JPEG_ENC_MODE
enumerator JPEG_YUV_MODE
enum jpeg_sys_clk_t

Values:

enumerator JPEG_SYS_CLK_320M
enumerator JPEG_SYS_CLK_480M
enum jpeg_mclk_div_t

Values:

enumerator JPEG_MCLK_DIV_4
enumerator JPEG_MCLK_DIV_6
enumerator JPEG_MCLK_DIV_2
enumerator JPEG_MCLK_DIV_3
enum jpeg_yuv_format_t

jpeg_yuv_format_t when jpeg encode at yuv mode, the output yuv format type

1. fllow type out base on input YUYV

Values:

enumerator JPEG_YUYV

YUYV, bit[31-0]=[YUYV]

enumerator JPEG_UYVY

UYVY, bit[31-0]=[UYVY]

enumerator JPEG_YYUV

YYUV, bit[31-0]=[YYUV]

enumerator JPEG_UVYY

UVYY, bit[31-0]=[UVYY]

enum jpeg_isr_type_t

Values:

enumerator JPEG_EOY

when work at yuv mode, transfer a complete frame will trigger this isr

enumerator JPEG_HEAD_OUTPUT

when work at jpeg encode mode, the head output complete will trigger this isr

enumerator JPEG_SOF

when work at jpeg encode mode, detect vsync rising edge after few cycle will trigger this isr

enumerator JPEG_EOF

when work at jpeg encode mode, transfer a complete frame will trigger this isr

enumerator JPEG_VSYNC_NEGEDGE

when detect vsync negedge will trigger this isr

enumerator JPEG_ISR_MAX
enum jpeg_gpio_mode_t

Values:

enumerator JPEG_ENABLE_CLK

enable jpeg mclk and pclk gpio function

enumerator JPEG_ENABLE_DATA

enable jpeg vsync/hsync/D0-D7 gpio function

enumerator JPEG_ENABLE_ALL

enable all jpeg gpio function

enumerator JPEG_DISABLE_ALL

disable all jpeg gpio function

enum lcd_satus_t

Values:

enumerator READY

jpeg deca and display ready

enumerator MEMCPYING

jepg data mem cpying

enumerator JPEGDE_START

jepg dec start

enumerator JPEGDECING

jepg decing

enumerator DISPLAYING

jepg dec complete, lcd display

enumerator JPEGDED