Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Enumerations | Functions
LCD_5110_HAL_AVR32_UC3A3_HW_interface.h File Reference

Hardware Abstraction Layer for AVR32 and LCD used in nokia 5110.
Use hardware SPI module on AVR. More...

`#include <avr32/io.h>`
`#include <inttypes.h>`
`#include "gpio.h"`

Go to the source code of this file.

## Macros
#define | LCD_5110_IO_LOW_simple(PIN)
#define | LCD_5110_IO_LOW(PIN) LCD_5110_IO_LOW_simple(PIN)
#define | LCD_5110_IO_HIGH_simple(PIN)
#define | LCD_5110_IO_HIGH(PIN) LCD_5110_IO_HIGH_simple(PIN)
#define | LCD_5110_SPI_SCBR ((LCD_5110_SPI_CLK_SOURCE / LCD_5110_SPI_BAUDRATE))
Basic settings SPI interface
Todo: Try remove this dependency
#define | LCD_5110_CS_support 1
| Enable (1) or disable (0) Chip Select support. More...
#define | LCD_5110_RESET_support 1
| Enable (1) or disable (0) Reset pin support. More...
#define | LCD_5110_LIGHT_support 1
| Enable (1) or disable (0) support for backlight. More...
#define | LCD_5110_SPI_DEVICE (&AVR32_SPI0)
| SPI interface. More...
#define | LCD_5110_SPI_CHIP_SELECT 0
| Chip/Slave select pin. More...
#define | LCD_5110_SPI_CLK_SOURCE 66000000UL
| Clock speed in Hz. More...
Definition of SPI pins
There are defined pins and their functions
#define | LCD_5110_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
| SCK pin - must be defined! More...
#define | LCD_5110_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
| SCK function - must be defined! More...
#define | LCD_5110_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
| MISO pin - must be defined! More...
#define | LCD_5110_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
| MISO function - must be defined! More...
#define | LCD_5110_SPI_CS_PIN AVR32_SPI0_NPCS_0_0_PIN
| Chip select pin. More...
#define | LCD_5110_SPI_CS_FUNCTION AVR32_SPI0_NPCS_0_0_FUNCTION
| Chip select function (CS function) More...
Another connections for LCD 5110 module
#define | LCD_5110_SPI_DC_PIN AVR32_PIN_PA00
| Data/!Command used pin - must be defined! More...
#define | LCD_5110_RST_PIN AVR32_PIN_PA05
| Reset pin - active LOW. More...
#define | LCD_5110_LIGHT_PIN AVR32_PIN_PX14
| Backlight pin - active LOW. More...
Advanced settings SPI interface
#define | LCD_5110_SPI_BAUDRATE 0UL
| Baudrate in Hz - in real should not exceed 4 Mbit/s. More...
#define | LCD_5110_SPI_TIMEOUT 0UL
| Define timeout of SPI. More...
#define | LCD_5110_SPI_DELAY_BETWEEN_CS 0
| Delay between two chip select. More...
#define | LCD_5110_SPI_DELAY_SCK_START 0
| Delay between SCK and CS at start condition. More...
#define | LCD_5110_SPI_DELAY_CS_STOP 0
| Delay between CS and SCK at stop condition. More...
#define | LCD_5110_SPI_TIMEOUT 10000
| Define timeout of SPI. More...
#define | LCD_5110_SPI_BAUDRATE 4000000UL
| Baudrate in Hz - in real should not exceed 4 Mbit/s. More...
Other advanced settings that is not recommended to change
#define | LCD_5110_RESET_NUM_OF_CYCLES 0
| Number of cycles when reset support is disabled. More...
#define | LCD_5110_RESET_NUM_OF_CYCLES (LCD_5110_SPI_CLK_SOURCE/100)
| Number of cycles when reset support is disabled. More...

## Enumerations
enum | e_lcd_5110_status { LCD_5110_ERROR = -1, LCD_5110_OK = 0, LCD_5110_ERROR_TIMEOUT = 1, LCD_5110_ERROR_SPI_INVALID_PARAMETER = 2 }
| Enumeration of states, which can function returns. More...

## Functions
e_lcd_5110_status | LCD_5110_HAL_init (void)
| Initialize necessary HW and do initialize routine for LCD. More...
e_lcd_5110_status | LCD_5110_HAL_send_data_byte (uint8_t i_data)
| Send one data Byte to LCD module. More...
e_lcd_5110_status | LCD_5110_HAL_send_command_byte (uint8_t i_cmd)
| Send one command Byte to LCD module. More...
e_lcd_5110_status | LCD_5110_HAL_backlight_on (void)
| Turn on backlight on LCD module (set pin to high) More...
e_lcd_5110_status | LCD_5110_HAL_backlight_off (void)
| Turn off backlight on LCD module (set pin to low) More...

## Detailed Description

Hardware Abstraction Layer for AVR32 and LCD used in nokia 5110.
Use hardware SPI module on AVR.

Contains basic low level functions which depend on user architecture and
hardware. Thanks to this layer is possible use common higher level driver
and apply it thru many architectures and devices. Also this allow easy
updates independent to higher layer (new features and so on).

Created: 05.05.2014
Modified: 05.05.2014

Version
  0.1

Author
  Martin Stejskal

## Macro Definition Documentation

#define LCD_5110_CS_support 1

Enable (1) or disable (0) Chip Select support.

When Chip Select support is enabled (set to 1), then CS signal is set by
hardware. Else CS signal on target LCD must be connected to GND and SPI
device can be used only for this display.
Example:

#define LCD_5110_CS_support 1 // Enable chip select support

#define LCD_5110_IO_HIGH | ( |  | PIN) |  | LCD_5110_IO_HIGH_simple(PIN)

#define LCD_5110_IO_HIGH_simple | ( |  | PIN) |  |

Value:
gpio_port = \
&AVR32_GPIO.port[PIN >> 5]; \
gpio_port->ovrs = 1 << (PIN & 0x1F); \
gpio_port->oders = 1 << (PIN & 0x1F); \
gpio_port->gpers = 1 << (PIN & 0x1F)

#define LCD_5110_IO_LOW | ( |  | PIN) |  | LCD_5110_IO_LOW_simple(PIN)

#define LCD_5110_IO_LOW_simple | ( |  | PIN) |  |

Value:
gpio_port = \
&AVR32_GPIO.port[PIN >> 5]; \
gpio_port->ovrc = 1 << (PIN & 0x1F); \
gpio_port->oders = 1 << (PIN & 0x1F); \
gpio_port->gpers = 1 << (PIN & 0x1F)

#define LCD_5110_LIGHT_PIN AVR32_PIN_PX14

Backlight pin - active LOW.

When LCD_5110_LIGHT_support is enabled, this must be defined! Example:

#define LCD_5110_BACKLIGHT_PIN AVR32_PIN_PX21

#define LCD_5110_LIGHT_support 1

Enable (1) or disable (0) support for backlight.

In some low power applications may be useful turn off backlight. If this
option is enabled user can simply control backlight thru this driver.
Example:

#define LCD_5110_LIGHT_support 0 // Disable support for backlight

#define LCD_5110_RESET_NUM_OF_CYCLES 0

Number of cycles when reset support is disabled.

When LCD_5110_RESET_support is disabled MCU do not know if reset was done
or not. So wait. This number define how many cycles must MCU do in loop.
So this value should depend also on used clock. It is recommended to
let preprocessor calculate this value (set let there 0).
Anyway if You like hardcore You can set it manually.
Example: (LCD_5110_SPI_CLK_SOURCE/100)

#define LCD_5110_RESET_NUM_OF_CYCLES (LCD_5110_SPI_CLK_SOURCE/100)

Number of cycles when reset support is disabled.

When LCD_5110_RESET_support is disabled MCU do not know if reset was done
or not. So wait. This number define how many cycles must MCU do in loop.
So this value should depend also on used clock. It is recommended to
let preprocessor calculate this value (set let there 0).
Anyway if You like hardcore You can set it manually.
Example: (LCD_5110_SPI_CLK_SOURCE/100)

#define LCD_5110_RESET_support 1

Enable (1) or disable (0) Reset pin support.

When power supply is connected to LCD there should be some time reset pin
in low and then is possible to set reset pin back to high. After that
it is possible do initialization process. This process can be driven by
MCU or externally (for example by RC components). When reset is done by
external components, software just wait some time when initialization
function is called and then do initialize routine without any checks.
So it is up to external circuit to do reset before initialization function
is called. Or user can simply enable reset support and reset LCD is done
when needed. But it request one more wire to LCD module. Recommended is
enabled this feature.
Example:

#define LCD_5110_RESET_support 1 // Enable support for reset

#define LCD_5110_RST_PIN AVR32_PIN_PA05

Reset pin - active LOW.

When LCD_5110_RESET_support is enabled, this must be defined! Example:

#define LCD_5110_SPI_RST_PIN AVR32_PIN_PB31

#define LCD_5110_SPI_BAUDRATE 0UL

Baudrate in Hz - in real should not exceed 4 Mbit/s.

It is possible use higher baudrate than 4 Mbit/s, but this depend on
used module and designed PCB and connection to module. Also too low speed
decrease whole application performance.
For maximum performance is recommended to set this value to 0. Library itself will try to set maximum possible baudrate.
Example:

#define LCD_5110_SPI_BAUDRATE 4000000UL

Baudrate in Hz - in real should not exceed 4 Mbit/s.

It is possible use higher baudrate than 4 Mbit/s, but this depend on
used module and designed PCB and connection to module. Also too low speed
decrease whole application performance.
For maximum performance is recommended to set this value to 0. Library itself will try to set maximum possible baudrate.
Example:

#define LCD_5110_SPI_BAUDRATE 4000000UL

#define LCD_5110_SPI_CHIP_SELECT 0

Chip/Slave select pin.

Should be defined even if LCD_5110_CS_support is disabled. If You doubt, just
set it to 0. Anyway please remember: inside SPI module is CS set according
to this settings!
Example:

#define LCD_5110_SPI_CHIP_SELECT 1 // Chip select number: 1

#define LCD_5110_SPI_CLK_SOURCE 66000000UL

Clock speed in Hz.

User should define at least approximately speed of clock on which is SPI
module connected. This value is used to calculate correct values in
registers. After reset, MCU use slow oscillator, which in case UC3A3256
runs at 115 kHz. If your clock source is variable, then is recommended
set this constant to maximum used frequency. Anyway, if you want use
maximum possible speed, just set LCD_5110_SPI_BAUDRATE to 0 and
preprocessor do the rest :)
Example:

#define LCD_5110_SPI_CLK_SOURCE 115000UL

#define LCD_5110_SPI_CS_FUNCTION AVR32_SPI0_NPCS_0_0_FUNCTION

Chip select function (CS function)

Should be at least defined. In real function will not be used. This also
depend which CS user set! So please make sure that LCD_5110_SPI_CHIP_SELECT
match this CS!
Example:

#define LCD_5110_SPI_CS_FUNCTION AVR32_SPI0_NPCS_2_0_FUNCTION

#define LCD_5110_SPI_CS_PIN AVR32_SPI0_NPCS_0_0_PIN

Chip select pin.

Should be at least defined. In real pin will not be connect to GPIO.
This also
depend which CS user set! So please make sure that LCD_5110_SPI_CHIP_SELECT
match this CS!
Example:

#define LCD_5110_SPI_CS_PIN AVR32_SPI0_NPCS_2_0_PIN

#define LCD_5110_SPI_DC_PIN AVR32_PIN_PA00

Data/!Command used pin - must be defined!

Example:

#define LCD_5110_SPI_DC_PIN AVR32_PIN_PB30

#define LCD_5110_SPI_DELAY_BETWEEN_CS 0

Delay between two chip select.

When one SPI module is shared between many devices there should be some
time between two chip select. For example: deselect device1, time delay
(because of logic in devices), select device2. Anyway, if SPI module
handle just one device (this LCD module) then this value can be set to 0.
Else there should be some delay. Delay is in SPI clock periods.
Example:

#define LCD_5110_SPI_DELAY_BETWEEN_CS 0

#define LCD_5110_SPI_DELAY_CS_STOP 0

Delay between CS and SCK at stop condition.

SCK stop -> this delay -> CS disable
This delay should be set to 0 for optimal performance. Anyway in some
special cases can be used different value if needed.
Example:

#define LCD_5110_SPI_DELAY_CS_STOP 0

#define LCD_5110_SPI_DELAY_SCK_START 0

Delay between SCK and CS at start condition.

CS enable -> this delay -> SCK start
This delay should be set to 0 for optimal performance. Anyway in some
special cases can be used different value if needed.
Example:

#define LCD_5110_SPI_DELAY_SCK_START 0

#define LCD_5110_SPI_DEVICE (&AVR32_SPI0)

SPI interface.

Aka (*((volatile avr32_spi_t*)AVR32_SPI0_ADDRESS)) or (&AVR32_SPI0)
Example: LCD_5110_SPI_DEVICE (&AVR32_SPI0)

#define LCD_5110_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION

MISO function - must be defined!

Example:

#define LCD_5110_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION

#define LCD_5110_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN

MISO pin - must be defined!

Example:

#define LCD_5110_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN

#define LCD_5110_SPI_SCBR ((LCD_5110_SPI_CLK_SOURCE / LCD_5110_SPI_BAUDRATE))

#define LCD_5110_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION

SCK function - must be defined!

Example:

#define LCD_5110_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION

#define LCD_5110_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN

SCK pin - must be defined!

Example:

#define LCD_5110_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN

#define LCD_5110_SPI_TIMEOUT 0UL

Define timeout of SPI.

Well, sometimes can be SPI interface busy, so there can be limit for that
software will wait. After that return something like "timeout error" and
it is up to higher layers to deal with it. Anyway, here user can set own
delay. Delay is approximately in CPU cycles, so it depends.... However if
you are not sure, just set this value to 0 and preprocessor do the rest.
Example:

#define LCD_5110_SPI_TIMEOUT 7500UL

#define LCD_5110_SPI_TIMEOUT 10000

Define timeout of SPI.

Well, sometimes can be SPI interface busy, so there can be limit for that
software will wait. After that return something like "timeout error" and
it is up to higher layers to deal with it. Anyway, here user can set own
delay. Delay is approximately in CPU cycles, so it depends.... However if
you are not sure, just set this value to 0 and preprocessor do the rest.
Example:

#define LCD_5110_SPI_TIMEOUT 7500UL

## Enumeration Type Documentation

enum e_lcd_5110_status

Enumeration of states, which can function returns.

Generally if function return non-zero value then no problem occurs. This
enum also use LCD_5110 driver (higher layer of this driver).

Enumerator
LCD_5110_ERROR | Unspecified error.
LCD_5110_OK | All OK.
LCD_5110_ERROR_TIMEOUT | Timeout occurs.
LCD_5110_ERROR_SPI_INVALID_PARAMETER | //!< LCD_5110_ERROR_SPI_INVALID_PARAMETER Invalid parameter for SPI driver

## Function Documentation

e_lcd_5110_status LCD_5110_HAL_backlight_off | ( | void | ) |  |
| inline

Turn off backlight on LCD module (set pin to low)

LED should be controlled thru transistor, so that is reason why logic is
opposite to hardware design of LCD module.

Returns
  LCD_5110_OK (0) if support for backlight is enabled

e_lcd_5110_status LCD_5110_HAL_backlight_on | ( | void | ) |  |
| inline

Turn on backlight on LCD module (set pin to high)

LED should be controlled thru transistor, so that is reason why logic is
opposite to hardware design of LCD module.

Returns
  LCD_5110_OK (0) if support for backlight is enabled

e_lcd_5110_status LCD_5110_HAL_init | ( | void | ) |  |

Initialize necessary HW and do initialize routine for LCD.

Initialize SPI, GPIO and send initialization commands to LCD. This
function must be called first.

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_HAL_send_command_byte | ( | uint8_t | i_cmd) |  |

Send one command Byte to LCD module.

Parameters

  i_cmd | Command which will be send to LCD module

Returns
  LCD_5110_OK (0) if all OK

e_lcd_5110_status LCD_5110_HAL_send_data_byte | ( | uint8_t | i_data) |  |

Send one data Byte to LCD module.

Parameters

  i_Byte | Data byte which will be send to LCD module

Returns
  LCD_5110_OK (0) if all OK