SAM3S8/SD8 Software Package: libraries/libboard_sam3s-ek2/source/lcdd.c Source File

SAM3S8/SD8 Software Package 1.2

# lcdd.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------------
    00002  *         ATMEL Microcontroller Software Support
    00003  * ----------------------------------------------------------------------------
    00004  * Copyright (c) 2009, Atmel Corporation
    00005  *
    00006  * All rights reserved.
    00007  *
    00008  * Redistribution and use in source and binary forms, with or without
    00009  * modification, are permitted provided that the following conditions are met:
    00010  *
    00011  * - Redistributions of source code must retain the above copyright notice,
    00012  * this list of conditions and the disclaimer below.
    00013  *
    00014  * Atmel's name may not be used to endorse or promote products derived from
    00015  * this software without specific prior written permission.
    00016  *
    00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
    00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
    00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
    00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
    00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00027  * ----------------------------------------------------------------------------
    00028  */
    00029
    00030 /**
    00031  * \file
    00032  *
    00033  * Implementation of LCD driver, Include LCD initialization,
    00034  * LCD on/off and LCD backlight control.
    00035  *
    00036  */
    00037
    00038 /*----------------------------------------------------------------------------
    00039  *        Headers
    00040  *----------------------------------------------------------------------------*/
    00041 #include "board.h"
    00042
    00043 #include <stdint.h>
    00044
    00045 /*----------------------------------------------------------------------------
    00046  *        Exported functions
    00047  *----------------------------------------------------------------------------*/
    00048
    00049 /**
    00050  * \brief Initializes the LCD controller.
    00051  * Configure SMC to access LCD controller at 64MHz MCK.
    00052  */
    00053 extern void LCDD_Initialize( void )
    00054 {
    00055     const Pin pPins[] = {BOARD_LCD_PINS};
    00056     Smc *pSmc = SMC;
    00057
    00058     /* Enable pins */
    00059     PIO_Configure(pPins, PIO_LISTSIZE(pPins));
    00060
    00061     /* Enable peripheral clock */
    00062     PMC_EnablePeripheral( ID_SMC ) ;
    00063
    00064     /* EBI SMC Configuration */
    00065     pSmc->SMC_CS_NUMBER[1].SMC_SETUP = SMC_SETUP_NWE_SETUP(2)
    00066                                      | SMC_SETUP_NCS_WR_SETUP(2)
    00067                                      | SMC_SETUP_NRD_SETUP(2)
    00068                                      | SMC_SETUP_NCS_RD_SETUP(2);
    00069
    00070     pSmc->SMC_CS_NUMBER[1].SMC_PULSE = SMC_PULSE_NWE_PULSE(4)
    00071                                      | SMC_PULSE_NCS_WR_PULSE(4)
    00072                                      | SMC_PULSE_NRD_PULSE(10)
    00073                                      | SMC_PULSE_NCS_RD_PULSE(10);
    00074
    00075     pSmc->SMC_CS_NUMBER[1].SMC_CYCLE = SMC_CYCLE_NWE_CYCLE(10)
    00076                                      | SMC_CYCLE_NRD_CYCLE(22);
    00077
    00078     pSmc->SMC_CS_NUMBER[1].SMC_MODE = SMC_MODE_READ_MODE
    00079                                     | SMC_MODE_WRITE_MODE
    00080                                     | SMC_MODE_DBW_8_BIT;
    00081
    00082     /* Initialize LCD controller */
    00083     LCD_Initialize() ;
    00084
    00085     /* Initialize LCD controller */
    00086     LCD_SetDisplayPortrait( 0 ) ;
    00087
    00088     /* Set LCD backlight */
    00089     LCDD_SetBacklight( 2 ) ;
    00090 }
    00091
    00092 /**
    00093  * \brief Turn on the LCD.
    00094  */
    00095 void LCDD_On(void)
    00096 {
    00097     LCD_On();
    00098 }
    00099
    00100 /**
    00101  * \brief Turn off the LCD.
    00102  */
    00103 void LCDD_Off(void)
    00104 {
    00105     LCD_Off();
    00106 }
    00107
    00108 /**
    00109  * \brief Set the backlight of the LCD.
    00110  *
    00111  * \param level   Backlight brightness level [1..16], 1 means maximum brightness.
    00112  */
    00113 void LCDD_SetBacklight (uint32_t level)
    00114 {
    00115     uint32_t i;
    00116     const Pin pPins[] = {BOARD_BACKLIGHT_PIN};
    00117
    00118     /* Ensure valid level */
    00119     level = (level < 1) ? 1 : level;
    00120     level = (level > 16) ? 16 : level;
    00121
    00122     /* Enable pins */
    00123     PIO_Configure(pPins, PIO_LISTSIZE(pPins));
    00124
    00125     /* Switch off backlight */
    00126     PIO_Clear(pPins);
    00127     i = 600 * (BOARD_MCK / 1000000);    /* wait for at least 500us */
    00128     while(i--);
    00129
    00130     /* Set new backlight level */
    00131     for (i = 0; i < level; i++) {
    00132         PIO_Clear(pPins);
    00133         PIO_Clear(pPins);
    00134         PIO_Clear(pPins);
    00135
    00136         PIO_Set(pPins);
    00137         PIO_Set(pPins);
    00138         PIO_Set(pPins);
    00139     }
    00140 }

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines