Atmel Software Framework

HX8347A Display Controller Low Level driver

This is the low level driver for the HX8347A display controller.

It provides basic functions for initializing, writing and reading the controller. In addition to hardware control and use of the LCD controller internal functions.

Warning
This driver is not reentrant and can not be used in interrupt service routines without extra care

Before writing data to the display call hx8347a_init() which will set up the physical interface and the display. A configuration file conf_hx8347a.h is needed to define which interface to use, pin connections and communication speed.

An example conf_hx8347a.h file for the XMEGA could look like:

#define CONF_HX8347A_USART_SPI &USARTD1
#define CONF_HX8347A_CLOCK_SPEED 500000UL
#define CONF_HX8347A_CS_PIN IOPORT_CREATE_PIN(PORTD, 4)
#define CONF_HX8347A_TE_PIN IOPORT_CREATE_PIN(PORTD, 2)
#define CONF_HX8347A_BACKLIGHT_PIN IOPORT_CREATE_PIN(PORTD, 0)
#define CONF_HX8347A_RESET_PIN IOPORT_CREATE_PIN(PORTD, 1)

Dependencies

This driver depends on the following modules:

Macros

#define HX8347A_COLOR(r, g, b)
 This macro generates a 16-bit native color for the display from a 24-bit RGB value. More...
 
#define HX8347A_DEFAULT_HEIGHT   320
 Height of display using default orientation. More...
 
#define HX8347A_DEFAULT_WIDTH   240
 Width of display using default orientation. More...
 
#define HX8347A_FLIP_X   1
 Bit mask for flipping X for hx8347a_set_orientation() More...
 
#define HX8347A_FLIP_Y   2
 Bit mask for flipping Y for hx8347a_set_orientation() More...
 
#define HX8347A_SWITCH_XY   4
 Bit mask for swapping X and Y for hx8347a_set_orientation() More...
 
#define HX8347A_SWITCH_XY_HEIGHT   240
 Height of display using swapped X/Y orientation. More...
 
#define HX8347A_SWITCH_XY_WIDTH   320
 Width of display using swapped X/Y orientation. More...
 

Typedefs

typedef uint16_t hx8347a_color_t
 
typedef int16_t hx8347a_coord_t
 

Register manipulation functions

void hx8347a_write_register (uint8_t address, uint8_t value)
 Write a specific register in the controller with a single byte. More...
 
uint8_t hx8347a_read_register (uint8_t address)
 Read the value of a specific register in the controller. More...
 
void hx8347a_clear_register (uint8_t address, uint8_t bitmask)
 Helper function for easier register access. More...
 
void hx8347a_set_register (uint8_t address, uint8_t bitmask)
 Helper function for easier register access. More...
 

Controller primitive graphical functions

hx8347a_color_t hx8347a_read_gram (void)
 Read a single color from the graphical memory. More...
 
void hx8347a_write_gram (hx8347a_color_t color)
 Write the graphical memory with a single color pixel. More...
 
void hx8347a_set_top_left_limit (hx8347a_coord_t x, hx8347a_coord_t y)
 Set the display top left drawing limit. More...
 
void hx8347a_set_bottom_right_limit (hx8347a_coord_t x, hx8347a_coord_t y)
 Set the display bottom right drawing limit. More...
 
void hx8347a_set_limits (hx8347a_coord_t start_x, hx8347a_coord_t start_y, hx8347a_coord_t end_x, hx8347a_coord_t end_y)
 Set the fully display drawing limits. More...
 
void hx8347a_set_orientation (uint8_t flags)
 Set the display orientation. More...
 
void hx8347a_copy_pixels_to_screen (const hx8347a_color_t *pixels, uint32_t count)
 Copy pixels from SRAM to the screen. More...
 
void hx8347a_copy_progmem_pixels_to_screen (hx8347a_color_t PROGMEM_PTR_T pixels, uint32_t count)
 Copy pixels from progmem to the screen. More...
 
void hx8347a_copy_pixels_from_screen (hx8347a_color_t *pixels, uint32_t count)
 Copy pixels from the screen to a pixel buffer. More...
 
void hx8347a_duplicate_pixel (const hx8347a_color_t color, uint32_t count)
 Write a set color to the screen. More...
 

Controller and display initialization and management

void hx8347a_init (void)
 Initialize the controller. More...
 
void hx8347a_exit_standby (void)
 Send display commands to exit standby mode. More...
 
void hx8347a_reset_display (void)
 Reset the display using the digital control interface. More...
 
static __always_inline void hx8347a_backlight_on (void)
 Function to turn on the display back light. More...
 
static __always_inline void hx8347a_backlight_off (void)
 Function to turn off the display back light. More...
 

#define HX8347A_COLOR (   r,
  g,
 
)
Value:
Swap16((((uint16_t)b >> 3) << 11) |\
(((uint16_t)g >> 2) << 5) |\
(((uint16_t)r >> 3) << 0))
#define Swap16(u16)
Toggles the endianism of u16 (by swapping its bytes).
Definition: compiler.h:945

This macro generates a 16-bit native color for the display from a 24-bit RGB value.

Referenced by hx8347a_copy_pixels_from_screen(), and hx8347a_read_gram().

#define HX8347A_DEFAULT_HEIGHT   320

Height of display using default orientation.

Referenced by gfx_hx8347a_init(), and gfx_hx8347a_set_orientation().

#define HX8347A_DEFAULT_WIDTH   240

Width of display using default orientation.

Referenced by gfx_hx8347a_init(), and gfx_hx8347a_set_orientation().

#define HX8347A_FLIP_X   1

Bit mask for flipping X for hx8347a_set_orientation()

Referenced by hx8347a_set_orientation().

#define HX8347A_FLIP_Y   2

Bit mask for flipping Y for hx8347a_set_orientation()

Referenced by hx8347a_set_orientation().

#define HX8347A_SWITCH_XY   4

Bit mask for swapping X and Y for hx8347a_set_orientation()

Referenced by hx8347a_set_orientation().

#define HX8347A_SWITCH_XY_HEIGHT   240

Height of display using swapped X/Y orientation.

Referenced by gfx_hx8347a_set_orientation().

#define HX8347A_SWITCH_XY_WIDTH   320

Width of display using swapped X/Y orientation.

Referenced by gfx_hx8347a_set_orientation().

typedef uint16_t hx8347a_color_t
typedef int16_t hx8347a_coord_t

static __always_inline void hx8347a_backlight_off ( void  )
static

Function to turn off the display back light.

Use this function to simply set the pin controlling the back light low to turn off the back light.

References gpio_set_pin_low.

static __always_inline void hx8347a_backlight_on ( void  )
static

Function to turn on the display back light.

Use this function to simply set the pin controlling the back light high to turn on the back light.

Note
It is up to the top application if other means of controlling this pin should be used, e.g. a PWM signal to be able to dim the display.

References gpio_set_pin_high.

Referenced by gfx_hx8347a_init().

void hx8347a_clear_register ( uint8_t  address,
uint8_t  bitmask 
)

Helper function for easier register access.

Use this function to clear specific bits in the controller registers.

Parameters
addressthe address of the register to clear
bitmaskthe bitmask of the specific bits to clear

References hx8347a_read_register(), and hx8347a_write_register().

Referenced by hx8347a_exit_standby().

void hx8347a_copy_pixels_from_screen ( hx8347a_color_t pixels,
uint32_t  count 
)

Copy pixels from the screen to a pixel buffer.

Use this function to copy pixels from the display to an internal SRAM buffer. Limits have to be set prior to calling this function, e.g.:

1 hx8347a_set_top_left_limit(0, 0);
2 hx8347a_set_bottom_right_limit(320, 240);
3 ...
Parameters
pixelspointer to the pixel buffer to read to
countnumber of pixels to read

References Assert, HX8347A_COLOR, hx8347a_deselect_chip(), hx8347a_read_byte(), hx8347a_select_chip(), hx8347a_select_register(), hx8347a_send_byte(), HX8347A_SRAMWRITE, and HX8347A_START_READREG.

void hx8347a_copy_pixels_to_screen ( const hx8347a_color_t pixels,
uint32_t  count 
)

Copy pixels from SRAM to the screen.

Used to copy a large quantitative of data to the screen in one go. Limits have to be set prior to calling this function, e.g.:

1 hx8347a_set_top_left_limit(0, 0);
2 hx8347a_set_bottom_right_limit(320, 240);
3 ...
Parameters
pixelspointer to the pixel data
countnumber of pixels to copy to the screen

References Assert, byte_count, hx8347a_deselect_chip(), hx8347a_select_chip(), hx8347a_select_register(), hx8347a_send_byte(), HX8347A_SRAMWRITE, HX8347A_START_WRITEREG, and hx8347a_write_packet().

void hx8347a_copy_progmem_pixels_to_screen ( hx8347a_color_t PROGMEM_PTR_T  pixels,
uint32_t  count 
)

Copy pixels from progmem to the screen.

This function can be used to copy data from program memory (flash) to the display. Limits have to be set prior to calling this function, e.g.:

1 hx8347a_set_top_left_limit(0, 0);
2 hx8347a_set_bottom_right_limit(320, 240);
3 ...
Parameters
pixelspointer to the progmem data
countnumber of pixels to write

References Assert, byte_count, hx8347a_deselect_chip(), hx8347a_select_chip(), hx8347a_select_register(), hx8347a_send_byte(), HX8347A_SRAMWRITE, HX8347A_START_WRITEREG, PROGMEM_PTR_T, and PROGMEM_READ_BYTE.

void hx8347a_duplicate_pixel ( const hx8347a_color_t  color,
uint32_t  count 
)

Write a set color to the screen.

Use this function to write a certain number of pixels to the same color within a set limit. Limits have to be set prior to calling this function, e.g.:

1 hx8347a_set_top_left_limit(0, 0);
2 hx8347a_set_bottom_right_limit(320, 240);
3 ...
Parameters
colorthe color to write to the display
countthe number of pixels to write with this color

References Assert, hx8347a_deselect_chip(), hx8347a_select_chip(), hx8347a_select_register(), hx8347a_send_byte(), HX8347A_SRAMWRITE, HX8347A_START_WRITEREG, and hx8347a_write_packet().

void hx8347a_exit_standby ( void  )

Send display commands to exit standby mode.

This function is used to exit the display standby mode, which is the default mode after a reset signal to the display.

References delay_ms, hx8347a_clear_register(), HX8347A_OSC_EN, HX8347A_OSCCTRL1, HX8347A_POWERCTRL1, hx8347a_set_register(), and HX8347A_STB.

Referenced by hx8347a_init().

void hx8347a_init ( void  )

Initialize the controller.

Used to initialize the HX8347A display controller by setting up the hardware interface, and setting up the controller according to the manufacturer's description. It also set up the screen orientation to the default state (portrait).

References hx8347a_controller_init_registers(), hx8347a_exit_standby(), hx8347a_interface_init(), and hx8347a_reset_display().

Referenced by gfx_hx8347a_init().

hx8347a_color_t hx8347a_read_gram ( void  )

Read a single color from the graphical memory.

Use this function to read a color from the graphical memory of the controller. Limits have to be set prior to calling this function, e.g.:

1 hx8347a_set_top_left_limit(0, 0);
2 hx8347a_set_bottom_right_limit(320, 240);
3 ...
Return values
hx8347a_color_tthe read color pixel

References HX8347A_COLOR, hx8347a_deselect_chip(), hx8347a_read_byte(), hx8347a_select_chip(), hx8347a_select_register(), hx8347a_send_byte(), HX8347A_SRAMWRITE, and HX8347A_START_READREG.

Referenced by gfx_hx8347a_get_pixel().

uint8_t hx8347a_read_register ( uint8_t  address)

Read the value of a specific register in the controller.

Use this function to get the value of a specific register in the display controller.

Parameters
addressthe address of the register to read

References hx8347a_deselect_chip(), hx8347a_read_byte(), hx8347a_select_chip(), hx8347a_select_register(), hx8347a_send_byte(), and HX8347A_START_READREG.

Referenced by hx8347a_clear_register(), hx8347a_set_orientation(), and hx8347a_set_register().

void hx8347a_reset_display ( void  )

Reset the display using the digital control interface.

Controls the reset pin of the display controller to reset the display.

References delay_ms, gpio_set_pin_high, and gpio_set_pin_low.

Referenced by hx8347a_init().

void hx8347a_set_bottom_right_limit ( hx8347a_coord_t  x,
hx8347a_coord_t  y 
)

Set the display bottom right drawing limit.

Use this function to set the bottom right corner of the drawing limit box.

Parameters
xthe x coordinate of the bottom right corner
ythe y coordinate of the bottom right corner

References HX8347A_COLENDHIGH, HX8347A_COLENDLOW, HX8347A_ROWENDHIGH, HX8347A_ROWENDLOW, and hx8347a_write_register().

Referenced by hx8347a_set_limits().

void hx8347a_set_limits ( hx8347a_coord_t  start_x,
hx8347a_coord_t  start_y,
hx8347a_coord_t  end_x,
hx8347a_coord_t  end_y 
)

Set the fully display drawing limits.

Use this function to set the full drawing limit box.

Parameters
start_xthe x coordinate of the top left corner
start_ythe y coordinate of the top left corner
end_xthe x coordinate of the bottom right corner
end_ythe y coordinate of the bottom right corner

References hx8347a_set_bottom_right_limit(), and hx8347a_set_top_left_limit().

void hx8347a_set_orientation ( uint8_t  flags)

Set the display orientation.

This is used for orienting the display in different directions, the most obvious once are landscape or portrait mode.

Example of usage (for setting landscape mode):

1 hx8347a_set_orientation(HX8347A_FLIP_Y | HX8347A_SWITCH_XY);

Or use the GFX defines:

1 hx8347a_set_orientation(GFX_FLIP_Y | GFX_SWITCH_XY);
Parameters
flagsdifferent flags used to define what orientation to use.

References HX8347A_FLIP_X, HX8347A_FLIP_X_MASK, HX8347A_FLIP_Y, HX8347A_FLIP_Y_MASK, HX8347A_MEMACCESSCTRL, hx8347a_read_register(), HX8347A_SWITCH_XY, HX8347A_SWITCH_XY_MASK, and hx8347a_write_register().

Referenced by gfx_hx8347a_set_orientation().

void hx8347a_set_register ( uint8_t  address,
uint8_t  bitmask 
)

Helper function for easier register access.

Use this function to set specific bits in the controller registers.

Parameters
addressthe address of the controller register to set
bitmaskthe bitmask describing which bit to set

References hx8347a_read_register(), and hx8347a_write_register().

Referenced by hx8347a_exit_standby().

void hx8347a_set_top_left_limit ( hx8347a_coord_t  x,
hx8347a_coord_t  y 
)

Set the display top left drawing limit.

Use this function to set the top left limit of the drawing limit box.

Parameters
xthe x coordinate of the top left corner
ythe y coordinate of the top left corner

References HX8347A_COLSTARTHIGH, HX8347A_COLSTARTLOW, HX8347A_ROWSTARTHIGH, HX8347A_ROWSTARTLOW, and hx8347a_write_register().

Referenced by hx8347a_set_limits().

void hx8347a_write_gram ( hx8347a_color_t  color)

Write the graphical memory with a single color pixel.

Use this function to write a single color pixel to the controller memory. Limits have to be set prior to calling this function, e.g.:

1 hx8347a_set_top_left_limit(0, 0);
2 hx8347a_set_bottom_right_limit(320, 240);
3 ...
Parameters
colorthe color pixel to write to the screen

References Assert, hx8347a_deselect_chip(), hx8347a_select_chip(), hx8347a_select_register(), hx8347a_send_byte(), HX8347A_SRAMWRITE, and HX8347A_START_WRITEREG.

Referenced by gfx_hx8347a_draw_line_pixel(), and gfx_hx8347a_draw_pixel().

void hx8347a_write_register ( uint8_t  address,
uint8_t  value 
)

Write a specific register in the controller with a single byte.

Use this function to write a value to a specific register in the display controller.

Parameters
addressthe address of the register to write
valuethe value to be written

References hx8347a_deselect_chip(), hx8347a_select_chip(), hx8347a_select_register(), hx8347a_send_byte(), and HX8347A_START_WRITEREG.

Referenced by hx8347a_clear_register(), hx8347a_controller_init_registers(), hx8347a_set_bottom_right_limit(), hx8347a_set_orientation(), hx8347a_set_register(), and hx8347a_set_top_left_limit().