#ifndef _HW_LCDCONTROL_H_
#define _HW_LCDCONTROL_H_

#include "hw_memmap.h"


#define LCDCtrlBase (unsigned int)AHB1_LCDC_BASE

#define RegLCDC_ctrl LCDCtrlBase+0x00
#define RegLCDC_mcu_ctrl LCDCtrlBase+0x04
#define RegLCDC_hor_period LCDCtrlBase+0x08
#define RegLCDC_vert_period LCDCtrlBase+0x0c
#define RegLCDC_horpw LCDCtrlBase+0x10
#define RegLCDC_vertpw LCDCtrlBase+0x14
#define RegLCDC_horact LCDCtrlBase+0x18
#define RegLCDC_vertact LCDCtrlBase+0x1C
#define RegLCDC_horbp LCDCtrlBase+0x20
#define RegLCDC_vertbp LCDCtrlBase+0x24
#define RegLCDC_line0yaddr LCDCtrlBase+0x28
#define RegLCDC_line0uvaddr LCDCtrlBase+0x2c
#define RegLCDC_line1yaddr LCDCtrlBase+0x30
#define RegLCDC_line1uvaddr LCDCtrlBase+0x34
#define RegLCDC_line2yaddr LCDCtrlBase+0x38
#define RegLCDC_line2uvaddr LCDCtrlBase+0x3c
#define RegLCDC_line3yaddr LCDCtrlBase+0x40
#define RegLCDC_line3uvaddr LCDCtrlBase+0x44
#define RegLCDC_StartX LCDCtrlBase+0x48
#define RegLCDC_StartY LCDCtrlBase+0x4C
#define RegLCDC_DeltaX LCDCtrlBase+0x50
#define RegLCDC_DeltaY LCDCtrlBase+0x54
#define RegLCDC_intrmask LCDCtrlBase+0x58
#define RegLCDC_alpALeftX LCDCtrlBase+0x5C
#define RegLCDC_alpATopY LCDCtrlBase+0x60
#define RegLCDC_alpARightX LCDCtrlBase+0x64
#define RegLCDC_alpABottomY LCDCtrlBase+0x68
#define RegLCDC_alpBLeftX LCDCtrlBase+0x6C
#define RegLCDC_alpBTopY LCDCtrlBase+0x70
#define RegLCDC_alpBRightX LCDCtrlBase+0x74
#define RegLCDC_alpBBottomY LCDCtrlBase+0x78
#define RegLCDC_lcdcsta LCDCtrlBase+0x7c

#ifdef RS_HI //RS ÓĐЧ”çÆœžß
#define RegLCDC_CMD LCDCtrlBase+0x2004
#define RegLCDC_DAT LCDCtrlBase+0x2000
#else
#define RegLCDC_CMD LCDCtrlBase+0x2000
#define RegLCDC_DAT LCDCtrlBase+0x2004
#endif

#define RegLCDC_BUF LCDCtrlBase+0x2000
#define RegLCDC_LCDCFIFO(Offset) LCDCtrlBase+(Offset+0x40)*64


//Ò»Đ©ÎąČÙŚśșÍλČÙŚś
#define HWLCDC_SetAlp24bit() SetRegBit32(RegLCDC_ctrl, 13)
#define HWLCDC_SetAlp16bit() ClrRegBit32(RegLCDC_ctrl, 13)

#define HWLCDC_SetMCU8086IF() SetRegBit32(RegLCDC_ctrl, 7)
#define HWLCDC_SelectAlpFactor() SetRegBit32(RegLCDC_ctrl, 13)

#define HWLCDC_SetRGB24bit() SetRegBit32(RegLCDC_ctrl, 6)
#define HWLCDC_SetRGB16bit() ClrRegBit32(RegLCDC_ctrl, 6)

#define HWLCDC_StartEven() SetRegBit32(RegLCDC_ctrl, 5)
#define HWLCDC_StopRGBFrame() ClrRegBit32(RegLCDC_ctrl, 0)

#define HWLCDC_EnRGBMode() SetRegBit32(RegLCDC_ctrl, 1)
#define HWLCDC_DisRGBMode() ClrRegBit32(RegLCDC_ctrl, 1)

#define HWLCDC_EnAlpBuffer() SetRegBit32(RegLCDC_mcu_ctrl, 6)
#define HWLCDC_DisAlpBuffer() ClrRegBit32(RegLCDC_mcu_ctrl, 6)

#define HWLCDC_SetRS() SetRegBit32(RegLCDC_mcu_ctrl, 5)
#define HWLCDC_ClrRS() ClrRegBit32(RegLCDC_mcu_ctrl, 5)

#define HWLCDC_StartMcuBuf() SetRegBit32(RegLCDC_mcu_ctrl, 1)
#define HWLCDC_EnMcuBufIntr() SetRegBit32(RegLCDC_intrmask, 2)
#define HWLCDC_DisMcuBufIntr() ClrRegBit32(RegLCDC_intrmask, 2)


#define HWLCDC_McuBypassMode() SetRegBit32(RegLCDC_mcu_ctrl, 0)
#define HWLCDC_McuBufferMode() ClrRegBit32(RegLCDC_mcu_ctrl, 0)


#define HWLCDC_GetMcuIdleState() GetRegBit32(RegLCDC_lcdcsta,4)
#define HWLCDC_GetHactiveState() GetRegBit32(RegLCDC_lcdcsta,0)
#define HWLCDC_GetVactiveState() GetRegBit32(RegLCDC_lcdcsta,1)
#define HWLCDC_GetEvenLineState() GetRegBit32(RegLCDC_lcdcsta,2)



#define BitEnLCDC 1
#define BitMcu 7
#define BitBypass 0



/**************************************************************
*LCDC register
**************************************************************/
#define LCDC_BASE LCDCtrlBase

#define LCDC_CTRL ((LCDC_BASE +0*4 ))
#define b_DCLK_INVERTED (1<<14)
#define b_ALPHA_24B (1<<13)
#define b_ALPHA_16B (0<<13)
#define b_UVExchange (1<<12)
#define b_ALPHA(factor) (factor<<9)
#define b_Y_MIX (1<<8)
#define b_MCU_MODE (1<<7)
#define b_RGB_24B (1<<6)
#define b_RGB_16B (0<<6)
#define b_START_EVEN (1<<5)
#define b_EVEN_EN (1<<4)
#define b_RGB_DUMMY0 (0<<2)
#define b_RGB_DUMMY2 (2<<2)
#define b_RGB_DUMMY3 (3<<2)
#define b_RGB_DUMMY(Dummy) (Dummy<<2)
#define b_LCDC_EN (1<<1)
#define b_LCDC_STOP (1<<0)

#define BUFF_CTRL ((LCDC_BASE +1*4 )) // 0x04
#define b_ALPHA_BASE(Addr) (Addr<<8)
#define b_LCDC_FIFOEN (1<<6)
#define b_RS_HIGH (1<<5)
#define b_BUFF_LINE3 (3<<3)
#define b_BUFF_LINE2 (2<<3)
#define b_BUFF_LINE1 (1<<3)
#define b_BUFF_LINE0 (0<<3)
#define b_BUFF_WRITE (1<<2)
#define b_BUFF_START (1<<1)
#define b_MCU_BYPASS (1<<0)

#define HOR_PERIOD (LCDC_BASE +2*4 ) // 0x08
#define VERT_PERIOD (LCDC_BASE +3*4 ) // 0x0c
#define LCD_WAIT (LCDC_BASE +3*4 ) // 0x0c
#define HOR_PW (LCDC_BASE +4*4 ) // 0x10
#define VERT_PW (LCDC_BASE +5*4 ) // 0x14
#define HOR_BP (LCDC_BASE +6*4 ) // 0x18
#define VERT_BP (LCDC_BASE +7*4 ) // 0x1c
#define HOR_ACT (LCDC_BASE +8*4 ) // 0x20
#define BUFF_LEN (LCDC_BASE +8*4 ) // 0x20
#define VERT_ACT (LCDC_BASE +9*4 ) // 0x24

#define LINE0_YADDR (LCDC_BASE +10*4) // 0x28
#define b_ALPHA_EN (1<<14)
#define b_SCALE_EN (1<<13)
#define b_GBR_ORDER (1<<12)
#define b_YUV_SRC (1<<11)

#define LINE0_UVADDR (LCDC_BASE +11*4)
#define LINE1_YADDR (LCDC_BASE +12*4)
#define LINE1_UVADDR (LCDC_BASE +13*4)
#define LINE2_YADDR (LCDC_BASE +14*4)
#define LINE2_UVADDR (LCDC_BASE +15*4)
#define LINE3_YADDR (LCDC_BASE +16*4)
#define LINE3_UVADDR (LCDC_BASE +17*4)
#define START_X (LCDC_BASE +18*4)
#define START_Y (LCDC_BASE +19*4)
#define DELTA_X (LCDC_BASE +20*4)
#define DELTA_Y (LCDC_BASE +21*4)

#define INTR_MASK (LCDC_BASE +22*4)
#define b_INTR_PERLINE (1<<3)
#define b_INTR_EVENLINE (0<<3)
#define b_BUFF_INTR (1<<2)
#define b_VERT_INTR (1<<1)
#define b_HOR_INTR (1<<0)

#define ALPHA_ALX (LCDC_BASE +23*4)
#define ALPHA_ATY (LCDC_BASE +24*4)
#define ALPHA_ARX (LCDC_BASE +25*4)
#define ALPHA_ABY (LCDC_BASE +26*4)
#define ALPHA_BLX (LCDC_BASE +27*4)
#define ALPHA_BTY (LCDC_BASE +28*4)
#define ALPHA_BRX (LCDC_BASE +29*4)
#define ALPHA_BBY (LCDC_BASE +30*4)

#define LCDC_STA (LCDC_BASE +31*4)
#define b_CURR_LINE1 (1<<14)
#define b_MCU_IDLE (1<<12)
#define b_VERT_ACTIVE (1<<11)
#define b_HOR_ACTIVE (1<<0)

#define LCD_DATA (LCDC_BASE +0x1004)
#define LCD_COMMAND (LCDC_BASE +0x1000)


#define LCDC_FIFO (LCDC_BASE +0x1c00)
#define LCDC_FIFO_DEPTH 256 //480
#define LCDC_DWDMA_FIFO (LCDC_BASE +0x1000)
#define LCDC_BUFFER (LCDC_BASE +0x2000)
#define LCDC_DWDMA_BUFFER (LCDC_BASE +0x2000)

#define LCDMode_Bypass 0
#define LCDMode_DMABypass 1
#define LCDMode_Buffer 2



#endif/* _HW_LCDCONTROL_H_ */

/*********************************************************************
END OF FILE
*********************************************************************/