Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
gpio.c
00001 /** 00002 * @file gpio.c 00003 * @brief 00004 * 00005 * DAPLink Interface Firmware 00006 * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #include "LPC43xx.h" 00023 #include "lpc43xx_scu.h" 00024 #include "gpio.h" 00025 #include "compiler.h" 00026 #include "DAP_config.h" // For the nRESET and RESET_TXE port/pin info 00027 #include "IO_Config.h" 00028 00029 BOOL gpio_reset_pin_is_input = __TRUE; 00030 00031 // Connected LED P1_1: GPIO0[8] 00032 #define LED_CONNECTED_PORT 0 00033 #define LED_CONNECTED_BIT 8 00034 00035 // LPC43xx peripheral register bit masks (used by macros) 00036 #define CCU_CLK_CFG_RUN (1UL << 0) 00037 #define CCU_CLK_CFG_AUTO (1UL << 1) 00038 #define CCU_CLK_STAT_RUN (1UL << 0) 00039 00040 static void busy_wait(uint32_t cycles) 00041 { 00042 volatile uint32_t i; 00043 i = cycles; 00044 00045 while (i > 0) { 00046 i--; 00047 } 00048 } 00049 00050 void gpio_init(void) 00051 { 00052 /* Enable clock and init GPIO outputs */ 00053 LPC_CCU1->CLK_M4_GPIO_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN; 00054 00055 while (!(LPC_CCU1->CLK_M4_GPIO_STAT & CCU_CLK_STAT_RUN)); 00056 00057 /* Configure I/O pins: function number, input buffer enabled, */ 00058 /* no pull-up/down */ 00059 scu_pinmux(1, 1, GPIO_NOPULL, FUNC0); /* LED: GPIO0[8] */ 00060 scu_pinmux(2, 11, GPIO_NOPULL, FUNC0); /* ISPCTRL: GPIO1[11] */ 00061 scu_pinmux(2, 5, GPIO_PUP, FUNC4); /* nRESET: GPIO5[5] */ 00062 scu_pinmux(2, 6, GPIO_NOPULL, FUNC4); /* nRESET_OE: GPIO5[6] */ 00063 /* Configure: LED as output (turned off) */ 00064 LPC_GPIO_PORT->CLR[LED_CONNECTED_PORT] = (1 << LED_CONNECTED_BIT); 00065 LPC_GPIO_PORT->DIR[LED_CONNECTED_PORT] |= (1 << LED_CONNECTED_BIT); 00066 /* Configure: ISPCTRL as output and high */ 00067 LPC_GPIO_PORT->SET[ISPCTRL_PORT] = (1 << ISPCTRL_BIT); 00068 LPC_GPIO_PORT->DIR[ISPCTRL_PORT] |= (1 << ISPCTRL_BIT); 00069 /* configure Reset Button as input, Reset Output Enable as output LOW */ 00070 LPC_GPIO_PORT->DIR[PORT_nRESET] &= ~(1 << PIN_nRESET_IN_BIT); 00071 LPC_GPIO_PORT->CLR[PORT_RESET_TXE] = (1 << PIN_RESET_TXE_IN_BIT); 00072 LPC_GPIO_PORT->DIR[PORT_RESET_TXE] |= (1 << PIN_RESET_TXE_IN_BIT); 00073 /* Use Pin Interrupt 0 */ 00074 LPC_SCU->PINTSEL0 &= ~0xff; 00075 LPC_SCU->PINTSEL0 |= (PORT_nRESET << 5) | (PIN_nRESET_IN_BIT); 00076 00077 busy_wait(10000); 00078 } 00079 00080 void gpio_set_hid_led(gpio_led_state_t state) 00081 { 00082 if (state) { 00083 LPC_GPIO_PORT->SET[LED_CONNECTED_PORT] = (1 << LED_CONNECTED_BIT); 00084 } else { 00085 LPC_GPIO_PORT->CLR[LED_CONNECTED_PORT] = (1 << LED_CONNECTED_BIT); 00086 } 00087 } 00088 00089 void gpio_set_cdc_led(gpio_led_state_t state) 00090 { 00091 if (state) { 00092 LPC_GPIO_PORT->SET[LED_CONNECTED_PORT] = (1 << LED_CONNECTED_BIT); 00093 } else { 00094 LPC_GPIO_PORT->CLR[LED_CONNECTED_PORT] = (1 << LED_CONNECTED_BIT); 00095 } 00096 } 00097 00098 void gpio_set_msc_led(gpio_led_state_t state) 00099 { 00100 if (state) { 00101 LPC_GPIO_PORT->SET[LED_CONNECTED_PORT] = (1 << LED_CONNECTED_BIT); 00102 } else { 00103 LPC_GPIO_PORT->CLR[LED_CONNECTED_PORT] = (1 << LED_CONNECTED_BIT); 00104 } 00105 } 00106 00107 void gpio_set_isp_pin(uint8_t state) 00108 { 00109 if (state) { 00110 LPC_GPIO_PORT->SET[ISPCTRL_PORT] = (1 << ISPCTRL_BIT); 00111 } else { 00112 LPC_GPIO_PORT->CLR[ISPCTRL_PORT] = (1 << ISPCTRL_BIT); 00113 } 00114 } 00115 00116 uint8_t gpio_get_reset_btn_no_fwrd(void) 00117 { 00118 return LPC_GPIO_PORT->W[PORT_nRESET * 32 + PIN_nRESET_IN_BIT] ? 0 : 1; 00119 } 00120 00121 uint8_t gpio_get_reset_btn_fwrd(void) 00122 { 00123 return 0; 00124 } 00125 00126 void gpio_set_board_power(bool powerEnabled) 00127 { 00128 }
Generated on Tue Jul 12 2022 15:37:18 by
