This commit is contained in:
huxi
2025-12-03 11:12:34 +08:00
parent c23ae4f24c
commit bc195654bf
8163 changed files with 3799544 additions and 92 deletions
+538
View File
@@ -0,0 +1,538 @@
/* Copyright(C)
* not free
* All right reserved
*
* @file dbi.h
* @brief DBI模块驱动API头文件。DBI模块为专门用于推屏的独立硬件模块,与硬件SPI无关。其配置仅在屏幕驱动的结构体中,推屏时钟的频率为内部通过推屏帧率计算而得,但时钟是由PLL进行分频而来,因此实际时钟频率仅会在分频组合允许的前提下尽可能接近所需的目标频率(实际测量的推屏时钟与计算并非绝对一致)。
* @author zhuhaifang@zh-jieli.com
* @version V201
* @date 2023-01-10
*/
#ifndef __DBI_H__
#define __DBI_H__
#include "generic/typedef.h"
#include "os/os_api.h"
#include "gpio.h"
extern const u8 lvgl_ui_enable;
enum OUTPUT_FORMAT {
/* 0 */OUTPUT_FORMAT_RGB888,
/* 1 */OUTPUT_FORMAT_RGB565,
};
/* ------------------------------------------------------------------------------------*/
/**
* @brief DBI模块私有变量。注意:该变量内部使用,外部禁止操作,否则会导致不可预测的问题。
*/
/* ------------------------------------------------------------------------------------*/
extern struct dbi_variable dbi_var;
/* ------------------------------------------------------------------------------------*/
/**
* @brief 模块驱动接口组,DBI模块下管理了SPI, MCU, RGB三组驱动接口,具体驱动接口在这里
* 注册给DBI模块管理使用。注意:该变量内部使用,外部无需修改,否则会导致不可预测的问题。
*/
/* ------------------------------------------------------------------------------------*/
struct dbi_driver {
void (*init)(struct dbi_variable *priv);
void (*write)(u32, u8 *, u32);
void (*read)(u32, u8 *, u32);
void (*set_draw_area)(int, int, int, int);
void (*clear)(u32, int, int, int, int);
void (*draw)(u8 *, int, int, int, int);
void (*draw_continue)(u8 *, int, int, int, int);
void (*enter_sleep)();
void (*exit_sleep)();
};
//[DBI接口IO定义]
#define DBI_CSX_VSYNC IO_PORTA_07
#define DBI_DCX_HSYNC IO_PORTA_13
#define DBI_SCL_WRX IO_PORTA_12
#define DBI_D0 IO_PORTA_08
#define DBI_D1 IO_PORTA_09
#define DBI_D2 IO_PORTA_10
#define DBI_D3 IO_PORTA_11
#define DBI_D4 IO_PORTC_00
#define DBI_D5 IO_PORTC_01
#define DBI_D6 IO_PORTC_02
#define DBI_D7 IO_PORTC_03
#define DBI_RDX_DEN IO_PORTC_10
// <<<[lcd接口配置]>>>
#define SPI_MODE (0<<4)
#define DSPI_MODE (1<<4)
#define QSPI_MODE (2<<4)
// SPI线数标志(clk + dat)
#define SPI_WIRE3 0
#define SPI_WIRE4 1
// QSPI的子模式标志(除SUBMODE0为1 dat线之外,其余模式都为4 dat线)
#define QSPI_SUBMODE0 0//0x02
#define QSPI_SUBMODE1 1//0x32
#define QSPI_SUBMODE2 2//0x12
#define QSPI_RAMLESS 3//0xde
#define QSPI_FT2388 4//0x32 1ch cmd + 4ch data
#define QSPI_SD3302 5
// LCD时序标志(根据LCD数据手册配置,常用时序均已组合到LCD_DRIVE_CONFIG宏,在LCD驱动文件配置)
#define PIXEL_1P1T (0<<5)
#define PIXEL_1P2T (1<<5)
#define PIXEL_1P3T (2<<5)
#define PIXEL_2P3T (3<<5)
#define PIXEL_1T2B 1
#define PIXEL_1T6B 5
#define PIXEL_1T8B 7
#define PIXEL_1T9B 8
#define PIXEL_1T12B 11
#define PIXEL_1T16B 15
#define PIXEL_1T18B 17
#define PIXEL_1T24B 23
#define FORMAT_RGB565 1//0//1P2T
#define FORMAT_RGB666 2//1//1P3T
#define FORMAT_RGB888 0//2//1P3T
#define SPI_MODE_UNIDIR 0//半双工,d0分时发送接收
#define SPI_MODE_BIDIR 1//全双工,d0发送、d1接收
enum {
CMD_MODE,
};
enum {
CMD_8BIT,
CMD_16BIT,
CMD_24BIT,
};
/*
** dbi私有全局变量定义
*/
struct dbi_variable {
volatile u8 dbi_busy; // dbi忙碌标志
u8 clock_init: 1; // dbi时钟初始化标志
u8 clock_div_sel: 7; // dbi时钟
u8 sfr_save; // 寄存器保存标志
u8 row_align; // 行对齐
u8 column_align;// 列对齐
int (*te_stat)(); // TE 信号检测,返回值为TE脚电平,使用内部等待TE信号时,这个函数须注册
void (*te_wait)(); // TE 信号等待,如果使用外部TE等待函数,注册这个回调,则等TE时会调用这
struct dbi_param *param;
int (*dbi_callback)(void *priv);//dbi回调
u8 cmd_mode;
OS_SEM draw_sem;
u8 *frameBufferOld;
u8 *frameBuffer;
u32 frameBufferSize;
u32 clearColor;
int frameBufferChanged;
int xstart;
int xend;
int ystart;
int yend;
float actual_fps;
int soft_cs_pin;
volatile int cs_high;
};
/* ------------------------------------------------------------------------------------*/
/**
* @brief 屏幕驱动接口类型定义,根据屏幕的接口类型在屏驱内配置使用
*/
/* ------------------------------------------------------------------------------------*/
typedef enum lcd_type_cfg {
LCD_TYPE_SPI, // SPI屏
LCD_TYPE_SPI_RAMLESS, // SPI RAMLESS屏
LCD_TYPE_MCU, // MCU屏
LCD_TYPE_RGB, // RGB屏
LCD_TYPE_MAX,
} LCD_TYPE;
typedef enum {
DC_PIN_SEL_PA9,
DC_PIN_SEL_PA13,
DC_PIN_SEL_SOFT,
} DC_PIN_SEL;
typedef enum {
CS_PIN_SEL_PA7,
CS_PIN_SEL_SOFT,
} CS_PIN_SEL;
// 以下配置只对SPI_MODE_UNIDIR模式生效, SPI_MODE_BIDIR模式固定PA9
// 具体使用SPI/DSPI/QSPI哪个通道读数据,可查询屏DriverIC手册或者咨询屏厂,
// 读IO肯定是PA8/PA9/PA10/PA11其中的某一个, 也可以逐个试一下,看读0x0A寄存器的值是否正常
typedef enum {
READ_PIN_SEL_PA8,
READ_PIN_SEL_PA9,
READ_PIN_SEL_SOFT,
} READ_PIN_SEL;
// 只适用于MCU屏配置
// 若需要读寄存器,RDX引脚固定选PA13,由硬件控制
// 若没有读寄存器的需求,RDX引脚可不打开,可以省一个IO,屏驱上的DCX脚需要接高电平
typedef enum {
RDX_PIN_SEL_PA13,
RDX_PIN_SEL_NONE,
} RDX_PIN_SEL;
typedef enum {
CLOCK_POLARITY_IDLE_LOW, // 空闲时为低电平
CLOCK_POLARITY_IDLE_HIGH, // 空闲时为高电平
} CLOCK_POLARITY;
struct dbi_param {
// 显示区域相关(用于配置推屏区域,可不推全屏)
int scr_x;
int scr_y;
int scr_w;
int scr_h;
// lcd配置
int lcd_width;
int lcd_height;
LCD_TYPE lcd_type; // LCD接口类型:SPI, SPI Ramless, MCU, RGB
// 显存配置
int buffer_num;
int buffer_size;
// dbi模块的输入,与imb模块一起用时,也是imb模块的输出
int in_width;
int in_height;
int in_format;
int in_stride;
// debug模式(推新屏时,可使能debug模式,先推纯色测试)
int debug_mode_en;
int debug_mode_color;
// 帧率配置(用于计算DBI模块时钟频率,但实际推屏帧率仅会接近配置,并非100%一致)
int fps;
// 以下为三种屏驱动相关配置,out_format为屏幕的像素格式类型
struct spi_param {
int spi_mode;
int pixel_type;
int out_format;
int spi_dat_mode;
DC_PIN_SEL dc_pin_select; //若选择SPI_4WIRE_RGB888_1T8B/SPI_4WIRE_RGB888_1T24B/SPI_4WIRE_RGB666_1T18B/SPI_4WIRE_RGB565_1T8B/SPI_4WIRE_RGB565_1T16B时序,
//dc_pin_select = DC_PIN_SEL_PA9, dc信号从PA9输出(硬件控制)
//dc_pin_select = DC_PIN_SEL_PA13, dc信号从PA13输出(硬件控制)
//dc_pin_select = DC_PIN_SEL_SOFT, dc信号从soft_dc_pin指定的引脚输出(软件控制,只对4线spi有效)
int soft_dc_pin; //软件dc脚, 可指定任意gpio, IO_PORTX_xx
CS_PIN_SEL cs_pin_select;
//cs_pin_select = CS_PIN_SEL_PA7, cs信号从PA7输出(硬件控制)
//cs_pin_select = CS_PIN_SEL_SOFT, cs信号从soft_cs_pin指定的引脚输出(软件控制, 对spi/dspi/qspi有效, qspi ramless时序不支持)
int soft_cs_pin; //软件cs脚, 可指定任意gpio, IO_PORTX_xx
READ_PIN_SEL read_pin_select;
//read_pin_select = READ_PIN_SEL_PA8, 从PA8接收sdo信号(硬件控制)
//read_pin_select = READ_PIN_SEL_PA9, 从PA9接收sdo信号(硬件控制)
//read_pin_select = READ_PIN_SEL_SOFT, 从soft_read_pin指定的引脚接收sdo信号(软件控制)
int soft_read_pin; //软件输入脚, 可指定任意gpio, IO_PORTX_xx
struct qspi_cmd {
u8 write_cmd;
u8 read_cmd;
u8 submode0_cmd;//0x2c/0x3c/数据单线, default value 0x02
u8 submode1_cmd;//0x2c/0x3c单线,数据四线,default value 0x32
u8 submode2_cmd;//0x2c/0x3c/数据四线, default value 0x12
} qspi_cmd;
struct ramless {
u32 frame_sync_cmd;//ramless cmd
u32 porch_sync_cmd;//ramless cmd
u32 line_sync_cmd;//ramless cmd
u16 hsync;
u16 hbp; //hori back porch
u16 hact; //hori actual
u16 hfp; //hori front porch
u16 vsync;
u16 vbp; //vert back porch
u16 vact; //vert actual line
u16 vfp; //vert front porch
} ramless;
u8 caset_cmd;//Column Address Set, default value 0x2a
u8 paset_cmd;//Page Address Set, default value 0x2b
u8 ramwr_cmd;//Memory Write Start, default value 0x2c
u8 ramwrc_cmd;//Memory Write Continue, default valus 0x3c
CLOCK_POLARITY clk_pol; // 时钟极性
} spi;
struct pap_param {
RDX_PIN_SEL rdx_pin_select; //dcx 引脚配置
int out_format;
} pap;
struct rgb_param {
int use_spi;
int out_format;
int continue_frames;
int hpw_prd;
int hbw_prd;
int hfw_prd;
int hact_prd;
int vpw_prd;
int vbw_prd;
int vfw_prd;
int vact_prd;
} rgb;
};
struct dbi_ramless_callback_param {
int lcd_buff_update;
u32 lcd_buff_old;
u32 lcd_buff_new;
};
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_init DBI模块初始化(注意:需要操作DBI或从DBI获取信息时,必须先初始化)
*
* @param param DBI配置句柄
*
* @return 0
*/
/* ------------------------------------------------------------------------------------*/
int lcd_init(struct dbi_param *param);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_write_cmd DBI模块向LCD指定地址写数据
*
* @param cmd 待操作的LCD命令地址
* @param buf 数据缓存buf(如果不需要写数据,可传入NULL)
* @param len 数据缓存长度(如果不写数据,需将len配置为0)
*/
/* ------------------------------------------------------------------------------------*/
void lcd_write_cmd(u32 cmd, u8 *buf, u32 len);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_read_cmd DBI模块从LCD指定地址读数据
*
* @param cmd 待操作的LCD命令地址
* @param buf 数据缓存buf(输出)
* @param len 读取的数据长度(需与buf匹配,不可超过buf大小)
*/
/* ------------------------------------------------------------------------------------*/
void lcd_read_cmd(u32 cmd, u8 *buf, u32 len);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_draw_area 设置LCD显示区域(2A, 2B命令)
*
* @param xstart X起始像素坐标
* @param xend X结束像素坐标
* @param ystart Y起始像素坐标
* @param yend Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_draw_area(int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_draw DBI硬件写显示数据到LCD, 非阻塞接口,与lcd_set_draw_area配合使用
*
* @param buf 待写出数据
* @param xstart X起始像素坐标
* @param xend X结束像素坐标
* @param ystart Y起始像素坐标
* @param yend Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
void lcd_draw(u8 *buf, int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_draw_continue DBI硬件以续传方式写显示数据到LCD, 非阻塞接口,与lcd_set_draw_area、lcd_draw配合使用
*
* @param buf 待写出数据
* @param xstart X起始像素坐标
* @param xend X结束像素坐标
* @param ystart Y起始像素坐标
* @param yend Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
void lcd_draw_continue(u8 *buf, int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_clear 纯色填充LCD指定区域
*
* @param color 待填充的RGB888颜色值
* @param xstart 待填充的X起始像素坐标
* @param xend 待填充的X结束像素坐标
* @param ystart 待填充的Y起始像素坐标
* @param yend 待填充的Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
void lcd_clear(u32 color, int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_ctrl_pin_func 配置LCD控制脚操作函数
*
* @param te_stat TE脚控制函数
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_ctrl_pin_func(int (*te_stat)());
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_te_wait_cb 配置TE信号等待回调函数,如果注册,等待TE时将调用回调进行等待
*
* @Params te_wait 应用层实现的TE等待函数
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_te_wait_cb(void (*te_wait)());
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_align 设置LCD对齐参数
*
* @param row_align 设置行对齐参数
* @param column_align 设置列对齐参数
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_align(u8 row_align, u8 column_align);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_get_align 设置LCD对齐参数
*
* @param row_align 获取行对齐参数
* @param column_align 获取列对齐参数
*/
/* ------------------------------------------------------------------------------------*/
void lcd_get_align(u8 *row_align, u8 *column_align);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_check_align 检查LCD刷屏区域参数是否对齐
*
* @param xstart X起始像素坐标
* @param xend X结束像素坐标
* @param ystart Y起始像素坐标
* @param yend Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
int lcd_check_align(int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_wait_busy 等待lcd空闲
* 注意:本函数一般在推屏buffer释放前调用,等待推屏结束
*/
/* ------------------------------------------------------------------------------------*/
void lcd_wait_busy();
/* ------------------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_draw_kistart 无等待推屏接口
*/
/* ------------------------------------------------------------------------------------*/
void lcd_draw_kistart(uint8_t *buf, int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_draw_set_callback 设置推屏结束回调, lcd_draw、lcd_draw_continue推屏结束时调用该回调
*/
/* ------------------------------------------------------------------------------------*/
int lcd_draw_set_callback(int (*callback)(void *priv));
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_te_trig_kistart_set_busy 设置LCD繁忙状态,需TE中断调用lcd_draw_kistart接口推屏,推屏结束后会自动消除繁忙状态,
* 另外附加作用是打印调试接口,如果是kistart是由TE来引导的,那么wait lcd busy就是正常的, 不用打印出来
*/
/* ------------------------------------------------------------------------------------*/
void lcd_te_trig_kistart_set_busy(void);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_param 设置LCD模式
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_param(u8 mode, int priv);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_get_param 获取LCD模式
*/
/* ------------------------------------------------------------------------------------*/
int lcd_get_param(u8 mode);
float dbi_get_actual_fps();
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_clock_reinit LCD时钟重新初始化(必须在lcd空闲时调用!!!)
*/
/* ------------------------------------------------------------------------------------*/
void lcd_clock_reinit(int fps);
void lcd_enter_sleep();
void lcd_exit_sleep();
/* ------------------------------------------------------------------------------------*/
/* -------------------------------- SPI/DSPI/QSPI专用接口 ---------------------------*/
/* ------------------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_spi_set_cs_pin 设置软件cs脚(cs_pin_select指定CS_PIN_SEL_SOFT时生效)
*
* @param gpio 指定普通io作为软件cs脚
*
*/
/* ------------------------------------------------------------------------------------*/
void lcd_spi_set_cs_pin(int gpio);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_spi_get_cs_pin 获取软件cs脚(cs_pin_select指定CS_PIN_SEL_SOFT时生效)
*
* @return gpio : 软件cs脚
*
*/
/* ------------------------------------------------------------------------------------*/
int lcd_spi_get_cs_pin();
#endif
+265
View File
@@ -0,0 +1,265 @@
#ifndef __DBI_SFR_H__
#define __DBI_SFR_H__
//===============================================================================//
//
// config code mapping
//
//===============================================================================//
// dbi_img_con -> fmt
//**********************************
typedef enum {
DBI_IN_RGB565
, DBI_IN_RGB888
} DBI_IN_FMT_ENUM;
// dbi_hdl_con -> op
//**********************************
typedef enum {
DBI_OP_SET_START // 开启CS
, DBI_OP_SET_END // 关闭CS
, DBI_OP_SET_TXC // 切换到命令发送模式
, DBI_OP_SET_TXD // 切换到数据发送模式
, DBI_OP_SET_RXD // 切换到数据接收模式
, DBI_OP_SEND_DLY // 发送delay,无时钟输出
, DBI_OP_SEND_DMY // 发送dummy,有时钟输出
, RESERVED
, DBI_OP_SEND_DAT // 发送数据
, DBI_OP_RECE_DAT // 接收数据
} DBI_OPCODE_ENUM;
// dbi_flow_con0 -> protocol
//**********************************
typedef enum {
DBI_TA
, DBI_TB
, DBI_TC_O1
, DBI_TC_O3
, DBI_TC_O4
, DBI_MSPI
} DBI_PROTOCOL_ENUM;
// dbi_flow_con0 -> pix_fmt
//**********************************
typedef enum {
DBI_OUT_RGB565
, DBI_OUT_RGB666
, DBI_OUT_RGB888
} DBI_OUT_FMT_ENUM;
// dbi_flow_con0 -> pix_line
// dbi_flow_con0 -> cmd_line
// dbi_flow_con0 -> adr_line
// dbi_flow_con0 -> dma_line
// dbi_hdl_con -> line
//**********************************
typedef enum {
DBI_LINE1
, DBI_LINE2
, DBI_LINE4
, DBI_LINE8
, DBI_LINE9
, DBI_LINE16
, DBI_LINE18
} DBI_LINE_ENUM;
// dbi_flow_con0 -> pix_num
//**********************************
typedef enum {
DBI_1_PIX
, DBI_2_PIX
} DBI_PNUM_ENUM;
// dbi_flow_con0 -> pix_spl
//**********************************
typedef enum {
DBI_1_TRANS
, DBI_2_TRANS
, DBI_3_TRANS
} DBI_TNUM_ENUM;
// dbi_flow_sline -> seg
// dbi_flow_pline -> seg
// dbi_flow_aline -> seg
//**********************************
#define DBI_SEG_START BIT(0)
#define DBI_SEG_CMD BIT(1)
#define DBI_SEG_DMY0 BIT(2)
#define DBI_SEG_DCX1 BIT(3)
#define DBI_SEG_ADR0 BIT(4)
#define DBI_SEG_ADR1 BIT(5)
#define DBI_SEG_ADR2 BIT(6)
#define DBI_SEG_DMY1 BIT(7)
#define DBI_SEG_HBP BIT(8)
#define DBI_SEG_HACT BIT(9)
#define DBI_SEG_HFP BIT(10)
#define DBI_SEG_DMY2 BIT(11)
#define DBI_SEG_END BIT(12)
//===============================================================================//
//
// SFR sub function mapping
//
//===============================================================================//
typedef struct {
__RW __u32 cf_hdl_done : 1; // [0]
__RW __u32 cf_task_done : 1; // [1]
__RW __u32 tg_task_done : 1; // [2]
__RW __u32 tg_task_tout : 1; // [3]
} t_dbi_pnd;
typedef struct {
__RW __u32 : 1; // [0]
__RW __u32 cf_task_kick : 1; // [1]
__RW __u32 tg_task_kick : 1; // [2]
__RO __u32 : 1; // [3]
__RO __u32 xcvr_sta : 4; // [7:4]
__RO __u32 cf_hdl_busy : 1; // [8]
__RO __u32 cf_task_busy : 1; // [9]
__RO __u32 tg_task_busy : 1; // [10]
__RO __u32 fc_task_busy : 1; // [11]
__RO __u32 fc_sbuf_busy : 1; // [12]
} t_dbi_sta_con;
typedef struct {
__RW __u32 bus_nrst : 1; // [0]
__RW __u32 vdo_mode : 1; // [1]
__RW __u32 dma_mode : 1; // [2]
__RW __u32 test_mode : 1; // [3]
__RO __u32 : 4; // [7:4]
__RW __u32 test_color : 24; // [31:8]
} t_dbi_com_con;
typedef struct {
__RW __u32 dat_en : 18; // [17:0]
__RW __u32 csx_en : 1; // [18]
__RW __u32 dcx_en : 1; // [19]
__RW __u32 rwx_en : 1; // [20]
__RW __u32 ck_en : 1; // [21]
__RW __u32 csx_pol : 1; // [22]
__RW __u32 dcx_pol : 1; // [23]
__RW __u32 rwx_pol : 1; // [24]
__RW __u32 ck_pol : 1; // [25]
__RW __u32 ck_phase : 1; // [26]
__RW __u32 force_cken : 1; // [27]
} t_dbi_port_con;
typedef struct {
__RW __u32 fmt : 1; // [0]
__RW __u32 big_end : 1; // [1]
__RW __u32 rb_swap : 1; // [2]
} t_dbi_img_con;
typedef struct {
__RW __u32 continue_mode: 1; // [0]
__RW __u32 vsyn_oe : 1; // [1]
__RW __u32 vbp_oe : 1; // [2]
__RW __u32 vfp_oe : 1; // [3]
__RW __u32 vact_oe : 1; // [4]
} t_dbi_tgen_con;
typedef struct {
__RW __u32 protocol : 3; // [2:0]
__RW __u32 pix_line : 3; // [5:3]
__RW __u32 pix_num : 1; // [6]
__RW __u32 pix_spl : 2; // [8:7]
__RW __u32 pix_fmt : 2; // [10:9]
__RW __u32 cmd_line : 3; // [13:11]
__RW __u32 adr_line : 3; // [16:14]
__RW __u32 dma_line : 3; // [19:17]
} t_dbi_flow_con0;
typedef struct {
__RW __u32 dmy_cfg0 : 8; // [7:0]
__RW __u32 dmy_cfg1 : 8; // [15:8]
__RW __u32 dmy_cfg2 : 8; // [23:16]
__RW __u32 dly_mod0 : 1; // [24]
__RW __u32 dly_mod1 : 1; // [25]
__RW __u32 dly_mod2 : 1; // [26]
} t_dbi_flow_con1;
typedef struct {
__RW __u32 seg : 13; // [12:0]
__RO __u32 : 19; // [31:13]
__RW __u32 cmd : 8; // [7:0]
__RW __u32 adr0 : 8; // [15:8]
__RW __u32 adr1 : 8; // [23:16]
__RW __u32 adr2 : 8; // [31:24]
} t_dbi_xline;
typedef struct {
__RW __u32 cs_setup : 8; // [7:0]
__RW __u32 cs_hold : 8; // [15:8]
__RW __u32 sta_setup : 8; // [23:16]
} t_dbi_flow_con8;
typedef struct {
__RW __u32 op : 4; // [3:0]
__RW __u32 line : 3; // [6:4]
__RW __u32 num : 2; // [8:7]
__RW __u32 rx_mode : 1; // [9]
__RW __u32 rx_div : 8; // [17:10]
__RW __u32 rx_bsel : 1; // [18]
} t_dbi_hdl_con;
typedef struct {
__RW __u32 pix_fmt : 2; // [1:0]
__RW __u32 pix_cyc : 2; // [3:2]
__RW __u32 blk_mod : 1; // [4]
__RW __u32 rb_swap : 1; // [5]
__RW __u32 big_end : 1; // [6]
} t_dbi_rgb_con;
//===============================================================================//
//
// SFR address mapping
//
//===============================================================================//
#define dip_prp0_base (hs_base + map_adr(0x22, 0x00))
#define dbi_msfr(i,j) ((j *)(u32)(dip_prp0_base + i*4))
#define dbi_wsfr(i) (*(volatile u32 *)(dip_prp0_base + i*4))
#define dbi_pnd_con dbi_msfr(0x01, t_dbi_pnd)
#define dbi_pnd_clr dbi_msfr(0x02, t_dbi_pnd)
#define dbi_pnd_ie dbi_msfr(0x03, t_dbi_pnd)
#define dbi_sta_con dbi_msfr(0x08, t_dbi_sta_con)
#define dbi_com_con dbi_msfr(0x09, t_dbi_com_con)
#define dbi_port_con dbi_msfr(0x0a, t_dbi_port_con)
#define dbi_img_con dbi_msfr(0x10, t_dbi_img_con)
#define dbi_img_high dbi_wsfr(0x11)
#define dbi_img_burst dbi_wsfr(0x12)
#define dbi_img_stride dbi_wsfr(0x13)
#define dbi_img_addr dbi_wsfr(0x14)
#define dbi_tgen_con dbi_msfr(0x20, t_dbi_tgen_con)
#define dbi_tgen_vsyn dbi_wsfr(0x21)
#define dbi_tgen_vbp dbi_wsfr(0x22)
#define dbi_tgen_vfp dbi_wsfr(0x23)
#define dbi_tgen_vact dbi_wsfr(0x24)
#define dbi_tgen_httl dbi_wsfr(0x25)
#define dbi_flow_hsyn dbi_wsfr(0x30)
#define dbi_flow_hbp dbi_wsfr(0x31)
#define dbi_flow_hfp dbi_wsfr(0x32)
#define dbi_flow_hact dbi_wsfr(0x33)
#define dbi_flow_con0 dbi_msfr(0x34, t_dbi_flow_con0)
#define dbi_flow_con1 dbi_msfr(0x35, t_dbi_flow_con1)
#define dbi_flow_sline dbi_msfr(0x36, t_dbi_xline)
//#define dbi_flow_con2 dbi_wsfr(0x36)
//#define dbi_flow_con3 dbi_wsfr(0x37)
#define dbi_flow_pline dbi_msfr(0x38, t_dbi_xline)
//#define dbi_flow_con4 dbi_wsfr(0x38)
//#define dbi_flow_con5 dbi_wsfr(0x39)
#define dbi_flow_aline dbi_msfr(0x3a, t_dbi_xline)
//#define dbi_flow_con6 dbi_wsfr(0x3a)
//#define dbi_flow_con7 dbi_wsfr(0x3b)
#define dbi_flow_con8 dbi_msfr(0x3c, t_dbi_flow_con8)
#define dbi_hdl_con dbi_wsfr(0x3d) //, t_dbi_hdl_con)
#define dbi_hdl_buf dbi_wsfr(0x3e)
#define dbi_rgb_con dbi_msfr(0x3f, t_dbi_rgb_con)
#endif
+27
View File
@@ -0,0 +1,27 @@
#ifndef __LIB_GPU_FORMAT_H__
#define __LIB_GPU_FORMAT_H__
int res_format_to_gpu(int res_format);
int gpu_format_to_res(int gpu_format);
int text_format_to_gpu(int res_format);
int gpu_format_to_text(int gpu_format);
int get_clut_format_tabsize(int res_format, int clut_format);
int gpu_format_to_lut_size(int gpu_format, int clut_format);
/* ------------------------------------------------------------------------------------*/
/**
* @brief texture_line_to_tile_base 纹理行排列转为块排列
*
* @Params dst 纹理输出(注意对齐)
* @Params src 纹理输入
* @Params src_w 纹理输入宽度
* @Params src_h 纹理输入高度
* @Params format 纹理格式,参考 GPU_format_t
*/
/* ------------------------------------------------------------------------------------*/
void texture_line_to_tile_base(void *dst, void *src, int src_w, int src_h, int format);
#endif
File diff suppressed because it is too large Load Diff
+603
View File
@@ -0,0 +1,603 @@
#ifndef __JLGPU_DRIVER_H__
#define __JLGPU_DRIVER_H__
#define GPU_PLATFORM_PC 0
#if GPU_PLATFORM_PC
#include <stdint.h>
#else
#include "asm/cpu.h"
#include "system/includes.h"
#include "jlgpu_math.h"
#endif
#define GPU_COLOR_RAMP_SPREAD_PAD 0x00000000U
#define GPU_COLOR_RAMP_SPREAD_REFLECT 0x00000001U
#define GPU_COLOR_RAMP_SPREAD_REPEAT 0x00000002U
#define GPU_BLEND_SRC 0x00000000U
#define GPU_BLEND_SRC_OVER 0x00000001U
#define GPU_BLEND_DST_OUT 0x00000002U
#define GPU_BLEND_DST_IN 0x00000003U
#define GPU_BLEND_MAX 0x00000004U
#define GPU_BLEND_DST_OVER 0x00000005U
#define GPU_BLEND_SRC_OUT 0x00000006U
#define GPU_BLEND_SRC_IN 0x00000007U
#define GPU_FILL 0x00000000U
#define GPU_FILL_MASK 0x00000001U
#define GPU_FILL_AFFINE 0x00000002U
#define GPU_LINEGRAD 0x00000002U
#define GPU_FILL_PERSPECTIVE 0x00000003U
#define GPU_LINEGRAD_PERSPECTIVE 0x00000003U
#define GPU_TEXTURE 0x00000004U
#define GPU_TEXTURE_MASK 0x00000005U
#define GPU_TEXTURE_AFFINE 0x00000006U
#define GPU_TEXTURE_PERSPECTIVE 0x00000007U
#define LINEGRAD(mode) ((mode) << 4) // 线性渐变左移4bit,用于和FILL区分开
#define GPU_OUTPUT_WIN_MAX 0xFFFF // uint16_t
#define GPU_BOUND_BOX_MAX 0x07FF // uint32_t 11bit
#define GPU_API_CODE AT(.gpu_api.text.cache.L2)
typedef enum {
GPU_FORMAT_ARGB8888 = 0x00,
GPU_FORMAT_ARGB8565 = 0x01, //out
GPU_FORMAT_ARGB1555 = 0x02,
GPU_FORMAT_ARGB4444 = 0x03,
GPU_FORMAT_RGB888 = 0x04,
GPU_FORMAT_RGB565 = 0x05, //out
GPU_FORMAT_YUV422_BT601 = 0x06,
GPU_FORMAT_YUV422_BT709 = 0x07,
GPU_FORMAT_AL88 = 0x08,
GPU_FORMAT_AL44 = 0x10,
GPU_FORMAT_AL22 = 0x11,
GPU_FORMAT_L8 = 0x12,
GPU_FORMAT_L4 = 0x13,
GPU_FORMAT_L2 = 0x14,
GPU_FORMAT_L1 = 0x15,
GPU_FORMAT_A8 = 0x16,//out
GPU_FORMAT_A4 = 0x17,//out,
GPU_FORMAT_A2 = 0x18,//out,
GPU_FORMAT_A1 = 0x19,//out,
} GPU_format_t;
typedef enum {
GPU_MASK_FORMAT_A8 = 0x00,
GPU_MASK_FORMAT_A4 = 0x01,
GPU_MASK_FORMAT_A2 = 0x02,
GPU_MASK_FORMAT_A1 = 0x03,
} GPU_mask_format_t;
typedef enum {
GPU_OUT_FORMAT_ARGB8565 = 0x01, //out
GPU_OUT_FORMAT_RGB565 = 0x05, //out
GPU_OUT_FORMAT_A8 = 0x16,//out
GPU_OUT_FORMAT_A4 = 0x17,//out,
GPU_OUT_FORMAT_A2 = 0x18,//out,
GPU_OUT_FORMAT_A1 = 0x19,//out,
} GPU_out_format_t;
typedef enum {
GPU_CLUT_FORMAT_ARGB8888 = 0x00,
GPU_CLUT_FORMAT_ARGB8565 = 0x01,
GPU_CLUT_FORMAT_RGB888 = 0x02,
GPU_CLUT_FORMAT_RGB565 = 0x03,
} GPU_clut_format_t;
// mmu table page size symbol define.
typedef enum {
MMU_PAGE_4K = 0x00,
MMU_PAGE_16K = 0x01,
MMU_PAGE_32K = 0x02,
MMU_PAGE_64K = 0x03,
} GPU_mmu_page_size_t;
// 状态定义
typedef enum {
GPU_STA_IDLE = 0,
GPU_STA_RUNNING,
GPU_STA_BREAK,
GPU_STA_PAUSE,
GPU_STA_TIMEOUT,
} GPU_State;
typedef struct {
uint8_t *data;
uint32_t stride;
uint8_t format;
uint8_t rbs;
uint8_t rgba;
uint8_t endian;
uint16_t win_x_min;
uint16_t win_x_max;
uint16_t win_y_min;
uint16_t win_y_max;
uint16_t offset_left;
} gpu_out_params_t;
typedef struct {
uint8_t format;
uint8_t compress_mode;
uint8_t adr_mode;
uint8_t big_end;
uint8_t alpha_end;
uint8_t rbs;
uint8_t color_ext_mode;
uint16_t stride;
uint8_t *data;
uint32_t compress_size;
} gpu_texture_params_t;
typedef struct {
uint8_t *clut;
uint8_t layer_en;
uint8_t pad_mode;
uint8_t trans_mode;
uint8_t mask_en;
uint8_t blend_mode;
uint8_t colorkey_en;
uint8_t dither_en;
uint8_t clut_format;
uint8_t premult;
uint8_t ext_mode;
uint8_t breakpoint_en;
uint16_t act_x_min;
uint16_t act_x_max;
uint16_t act_y_min;
uint16_t act_y_max;
uint8_t global_alpha;
uint8_t alpha;
uint8_t red;
uint8_t green;
uint8_t blue;
//linegrad
uint8_t spread_mode;
uint8_t lut_lvl;
} gpu_basic_params_t;
typedef struct {
uint8_t sample_mode;
uint8_t shift_sel;
float M00;
float M01;
float M02;
float M10;
float M11;
float M12;
float M20;
float M21;
float M22;
uint8_t coeff0;
uint8_t coeff1;
uint8_t coeff2;
uint8_t coeff3;
uint8_t coeff4;
uint8_t coeff5;
uint16_t fg_x_min;
uint16_t fg_x_max;
uint16_t fg_y_min;
uint16_t fg_y_max;
} gpu_transform_params_t;
typedef struct {
uint8_t *data;
uint32_t stride;
uint8_t mask_inv;
uint8_t mask_big_end;
uint8_t mask_format;
uint16_t mask_x_min;
uint16_t mask_x_max;
uint16_t mask_y_min;
uint16_t mask_y_max;
} gpu_mask_params_t; //add
void gpu_set_sfr(uint8_t *param, uint8_t *out_data);
void gpu_set_out_layer(gpu_out_params_t *param);
void gpu_set_texture_mmu(uint8_t *mmu_tb_base, uint8_t mmu_en, uint8_t mmu_page_size, uint8_t mode);
int gpu_init();
int gpu_free();
int gpu_run();
int gpu_wait_done();
void gpu_reset_all_regs(uint8_t mode);
uint32_t gpu_get_format_bpp(uint32_t format);
uint32_t gpu_get_mask_format_bpp(uint32_t format);
void gpu_computeLinearParameters(int x0, int y0, int x1, int y1, gpu_transform_params_t *transform_params);
void gpu_fill(gpu_basic_params_t *basic_params);
void gpu_fill_mask(gpu_basic_params_t *basic_params, gpu_mask_params_t *mask_params);
void gpu_fill_affine(gpu_basic_params_t *basic_params, gpu_transform_params_t *transform_params);
void gpu_lineargrad(gpu_basic_params_t *basic_params, gpu_transform_params_t *transform_params);
void gpu_fill_perspective(gpu_basic_params_t *basic_params, gpu_transform_params_t *transform_params);
void gpu_lineargrad_perspective(gpu_basic_params_t *basic_params, gpu_transform_params_t *transform_params);
void gpu_texture(gpu_basic_params_t *basic_params, gpu_texture_params_t *texture_params);
void gpu_texture_mask(gpu_basic_params_t *basic_params, gpu_texture_params_t *texture_params, gpu_mask_params_t *mask_params);
void gpu_texture_affine(gpu_basic_params_t *basic_params, gpu_texture_params_t *texture_params, gpu_transform_params_t *transform_params);
void gpu_texture_perspective(gpu_basic_params_t *basic_params, gpu_texture_params_t *texture_params, gpu_transform_params_t *transform_params);
void *gpu_get_current_task();
void *gpu_create_task(uint8_t mode);
void gpu_free_all_tasks();
void gpu_dumcp_all_tasks();
void gpu_fill(gpu_basic_params_t *basic_params);
void gpu_set_out_layer(gpu_out_params_t *param);
// 获取状态
GPU_State gpu_get_state(void);
int gpu_get_break_state(void);
//清除状态
int gpu_clr_break_state(u8 state);
int gpu_clr_break_state_all();
int gpu_isr_sem_clr();
uint32_t gpu_pack_pixel(uint8_t a, uint8_t r, uint8_t g, uint8_t b, uint32_t format);
typedef struct {
int x, y, w, h;
} gpu_rectangle_t;
void gpu_rectangle_intersect(gpu_rectangle_t *dst, gpu_rectangle_t *src0, gpu_rectangle_t *src1);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_get_len 根据类型获取 GPU 任务所需的 BUF 长度
*
* @Params mode GPU 任务类型
*
* @return GPU 任务所需的 BUF 长度
*/
/* ------------------------------------------------------------------------------------*/
uint32_t gpu_task_get_len(uint8_t mode);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_add_to_list GPU 任务追加到任务链末尾
*
* @Params base_task GPU 任务链起始地址
* @Params new_task 待追加的 GPU 任务
*
* @return 待追加的 GPU 任务
*/
/* ------------------------------------------------------------------------------------*/
void *gpu_task_add_to_list(void *base_task, void *new_task);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_add_to_next 在指定任务下追加下一个任务
*
* @Params curr_task 指定任务
* @Params next_task 下一个任务
*
* @return 下一个任务
*/
/* ------------------------------------------------------------------------------------*/
void *gpu_task_add_to_next(void *curr_task, void *next_task);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_have_next 判断指定任务是否有下一个任务
*
* @Params curr_task 指定任务
*
* @return 0 无下一个任务,1 有下一个任务
*/
/* ------------------------------------------------------------------------------------*/
int gpu_task_have_next(void *curr_task);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_get_next 获取指定任务的下一个任务
*
* @Params curr_task 指定任务
*
* @return NULL 指定任务无下一个任务,其他 指定任务的下一个任务
*/
/* ------------------------------------------------------------------------------------*/
void *gpu_task_get_next(void *curr_task);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_del_next 删除指定任务的下一个任务
*
* @Params curr_task 指定任务
*
* @return NULL 指定任务无下一个任务,其他 指定任务原来的下一个任务
*/
/* ------------------------------------------------------------------------------------*/
void *gpu_task_del_next(void *curr_task);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_mode 设置指定任务的类型
*
* @Params taskp 任务指针
* @Params mode 任务类型
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_mode(void *taskp, uint8_t mode);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_get_mode 获取指定任务的类型
*
* @Params task_p 任务指针
*
* @return 任务类型
*/
/* ------------------------------------------------------------------------------------*/
uint8_t gpu_task_get_mode(void *task_p);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_enable 设置GPU任务使能开关
*
* @Params task_p 任务指针
* @Params enable 1 使能,0 不使能
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_enable(void *task_p, u32 enable);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_get_enable 获取指定任务的使能标志
*
* @Params task_p 任务指针
*
* @return 1 任务使能,0 任务未使能
*/
/* ------------------------------------------------------------------------------------*/
int gpu_task_get_enable(void *task_p);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_breakpoint_enable 设置断点使能
*
* @param task_p
* @param enable
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_breakpoint_enable(void *task_p, u32 enable);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_get_bbox 获取GPU任务的绘图区域
*
* @Params task_p 任务指针
* @Params xmin x最小值,输出
* @Params xmax x最大值,输出
* @Params ymin y最小值,输出
* @Params ymax y最大值,输出
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_get_bbox(void *task_p, u16 *xmin, u16 *xmax, u16 *ymin, u16 *ymax);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_fill 设置 GPU_FILL 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_fill(void *task_p, gpu_basic_params_t *basic_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_fill_mask 设置 GPU_FILL_MASK 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params mask_params gpu_mask_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_fill_mask(void *task_p, gpu_basic_params_t *basic_params, gpu_mask_params_t *mask_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_fill_affine 设置 GPU_FILL_AFFINE 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params transform_params gpu_transform_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_fill_affine(void *task_p, gpu_basic_params_t *basic_params, gpu_transform_params_t *transform_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_fill_perspective 设置 GPU_FILL_PERSPECTIVE 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params transform_params gpu_transform_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_fill_perspective(void *task_p, gpu_basic_params_t *basic_params, gpu_transform_params_t *transform_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_lineargrad 设置 GPU_LINEGRAD 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params transform_params gpu_transform_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_lineargrad(void *task_p, gpu_basic_params_t *basic_params, gpu_transform_params_t *transform_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_lineargrad_perspective 设置 GPU_LINEGRAD_PERSPECTIVE 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params transform_params gpu_transform_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_lineargrad_perspective(void *task_p, gpu_basic_params_t *basic_params, gpu_transform_params_t *transform_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_texture 设置 GPU_TEXTURE 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params texture_params gpu_texture_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_texture(void *task_p, gpu_basic_params_t *basic_params, gpu_texture_params_t *texture_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_texture_mask 设置 GPU_TEXTURE_MASK 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params texture_params gpu_texture_params_t
* @Params mask_params gpu_mask_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_texture_mask(void *task_p, gpu_basic_params_t *basic_params, gpu_texture_params_t *texture_params, gpu_mask_params_t *mask_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_texture_affine 设置 GPU_TEXTURE_AFFINE 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params texture_params gpu_texture_params_t
* @Params transform_params gpu_transform_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_texture_affine(void *task_p, gpu_basic_params_t *basic_params, gpu_texture_params_t *texture_params, gpu_transform_params_t *transform_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_texture_perspective 设置 GPU_TEXTURE_PERSPECTIVE 任务参数
*
* @Params task_p 任务指针
* @Params basic_params gpu_basic_params_t
* @Params texture_params gpu_texture_params_t
* @Params transform_params gpu_transform_params_t
*/
/* ------------------------------------------------------------------------------------*/
void gpu_task_set_texture_perspective(void *task_p, gpu_basic_params_t *basic_params, gpu_texture_params_t *texture_params, gpu_transform_params_t *transform_params);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_set_texture_mmu 设置 GPU_TEXTURE 任务的MMU(文件table表)
*
* @Params task_p 任务指针
* @Params mmu_tb_base mmu 起始地址,相当于第一个 page 的偏移地址
* @Params mmu_en mmu 使能标志:1 使能,0 不使能
* @Params mmu_page_size mmu page 大小,参考 GPU_mmu_page_size_t
*
* @return int 0 设置成功,-1 设置失败,任务没有 mmu 命令(任务类型错误)
*/
/* ------------------------------------------------------------------------------------*/
int gpu_task_set_texture_mmu(void *task_p, uint8_t *mmu_tb_base, uint8_t mmu_en, uint8_t mmu_page_size);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_get_next_task_by_reg 从GPU模块寄存器获取下一个GPU任务(非必要情况禁止使用)
*
* @return 下一个GPU任务指针
*/
/* ------------------------------------------------------------------------------------*/
void *gpu_get_next_task_by_reg();
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_get_curr_task_by_reg 从GPU模块寄存器获取当前的GPU任务(非必要情况禁止使用)
*
* @return 当前的CPU任务指针
*/
/* ------------------------------------------------------------------------------------*/
void *gpu_get_curr_task_by_reg();
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_task_list_run 运行 GPU 任务链
*
* @Params base_task_addr GPU 任务链首地址
*
* @return 0 运行成功,其他 运行失败
*/
/* ------------------------------------------------------------------------------------*/
int gpu_task_list_run(void *base_task_addr);
/* ------------------------------------------------------------------------------------*/
/**
* @brief gpu_dump_task_list 打印任务链中所有任务信息,用于 debug
*
* @Params base_task 任务链起始地址
*/
/* ------------------------------------------------------------------------------------*/
void gpu_dump_task_list(void *base_task);
void jlgpu_driver_get_matrix(void *p, gpu_matrix_t *matrix);
void jlgpu_driver_set_matrix(void *p, gpu_matrix_t *matrix);
void jlgpu_driver_set_bbox(void *p, gpu_boundbox_t *bbox);
void jlgpu_driver_get_bbox(void *p, gpu_boundbox_t *bbox);
uint8_t jlgpu_driver_mode(void *p);
void jlgpu_driver_set_next_inst_addr(void *p, u32 addr);
void jlgpu_driver_set_trans_mode(void *p, int trans_mode);
void jlgpu_driver_get_clip(void *p, int *clip_x_min, int *clip_x_max, int *clip_y_min, int *clip_y_max, int width, int height);
void jlgpu_driver_set_clip(void *p, int *clip_x_min, int *clip_x_max, int *clip_y_min, int *clip_y_max);
void jlgpu_driver_set_breakpoint(void *p, u32 enable);
void jlgpu_driver_get_texture_addr(void *p, u32 *mmu_en, u32 *mmu_tb_base, u32 *tex_base_adr, u32 *rle_limit_adr, u32 *tex_stride);
void jlgpu_driver_set_texture_addr(void *p, u32 *mmu_en, u32 *mmu_tb_base, u32 *tex_base_adr, u32 *rle_limit_adr, u32 *tex_stride);
int jlgpu_driver_get_format(void *p);
int jlgpu_driver_get_clut_format(void *p);
void *jlgpu_driver_get_clut_addr(void *p);
void jlgpu_driver_set_texture_big_end(void *p, int big_end);
#endif
+72
View File
@@ -0,0 +1,72 @@
#ifndef __GPU_MATH_H__
#define __GPU_MATH_H__
// #include <stdint.h>
#include "asm/cpu.h"
#include "system/includes.h"
#define GPU_MATH_CODE AT(.math_api.text.cache.L2)
typedef struct {
float m[3][3];
} gpu_matrix_t;
typedef struct {
float x;
float y;
} gpu_point2_t;
typedef struct {
float x;
float y;
float z;
} gpu_point3_t;
typedef struct {
int minx;
int maxx;
int miny;
int maxy;
} gpu_boundbox_t;
float gpu_sinf(float x);
float gpu_cosf(float x);
gpu_matrix_t *gpu_matrix_create();
void gpu_matrix_free_(gpu_matrix_t *m);
void gpu_matrix_set_identity(gpu_matrix_t *m);
void gpu_matrix_set_translate(gpu_matrix_t *m, float tx, float ty);
void gpu_matrix_set_scale(gpu_matrix_t *m, float sx, float sy);
void gpu_matrix_set_shear(gpu_matrix_t *m, float shx, float shy);
void gpu_matrix_set_rotate(gpu_matrix_t *m, float a);
void gpu_matrix_set_flip(gpu_matrix_t *m, int x_en, int y_en);
void gpu_matrix_multiply(gpu_matrix_t *d, gpu_matrix_t *s0, gpu_matrix_t *s1);
void gpu_matrix_mul_const(gpu_matrix_t *m, float f);
int gpu_matrix_is_affine(gpu_matrix_t *m);
int gpu_matrix_invert(gpu_matrix_t *dm, gpu_matrix_t *m);
void gpu_matrix_translate(gpu_matrix_t *m, float tx, float ty);
void gpu_matrix_scale(gpu_matrix_t *m, float sx, float sy);
void gpu_matrix_shear(gpu_matrix_t *m, float shx, float shy);
void gpu_matrix_rotate(gpu_matrix_t *m, float a);
void gpu_matrix_flip(gpu_matrix_t *m, int x_en, int y_en);
void gpu_transform_point2(gpu_point2_t *dp, gpu_matrix_t *m, gpu_point2_t *sp);
void gpu_point2_add(gpu_point2_t *d, gpu_point2_t *s0, gpu_point2_t *s1);
void gpu_point2_sub(gpu_point2_t *d, gpu_point2_t *s0, gpu_point2_t *s1);
void gpu_point2_mul(gpu_point2_t *d, gpu_point2_t *s0, gpu_point2_t *s1);
float gpu_point2_len(gpu_point2_t *s0, gpu_point2_t *s1);
void gpu_matrix_get_boundbox(gpu_matrix_t *matrix, gpu_boundbox_t *src, gpu_boundbox_t *dst);
int gpu_matrix_calc_by_point(gpu_matrix_t *matrix, int pt_w, int pt_h, float points[8]);
#endif
+376
View File
@@ -0,0 +1,376 @@
/*----------------------------------------------*/
/* JL HW JEPG CODEC */
/*----------------------------------------------*/
#ifndef _JL_HW_JPGDEC
#define _JL_HW_JPGDEC
#include "typedef.h"
#include "generic/rect.h"
#ifdef __cplusplus
extern "C" {
#endif
//#define MCU_BUFF_NUM 1
#ifndef MCU_BUFF_NUM
#define MCU_BUFF_NUM 2
#endif
/* Allow the number of cached MUC blocks , Default to 2 , 默认双buff乒乓,支持多 buff 模式,最小可以设置为 1 */
/* 当上层触发解码动作的速度比解码速度快时,适当改大可以提高速度,比如直接设置整幅图片的总 MCU 数量, 即硬件直接解完,效率只受限于解码速度*/
/* 当上层触发解码动作的速度比解码速度慢时,使用 2 个buff即保证每次来取数据都有已经解码完成的内容,改大没有意义 */
//#define BIT_BUFF_NUM 1
#ifndef BIT_BUFF_NUM
#define BIT_BUFF_NUM 1
#endif
/* Allow the number of cached MUC blocks , Default to 2 , 双buff乒乓或者单buff阻塞使用 */
/* 大致情况和 MCU 类似,主要考虑到输入bit流需要时32位对齐的地址空间,原始 bit 流需要从 flash 或者 SD 卡之中进行拷贝到RAM中,因此建议乒乓操作, 更多的 buff 没有意义,因为取 bit 流的动作会比解码动作慢 */
//#define JDEC_SZBUF 1024 * 8
#ifndef JDEC_SZBUF
#define JDEC_SZBUF 512
#endif
/* Specifies size of stream input buffer , >= 17 + 256 */
#define JDEC_MAGIC "JLHWJPEG"
typedef enum {
JPG_TEM = 0X01, //算术编码中作临时之用
//非层次哈夫曼编码
JPIF_SOF0 = 0XC0, //基线离散余弦变换/*只支持这种编码格式的图片*/
JPIF_SOF1, //扩展顺序离散余弦变换
JPIF_SOF2, //递进离散余弦变换
JPIF_SOF3, //空间顺序无损
JPIF_DHT = 0XC4, //哈夫曼表
//层次哈夫曼编码
JPIF_SOF5, //差分离散余弦变换
JPIF_SOF6, //差分层次离散余弦变换
JPIF_SOF7, //差分空间无损
//非层次算术编码
JPIF_SOF8, //为JPEG扩展保留
JPIF_SOF9, //扩展顺序离散余弦变换
JPIF_SOF10, //递进离散余弦变换
JPIF_SOF11, //空间顺序无损
JPIF_DAC = 0XCC, //算术编码表
//层次算术编码
JPIF_SOF13, //差分离散余弦变换
JPIF_SOF14, //差分层次离散余弦变换
JPIF_SOF15, //差分空间无损
JPIF_RST0 = 0XD0, //每隔n个MCU 块就有一个RST标记
JPIF_RST1,
JPIF_RST2,
JPIF_RST3,
JPIF_RST4,
JPIF_RST5,
JPIF_RST6,
JPIF_RST7 = 0XD7,
JPIF_SOI = 0XD8, //文件头
JPIF_EOI = 0XD9, //文件尾
JPIF_SOS = 0XDA, //扫描行开始
JPIF_DQT = 0XDB, //量化表
JPIF_DNL = 0XDC, //线数
JPIF_DRI = 0XDD, //重新开始间隔
JPIF_DHP = 0XDE, //层次级数
JPIF_EXP = 0XDF, //展开参考图像
JPIF_APP0 = 0XE0, //交换格式和图像识别信息
JPIF_APP1,
JPIF_APP2,
JPIF_APP3,
JPIF_APP4,
JPIF_APP5,
JPIF_APP6,
JPIF_APP7,
JPIF_APP8,
JPIF_APP9,
JPIF_APP10,
JPIF_APP11,
JPIF_APP12,
JPIF_APP13,
JPIF_APP14,
JPIF_APP15,
JPIF_COM = 0XFE, //注释
JPIF_MASK = 0XFF,
} JPG_TYPE;
/* Decode event code */
typedef enum {
JDEC_INTER_MCU, /* 0: The specified number of MCU blocks finishes decoding */
JDEC_INTER_BIT, /* 1: End of bit stream */
JDEC_INTER_FINISH, /* 2: End of file decoding */
} jdec_msg;
/* Error code */
typedef enum {
JDEC_OK = 0, /* 0: Succeeded */
JDEC_INP, /* 1: Device error or wrong termination of input stream */
JDEC_MEM1, /* 2: Memory request failed */
JDEC_MEM2, /* 3: Memory space not requested */
JDEC_MEM3, /* 4: Exceeds input buffer size : > JDEC_SZBUF */
JDEC_FMT1, /* 5: Data format error (may be broken data) */
JDEC_FMT2, /* 6: Right format but not supported */
JDEC_FMT3, /* 7: Not supported JPEG standard */
JDEC_FMT4, /* 8: Decoding execution error*/
JDEC_STA, /* 9: Jpeg work status error*/
JDEC_TIMEOUT,/*10: DEC_TIMEOUT*/
JDEC_HD_ERR,/*11:DEC_HD ERR*/
} jdec_err;
/* HW JPEG work state code */
typedef enum {
JDEC_WORK_STATE_CLOSE = 0, /* The jpeg decoding module is turned off */
JDEC_WORK_STATE_INIT, /* The jpeg decoding module is inited*/
JDEC_WORK_STATE_OPEN, /* The jpeg decoding module is enabled */
JDEC_WORK_STATE_START, /* jpeg decoding begins */
JDEC_WORK_STATE_STOP, /* End of jpeg decoding */
JDEC_WORK_STATE_SUSPEND, /* Pause during jpeg decoding */
} jdec_work_state;
/* MCU/BIT buff state code */
typedef enum {
JDEC_BUFF_STATE_INVALID = 0, /* 0: The buff is invalid, and the data is outdated or invalid */
JDEC_BUFF_STATE_UNDECODED, /* 1: The mcu block or bit stream that has not yet begun decoding */
JDEC_BUFF_STATE_DECODING, /* 2: Wait for the mcu block or bit stream to decode */
JDEC_BUFF_STATE_DECODED, /* 3: The decoding of the mcu block or bit stream is completed */
JDEC_BUFF_STATE_COPY, /* 4: MCU buf copy to line buf */
} jdec_buff_state;
/* Mcu buff information structure */
typedef struct _jdec_muc_buff {
jdec_buff_state state; /* mcu block usage status */
u16 mcuid; /* mcu block ID */
u8 *buf; /* data buffer */
} jdec_mcu_buff;
/* Bit buff information structure */
typedef struct _jdec_bit_buff {
jdec_buff_state state; /* bit stream usage status */
u32 len; /* data len */
u8 *buf; /* data buffer */
} jdec_bit_buff;
/* Huffman table structs */
typedef struct _huff_tab {
u16 *min;
u8 *index;
u8 *pval;
} huff_tab;
/* Decompressor object structure */
typedef struct _jdec_opj {
void *magic; /* Decoder magic */
jdec_work_state work_state: 4; /* Working state of the jpeg decoder module */
u8 msx: 4;
u8 msy: 4; /* MCU size in unit of block (width, height) */
u8 ycnt: 2; /* Y in the proportion of MCU components: 0:YUV444;1:YUV422;3:YUV411/YUV420 */
u8 isr_flags: 4; /* BIT0:MCU BIT2:BITS BIT3:LINE BIT4:REV */
u8 ncomp: 2; /* Number of color components 1:grayscale, 3:color */
u8 format: 1; /*1:565 0:888*/
u8 line_buf_vaild: 1; /*line buf 有效位*/
u8 bit_buff_sw: 1; /*bits_buff*/
u8 dri_enable: 1; /*dri_enable*/
u8 cur_rst_flag: 3; /*rst_flag:0xff d0~d7*/
u32 rev: 5; /* 预留拓展*/
u16 wmcu_num; /* The number of mcu blocks in the horizontal direction */
u16 hmcu_num; /* The number of mcu blocks in the vertical direction */
u16 all_mcucnt; /* The total number of mcu blocks of the picture */
u16 curr_mcuid; /* The mcu block ID currently to be decodeid: 0 - (all_mcucnt - 1) */
u16 start_mcuid; /*单次解码的开始id*/
u16 end_mcuid; /*单次解码的结束id*/
u16 mcu_cnt; /*单次解码 MCU 块的数量*/
u16 mcu_size; /*单个 MCU 块的大小*/
u8 qtid[3]; /* Quantization table ID of each component, Y, Cb, Cr */
u16 width; /* Size of the input image (pixel) */
u16 height; /* Size of the input image (pixel) */
u32(*infunc)(struct _jdec_opj *, u8 *buf, u32 len); /* Pointer to jpeg stream input function */
void (*decode_msg)(struct _jdec_opj *, jdec_msg); /* Pointer to the jpeg decoding event function */
void (*decode_wait)(struct _jdec_opj *); /* The decoder event waits for the callback */
void *device; /* Pointer to I/O device identifiler for the session */
int curr_offset; /*文件内偏移*/
u8 *outbuf; /* YUV422 to RGB buff: 这个 buff 从上层应用传下来装载数据 */
huff_tab hufftbl[2][2]; /* Huffman tables [id][dcac] */
u16 *qt_table;
s16 *qttbl[2]; /* Dequantizer tables [id] */
u16 *std_huffman_table;
u32 *huffman;
jdec_mcu_buff mcu_buff[MCU_BUFF_NUM]; /* MCU_BUFF_NUM mcu block buffers: 这些 buff 负责暂存解码后的 MCU 块数据和 MCU 块信息 */
jdec_bit_buff bit_buff[BIT_BUFF_NUM]; /* BIT_BUFF_NUM bit stream buffers: 这些 buff 负责暂存原始的 JPEG 数据或者 JPEG 段信息 */
u8 *line_buf; /*mcu解码后数据先暂存到linebuf再统一变换输出,同时缓存部分数据给下一次解码使用,避免重复*/
struct rect draw_rect; /*jpeg在屏幕的绘制区域*/
struct rect jpeg_rect; /*在jpeg解码的相对位置*/
struct rect obuf_rect; /*输出buffer的区域*/
struct rect cover_rect;
void *matrix; /* affine matrix: 用于合成这个JPG时做GPU变换 */
s16 surplus_line; /* line buf 剩余未使用数据*/
u16 nrst;
u32 bit_cnt_start; /*位流起始地址*/
unsigned long bit_usec; /*bit usec*/
unsigned long mcu_usec; /*mcu_usec*/
} jdec_opj;
extern const char jljpeg_magic[]; //识别解码器的标志字
/* JL JPEG DEC API functions */
void jljpeg_os_init(void);
void jljpeg_hw_config_stage1(jdec_opj *opj, bool os_flag);
jdec_err jljpeg_hw_config_stage2(void (*decode_msg)(struct _jdec_opj *, jdec_msg), void (*decode_wait)(struct _jdec_opj *), \
uint16_t mcu_cnt, uint8_t *mcu_buff);
jdec_err jljpeg_hw_config_stage3(uint16_t x, uint16_t y, uint8_t *buf);
void jljpeg_hw_release(void);
void jljpeg_hw_resource_release(bool os_flag);
jdec_opj *jpeg_hw_get(void);
void jpeg_hw_set(jdec_opj *opj);
void jljpeg_hw_init(jdec_opj *opj);
void jljpeg_hw_reset(void);
void jljpeg_hw_restart(void);
void jljpeg_hw_mcubuff_reset(jdec_opj *opj, uint16_t mcu_cnt, uint8_t *mcu_buff);
void *jpeg_malloc(int size);
void jpeg_free(void *p);
#define JPEG_MALLOC(a) jpeg_malloc(a)
#define JPEG_FREE(a) jpeg_free(a)
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_img_info_get 读取文件头
*
* @param opj
* @param infunc
* @param dev
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
jdec_err jljpeg_img_info_get(jdec_opj *opj, u32(*infunc)(jdec_opj *opj, u8 *buf, u32 size), void *dev);
/* ------------------------------------------------------------------------------------*/
/**
* @brief jpeg_decode_module_init jpeg 模块初始化
*
* @param malloc 申请
* @param free 释放
* @param gpu_blend 绘图
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
int jpeg_decode_module_init(
void *(*malloc)(int size, u32 ram_type, u32 module_type),
void (*free)(void *p, u32 ram_type, u32 module_type),
int (*gpu_blend)(u8 *dst_buf, struct rect *dst_rect, u8 *src_buf, struct rect *src_rect, struct rect *draw_rect, int src_stride, int format, void *p, int line_surpule, struct rect *cover)
);
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_decode_init 初始化解码
*
* @param opj
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
int jljpeg_decode_init(jdec_opj *opj);
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_decode_set_callback 注册回调
*
* @param opj 句柄
* @param infunc 输入数据流回调
* @param decode_msg
* @param decode_wait
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
int jljpeg_decode_set_callback(jdec_opj *opj,
u32(*infunc)(struct _jdec_opj *opj, u8 *buf, u32 len),
void (*decode_msg)(struct _jdec_opj *, jdec_msg),
void (*decode_wait)(struct _jdec_opj *)
);
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_decode_start 启动jpeg解码
*
* @param opj 解码句柄
* @param draw_rect 图片绘制区域
* @param jpeg_rect 在jpeg中的解码区域
* @param cover_rect 图片限制区域
* @param obuf_rect 输出buf区域
* @param dec_out_buf 输出buf
*
* @return jdec_err
*/
/* ------------------------------------------------------------------------------------*/
jdec_err jljpeg_decode_start(jdec_opj *opj, struct rect *draw_rect, struct rect *jpeg_rect, struct rect *cover_rect, struct rect *obuf_rect, void *dec_out_buf);
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_decode_release
*
* @param opj 解码句柄
* @param global_hd_clr 将全局解码句柄置为NULL,需应用层free句柄
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
int jljpeg_decode_release(jdec_opj *opj, int global_hd_clr);
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_get_decode_hd 将当前解码句柄置为NULL,需应用层free句柄
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
void jljpeg_get_decode_hd_clr();
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_get_decode_hd 获取文件句柄
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
void *jljpeg_get_decode_hd();
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_decode_reset_curr 重新解码当前文件(废)
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
int jljpeg_decode_reset_curr();
/* ------------------------------------------------------------------------------------*/
/**
* @brief jljpeg_decode_hdl_reset 重新解码当前文件
*
* @param opj
*
* @return
*/
/* ------------------------------------------------------------------------------------*/
int jljpeg_decode_hdl_reset(jdec_opj *opj);
#ifdef __cplusplus
}
#endif
#endif /* _JL_HW_JPGDEC */