Atmel Software Framework

ili9341.c File Reference

ILI9341 display controller component driver.

Copyright (c) 2012-2014 Atmel Corporation. All rights reserved.

#include "conf_ili9341.h"
#include "ili9341.h"
#include "ili9341_regs.h"
#include <sysclk.h>
#include <ioport.h>
#include <delay.h>

Functions

static void ili9341_controller_init_registers (void)
 Initialize all the display registers. More...
 
void ili9341_copy_pixels_from_screen (ili9341_color_t *pixels, uint32_t count)
 Copy pixels from the screen to a pixel buffer. More...
 
void ili9341_copy_pixels_to_screen (const ili9341_color_t *pixels, uint32_t count)
 Copy pixels from SRAM to the screen. More...
 
static __always_inline void ili9341_deselect_chip (void)
 Helper function to de-select the CS of the controller on the bus. More...
 
void ili9341_duplicate_pixel (const ili9341_color_t color, uint32_t count)
 Set a given number of pixels to the same color. More...
 
static void ili9341_exit_standby (void)
 Send display commands to exit standby mode. More...
 
void ili9341_init (void)
 Initialize the controller. More...
 
static void ili9341_interface_init (void)
 Initialize the hardware interface to the controller. More...
 
static __always_inline uint8_t ili9341_read_byte (void)
 Helper function to read a byte from an arbitrary interface. More...
 
ili9341_color_t ili9341_read_gram (void)
 Read a single color from the graphical memory. More...
 
static void ili9341_reset_display (void)
 Reset the display using the digital control interface. More...
 
static __always_inline void ili9341_select_chip (void)
 Helper function to select the CS of the controller on the bus. More...
 
static __always_inline void ili9341_select_command_mode (void)
 Helper function to select command byte transmission mode. More...
 
static __always_inline void ili9341_select_data_mode (void)
 Helper function to select data byte transmission mode. More...
 
static __always_inline void ili9341_send_byte (uint8_t data)
 Helper function to send a byte over an arbitrary interface. More...
 
static void ili9341_send_command (uint8_t command)
 Sends a command to the controller, and prepares for parameter transfer. More...
 
static void ili9341_send_draw_limits (const bool send_end_limits)
 Helper function to send the drawing limits (boundaries) to the display. More...
 
void ili9341_set_bottom_right_limit (ili9341_coord_t x, ili9341_coord_t y)
 Set the display bottom right drawing limit. More...
 
void ili9341_set_limits (ili9341_coord_t start_x, ili9341_coord_t start_y, ili9341_coord_t end_x, ili9341_coord_t end_y)
 Set the full display drawing limits. More...
 
void ili9341_set_orientation (uint8_t flags)
 Sets the orientation of the display data. More...
 
void ili9341_set_top_left_limit (ili9341_coord_t x, ili9341_coord_t y)
 Set the display top left drawing limit. More...
 
static __always_inline void ili9341_wait_for_send_done (void)
 Helper function to wait for the last send operation to complete. More...
 
void ili9341_write_gram (ili9341_color_t color)
 Write the graphical memory with a single color pixel. More...
 

Variables

static ili9341_coord_t limit_end_x
 
static ili9341_coord_t limit_end_y
 
static ili9341_coord_t limit_start_x
 
static ili9341_coord_t limit_start_y
 

static void ili9341_exit_standby ( void  )
static

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, ILI9341_CMD_DISPLAY_ON, ILI9341_CMD_SLEEP_OUT, ili9341_deselect_chip(), and ili9341_send_command().

Referenced by ili9341_init().

static void ili9341_interface_init ( void  )
static

Initialize the hardware interface to the controller.

This will initialize the module used for communication with the controller. Currently supported interfaces by this component driver are the SPI interface through either the SPI module in master mode or the USART in Master SPI mode. Configuration must be done in the associated conf_ili9341.h file.

References usart_spi_device::id, spi_device::id, spi_enable(), spi_master_init(), spi_master_setup_device(), SPI_MODE_0, spi_set_chipselect(), spi_write_single(), sysclk_enable_peripheral_clock(), usart_spi_init(), and usart_spi_setup_device().

Referenced by ili9341_init().

static __always_inline uint8_t ili9341_read_byte ( void  )
static

Helper function to read a byte from an arbitrary interface.

This function is used to hide what interface is used by the component driver, e.g. the component driver does not need to know if USART in SPI mode is used or the native SPI module.

Return values
uint8_tByte of data read from the display controller

References data, ili9341_wait_for_send_done(), spi_is_rx_full(), spi_read_single(), spi_write_single(), and usart_spi_read_single().

Referenced by ili9341_copy_pixels_from_screen(), and ili9341_read_gram().

static void ili9341_reset_display ( void  )
static

Reset the display using the digital control interface.

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

References delay_ms, and ioport_set_pin_level().

Referenced by ili9341_init().

static __always_inline void ili9341_select_chip ( void  )
static

Helper function to select the CS of the controller on the bus.

References ioport_set_pin_level().

Referenced by ili9341_send_command().

static __always_inline void ili9341_select_command_mode ( void  )
static

Helper function to select command byte transmission mode.

References ioport_set_pin_level().

Referenced by ili9341_send_command().

static __always_inline void ili9341_select_data_mode ( void  )
static

Helper function to select data byte transmission mode.

References ioport_set_pin_level().

Referenced by ili9341_send_command().

static __always_inline void ili9341_send_byte ( uint8_t  data)
static

Helper function to send a byte over an arbitrary interface.

This function is used to hide what interface is used by the component driver, e.g. the component driver does not need to know if USART in SPI mode is used or the native SPI module.

Parameters
dataThe byte to be transfered

References cpu_irq_restore(), cpu_irq_save(), ili9341_wait_for_send_done(), spi_write_single(), and usart_spi_write_single().

Referenced by ili9341_controller_init_registers(), ili9341_copy_pixels_to_screen(), ili9341_duplicate_pixel(), ili9341_send_command(), ili9341_send_draw_limits(), ili9341_set_orientation(), and ili9341_write_gram().

static void ili9341_send_command ( uint8_t  command)
static

Sends a command to the controller, and prepares for parameter transfer.

Helper function to use for sending a command to the controller.

Note
After the command is sent, the display remains selected.
Parameters
commandThe command to send

References ili9341_select_chip(), ili9341_select_command_mode(), ili9341_select_data_mode(), ili9341_send_byte(), and ili9341_wait_for_send_done().

Referenced by ili9341_controller_init_registers(), ili9341_copy_pixels_from_screen(), ili9341_copy_pixels_to_screen(), ili9341_duplicate_pixel(), ili9341_exit_standby(), ili9341_read_gram(), ili9341_send_draw_limits(), ili9341_set_orientation(), and ili9341_write_gram().

static void ili9341_send_draw_limits ( const bool  send_end_limits)
static

Helper function to send the drawing limits (boundaries) to the display.

This function is used to send the currently set upper-left and lower-right drawing limits to the display, as set through the various limit functions.

Parameters
send_end_limitsTrue to also send the lower-right drawing limits

References ILI9341_CMD_COLUMN_ADDRESS_SET, ILI9341_CMD_PAGE_ADDRESS_SET, ili9341_deselect_chip(), ili9341_send_byte(), ili9341_send_command(), ili9341_wait_for_send_done(), limit_end_x, limit_end_y, limit_start_x, and limit_start_y.

Referenced by ili9341_set_bottom_right_limit(), ili9341_set_limits(), and ili9341_set_top_left_limit().