Microchip® Advanced Software Framework

et024006dhu.c File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "compiler.h"
#include "et024006dhu.h"
#include "conf_et024006dhu.h"
#include "smc.h"
#include "board.h"
#include "gpio.h"
#include "cycle_counter.h"

Macros

#define ET024006_BS0   0x04
 
#define et024006_DeselectSPI()   (PORTC.OUTSET = PIN4_bm)
 
#define ET024006_DMA_USAGE_LIMIT   10
 
#define ET024006_ID   0x70
 
#define et024006_ReadSPI()   (SPIC.DATA)
 
#define ET024006_RS   0x02
 
#define ET024006_RW   0x01
 
#define et024006_SelectSPI()   (PORTC.OUTCLR = PIN4_bm)
 
#define et024006_SendDummySPI()   et024006_SendSPI( 0xff );
 
#define et024006_SendSPI(value)
 
#define HIMAX_AP0   0
 
#define HIMAX_AP1   1
 
#define HIMAX_AP2   2
 
#define HIMAX_BGR   3
 
#define HIMAX_COL_ADDR_END1   0x05
 
#define HIMAX_COL_ADDR_END2   0x04
 
#define HIMAX_COL_ADDR_START1   0x03
 
#define HIMAX_COL_ADDR_START2   0x02
 
#define HIMAX_CYCLECTRL1   0x3A
 
#define HIMAX_CYCLECTRL14   0x41
 
#define HIMAX_CYCLECTRL1_x   0x23
 
#define HIMAX_CYCLECTRL2   0x3B
 
#define HIMAX_CYCLECTRL2_x   0x24
 
#define HIMAX_CYCLECTRL3   0x3C
 
#define HIMAX_CYCLECTRL3_x   0x25
 
#define HIMAX_CYCLECTRL4   0x3D
 
#define HIMAX_CYCLECTRL5   0x3E
 
#define HIMAX_CYCLECTRL6   0x40
 
#define HIMAX_D0   2
 
#define HIMAX_D1   3
 
#define HIMAX_DISPCTRL1   0x26
 
#define HIMAX_DISPCTRL10   0x36
 
#define HIMAX_DISPCTRL2   0x27
 
#define HIMAX_DISPCTRL3   0x28
 
#define HIMAX_DISPCTRL4   0x29
 
#define HIMAX_DISPCTRL5   0x2A
 
#define HIMAX_DISPCTRL6   0x2C
 
#define HIMAX_DISPCTRL7   0x2D
 
#define HIMAX_DISPCTRL8   0x90
 
#define HIMAX_DISPCTRL9   0x35
 
#define HIMAX_DISPMODECTRL   0x01
 
#define HIMAX_DK   3
 
#define HIMAX_DTE   4
 
#define HIMAX_GAMMACTRL1   0x46
 
#define HIMAX_GAMMACTRL10   0x4F
 
#define HIMAX_GAMMACTRL11   0x50
 
#define HIMAX_GAMMACTRL12   0x51
 
#define HIMAX_GAMMACTRL2   0x47
 
#define HIMAX_GAMMACTRL3   0x48
 
#define HIMAX_GAMMACTRL4   0x49
 
#define HIMAX_GAMMACTRL5   0x4A
 
#define HIMAX_GAMMACTRL6   0x4B
 
#define HIMAX_GAMMACTRL7   0x4C
 
#define HIMAX_GAMMACTRL8   0x4D
 
#define HIMAX_GAMMACTRL9   0x4E
 
#define HIMAX_GASENB   7
 
#define HIMAX_GATE_SCAN_CTRL   0x18
 
#define HIMAX_GON   5
 
#define HIMAX_ID_CODE   0x67
 
#define HIMAX_ID_CODE_VALUE   0x47
 
#define HIMAX_INTERNAL28   0x70
 
#define HIMAX_INVON   2
 
#define HIMAX_MEMACCESSCTRL   0x16
 
#define HIMAX_MV   5
 
#define HIMAX_MX   6
 
#define HIMAX_MY   7
 
#define HIMAX_NORON   1
 
#define HIMAX_OSC_EN   0
 
#define HIMAX_OSCCTRL1   0x19
 
#define HIMAX_OSCCTRL2   0x1A
 
#define HIMAX_OSCCTRL3   0x93
 
#define HIMAX_PA_END_ROW_HB   0x0C
 
#define HIMAX_PA_END_ROW_LB   0x0D
 
#define HIMAX_PA_START_ROW_HB   0x0A
 
#define HIMAX_PA_START_ROW_LB   0x0B
 
#define HIMAX_PON   4
 
#define HIMAX_POWERCTRL1   0x1B
 
#define HIMAX_POWERCTRL2   0x1c
 
#define HIMAX_POWERCTRL3   0x1D
 
#define HIMAX_POWERCTRL4   0x1E
 
#define HIMAX_POWERCTRL5   0x1F
 
#define HIMAX_POWERCTRL6   0x20
 
#define HIMAX_PT0   6
 
#define HIMAX_PT1   7
 
#define HIMAX_ROW_ADDR_END1   0x09
 
#define HIMAX_ROW_ADDR_END2   0x08
 
#define HIMAX_ROW_ADDR_START1   0x07
 
#define HIMAX_ROW_ADDR_START2   0x06
 
#define HIMAX_SAP   0x90
 
#define HIMAX_SCROLL_ON   0x2
 
#define HIMAX_SRAMWRITE   0x22
 
#define HIMAX_STB   0
 
#define HIMAX_TEON   3
 
#define HIMAX_VCOMCTRL1   0x43
 
#define HIMAX_VCOMCTRL2   0x44
 
#define HIMAX_VCOMCTRL3   0x45
 
#define HIMAX_VCOMG   7
 
#define HIMAX_VS_BFA_HB   0x12
 
#define HIMAX_VS_BFA_LB   0x13
 
#define HIMAX_VS_TFA_HB   0x0E
 
#define HIMAX_VS_TFA_LB   0x0F
 
#define HIMAX_VS_VSA_HB   0x10
 
#define HIMAX_VS_VSA_LB   0x11
 
#define HIMAX_VS_VSP_HB   0x14
 
#define HIMAX_VS_VSP_LB   0x15
 
#define HIMAX_VTFT_TRI   1
 
#define HIMAX_XDK   2
 
#define TFT_QUADRANT0   ((1 << 1) | (1 << 0))
 
#define TFT_QUADRANT1   ((1 << 3) | (1 << 2))
 
#define TFT_QUADRANT2   ((1 << 5) | (1 << 4))
 
#define TFT_QUADRANT3   ((1 << 7) | (1 << 6))
 

Functions

static void et024006_AdjustGamma (void)
 Display gamma setup. More...
 
static void et024006_AdjustSleepingGamma (void)
 
et024006_color_t et024006_Color (uint8_t r, uint8_t g, uint8_t b)
 Converts a RGB 8:8:8 color to RGB 5:6:5. More...
 
static void et024006_CopyBitsToScreen (void *bitmap, uint32_t count, et024006_color_t foreground_color, et024006_color_t background_color)
 
void et024006_CopyPixelsFromScreen (et024006_color_t *pixels, uint32_t count)
 
void et024006_CopyPixelsToScreen (et024006_color_t const *pixels, uint32_t count)
 
void et024006_DrawBitmap (const uint16_t data[], U16 columnOffset, U16 rowOffset)
 
void et024006_DrawFilledCircle (uint16_t x, uint16_t y, uint16_t radius, uint16_t color, uint8_t quadrantMask)
 
void et024006_DrawFilledRect (uint16_t x, uint16_t y, uint16_t width, uint16_t height, et024006_color_t color)
 
void et024006_DrawHorizLine (uint16_t x, uint16_t y, uint16_t length, et024006_color_t color)
 
void et024006_DrawLine (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, et024006_color_t color)
 
void et024006_DrawPixel (uint16_t x, uint16_t y, et024006_color_t color)
 
void et024006_DrawQuickPixel (uint16_t x, uint16_t y, et024006_color_t color)
 
void et024006_DrawVertLine (uint16_t x, uint16_t y, uint16_t length, et024006_color_t color)
 
void et024006_DuplicatePixel (et024006_color_t color, uint32_t count)
 
void et024006_enter_idle (void)
 Make display enter in an idle mode. More...
 
static void et024006_GeneralSettings (void)
 General display settings. More...
 
et024006_color_t et024006_GetPixel (uint16_t x, uint16_t y)
 
void et024006_GetPixmap (et024006_color_t *pixmap, uint16_t map_width, uint16_t map_x, uint16_t map_y, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
 
void et024006_Init (unsigned long cpu_hz, unsigned long hsb_hz)
 Initialize the TFT display. More...
 
static void et024006_InterfaceSettings (void)
 Sets display interface. More...
 
void et024006_leave_idle (void)
 Make display leave the idle mode. More...
 
static void et024006_PowerOn (void)
 Turns the display on. More...
 
static void et024006_PowerSettings (void)
 Power setup. More...
 
static void et024006_PowerUp (void)
 Power up display. More...
 
void et024006_PrintConsole (char *lcd_string, uint16_t fcolor, int bcolor)
 
void et024006_PrintString (char *lcd_string, const unsigned char *font_style, uint16_t x, uint16_t y, uint16_t fcolor, int bcolor)
 Writes a string to the display. More...
 
void et024006_PutBitmap (void *bitmap, uint16_t map_width, uint16_t x, uint16_t y, uint16_t width, uint16_t height, et024006_color_t foreground_color, et024006_color_t background_color)
 
void et024006_PutPixmap (et024006_color_t const *pixmap, uint16_t map_width, uint16_t map_x, uint16_t map_y, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
 
static __inline__ uint8_t et024006_ReadRegister (uint8_t address)
 
static void et024006_ResetDisplay (void)
 Does a hard reset of the display. More...
 
void et024006_Scroll (int16_t lines)
 Scroll the scroll area down/up some lines. More...
 
void et024006_ScrollAreaSetup (uint16_t tfa, uint16_t vsa, uint16_t bfa)
 Configures a scroll area on the display. More...
 
void et024006_ScrollDisable ()
 Disables the scrolling. More...
 
void et024006_ScrollEnable ()
 Enables the scrolling feature. More...
 
static __inline__ void et024006_SelectRegister (uint8_t address)
 
void et024006_SetLimits (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
 Sets the display limits according to the corner coordinates. Writing to the display will result in writing to the area specified through this function. More...
 
void et024006_SetQuickLimits (uint16_t x, uint16_t y)
 Set the starting point of the next read/write from/to RAM. This sets only the start point of the RAM window. More...
 
void et024006_SetQuickLimits2 (uint16_t x, uint16_t y)
 Set the ending point of the next read/write from/to RAM. This sets only the end point of the RAM window. More...
 
static void et024006_SetRegister (uint8_t address, uint8_t bitmask)
 
static void et024006_SetupInterface (void)
 
int et024006_TestDisplay (void)
 Tests if a valid and functional display is connected. This function currently works only for the 16-bit color space configuration. For other configurations the read values of the display ram are different due to the internal handling. More...
 
static __inline__ void et024006_WriteRegister (uint8_t address, uint8_t value)
 

Variables

const unsigned char FONT6x8 [97][8]
 
const unsigned char FONT8x16 [97][16]
 
const unsigned char FONT8x8 [97][8]
 
struct {
   unsigned long   cpu_hz
 
   unsigned long   hsb_hz
 
tft_data
 Local storage of TFT driver data. More...
 

#define ET024006_DMA_USAGE_LIMIT   10

Referenced by et024006_DuplicatePixel().

#define et024006_ReadSPI ( )    (SPIC.DATA)
#define ET024006_RW   0x01
#define et024006_SendDummySPI ( )    et024006_SendSPI( 0xff );
#define et024006_SendSPI (   value)
Value:
SPIC.DATA = (value); \
do {} while ((SPIC.STATUS & SPI_IF_bm) == 0x00);

Referenced by et024006_CopyPixelsFromScreen(), et024006_CopyPixelsToScreen(), et024006_DrawPixel(), et024006_DrawQuickPixel(), et024006_DuplicatePixel(), and et024006_GetPixel().

#define HIMAX_AP0   0
#define HIMAX_AP1   1
#define HIMAX_AP2   2
#define HIMAX_BGR   3
#define HIMAX_COL_ADDR_END1   0x05
#define HIMAX_COL_ADDR_END2   0x04
#define HIMAX_COL_ADDR_START1   0x03
#define HIMAX_COL_ADDR_START2   0x02
#define HIMAX_CYCLECTRL1   0x3A
#define HIMAX_CYCLECTRL14   0x41
#define HIMAX_CYCLECTRL1_x   0x23

Referenced by et024006_PowerSettings().

#define HIMAX_CYCLECTRL2   0x3B
#define HIMAX_CYCLECTRL2_x   0x24

Referenced by et024006_PowerSettings().

#define HIMAX_CYCLECTRL3   0x3C
#define HIMAX_CYCLECTRL3_x   0x25

Referenced by et024006_PowerSettings().

#define HIMAX_CYCLECTRL4   0x3D
#define HIMAX_CYCLECTRL5   0x3E
#define HIMAX_CYCLECTRL6   0x40
#define HIMAX_D0   2

Referenced by et024006_PowerOn().

#define HIMAX_D1   3

Referenced by et024006_PowerOn().

#define HIMAX_DISPCTRL1   0x26

Referenced by et024006_PowerOn().

#define HIMAX_DISPCTRL10   0x36

Referenced by et024006_PowerSettings().

#define HIMAX_DISPCTRL2   0x27
#define HIMAX_DISPCTRL3   0x28
#define HIMAX_DISPCTRL4   0x29
#define HIMAX_DISPCTRL5   0x2A
#define HIMAX_DISPCTRL6   0x2C
#define HIMAX_DISPCTRL7   0x2D
#define HIMAX_DISPCTRL8   0x90

Referenced by et024006_PowerSettings().

#define HIMAX_DISPCTRL9   0x35

Referenced by et024006_PowerSettings().

#define HIMAX_DISPMODECTRL   0x01
#define HIMAX_DK   3

Referenced by et024006_PowerUp().

#define HIMAX_DTE   4

Referenced by et024006_PowerOn().

#define HIMAX_GAMMACTRL1   0x46
#define HIMAX_GAMMACTRL10   0x4F
#define HIMAX_GAMMACTRL11   0x50

Referenced by et024006_AdjustGamma().

#define HIMAX_GAMMACTRL12   0x51

Referenced by et024006_AdjustGamma().

#define HIMAX_GAMMACTRL2   0x47
#define HIMAX_GAMMACTRL3   0x48

Referenced by et024006_AdjustGamma().

#define HIMAX_GAMMACTRL4   0x49

Referenced by et024006_AdjustGamma().

#define HIMAX_GAMMACTRL5   0x4A

Referenced by et024006_AdjustGamma().

#define HIMAX_GAMMACTRL6   0x4B
#define HIMAX_GAMMACTRL7   0x4C
#define HIMAX_GAMMACTRL8   0x4D

Referenced by et024006_AdjustGamma().

#define HIMAX_GAMMACTRL9   0x4E

Referenced by et024006_AdjustGamma().

#define HIMAX_GASENB   7
#define HIMAX_GATE_SCAN_CTRL   0x18
#define HIMAX_GON   5

Referenced by et024006_PowerOn().

#define HIMAX_ID_CODE   0x67

Referenced by et024006_TestDisplay().

#define HIMAX_ID_CODE_VALUE   0x47
#define HIMAX_INTERNAL28   0x70

Referenced by et024006_PowerOn().

#define HIMAX_INVON   2
#define HIMAX_MEMACCESSCTRL   0x16
#define HIMAX_MV   5
#define HIMAX_MX   6
#define HIMAX_MY   7
#define HIMAX_NORON   1
#define HIMAX_OSC_EN   0
#define HIMAX_OSCCTRL1   0x19
#define HIMAX_OSCCTRL2   0x1A
#define HIMAX_OSCCTRL3   0x93
#define HIMAX_PA_END_ROW_HB   0x0C
#define HIMAX_PA_END_ROW_LB   0x0D
#define HIMAX_PA_START_ROW_HB   0x0A
#define HIMAX_PA_START_ROW_LB   0x0B
#define HIMAX_PON   4

Referenced by et024006_PowerUp().

#define HIMAX_POWERCTRL1   0x1B

Referenced by et024006_PowerUp().

#define HIMAX_POWERCTRL2   0x1c

Referenced by et024006_PowerUp().

#define HIMAX_POWERCTRL3   0x1D

Referenced by et024006_PowerSettings().

#define HIMAX_POWERCTRL4   0x1E

Referenced by et024006_PowerSettings().

#define HIMAX_POWERCTRL5   0x1F

Referenced by et024006_PowerSettings().

#define HIMAX_POWERCTRL6   0x20

Referenced by et024006_PowerSettings().

#define HIMAX_PT0   6
#define HIMAX_PT1   7
#define HIMAX_ROW_ADDR_END1   0x09
#define HIMAX_ROW_ADDR_END2   0x08
#define HIMAX_ROW_ADDR_START1   0x07
#define HIMAX_ROW_ADDR_START2   0x06
#define HIMAX_SAP   0x90
#define HIMAX_SCROLL_ON   0x2

Referenced by et024006_ScrollEnable().

#define HIMAX_STB   0
#define HIMAX_TEON   3

Referenced by et024006_PowerOn().

#define HIMAX_VCOMCTRL1   0x43

Referenced by et024006_PowerUp().

#define HIMAX_VCOMCTRL2   0x44

Referenced by et024006_PowerSettings().

#define HIMAX_VCOMCTRL3   0x45

Referenced by et024006_PowerSettings().

#define HIMAX_VCOMG   7

Referenced by et024006_PowerUp().

#define HIMAX_VS_BFA_HB   0x12
#define HIMAX_VS_BFA_LB   0x13
#define HIMAX_VS_TFA_HB   0x0E
#define HIMAX_VS_TFA_LB   0x0F
#define HIMAX_VS_VSA_HB   0x10
#define HIMAX_VS_VSA_LB   0x11
#define HIMAX_VS_VSP_HB   0x14

Referenced by et024006_Scroll().

#define HIMAX_VS_VSP_LB   0x15

Referenced by et024006_Scroll().

#define HIMAX_VTFT_TRI   1
#define HIMAX_XDK   2
#define TFT_QUADRANT0   ((1 << 1) | (1 << 0))
#define TFT_QUADRANT1   ((1 << 3) | (1 << 2))
#define TFT_QUADRANT2   ((1 << 5) | (1 << 4))
#define TFT_QUADRANT3   ((1 << 7) | (1 << 6))

static void et024006_AdjustGamma ( void  )
static
static void et024006_AdjustSleepingGamma ( void  )
static
static void et024006_CopyBitsToScreen ( void *  bitmap,
uint32_t  count,
et024006_color_t  foreground_color,
et024006_color_t  background_color 
)
static

References ET024006_PARAM_ADDR, and Tst_bits.

Referenced by et024006_PutBitmap().

static void et024006_GeneralSettings ( void  )
static
static void et024006_InterfaceSettings ( void  )
static

Sets display interface.

Configures screen orientation and color mode.

References et024006_WriteRegister(), HIMAX_BGR, HIMAX_MEMACCESSCTRL, HIMAX_MV, and HIMAX_MX.

Referenced by et024006_Init().

static void et024006_PowerOn ( void  )
static
static void et024006_PowerSettings ( void  )
static
static void et024006_PowerUp ( void  )
static

Power up display.

Turns on DC/DC converters.

References cpu_delay_ms(), et024006_WriteRegister(), HIMAX_DK, HIMAX_PON, HIMAX_POWERCTRL1, HIMAX_POWERCTRL2, HIMAX_VCOMCTRL1, HIMAX_VCOMG, and tft_data.

Referenced by et024006_Init().

static __always_inline uint8_t et024006_ReadRegister ( uint8_t  address)
static
static void et024006_ResetDisplay ( void  )
static

Does a hard reset of the display.

References cpu_delay_ms(), cpu_delay_us(), ET024006DHU_RESET_PIN, gpio_clr_gpio_pin(), gpio_set_gpio_pin(), and tft_data.

Referenced by et024006_Init().

static void et024006_SetRegister ( uint8_t  address,
uint8_t  bitmask 
)
static

unsigned long cpu_hz

Referenced by et024006_Init().

unsigned long hsb_hz

Referenced by et024006_Init().

struct { ... } tft_data
Initial value:
=
{
.cpu_hz = 0,
.hsb_hz = 0
}

Local storage of TFT driver data.

Referenced by et024006_Init(), et024006_PowerOn(), et024006_PowerUp(), and et024006_ResetDisplay().