Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
COMPONENT - Display - HX8347A Controller

Low-level driver for the HX8347A LCD controller.

This driver provides access to the main features of the HX8347A controller.

Macros

#define LCD_DATA_CACHE_SIZE   HX8347A_LCD_WIDTH
 

Functions

static void hx8347a_check_box_coordinates (uint32_t *p_ul_x1, uint32_t *p_ul_y1, uint32_t *p_ul_x2, uint32_t *p_ul_y2)
 Check box coordinates. More...
 
static void hx8347a_delay (uint32_t ul_ms)
 Delay function. More...
 
void hx8347a_disable_scroll (void)
 Disables the scrolling. More...
 
void hx8347a_display_off (void)
 Turn off the LCD. More...
 
void hx8347a_display_on (void)
 Turn on the LCD. More...
 
static void hx8347a_draw_char (uint32_t ul_x, uint32_t ul_y, uint8_t uc_c)
 Draw an ASCII character on LCD. More...
 
uint32_t hx8347a_draw_circle (uint32_t ul_x, uint32_t ul_y, uint32_t ul_r)
 Draw a circle on LCD. More...
 
uint32_t hx8347a_draw_filled_circle (uint32_t ul_x, uint32_t ul_y, uint32_t ul_r)
 Draw a filled circle on LCD. More...
 
void hx8347a_draw_filled_rectangle (uint32_t ul_x1, uint32_t ul_y1, uint32_t ul_x2, uint32_t ul_y2)
 Draw a filled rectangle on LCD. More...
 
void hx8347a_draw_line (uint32_t ul_x1, uint32_t ul_y1, uint32_t ul_x2, uint32_t ul_y2)
 Draw a line on LCD. More...
 
static void hx8347a_draw_line_bresenham (uint32_t ul_x1, uint32_t ul_y1, uint32_t ul_x2, uint32_t ul_y2)
 Draw a line on LCD, which is not horizontal or vertical. More...
 
uint32_t hx8347a_draw_pixel (uint32_t ul_x, uint32_t ul_y)
 Draw a pixel on LCD. More...
 
void hx8347a_draw_pixmap (uint32_t ul_x, uint32_t ul_y, uint32_t ul_width, uint32_t ul_height, const hx8347a_color_t *p_ul_pixmap)
 Draw a pixmap on LCD. More...
 
void hx8347a_draw_rectangle (uint32_t ul_x1, uint32_t ul_y1, uint32_t ul_x2, uint32_t ul_y2)
 Draw a rectangle on LCD. More...
 
void hx8347a_draw_string (uint32_t ul_x, uint32_t ul_y, const uint8_t *p_str)
 Draw a string on LCD. More...
 
void hx8347a_enable_scroll (void)
 Enables the scrolling feature. More...
 
void hx8347a_fill (hx8347a_color_t us_color)
 Fill the LCD buffer with the specified color. More...
 
hx8347a_color_t hx8347a_get_pixel (uint32_t ul_x, uint32_t ul_y)
 Get a pixel from LCD. More...
 
uint32_t hx8347a_init (struct hx8347a_opt_t *p_opt)
 Initialize the HX8347A lcd driver. More...
 
static hx8347a_color_t hx8347a_read_ram (void)
 Read data to LCD GRAM. More...
 
static void hx8347a_read_ram_prepare (void)
 Prepare to read GRAM data. More...
 
static uint16_t hx8347a_read_register (uint8_t uc_reg)
 Read data from LCD Register. More...
 
void hx8347a_scroll (int32_t ul_lines)
 Scroll up/down for the number of specified lines. More...
 
void hx8347a_set_cursor_position (uint16_t us_x, uint16_t us_y)
 Set cursor of LCD screen. More...
 
void hx8347a_set_display_direction (display_direction_t dd)
 Set display direction. More...
 
void hx8347a_set_foreground_color (hx8347a_color_t us_color)
 Set foreground color. More...
 
void hx8347a_set_window (uint32_t ul_x, uint32_t ul_y, uint32_t ul_width, uint32_t ul_height)
 Set display window. More...
 
static void hx8347a_write_ram (hx8347a_color_t us_color)
 Write data to LCD GRAM. More...
 
static void hx8347a_write_ram_buffer (const hx8347a_color_t *p_ul_buf, uint32_t ul_size)
 Write multiple data in buffer to LCD controller. More...
 
static void hx8347a_write_ram_prepare (void)
 Prepare to write GRAM data. More...
 
static void hx8347a_write_register (uint8_t uc_reg, uint16_t us_data)
 Write data to LCD Register. More...
 

Variables

static hx8347a_color_t g_ul_pixel_cache [LCD_DATA_CACHE_SIZE]
 
struct font gfont = {10, 14}
 
const uint8_t p_uc_charset10x14 []
 Character set table for font 10x14 Coding format: Char height is 14 bits, which is coded using 2 bytes per column (2 unused bits). More...
 

#define LCD_DATA_CACHE_SIZE   HX8347A_LCD_WIDTH

static void hx8347a_check_box_coordinates ( uint32_t *  p_ul_x1,
uint32_t *  p_ul_y1,
uint32_t *  p_ul_x2,
uint32_t *  p_ul_y2 
)
static

Check box coordinates.

Parameters
p_ul_x1X coordinate of upper-left corner on LCD.
p_ul_y1Y coordinate of upper-left corner on LCD.
p_ul_x2X coordinate of lower-right corner on LCD.
p_ul_y2Y coordinate of lower-right corner on LCD.

References HX8347A_LCD_HEIGHT, and HX8347A_LCD_WIDTH.

Referenced by hx8347a_draw_filled_rectangle(), hx8347a_draw_pixmap(), and hx8347a_draw_rectangle().

static void hx8347a_delay ( uint32_t  ul_ms)
static

Delay function.

Referenced by hx8347a_display_on(), and hx8347a_init().

void hx8347a_disable_scroll ( void  )

Disables the scrolling.

References HX8347A_GATE_SCAN_CTRL, and hx8347a_write_register().

void hx8347a_display_off ( void  )

Turn off the LCD.

References HX8347A_DISP_CTRL1, HX8347A_DISP_CTRL8, and hx8347a_write_register().

static void hx8347a_draw_char ( uint32_t  ul_x,
uint32_t  ul_y,
uint8_t  uc_c 
)
static

Draw an ASCII character on LCD.

Parameters
ul_xX coordinate of character upper-left corner.
ul_yY coordinate of character upper-left corner.
uc_ccharacter to print.

References hx8347a_draw_pixel().

Referenced by hx8347a_draw_string().

uint32_t hx8347a_draw_circle ( uint32_t  ul_x,
uint32_t  ul_y,
uint32_t  ul_r 
)

Draw a circle on LCD.

Parameters
ul_xX coordinate of circle center.
ul_yY coordinate of circle center.
ul_rcircle radius.
Returns
0 if succeeds, otherwise fails.

References hx8347a_draw_pixel().

uint32_t hx8347a_draw_filled_circle ( uint32_t  ul_x,
uint32_t  ul_y,
uint32_t  ul_r 
)

Draw a filled circle on LCD.

Parameters
ul_xX coordinate of circle center.
ul_yY coordinate of circle center.
ul_rcircle radius.
Returns
0 if succeeds, otherwise fails.

References hx8347a_draw_filled_rectangle().

void hx8347a_draw_filled_rectangle ( uint32_t  ul_x1,
uint32_t  ul_y1,
uint32_t  ul_x2,
uint32_t  ul_y2 
)

Draw a filled rectangle on LCD.

Parameters
ul_x1X coordinate of upper-left corner on LCD.
ul_y1Y coordinate of upper-left corner on LCD.
ul_x2X coordinate of lower-right corner on LCD.
ul_y2Y coordinate of lower-right corner on LCD.

References hx8347a_check_box_coordinates(), HX8347A_LCD_HEIGHT, HX8347A_LCD_WIDTH, hx8347a_set_cursor_position(), hx8347a_set_window(), hx8347a_write_ram_buffer(), hx8347a_write_ram_prepare(), and LCD_DATA_CACHE_SIZE.

Referenced by hx8347a_draw_filled_circle(), hx8347a_draw_line(), and hx8347a_draw_rectangle().

void hx8347a_draw_line ( uint32_t  ul_x1,
uint32_t  ul_y1,
uint32_t  ul_x2,
uint32_t  ul_y2 
)

Draw a line on LCD.

Parameters
ul_x1X coordinate of line start.
ul_y1Y coordinate of line start.
ul_x2X coordinate of line end.
ul_y2Y coordinate of line end.

References hx8347a_draw_filled_rectangle(), and hx8347a_draw_line_bresenham().

static void hx8347a_draw_line_bresenham ( uint32_t  ul_x1,
uint32_t  ul_y1,
uint32_t  ul_x2,
uint32_t  ul_y2 
)
static

Draw a line on LCD, which is not horizontal or vertical.

Parameters
ul_x1X coordinate of line start.
ul_y1Y coordinate of line start.
ul_x2X coordinate of line end.
ul_y2Y coordinate of line endl.

References hx8347a_draw_pixel().

Referenced by hx8347a_draw_line().

uint32_t hx8347a_draw_pixel ( uint32_t  ul_x,
uint32_t  ul_y 
)

Draw a pixel on LCD.

Parameters
ul_xX coordinate of pixel.
ul_yY coordinate of pixel.
Returns
0 if succeeds, otherwise fails.

References HX8347A_LCD_HEIGHT, HX8347A_LCD_WIDTH, hx8347a_set_cursor_position(), hx8347a_write_ram(), and hx8347a_write_ram_prepare().

Referenced by hx8347a_draw_char(), hx8347a_draw_circle(), and hx8347a_draw_line_bresenham().

void hx8347a_draw_pixmap ( uint32_t  ul_x,
uint32_t  ul_y,
uint32_t  ul_width,
uint32_t  ul_height,
const hx8347a_color_t p_ul_pixmap 
)

Draw a pixmap on LCD.

Parameters
ul_xX coordinate of upper-left corner on LCD.
ul_yY coordinate of upper-left corner on LCD.
ul_widthwidth of the picture.
ul_heightheight of the picture.
p_ul_pixmappixmap of the image.

References hx8347a_check_box_coordinates(), HX8347A_LCD_HEIGHT, HX8347A_LCD_WIDTH, hx8347a_set_cursor_position(), hx8347a_set_window(), hx8347a_write_ram_buffer(), and hx8347a_write_ram_prepare().

void hx8347a_draw_rectangle ( uint32_t  ul_x1,
uint32_t  ul_y1,
uint32_t  ul_x2,
uint32_t  ul_y2 
)

Draw a rectangle on LCD.

Parameters
ul_x1X coordinate of upper-left corner on LCD.
ul_y1Y coordinate of upper-left corner on LCD.
ul_x2X coordinate of lower-right corner on LCD.
ul_y2Y coordinate of lower-right corner on LCD.

References hx8347a_check_box_coordinates(), and hx8347a_draw_filled_rectangle().

void hx8347a_draw_string ( uint32_t  ul_x,
uint32_t  ul_y,
const uint8_t *  p_str 
)

Draw a string on LCD.

Parameters
ul_xX coordinate of string top-left corner.
ul_yY coordinate of string top-left corner.
p_strString to display.

References font::height, hx8347a_draw_char(), and font::width.

void hx8347a_enable_scroll ( void  )

Enables the scrolling feature.

References HX8347A_GATE_SCAN_CTRL, HX8347A_GATE_SCAN_CTRL_SCROLL_ON, and hx8347a_write_register().

void hx8347a_fill ( hx8347a_color_t  us_color)

Fill the LCD buffer with the specified color.

Parameters
us_colorfill color.

References HX8347A_LCD_HEIGHT, HX8347A_LCD_WIDTH, hx8347a_set_cursor_position(), hx8347a_write_ram(), and hx8347a_write_ram_prepare().

hx8347a_color_t hx8347a_get_pixel ( uint32_t  ul_x,
uint32_t  ul_y 
)

Get a pixel from LCD.

Parameters
ul_xX coordinate of pixel.
ul_yY coordinate of pixel.
Returns
the pixel color.

References Assert, HX8347A_LCD_HEIGHT, HX8347A_LCD_WIDTH, hx8347a_read_ram(), hx8347a_read_ram_prepare(), and hx8347a_set_cursor_position().

uint32_t hx8347a_init ( struct hx8347a_opt_t p_opt)

Initialize the HX8347A lcd driver.

Note
Make sure below works have been done before calling hx8347a_init()
  1. HX8347A related Pins have been initialized correctly.
  2. SMC has been configured correctly for access HX8347A (16-bit system interface for now).
Parameters
p_optpointer to HX8347A option structure.
Returns
0 if initialization succeeds, otherwise fails.

References hx8347a_opt_t::foreground_color, HX8347A_COL_ADDR_END1, HX8347A_COL_ADDR_END1_EC, HX8347A_COL_ADDR_END2, HX8347A_COL_ADDR_END2_EC, HX8347A_COL_ADDR_START1, HX8347A_COL_ADDR_START1_SC, HX8347A_COL_ADDR_START2, HX8347A_COL_ADDR_START2_SC, HX8347A_CYCLE_CTRL1, HX8347A_CYCLE_CTRL1_N_NW, HX8347A_CYCLE_CTRL2, HX8347A_CYCLE_CTRL2_PI_NW, HX8347A_CYCLE_CTRL3, HX8347A_CYCLE_CTRL3_I_RTN, HX8347A_CYCLE_CTRL4, HX8347A_CYCLE_CTRL5, HX8347A_CYCLE_CTRL5_SON, HX8347A_CYCLE_CTRL6, HX8347A_CYCLE_CTRL6_GDON, HX8347A_CYCLE_CTRL7, HX8347A_CYCLE_CTRL7_GDOF, HX8347A_CYCLE_CTRL_1, HX8347A_CYCLE_CTRL_1_N_DC, HX8347A_CYCLE_CTRL_2, HX8347A_CYCLE_CTRL_2_PI_DC, HX8347A_CYCLE_CTRL_3, HX8347A_CYCLE_CTRL_3_I_DC, hx8347a_delay(), HX8347A_DEVICE_CODE, HX8347A_DISP_CTRL2, HX8347A_DISP_CTRL2_N_BP, HX8347A_DISP_CTRL3, HX8347A_DISP_CTRL3_N_FP, HX8347A_DISP_CTRL4, HX8347A_DISP_CTRL4_PI_BP, HX8347A_DISP_CTRL5, HX8347A_DISP_CTRL5_PI_FP, HX8347A_DISP_CTRL6, HX8347A_DISP_CTRL6_I_BP, HX8347A_DISP_CTRL7, HX8347A_DISP_CTRL7_I_FP, HX8347A_DISP_MODE_CTRL, HX8347A_DISP_MODE_CTRL_INVON, HX8347A_DISP_MODE_CTRL_NORON, HX8347A_HIMAX_ID_CODE, HX8347A_MEMORY_ACCESS_CTRL, HX8347A_MEMORY_ACCESS_CTRL_BGR, HX8347A_MEMORY_ACCESS_CTRL_MX, HX8347A_MEMORY_ACCESS_CTRL_MY, HX8347A_OSC_CTRL1, HX8347A_OSC_CTRL1_CADJ, HX8347A_OSC_CTRL1_CUADJ, HX8347A_OSC_CTRL1_OSC_EN, HX8347A_OSC_CTRL3, HX8347A_OSC_CTRL3_RADJ, HX8347A_POWER_CTRL1, HX8347A_POWER_CTRL1_PON, HX8347A_POWER_CTRL2, HX8347A_POWER_CTRL2_AP, HX8347A_POWER_CTRL3, HX8347A_POWER_CTRL3_VC1, HX8347A_POWER_CTRL4, HX8347A_POWER_CTRL4_VC3, HX8347A_POWER_CTRL5, HX8347A_POWER_CTRL5_VRH, HX8347A_POWER_CTRL6, HX8347A_POWER_CTRL6_BT, HX8347A_R_CTRL1, HX8347A_R_CTRL10, HX8347A_R_CTRL10_CGMP2, HX8347A_R_CTRL10_OP12, HX8347A_R_CTRL10_OP13, HX8347A_R_CTRL11, HX8347A_R_CTRL11_CGMN10, HX8347A_R_CTRL11_ON01, HX8347A_R_CTRL11_ON02, HX8347A_R_CTRL12, HX8347A_R_CTRL12_CGMN2, HX8347A_R_CTRL12_ON11, HX8347A_R_CTRL12_ON12, HX8347A_R_CTRL1_CP00, HX8347A_R_CTRL1_CP02, HX8347A_R_CTRL1_CP10, HX8347A_R_CTRL1_GSEL, HX8347A_R_CTRL2, HX8347A_R_CTRL2_CN00, HX8347A_R_CTRL2_CN10, HX8347A_R_CTRL2_CN12, HX8347A_R_CTRL3, HX8347A_R_CTRL4, HX8347A_R_CTRL4_NP21, HX8347A_R_CTRL4_NP22, HX8347A_R_CTRL4_NP30, HX8347A_R_CTRL4_NP31, HX8347A_R_CTRL5, HX8347A_R_CTRL5_NP40, HX8347A_R_CTRL5_NP50, HX8347A_R_CTRL6, HX8347A_R_CTRL6_NN01, HX8347A_R_CTRL6_NN02, HX8347A_R_CTRL6_NN11, HX8347A_R_CTRL6_NN12, HX8347A_R_CTRL7, HX8347A_R_CTRL7_NN22, HX8347A_R_CTRL7_NN30, HX8347A_R_CTRL8, HX8347A_R_CTRL8_NN40, HX8347A_R_CTRL8_NN41, HX8347A_R_CTRL8_NN42, HX8347A_R_CTRL8_NN50, HX8347A_R_CTRL8_NN51, HX8347A_R_CTRL8_NN52, HX8347A_R_CTRL9, HX8347A_R_CTRL9_CGMP00, HX8347A_R_CTRL9_OP00, HX8347A_R_CTRL9_OP01, hx8347a_read_register(), HX8347A_ROW_ADDR_END1, HX8347A_ROW_ADDR_END1_EP, HX8347A_ROW_ADDR_END2, HX8347A_ROW_ADDR_END2_EP, HX8347A_ROW_ADDR_START1, HX8347A_ROW_ADDR_START1_SP, HX8347A_ROW_ADDR_START2, HX8347A_ROW_ADDR_START2_SP, hx8347a_set_cursor_position(), hx8347a_set_foreground_color(), hx8347a_set_window(), HX8347A_VCOM_CTRL1, HX8347A_VCOM_CTRL1_VCOMG, HX8347A_VCOM_CTRL2, HX8347A_VCOM_CTRL2_VCM, HX8347A_VCOM_CTRL3, HX8347A_VCOM_CTRL3_VDV, hx8347a_write_register(), hx8347a_opt_t::ul_height, and hx8347a_opt_t::ul_width.

static hx8347a_color_t hx8347a_read_ram ( void  )
static

Read data to LCD GRAM.

Note
Because pixel data LCD GRAM is 18-bits, so conversion to RGB 24-bits will cause lost low color bits.
Returns
16-bits RGB color.

Referenced by hx8347a_get_pixel().

static void hx8347a_read_ram_prepare ( void  )
static

Prepare to read GRAM data.

References HX8347A_SRAM_WRITE_CTRL.

Referenced by hx8347a_get_pixel().

static uint16_t hx8347a_read_register ( uint8_t  uc_reg)
static

Read data from LCD Register.

Parameters
uc_regregister address.
Returns
register value.

Referenced by hx8347a_init().

void hx8347a_scroll ( int32_t  ul_lines)

Scroll up/down for the number of specified lines.

Parameters
ul_linesnumber of lines to scroll.

References HX8347A_VERTICAL_SCROLL_START_ADDR1, HX8347A_VERTICAL_SCROLL_START_ADDR1_VSP, HX8347A_VERTICAL_SCROLL_START_ADDR2, HX8347A_VERTICAL_SCROLL_START_ADDR2_VSP, and hx8347a_write_register().

void hx8347a_set_cursor_position ( uint16_t  us_x,
uint16_t  us_y 
)

Set cursor of LCD screen.

Parameters
us_xX coordinate of upper-left corner on LCD.
us_yY coordinate of upper-left corner on LCD.

References HX8347A_COL_ADDR_START1, HX8347A_COL_ADDR_START2, HX8347A_ROW_ADDR_START1, HX8347A_ROW_ADDR_START2, and hx8347a_write_register().

Referenced by hx8347a_draw_filled_rectangle(), hx8347a_draw_pixel(), hx8347a_draw_pixmap(), hx8347a_fill(), hx8347a_get_pixel(), and hx8347a_init().

void hx8347a_set_display_direction ( display_direction_t  dd)
void hx8347a_set_foreground_color ( hx8347a_color_t  us_color)

Set foreground color.

Parameters
us_colorforeground color.

References LCD_DATA_CACHE_SIZE.

Referenced by hx8347a_init().

void hx8347a_set_window ( uint32_t  ul_x,
uint32_t  ul_y,
uint32_t  ul_width,
uint32_t  ul_height 
)

Set display window.

Parameters
ul_xHorizontal address start position
ul_yVertical address start position
ul_widthThe width of the window.
ul_heightThe height of the window.

References Assert, HX8347A_COL_ADDR_END1, HX8347A_COL_ADDR_END2, HX8347A_COL_ADDR_START1, HX8347A_COL_ADDR_START2, HX8347A_ROW_ADDR_END1, HX8347A_ROW_ADDR_END2, HX8347A_ROW_ADDR_START1, HX8347A_ROW_ADDR_START2, and hx8347a_write_register().

Referenced by hx8347a_draw_filled_rectangle(), hx8347a_draw_pixmap(), and hx8347a_init().

static void hx8347a_write_ram ( hx8347a_color_t  us_color)
static

Write data to LCD GRAM.

Parameters
us_color16-bits RGB color.

Referenced by hx8347a_draw_pixel(), hx8347a_fill(), and hx8347a_write_ram_buffer().

static void hx8347a_write_ram_buffer ( const hx8347a_color_t p_ul_buf,
uint32_t  ul_size 
)
static

Write multiple data in buffer to LCD controller.

Parameters
p_ul_bufdata buffer.
ul_sizesize in pixels.

References addr, and hx8347a_write_ram().

Referenced by hx8347a_draw_filled_rectangle(), and hx8347a_draw_pixmap().

static void hx8347a_write_ram_prepare ( void  )
static
static void hx8347a_write_register ( uint8_t  uc_reg,
uint16_t  us_data 
)
static

hx8347a_color_t g_ul_pixel_cache[LCD_DATA_CACHE_SIZE]
static
struct font gfont = {10, 14}
const uint8_t p_uc_charset10x14[]

Character set table for font 10x14 Coding format: Char height is 14 bits, which is coded using 2 bytes per column (2 unused bits).

Char width is 10 bits.