1 /******************************************************************************* 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Except as contained in this notice, the name of Maxim Integrated 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated 24 * Products, Inc. Branding Policy. 25 * 26 * The mere transfer of this software does not imply any licenses 27 * of trade secrets, proprietary technology, copyrights, patents, 28 * trademarks, maskwork rights, or any other form of intellectual 29 * property whatsoever. Maxim Integrated Products, Inc. retains all 30 * ownership rights. 31 * 32 * $Date: 2016-03-17 14:27:29 -0700 (Thu, 17 Mar 2016) $ 33 * $Revision: 21966 $ 34 * 35 ******************************************************************************/ 36 37 #include <stdio.h> 38 #include "mxc_config.h" 39 #include "mxc_assert.h" 40 #include "board.h" 41 #include "gpio.h" 42 #include "uart.h" 43 #include "spim.h" 44 #include "max14690n.h" 45 46 /***** Global Variables *****/ 47 48 // LEDs 49 // Note: EvKit board uses 3.3v supply so these must be open-drain. 50 const gpio_cfg_t led_pin[] = { 51 { PORT_2, PIN_4, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN }, 52 { PORT_2, PIN_5, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN }, 53 { PORT_2, PIN_6, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN }, 54 }; 55 const unsigned int num_leds = (sizeof(led_pin) / sizeof(gpio_cfg_t)); 56 57 // Pushbuttons 58 const gpio_cfg_t pb_pin[] = { 59 { PORT_2, PIN_3, GPIO_FUNC_GPIO, GPIO_PAD_INPUT_PULLUP }, 60 }; 61 const unsigned int num_pbs = (sizeof(pb_pin) / sizeof(gpio_cfg_t)); 62 63 // Console UART configuration 64 const uart_cfg_t console_uart_cfg = { 65 .parity = UART_PARITY_DISABLE, 66 .size = UART_DATA_SIZE_8_BITS, 67 .extra_stop = 0, 68 .cts = 0, 69 .rts = 0, 70 .baud = CONSOLE_BAUD, 71 }; 72 const sys_cfg_uart_t console_sys_cfg = { 73 .clk_scale = CLKMAN_SCALE_AUTO, 74 .io_cfg = IOMAN_UART(CONSOLE_UART, IOMAN_MAP_A, IOMAN_MAP_UNUSED, IOMAN_MAP_UNUSED, 1, 0, 0) 75 }; 76 77 // MAX14690 PMIC 78 const ioman_cfg_t max14690_io_cfg = IOMAN_I2CM2(IOMAN_MAP_A, 1); 79 const gpio_cfg_t max14690_int = { PORT_3, PIN_7, GPIO_FUNC_GPIO, GPIO_PAD_INPUT_PULLUP }; 80 const gpio_cfg_t max14690_mpc0 = { PORT_2, PIN_7, GPIO_FUNC_GPIO, GPIO_PAD_NORMAL }; 81 82 /***** File Scope Variables *****/ 83 84 /******************************************************************************/ 85 void mxc_assert(const char *expr, const char *file, int line) 86 { 87 printf("MXC_ASSERT %s #%d: (%s)\n", file, line, expr); 88 while (1); 89 } 90 91 /******************************************************************************/ 92 int Board_Init(void) 93 { 94 int err; 95 96 if ((err = Console_Init()) != E_NO_ERROR) { 97 MXC_ASSERT_FAIL(); 98 return err; 99 } 100 101 if ((err = LED_Init()) != E_NO_ERROR) { 102 MXC_ASSERT_FAIL(); 103 return err; 104 } 105 106 if ((err = PB_Init()) != E_NO_ERROR) { 107 MXC_ASSERT_FAIL(); 108 return err; 109 } 110 111 /* On the Pegasus board MPC1 is connected to CAP which is high when VBUS is present. 112 * The LDO_OUTPUT_MPC1 setting will automatically enable the output when VBUS is present. 113 * The LDO_OUTPUT_MPC1 setting will also disable the output when powered from the battery. 114 * The Pegasus board uses LDO2 for VDDB (USB), LEDs and the SD card connector. 115 * Use the MAX14690_LDO2setMode(mode) function to enable LDO2 when needed. 116 */ 117 if ((err = MAX14690N_Init(3.3, LDO_OUTPUT_MPC1, 3.3, LDO_OUTPUT_DISABLED)) != E_NO_ERROR) { 118 MXC_ASSERT_FAIL(); 119 return err; 120 } 121 122 return E_NO_ERROR; 123 } 124 125 /******************************************************************************/ 126 int Console_Init(void) 127 { 128 int err; 129 130 if ((err = UART_Init(MXC_UART_GET_UART(CONSOLE_UART), &console_uart_cfg, &console_sys_cfg)) != E_NO_ERROR) { 131 MXC_ASSERT_FAIL(); 132 return err; 133 } 134 135 return E_NO_ERROR; 136 } 137 138 /******************************************************************************/ 139 int Console_PrepForSleep(void) 140 { 141 fflush(stdout); 142 return UART_PrepForSleep(MXC_UART_GET_UART(CONSOLE_UART)); 143 } 144