Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gpio.c Source File

gpio.c

00001 /* CMSIS-DAP Interface Firmware
00002  * Copyright (c) 2009-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "max32620.h"
00018 #include "clkman_regs.h"
00019 #include "gpio_regs.h"
00020 #include "IO_Config.h"
00021 #include "gpio.h"
00022 
00023 /******************************************************************************/
00024 void gpio_init(void)
00025 {
00026     int i;
00027     uint32_t out_mode;
00028 
00029     // Ensure that the GPIO clock is enabled
00030     if (MXC_CLKMAN->sys_clk_ctrl_6_gpio == MXC_S_CLKMAN_CLK_SCALE_DISABLED) {
00031         MXC_CLKMAN->sys_clk_ctrl_6_gpio = MXC_S_CLKMAN_CLK_SCALE_DIV_1;
00032     }
00033 
00034     // All inputs readable
00035     for (i = 0; i < MXC_GPIO_NUM_PORTS; i++) {
00036         MXC_GPIO->in_mode[i] = 0x00000000;
00037     }
00038 
00039     // LED initial state off
00040     MXC_GPIO->out_val[PIN_DAP_LED_PORT] |= (1 << PIN_DAP_LED_PIN);
00041     MXC_GPIO->out_val[PIN_MSD_LED_PORT] |= (1 << PIN_MSD_LED_PIN);
00042     MXC_GPIO->out_val[PIN_CDC_LED_PORT] |= (1 << PIN_CDC_LED_PIN);
00043 
00044     // LED outputs
00045     out_mode = MXC_GPIO->out_mode[PIN_DAP_LED_PORT];
00046     out_mode &= ~(0xFU << (4 * PIN_DAP_LED_PIN));
00047     out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (4 * PIN_DAP_LED_PIN));
00048     MXC_GPIO->out_mode[PIN_DAP_LED_PORT] = out_mode;
00049 
00050     out_mode = MXC_GPIO->out_mode[PIN_MSD_LED_PORT];
00051     out_mode &= ~(0xFU << (4 * PIN_MSD_LED_PIN));
00052     out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (4 * PIN_MSD_LED_PIN));
00053     MXC_GPIO->out_mode[PIN_MSD_LED_PORT] = out_mode;
00054 
00055     out_mode = MXC_GPIO->out_mode[PIN_CDC_LED_PORT];
00056     out_mode &= ~(0xFU << (4 * PIN_CDC_LED_PIN));
00057     out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (4 * PIN_CDC_LED_PIN));
00058     MXC_GPIO->out_mode[PIN_CDC_LED_PORT] = out_mode;
00059 
00060     // Button input
00061     out_mode = MXC_GPIO->out_mode[PIN_RESET_IN_NO_FWRD_PORT];
00062     out_mode &= ~(0xFU << (4 * PIN_RESET_IN_NO_FWRD_PIN));
00063     out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN_WEAK_PULLUP << (4 * PIN_RESET_IN_NO_FWRD_PIN));
00064     MXC_GPIO->out_mode[PIN_RESET_IN_NO_FWRD_PORT] = out_mode;
00065     MXC_GPIO->out_val[PIN_RESET_IN_NO_FWRD_PORT] |= (0x1 << PIN_RESET_IN_NO_FWRD_PIN);
00066 }
00067 
00068 /******************************************************************************/
00069 void gpio_set_hid_led(gpio_led_state_t state)
00070 {
00071     if (state == GPIO_LED_ON) {
00072         MXC_CLRBIT(&MXC_GPIO->out_val[PIN_DAP_LED_PORT], PIN_DAP_LED_PIN);
00073     } else {
00074         MXC_SETBIT(&MXC_GPIO->out_val[PIN_DAP_LED_PORT], PIN_DAP_LED_PIN);
00075     }
00076 }
00077 
00078 /******************************************************************************/
00079 void gpio_set_msc_led(gpio_led_state_t state)
00080 {
00081     if (state == GPIO_LED_ON) {
00082         MXC_CLRBIT(&MXC_GPIO->out_val[PIN_MSD_LED_PORT], PIN_MSD_LED_PIN);
00083     } else {
00084         MXC_SETBIT(&MXC_GPIO->out_val[PIN_MSD_LED_PORT], PIN_MSD_LED_PIN);
00085     }
00086 }
00087 
00088 /******************************************************************************/
00089 void gpio_set_cdc_led(gpio_led_state_t state)
00090 {
00091     if (state == GPIO_LED_ON) {
00092         MXC_CLRBIT(&MXC_GPIO->out_val[PIN_CDC_LED_PORT], PIN_CDC_LED_PIN);
00093     } else {
00094         MXC_SETBIT(&MXC_GPIO->out_val[PIN_CDC_LED_PORT], PIN_CDC_LED_PIN);
00095     }
00096 }
00097 
00098 /******************************************************************************/
00099 uint8_t gpio_get_reset_btn_no_fwrd(void)
00100 {
00101     return !MXC_GETBIT(&MXC_GPIO->in_val[PIN_RESET_IN_NO_FWRD_PORT], PIN_RESET_IN_NO_FWRD_PIN);
00102 }
00103 
00104 /******************************************************************************/
00105 uint8_t gpio_get_reset_btn_fwrd(void)
00106 {
00107     return 0;
00108 }
00109 
00110 /******************************************************************************/
00111 void gpio_set_board_power(bool powerEnabled)
00112 {
00113 }