feature(jpeg): Introduce JPEG hal layer

This commit is contained in:
Cao Sen Miao 2023-12-14 11:42:19 +08:00
parent 31ede5b09d
commit 40e882afae
7 changed files with 758 additions and 10 deletions

View File

@ -77,8 +77,6 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en
return HP_SYS_CLKRST_REG_RST_EN_CSI_BRG;
case PERIPH_ISP_MODULE:
return HP_SYS_CLKRST_REG_RST_EN_ISP;
case PERIPH_JPEG_MODULE:
return HP_SYS_CLKRST_REG_RST_EN_JPEG;
case PERIPH_DMA2D_MODULE:
return HP_SYS_CLKRST_REG_RST_EN_DMA2D;
case PERIPH_PPA_MODULE:
@ -169,7 +167,6 @@ static inline uint32_t periph_ll_get_rst_en_reg(periph_module_t periph)
case PERIPH_MSPI_FLASH_MODULE:
case PERIPH_MSPI_PSRAM_MODULE:
case PERIPH_ISP_MODULE:
case PERIPH_JPEG_MODULE:
case PERIPH_DMA2D_MODULE:
return HP_SYS_CLKRST_HP_RST_EN0_REG;
case PERIPH_PPA_MODULE:

View File

@ -0,0 +1,634 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "hal/misc.h"
#include "hal/assert.h"
#include "soc/jpeg_struct.h"
#include "hal/jpeg_types.h"
#include "soc/hp_sys_clkrst_struct.h"
#ifdef __cplusplus
extern "C" {
#endif
#define JPEG_LL_GET_HW(num) (&JPEG)
typedef enum {
JPEG_LL_DONE = (1 << 0),
JPEG_LL_DCT_DONE = (1 << 11),
} jpeg_ll_codec_intr_t;
typedef enum {
JPEG_LL_INTR_CID_ERR = (1 << 2),
JPEG_LL_INTR_C_DHT_DC_ID = (1 << 3),
JPEG_LL_INTR_C_DHT_AC_ID = (1 << 4),
JPEG_LL_INTR_C_DQT_ID = (1 << 5),
JPEG_LL_INTR_RST_UXP_ERR = (1 << 6),
JPEG_LL_INTR_RST_CHECK_NON_ERR = (1 << 7),
JPEG_LL_INTR_RST_CHECK_POS_ERR = (1 << 8),
JPEG_LL_INTR_OUT_EOF = (1 << 9),
JPEG_LL_INTR_SCAN_CHECK_NONE = (1 << 13),
JPEG_LL_INTR_SCAN_POS_ERR = (1 << 14),
JPEG_LL_INTR_UXP_DET = (1 << 15),
JPEG_LL_INTR_DE_FRAME_EOF_ERR = (1 << 18),
JPEG_LL_INTR_DE_FRAME_EOF_LACK = (1 << 19),
JPEG_LL_INTR_SOS_UNMATCH_ERR = (1 << 20),
JPEG_LL_INTR_MARKER_ERR_FST = (1 << 21),
JPEG_LL_INTR_MARKER_ERR_OTHER = (1 << 22),
JPEG_LL_INTR_UNDET = (1 << 23),
JPEG_LL_INTR_DECODE_TIMEOUT = (1 << 24),
} jpeg_ll_decoder_intr_t;
#define JPEG_LL_DECODER_EVENT_INTR (JPEG_LL_INTR_CID_ERR | \
JPEG_LL_INTR_C_DHT_DC_ID | \
JPEG_LL_INTR_C_DHT_AC_ID | \
JPEG_LL_INTR_C_DQT_ID | \
JPEG_LL_INTR_RST_UXP_ERR | \
JPEG_LL_INTR_RST_CHECK_NON_ERR | \
JPEG_LL_INTR_RST_CHECK_POS_ERR | \
JPEG_LL_INTR_OUT_EOF | \
JPEG_LL_INTR_SCAN_CHECK_NONE | \
JPEG_LL_INTR_SCAN_POS_ERR | \
JPEG_LL_INTR_UXP_DET | \
JPEG_LL_INTR_DE_FRAME_EOF_ERR | \
JPEG_LL_INTR_DE_FRAME_EOF_LACK | \
JPEG_LL_INTR_SOS_UNMATCH_ERR | \
JPEG_LL_INTR_MARKER_ERR_FST | \
JPEG_LL_INTR_MARKER_ERR_OTHER | \
JPEG_LL_INTR_UNDET | \
JPEG_LL_INTR_DECODE_TIMEOUT)
typedef enum {
JPEG_LL_RLE_PARALLEL_ERR = (1 << 1),
JPEG_LL_BS_LAST_BLOCK_EOF = (1 << 12),
JPEG_LL_EN_FRAME_EOF_ERR = (1 << 16),
JPEG_LL_EN_FRAME_EOF_LACK = (1 << 16),
} jpeg_ll_encoder_intr_t;
/**
* @brief Enable the hardware clock for JPEG module
*
* @param enable True to enable; false to disable
*/
static inline void jpeg_ll_enable_bus_clock(bool enable)
{
HP_SYS_CLKRST.soc_clk_ctrl1.reg_jpeg_sys_clk_en = enable;
}
/// use a macro to wrap the function, force the caller to use it in a critical section
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define jpeg_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; jpeg_ll_enable_bus_clock(__VA_ARGS__)
/**
* @brief Reset the JPEG module
*/
static inline void jpeg_ll_reset_module_register(void)
{
HP_SYS_CLKRST.hp_rst_en0.reg_rst_en_jpeg = 1;
HP_SYS_CLKRST.hp_rst_en0.reg_rst_en_jpeg = 0;
}
/// use a macro to wrap the function, force the caller to use it in a critical section
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define jpeg_ll_reset_module_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; jpeg_ll_reset_module_register(__VA_ARGS__)
/**
* @brief Write the numbers of 1~n codewords length sum of ac0 table and write the minimum codeword of code length
* for 1~16 of ac0 table
*
* @param hw Pointer to JPEG hardware
* @param huffman_bits_table Pointer to huffman table
* @param minimum_code_table Pointer to minimum huffman code table
*/
static inline void jpeg_ll_dht_ac0_write_codeword(jpeg_dev_t *hw, uint8_t *huffman_bits_table, uint32_t *minimum_code_table)
{
uint32_t element_number = 0;
for (int idx = 0; idx < JEPG_HUFFMAN_BITS_LEN_TABLE_LEN; idx++) {
element_number += (uint32_t)huffman_bits_table[idx];
hw->dht_totlen_ac0.dht_totlen_ac0 = element_number;
hw->dht_codemin_ac0.dht_codemin_ac0 = minimum_code_table[idx];
}
}
/**
* @brief Write the symbols corresponding to the decoded codeword for AC0 huffman table in FIFO mode
*
* @param hw Pointer to JPEG hardware.
* @param huffman_value_table Pointer to huffman value table.
*/
static inline void jpeg_ll_dht_ac0_write_value(jpeg_dev_t *hw, uint8_t *huffman_value_table)
{
for (int idx = 0; idx < JPEG_HUFFMAN_AC_VALUE_TABLE_LEN; idx++) {
hw->dht_val_ac0.dht_val_ac0 = (uint32_t)huffman_value_table[idx];
}
}
/**
* @brief Write the numbers of 1~n codewords length sum of ac1 table and write the minimum codeword of code length
* for 1~16 of ac1 table
*
* @param hw Pointer to JPEG hardware
* @param huffman_bits_table Pointer to huffman table
* @param minimum_code_table Pointer to minimum huffman code table
*/
static inline void jpeg_ll_dht_ac1_write_codeword(jpeg_dev_t *hw, uint8_t *huffman_bits_table, uint32_t *minimum_code_table)
{
uint32_t element_number = 0;
for (int idx = 0; idx < JEPG_HUFFMAN_BITS_LEN_TABLE_LEN; idx++) {
element_number += (uint32_t)huffman_bits_table[idx];
hw->dht_totlen_ac1.dht_totlen_ac1 = element_number;
hw->dht_codemin_ac1.dht_codemin_ac1 = minimum_code_table[idx];
}
}
/**
* @brief Write the symbols corresponding to the decoded codeword for AC1 huffman table in FIFO mode
*
* @param hw Pointer to JPEG hardware.
* @param huffman_value_table Pointer to huffman value table.
*/
static inline void jpeg_ll_dht_ac1_write_value(jpeg_dev_t *hw, uint8_t *huffman_value_table)
{
for (int idx = 0; idx < JPEG_HUFFMAN_AC_VALUE_TABLE_LEN; idx++) {
hw->dht_val_ac1.dht_val_ac1 = (uint32_t)huffman_value_table[idx];
}
}
/**
* @brief Write the numbers of 1~n codewords length sum of dc0 table and write the minimum codeword of code length
* for 1~16 of dc0 table
*
* @param hw Pointer to JPEG hardware
* @param huffman_bits_table Pointer to huffman table
* @param minimum_code_table Pointer to minimum huffman code table
*/
static inline void jpeg_ll_dht_dc0_write_codeword(jpeg_dev_t *hw, uint8_t *huffman_bits_table, uint32_t *minimum_code_table)
{
uint32_t element_number = 0;
for (int idx = 0; idx < JEPG_HUFFMAN_BITS_LEN_TABLE_LEN; idx++) {
element_number += (uint32_t)huffman_bits_table[idx];
hw->dht_totlen_dc0.dht_totlen_dc0 = element_number;
hw->dht_codemin_dc0.dht_codemin_dc0 = minimum_code_table[idx];
}
}
/**
* @brief Write the symbols corresponding to the decoded codeword for DC0 huffman table in FIFO mode
*
* @param hw Pointer to JPEG hardware
* @param huffman_value_table Pointer to huffman value table.
*/
static inline void jpeg_ll_dht_dc0_write_value(jpeg_dev_t *hw, uint8_t *huffman_value_table)
{
for (int idx = 0; idx < JPEG_HUFFMAN_DC_VALUE_TABLE_LEN; idx++) {
hw->dht_val_dc0.dht_val_dc0 = (uint32_t)huffman_value_table[idx];
}
}
/**
* @brief Write the numbers of 1~n codewords length sum of dc1 table and write the minimum codeword of code length
* for 1~16 of dc1 table
*
* @param hw Pointer to JPEG hardware
* @param huffman_bits_table Pointer to huffman table
* @param minimum_code_table Pointer to minimum huffman code table
*/
static inline void jpeg_ll_dht_dc1_write_codeword(jpeg_dev_t *hw, uint8_t *huffman_bits_table, uint32_t *minimum_code_table)
{
uint32_t element_number = 0;
for (int idx = 0; idx < JEPG_HUFFMAN_BITS_LEN_TABLE_LEN; idx++) {
element_number += (uint32_t)huffman_bits_table[idx];
hw->dht_totlen_dc1.dht_totlen_dc1 = element_number;
hw->dht_codemin_dc1.dht_codemin_dc1 = minimum_code_table[idx];
}
}
/**
* @brief Write the symbols corresponding to the decoded codeword for DC1 huffman table in FIFO mode
*
* @param hw Pointer to JPEG hardware
* @param huffman_value_table Pointer to huffman value table.
*/
static inline void jpeg_ll_dht_dc1_write_value(jpeg_dev_t *hw, uint8_t *huffman_value_table)
{
for (int idx = 0; idx < JPEG_HUFFMAN_DC_VALUE_TABLE_LEN; idx++) {
hw->dht_val_dc1.dht_val_dc1 = (uint32_t)huffman_value_table[idx];
}
}
/**
* @brief Configures the quantization coefficient table precision for the encoder
*
* @param hw Pointer to JPEG hardware
* @param qnr_presition precision of quantization coefficient table
*/
static inline void jpeg_ll_set_qnr_presition(jpeg_dev_t *hw, uint8_t qnr_presition)
{
hw->config.qnr_presition = qnr_presition;
}
/**
* @brief Configures it to write quantization coefficient for table0 in FIFO mode
*
* @param hw Pointer to JPEG hardware
* @param quantization_table Pointer to quantization table.
*/
static inline void jpeg_ll_write_quantization_coefficient_t0(jpeg_dev_t *hw, uint32_t *quantization_table)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->dqt_info, t0_dqt_info, 0);
for (int q = 0; q < JPEG_QUANTIZATION_TABLE_LEN; q++) {
hw->t0qnr.t0_qnr_val = quantization_table[q];
}
}
/**
* @brief Configures it to write quantization coefficient for table1 in FIFO mode
*
* @param hw Pointer to JPEG hardware
* @param quantization_table Pointer to quantization table.
*/
static inline void jpeg_ll_write_quantization_coefficient_t1(jpeg_dev_t *hw, uint32_t *quantization_table)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->dqt_info, t1_dqt_info, 1);
for (int q = 0; q < JPEG_QUANTIZATION_TABLE_LEN; q++) {
hw->t1qnr.chrominance_qnr_val = quantization_table[q];
}
}
/**
* @brief Configures it to write quantization coefficient for table2 in FIFO mode
*
* @param hw Pointer to JPEG hardware
* @param quantization_table Pointer to quantization table.
*/
static inline void jpeg_ll_write_quantization_coefficient_t2(jpeg_dev_t *hw, uint32_t *quantization_table)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->dqt_info, t2_dqt_info, 2);
for (int q = 0; q < JPEG_QUANTIZATION_TABLE_LEN; q++) {
hw->t2qnr.t2_qnr_val = quantization_table[q];
}
}
/**
* @brief Configures it to write quantization coefficient for table3 in FIFO mode
*
* @param hw Pointer to JPEG hardware
* @param quantization_table Pointer to quantization table.
*/
static inline void jpeg_ll_write_quantization_coefficient_t3(jpeg_dev_t *hw, uint32_t *quantization_table)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->dqt_info, t3_dqt_info, 3);
for (int q = 0; q < JPEG_QUANTIZATION_TABLE_LEN; q++) {
hw->t3qnr.t3_qnr_val = quantization_table[q];
}
}
/**
* @brief Configures images height
*
* @param hw Pointer to JPEG hardware
* @param height height of image.
*/
static inline void jpeg_ll_set_picture_height(jpeg_dev_t *hw, uint32_t height)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->pic_size, va, height);
}
/**
* @brief Configures images width
*
* @param hw Pointer to JPEG hardware
* @param height width of image.
*/
static inline void jpeg_ll_set_picture_width(jpeg_dev_t *hw, uint32_t width)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->pic_size, ha, width);
}
/**
* @brief Configure component0.
*
* @param hw Pointer to JPEG hardware
* @param identifier ID of component 0.
* @param horizontal_factor Configures the horizontal sampling factor of component 0.
* @param vertical_factor Configures the vertical sampling factor of component 0.
* @param qun_table_id Configures the selected quantization coefficient table ID for component 0.
*/
static inline void jpeg_ll_set_frame_info_component0(jpeg_dev_t *hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c0, c0_id, identifier);
hw->c0.c0_x_factor = horizontal_factor;
hw->c0.c0_y_factor = vertical_factor;
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c0, c0_dqt_tbl_sel, qun_table_id);
}
/**
* @brief Configure component1.
*
* @param hw Pointer to JPEG hardware
* @param identifier ID of component 1.
* @param horizontal_factor Configures the horizontal sampling factor of component 1.
* @param vertical_factor Configures the vertical sampling factor of component 1.
* @param qun_table_id Configures the selected quantization coefficient table ID for component 1.
*/
static inline void jpeg_ll_set_frame_info_component1(jpeg_dev_t *hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c1, c1_id, identifier);
hw->c1.c1_x_factor = horizontal_factor;
hw->c1.c1_y_factor = vertical_factor;
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c1, c1_dqt_tbl_sel, qun_table_id);
}
/**
* @brief Configure component2.
*
* @param hw Pointer to JPEG hardware
* @param identifier ID of component 2.
* @param horizontal_factor Configures the horizontal sampling factor of component 2.
* @param vertical_factor Configures the vertical sampling factor of component 2.
* @param qun_table_id Configures the selected quantization coefficient table ID for component 2.
*/
static inline void jpeg_ll_set_frame_info_component2(jpeg_dev_t *hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c2, c2_id, identifier);
hw->c2.c2_x_factor = horizontal_factor;
hw->c2.c2_y_factor = vertical_factor;
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c2, c2_dqt_tbl_sel, qun_table_id);
}
/**
* @brief Configure component3.
*
* @param hw Pointer to JPEG hardware
* @param identifier ID of component 3.
* @param horizontal_factor Configures the horizontal sampling factor of component 3.
* @param vertical_factor Configures the vertical sampling factor of component 3.
* @param qun_table_id Configures the selected quantization coefficient table ID for component 3.
*/
static inline void jpeg_ll_set_frame_info_component3(jpeg_dev_t *hw, uint8_t identifier, uint8_t horizontal_factor, uint8_t vertical_factor, uint8_t qun_table_id)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c3, c3_id, identifier);
hw->c3.c3_x_factor = horizontal_factor;
hw->c3.c3_y_factor = vertical_factor;
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->c3, c3_dqt_tbl_sel, qun_table_id);
}
/**
* @brief Get factor from component0
*
* @param hw Pointer to JPEG hardware
* @param component_factor Pointer to component factor
*/
static inline void jpeg_ll_get_component0_factor(jpeg_dev_t *hw, jpeg_component_factor_t *component_factor)
{
component_factor->horizontal = hw->c0.c0_x_factor;
component_factor->vertical = hw->c0.c0_y_factor;
}
/**
* @brief Get factor from component1
*
* @param hw Pointer to JPEG hardware
* @param component_factor Pointer to component factor
*/
static inline void jpeg_ll_get_component1_factor(jpeg_dev_t *hw, jpeg_component_factor_t *component_factor)
{
component_factor->horizontal = hw->c1.c1_x_factor;
component_factor->vertical = hw->c1.c1_y_factor;
}
/**
* @brief Configures whether or not to start compressing a new image
*
* @param hw Pointer to JPEG hardware
*/
static inline void jpeg_ll_process_start(jpeg_dev_t *hw)
{
hw->config.jpeg_start = 1;
}
/**
* @brief Configures whether or not pause the JPEG codec.
*
* @param hw Pointer to JPEG hardware
* @param en true: pause the jpeg codec, false: resume.
*/
static inline void jpeg_ll_codec_pause(jpeg_dev_t *hw, bool en)
{
hw->config.pause_en = en;
}
/**
* @brief Apply soft reset, this will reset the hardware fsm and fifo.
*
* @param hw Pointer to JPEG hardware.
*/
static inline void jpeg_ll_soft_rst(jpeg_dev_t *hw)
{
hw->config.soft_rst = 1;
hw->config.soft_rst = 0;
}
/**
* @brief Configures if the JPEG codec is working as an encoder or a decoder.
*
* @param hw Pointer to JPEG hardware.
* @param mode Refer to `jpeg_codec_mode_t`
*/
static inline void jpeg_ll_set_codec_mode(jpeg_dev_t *hw, jpeg_codec_mode_t mode)
{
uint8_t mode_val = 0;
switch (mode) {
case JPEG_CODEC_ENCODER:
mode_val = 0;
break;
case JPEG_CODEC_DECODER:
mode_val = 1;
break;
default:
HAL_ASSERT(false);
break;
}
hw->config.mode = mode_val;
}
/**
* @brief Configures whether or not to enable FIFO mode of configuring quantization coefficient tables.
*
* @param hw Pointer to JPEG hardware.
* @param mode 0: Use non-fifo mode. 1: Use fifo mode.
*/
static inline void jpeg_ll_set_access_qnr_ram_mode(jpeg_dev_t *hw, uint8_t mode)
{
hw->config.qnr_fifo_en = mode;
}
/**
* @brief Configures the number of color components in image when decoding
*
* @param hw Pointer to JPEG hardware.
* @param component_num Number of color components
*/
static inline void jpeg_ll_set_decode_component_num(jpeg_dev_t *hw, uint8_t component_num)
{
// ESP32P4 only support to decode color component not larger than 4
HAL_ASSERT(component_num <= 3);
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->decode_conf, component_num, component_num);
}
/**
* @brief Configures the format of the image to be compressed
*
* @param hw Pointer to JPEG hardware.
* @param mode_sel Select sample mode, refer to `jpeg_sample_mode_t`.
*/
static inline void jpeg_ll_sample_mode_select(jpeg_dev_t *hw, jpeg_sample_mode_t mode_sel)
{
uint8_t sample_sel = 0;
switch (mode_sel) {
case JPEG_SAMPLE_MODE_YUV444:
sample_sel = 0;
break;
case JPEG_SAMPLE_MODE_YUV422:
sample_sel = 1;
break;
case JPEG_SAMPLE_MODE_YUV420:
sample_sel = 0;
break;
default:
HAL_ASSERT(false);
break;
}
hw->config.sample_sel = sample_sel;
}
/**
* @brief Configure whether or not to reverse the original image's pixel order.
*
* @param hw Pointer to JPEG hardware.
* @param reverse_en 0: not revert; 1: revert.
*/
static inline void jpeg_ll_pixel_reverse(jpeg_dev_t *hw, bool reverse_en)
{
hw->config.pixel_rev = reverse_en;
}
/**
* @brief Configures whether or not to add EOI of 0xffd9 at the end of bitstream
*
* @param hw Pointer to JPEG hardware.
* @param tailer_en 1: Add `0xffd9` at the end ot bitstream.
*/
static inline void jpeg_ll_add_tail(jpeg_dev_t *hw, bool tailer_en)
{
hw->config.tailer_en = tailer_en;
}
/**
* @brief Configures whether or not to add 00 after ff
*
* @param hw Pointer to JPEG hardware.
* @param ff_check_en 0: not add `00` after `ff`; 1: Add.
*/
static inline void jpeg_ll_enable_ff_check(jpeg_dev_t *hw, bool ff_check_en)
{
hw->config.ff_check_en = ff_check_en;
}
/**
* @brief Configures the luma quantization table ID for the encoder
*
* @param hw Pointer to JPEG hardware.
* @param lqnr_id ID of luma quantization table.
*/
static inline void jpeg_ll_luminance_qnr_table_id(jpeg_dev_t *hw, uint8_t lqnr_id)
{
hw->config.lqnr_tbl_sel = lqnr_id;
}
/**
* @brief Configures the chroma quantization table ID for the encoder.
*
* @param hw Pointer to JPEG hardware.
* @param cqnr_id ID of chroma quantization table.
*/
static inline void jpeg_ll_chrominance_qnr_table_id(jpeg_dev_t *hw, uint8_t cqnr_id)
{
hw->config.cqnr_tbl_sel = cqnr_id;
}
/**
* @brief Configures the restart interval in DRI segment when decoding
*
* @param hw Pointer to JPEG hardware.
* @param restart_interval value of restart interval.
*/
static inline void jpeg_ll_set_restart_interval(jpeg_dev_t *hw, uint16_t restart_interval)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->decode_conf, restart_interval, restart_interval);
}
/**
* @brief Get JPEG interrupt status register address
*
* @param hw Pointer to JPEG hardware.
* @return address of interrupt status register.
*/
static inline volatile void *jpeg_ll_get_interrupt_status_reg(jpeg_dev_t *hw)
{
return &hw->int_st;
}
/**
* @brief Enable JPEG interrupt
*
* @param hw Pointer to JPEG hardware.
*/
static inline void jpeg_ll_enable_intr_mask(jpeg_dev_t *hw, uint32_t mask)
{
hw->int_ena.val |= mask;
}
/**
* @brief Clear JPEG interrupt
*
* @param hw Pointer to JPEG hardware.
*/
static inline void jpeg_ll_clear_intr_mask(jpeg_dev_t *hw, uint32_t mask)
{
hw->int_clr.val = mask;
}
/**
* @brief Disable JPEG interrupt
*
* @param hw Pointer to JPEG hardware.
*/
static inline void jpeg_ll_disable_intr_mask(jpeg_dev_t *hw, uint32_t mask)
{
hw->int_ena.val &= (~mask);
}
/**
* @brief Get JPEG interrupt status
*
* @param hw Pointer to JPEG hardware.
*/
static inline uint32_t jpeg_ll_get_intr_status(jpeg_dev_t *hw)
{
return hw->int_st.val;
}
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,46 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*******************************************************************************
* NOTICE
* The HAL is not public api, don't use in application code.
* See readme.md in hal/include/hal/readme.md
******************************************************************************/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct jpeg_dev_t *jpeg_soc_handle_t; // JPEG SOC layer handle
/**
* Context that should be maintained by both the driver and the HAL
*/
typedef struct {
jpeg_soc_handle_t dev; // JPEG SOC layer handle (i.e. register base address)
} jpeg_hal_context_t;
/**
* @brief Initialize the JPEG codec HAL driver
*
* @param hal: JPEG codec HAL context
*/
void jpeg_hal_init(jpeg_hal_context_t *hal);
/**
* @brief Deinitialize the JPEG codec HAL driver
*
* @param hal: JPEG codec HAL context
*/
void jpeg_hal_deinit(jpeg_hal_context_t *hal);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,51 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdlib.h>
#include <stdint.h>
#include "soc/soc_caps.h"
#include "hal/color_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define JEPG_HUFFMAN_BITS_LEN_TABLE_LEN (16)
#define JPEG_HUFFMAN_AC_VALUE_TABLE_LEN (256)
#define JPEG_HUFFMAN_DC_VALUE_TABLE_LEN (16)
#define JPEG_QUANTIZATION_TABLE_LEN (64)
/**
* @brief Enum for JPEG codec working mode.
*/
typedef enum {
JPEG_CODEC_ENCODER, ///< Encode mode
JPEG_CODEC_DECODER, ///< Decode mode
} jpeg_codec_mode_t;
/**
* @brief Structure for recording factor of component.
*/
typedef struct {
uint32_t horizontal; ///< horizontal factor
uint32_t vertical; ///< vertical factor
} jpeg_component_factor_t;
/**
* @brief Enum for JEPG sampling mode.
*/
typedef enum {
JPEG_SAMPLE_MODE_YUV444 = COLOR_PIXEL_YUV444, ///< sample in YUV444
JPEG_SAMPLE_MODE_YUV422 = COLOR_PIXEL_YUV422, ///< sample in YUV422
JPEG_SAMPLE_MODE_YUV420 = COLOR_PIXEL_YUV420, ///< sample in YUV420
} jpeg_sample_mode_t;
#ifdef __cplusplus
}
#endif

19
components/hal/jpeg_hal.c Normal file
View File

@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stddef.h>
#include "hal/jpeg_hal.h"
#include "hal/jpeg_ll.h"
void jpeg_hal_init(jpeg_hal_context_t *hal)
{
hal->dev = JPEG_LL_GET_HW();
}
void jpeg_hal_deinit(jpeg_hal_context_t *hal)
{
hal->dev = NULL;
}

View File

@ -64,13 +64,13 @@ extern "C" {
#define JPEG_DEBUG_DIRECT_OUT_EN_M (JPEG_DEBUG_DIRECT_OUT_EN_V << JPEG_DEBUG_DIRECT_OUT_EN_S)
#define JPEG_DEBUG_DIRECT_OUT_EN_V 0x00000001U
#define JPEG_DEBUG_DIRECT_OUT_EN_S 7
/** JPEG_GRAY_SEL : R/W; bitpos: [8]; default: 1;
/** JPEG_QNR_FIFO_SEL : R/W; bitpos: [8]; default: 1;
* 0:use non-fifo way to access qnr ram,1:use fifo way to access qnr ram
*/
#define JPEG_GRAY_SEL (BIT(8))
#define JPEG_GRAY_SEL_M (JPEG_GRAY_SEL_V << JPEG_GRAY_SEL_S)
#define JPEG_GRAY_SEL_V 0x00000001U
#define JPEG_GRAY_SEL_S 8
#define JPEG_QNR_FIFO_SEL (BIT(8))
#define JPEG_QNR_FIFO_SEL_M (JPEG_QNR_FIFO_SEL_V << JPEG_QNR_FIFO_SEL_S)
#define JPEG_QNR_FIFO_SEL_V 0x00000001U
#define JPEG_QNR_FIFO_SEL_S 8
/** JPEG_LQNR_TBL_SEL : R/W; bitpos: [10:9]; default: 0;
* choose luminance quntization table id(TBD)
*/

View File

@ -44,10 +44,10 @@ typedef union {
* 0:normal mode,1:debug mode for direct output from input
*/
uint32_t debug_direct_out_en:1;
/** gray_sel : R/W; bitpos: [8]; default: 1;
/** qnr_fifo_en : R/W; bitpos: [8]; default: 1;
* 0:use non-fifo way to access qnr ram,1:use fifo way to access qnr ram
*/
uint32_t gray_sel:1;
uint32_t qnr_fifo_en:1;
/** lqnr_tbl_sel : R/W; bitpos: [10:9]; default: 0;
* choose luminance quntization table id(TBD)
*/
@ -1449,6 +1449,7 @@ typedef struct {
volatile jpeg_version_reg_t version;
} jpeg_dev_t;
extern jpeg_dev_t JPEG;
#ifndef __cplusplus
_Static_assert(sizeof(jpeg_dev_t) == 0x100, "Invalid size of jpeg_dev_t structure");