Clemens Valens / board

Dependents:   kinetisizer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers board.c Source File

board.c

00001 /*
00002  * @brief LPCXpresso 1347 board file
00003  *
00004  * @note
00005  * Copyright(C) NXP Semiconductors, 2013
00006  * All rights reserved.
00007  *
00008  * @par
00009  * Software that is described herein is for illustrative purposes only
00010  * which provides customers with programming information regarding the
00011  * LPC products.  This software is supplied "AS IS" without any warranties of
00012  * any kind, and NXP Semiconductors and its licensor disclaim any and
00013  * all warranties, express or implied, including all implied warranties of
00014  * merchantability, fitness for a particular purpose and non-infringement of
00015  * intellectual property rights.  NXP Semiconductors assumes no responsibility
00016  * or liability for the use of the software, conveys no license or rights under any
00017  * patent, copyright, mask work right, or any other intellectual property rights in
00018  * or to any products. NXP Semiconductors reserves the right to make changes
00019  * in the software without notification. NXP Semiconductors also makes no
00020  * representation or warranty that such application will be suitable for the
00021  * specified use without further testing or modification.
00022  *
00023  * @par
00024  * Permission to use, copy, modify, and distribute this software and its
00025  * documentation is hereby granted, under NXP Semiconductors' and its
00026  * licensor's relevant copyrights in the software, without fee, provided that it
00027  * is used in conjunction with NXP Semiconductors microcontrollers.  This
00028  * copyright, permission, and disclaimer notice must appear in all copies of
00029  * this code.
00030  */
00031 
00032 #include "board.h"
00033 //#include "retarget.h"
00034 
00035 /*****************************************************************************
00036  * Private types/enumerations/variables
00037  ****************************************************************************/
00038 
00039 #if defined (BOARD_ELEKTOR_140182)
00040     #define BUTTONS_BUTTON1_GPIO_PORT_NUM           BOARD_KEYBOARD_ISP_PORT
00041     #define BUTTONS_BUTTON1_GPIO_BIT_NUM            BOARD_KEYBOARD_ISP_PIN
00042 #else
00043     #define BUTTONS_BUTTON1_GPIO_PORT_NUM           0
00044     #define BUTTONS_BUTTON1_GPIO_BIT_NUM            16
00045 #endif
00046 
00047 
00048 /*****************************************************************************
00049  * Public types/enumerations/variables
00050  ****************************************************************************/
00051 
00052 /*****************************************************************************
00053  * Private functions
00054  ****************************************************************************/
00055 
00056 /* System oscillator rate and clock rate on the CLKIN pin */
00057 const uint32_t OscRateIn = 12000000;
00058 const uint32_t ExtRateIn = 0;
00059 
00060 /*****************************************************************************
00061  * Public functions
00062  ****************************************************************************/
00063 
00064 /* Initialize pin muxing for UART interface */
00065 void Board_UART_Init(void)
00066 {
00067     /* Pin Muxing has already been done during SystemInit */
00068 }
00069 
00070 /* Sends a character on the UART */
00071 void Board_UARTPutChar(char ch)
00072 {
00073 #if defined(DEBUG_ENABLE)
00074     /* Wait for space in FIFO */
00075     while ((Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_THRE) == 0) {}
00076     Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch);
00077 #endif
00078 }
00079 
00080 /* Gets a character from the UART, returns EOF if no character is ready */
00081 int Board_UARTGetChar(void)
00082 {
00083 #if defined(DEBUG_ENABLE)
00084     if (Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_RDR) {
00085         return (int) Chip_UART_ReadByte(DEBUG_UART);
00086     }
00087 #endif
00088     return EOF;
00089 }
00090 
00091 /* Outputs a string on the debug UART */
00092 void Board_UARTPutSTR(char *str)
00093 {
00094 #if defined(DEBUG_ENABLE)
00095     while (*str != '\0') {
00096         Board_UARTPutChar(*str++);
00097     }
00098 #endif
00099 }
00100 
00101 /* Initialize debug output via UART for board */
00102 void Board_Debug_Init(void)
00103 {
00104 #if defined(DEBUG_ENABLE)
00105     Board_UART_Init();
00106 
00107     /* Setup UART for 115.2K8N1 */
00108     Chip_UART_Init(LPC_USART);
00109     Chip_UART_SetBaud(LPC_USART, 115200);
00110     Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
00111     Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
00112     Chip_UART_TXEnable(LPC_USART);
00113 #endif
00114 }
00115 
00116 /* Initializes board LED(s) */
00117 void Board_LED_Init(void)
00118 {
00119     // Set PIO0_8, _9, _10 & _18 as output.
00120     //Chip_GPIO_WriteDirBit(LPC_GPIO_PORT,BOARD_LED2_RED_PORT,BOARD_LED2_RED_PIN,OUTPUT);
00121     //Chip_GPIO_WriteDirBit(LPC_GPIO_PORT,BOARD_LED1_RED_PORT,BOARD_LED1_RED_PIN,OUTPUT);
00122     //Chip_GPIO_WriteDirBit(LPC_GPIO_PORT,BOARD_LED2_GREEN_PORT,BOARD_LED2_GREEN_PIN,OUTPUT);
00123     //Chip_GPIO_WriteDirBit(LPC_GPIO_PORT,BOARD_LED1_GREEN_PORT,BOARD_LED1_GREEN_PIN,OUTPUT);
00124     // Set PIO1_31 as output.
00125     //Chip_GPIO_WriteDirBit(LPC_GPIO_PORT,BOARD_LED3_PORT,BOARD_LED3_PIN,OUTPUT);
00126 }
00127 
00128 /* Sets the state of a board LED to on or off */
00129 void Board_LED_Set(uint8_t LEDNumber, bool On)
00130 {
00131     if (LEDNumber==BOARD_LED1_GREEN)
00132     {
00133         //Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LED1_GREEN_PORT,BOARD_LED1_GREEN_PIN,On);
00134     }
00135     else if (LEDNumber==BOARD_LED1_RED)
00136     {
00137         //Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LED1_RED_PORT,BOARD_LED1_RED_PIN,On);
00138     }
00139     else if (LEDNumber==BOARD_LED2_GREEN)
00140     {
00141         //Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LED2_GREEN_PORT,BOARD_LED2_GREEN_PIN,On);
00142     }
00143     else if (LEDNumber==BOARD_LED2_RED)
00144     {
00145         //Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LED2_RED_PORT,BOARD_LED2_RED_PIN,On);
00146     }
00147     else if (LEDNumber==BOARD_LED3)
00148     {
00149         //Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LED3_PORT,BOARD_LED3_PIN,On);
00150     }
00151 }
00152 
00153 /* Returns the current state of a board LED */
00154 bool Board_LED_Test(uint8_t LEDNumber)
00155 {
00156     bool state = false;
00157 
00158     if (LEDNumber==BOARD_LED1_GREEN)
00159     {
00160         //state = Chip_GPIO_ReadPortBit(LPC_GPIO_PORT,BOARD_LED1_GREEN_PORT,BOARD_LED1_GREEN_PIN);
00161     }
00162     else if (LEDNumber==BOARD_LED1_RED)
00163     {
00164         //state = Chip_GPIO_ReadPortBit(LPC_GPIO_PORT,BOARD_LED1_RED_PORT,BOARD_LED1_RED_PIN);
00165     }
00166     else if (LEDNumber==BOARD_LED2_GREEN)
00167     {
00168         //state = Chip_GPIO_ReadPortBit(LPC_GPIO_PORT,BOARD_LED2_GREEN_PORT,BOARD_LED2_GREEN_PIN);
00169     }
00170     else if (LEDNumber==BOARD_LED2_RED)
00171     {
00172         //state = Chip_GPIO_ReadPortBit(LPC_GPIO_PORT,BOARD_LED2_RED_PORT,BOARD_LED2_RED_PIN);
00173     }
00174     else if (LEDNumber==BOARD_LED3)
00175     {
00176         //state = Chip_GPIO_ReadPortBit(LPC_GPIO_PORT,BOARD_LED3_PORT,BOARD_LED3_PIN);
00177     }
00178 
00179     return state;
00180 }
00181 
00182 void Board_LED_Toggle(uint8_t LEDNumber)
00183 {
00184     Board_LED_Set(LEDNumber,Board_LED_Test(LEDNumber)==false?true:false);
00185 }
00186 
00187 
00188 void Board_LCD_Init(void)
00189 {
00190     // Setup backlight control.
00191     //Chip_IOCON_PinMuxSet(LPC_IOCON,BOARD_LCD_BACKLIGHT_PORT,BOARD_LCD_BACKLIGHT_PIN,IOCON_DIGMODE_EN);
00192     //Chip_GPIO_WriteDirBit(LPC_GPIO_PORT,BOARD_LCD_BACKLIGHT_PORT,BOARD_LCD_BACKLIGHT_PIN,OUTPUT);
00193 
00194     // Setup reset control.
00195     //Chip_IOCON_PinMuxSet(LPC_IOCON,BOARD_LCD_RESET_PORT,BOARD_LCD_RESET_PIN,IOCON_DIGMODE_EN);
00196     //Chip_GPIO_WriteDirBit(LPC_GPIO_PORT,BOARD_LCD_RESET_PORT,BOARD_LCD_RESET_PIN,OUTPUT);
00197 }
00198 
00199 
00200 void Board_LCD_ResetAssert(void)
00201 {
00202     //Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LCD_RESET_PORT,BOARD_LCD_RESET_PIN,false);
00203 }
00204 
00205 
00206 void Board_LCD_ResetDeassert(void)
00207 {
00208     //Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LCD_RESET_PORT,BOARD_LCD_RESET_PIN,true);
00209 }
00210 
00211 
00212 void Board_LCD_SetBacklight(uint8_t Intensity)
00213 {
00214     //if (Intensity!=0) Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LCD_BACKLIGHT_PORT,BOARD_LCD_BACKLIGHT_PIN,BOARD_LCD_BACKLIGHT_ON);
00215     //else Chip_GPIO_WritePortBit(LPC_GPIO_PORT,BOARD_LCD_BACKLIGHT_PORT,BOARD_LCD_BACKLIGHT_PIN,BOARD_LCD_BACKLIGHT_OFF);
00216 }
00217 
00218 
00219 /* Set up and initialize all required blocks and functions related to the
00220    board hardware */
00221 void Board_Init(void)
00222 {
00223     /* Sets up DEBUG UART */
00224     DEBUGINIT();
00225 
00226     /* Initialize GPIO */
00227     //Chip_GPIO_Init(LPC_GPIO_PORT);
00228 
00229     /* Initialize LEDs */
00230     Board_LED_Init();
00231     Board_LED_Set(BOARD_LED1_GREEN,BOARD_LED_OFF);
00232     Board_LED_Set(BOARD_LED1_RED,BOARD_LED_OFF);
00233     Board_LED_Set(BOARD_LED2_GREEN,BOARD_LED_OFF);
00234     Board_LED_Set(BOARD_LED2_RED,BOARD_LED_OFF);
00235     Board_LED_Set(BOARD_LED3,BOARD_LED_ON); // LED3 is inverted compared to LED1 & LED2.
00236 
00237     // Initialize LCD.
00238     Board_LCD_Init();
00239     // Put it in reset.
00240     Board_LCD_ResetAssert();
00241     // Backlight off.
00242     Board_LCD_SetBacklight(false);
00243 }
00244 
00245 /* Initialize pin muxing for SSP interface */
00246 void Board_SSP_Init(LPC_SSP_T *pSSP)
00247 {
00248     if (pSSP == LPC_SSP0) {
00249     }
00250     else {
00251         //Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 23, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); /* PIO1_23 connected to SSEL1 */
00252         //Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 20, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); /* PIO1_20 connected to SCK1 */
00253         //Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 21, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); /* PIO1_21 connected to MISO1 */
00254         //Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 22, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); /* PIO1_22 connected to MOSI1 */
00255     }
00256 }
00257 
00258 /* Configure pin for ADC channel 0 */
00259 void Board_ADC_Init(void)
00260 {
00261     /* Muxing already setup as part of SystemInit for AD0 */
00262 }
00263 
00264 /* Initialize buttons on the board */
00265 void Board_Buttons_Init(void)
00266 {
00267     //Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM, false);
00268 }
00269 
00270 /* Get button status */
00271 uint32_t Buttons_GetStatus(void)
00272 {
00273     uint8_t ret = NO_BUTTON_PRESSED;
00274     //if (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM) == 0x00) {
00275     //  ret |= BUTTONS_BUTTON1;
00276     //}
00277     return ret;
00278 }
00279