Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/hic_hal/maxim/max32620/gpio.c@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /* CMSIS-DAP Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * Copyright (c) 2009-2013 ARM Limited |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * you may not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 15 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 16 | |
Pawel Zarembski |
0:01f31e923fe2 | 17 | #include "max32620.h" |
Pawel Zarembski |
0:01f31e923fe2 | 18 | #include "clkman_regs.h" |
Pawel Zarembski |
0:01f31e923fe2 | 19 | #include "gpio_regs.h" |
Pawel Zarembski |
0:01f31e923fe2 | 20 | #include "IO_Config.h" |
Pawel Zarembski |
0:01f31e923fe2 | 21 | #include "gpio.h" |
Pawel Zarembski |
0:01f31e923fe2 | 22 | |
Pawel Zarembski |
0:01f31e923fe2 | 23 | /******************************************************************************/ |
Pawel Zarembski |
0:01f31e923fe2 | 24 | void gpio_init(void) |
Pawel Zarembski |
0:01f31e923fe2 | 25 | { |
Pawel Zarembski |
0:01f31e923fe2 | 26 | int i; |
Pawel Zarembski |
0:01f31e923fe2 | 27 | uint32_t out_mode; |
Pawel Zarembski |
0:01f31e923fe2 | 28 | |
Pawel Zarembski |
0:01f31e923fe2 | 29 | // Ensure that the GPIO clock is enabled |
Pawel Zarembski |
0:01f31e923fe2 | 30 | if (MXC_CLKMAN->sys_clk_ctrl_6_gpio == MXC_S_CLKMAN_CLK_SCALE_DISABLED) { |
Pawel Zarembski |
0:01f31e923fe2 | 31 | MXC_CLKMAN->sys_clk_ctrl_6_gpio = MXC_S_CLKMAN_CLK_SCALE_DIV_1; |
Pawel Zarembski |
0:01f31e923fe2 | 32 | } |
Pawel Zarembski |
0:01f31e923fe2 | 33 | |
Pawel Zarembski |
0:01f31e923fe2 | 34 | // All inputs readable |
Pawel Zarembski |
0:01f31e923fe2 | 35 | for (i = 0; i < MXC_GPIO_NUM_PORTS; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 36 | MXC_GPIO->in_mode[i] = 0x00000000; |
Pawel Zarembski |
0:01f31e923fe2 | 37 | } |
Pawel Zarembski |
0:01f31e923fe2 | 38 | |
Pawel Zarembski |
0:01f31e923fe2 | 39 | // LED initial state off |
Pawel Zarembski |
0:01f31e923fe2 | 40 | MXC_GPIO->out_val[PIN_DAP_LED_PORT] |= (1 << PIN_DAP_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 41 | MXC_GPIO->out_val[PIN_MSD_LED_PORT] |= (1 << PIN_MSD_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 42 | MXC_GPIO->out_val[PIN_CDC_LED_PORT] |= (1 << PIN_CDC_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 43 | |
Pawel Zarembski |
0:01f31e923fe2 | 44 | // LED outputs |
Pawel Zarembski |
0:01f31e923fe2 | 45 | out_mode = MXC_GPIO->out_mode[PIN_DAP_LED_PORT]; |
Pawel Zarembski |
0:01f31e923fe2 | 46 | out_mode &= ~(0xFU << (4 * PIN_DAP_LED_PIN)); |
Pawel Zarembski |
0:01f31e923fe2 | 47 | out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (4 * PIN_DAP_LED_PIN)); |
Pawel Zarembski |
0:01f31e923fe2 | 48 | MXC_GPIO->out_mode[PIN_DAP_LED_PORT] = out_mode; |
Pawel Zarembski |
0:01f31e923fe2 | 49 | |
Pawel Zarembski |
0:01f31e923fe2 | 50 | out_mode = MXC_GPIO->out_mode[PIN_MSD_LED_PORT]; |
Pawel Zarembski |
0:01f31e923fe2 | 51 | out_mode &= ~(0xFU << (4 * PIN_MSD_LED_PIN)); |
Pawel Zarembski |
0:01f31e923fe2 | 52 | out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (4 * PIN_MSD_LED_PIN)); |
Pawel Zarembski |
0:01f31e923fe2 | 53 | MXC_GPIO->out_mode[PIN_MSD_LED_PORT] = out_mode; |
Pawel Zarembski |
0:01f31e923fe2 | 54 | |
Pawel Zarembski |
0:01f31e923fe2 | 55 | out_mode = MXC_GPIO->out_mode[PIN_CDC_LED_PORT]; |
Pawel Zarembski |
0:01f31e923fe2 | 56 | out_mode &= ~(0xFU << (4 * PIN_CDC_LED_PIN)); |
Pawel Zarembski |
0:01f31e923fe2 | 57 | out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN << (4 * PIN_CDC_LED_PIN)); |
Pawel Zarembski |
0:01f31e923fe2 | 58 | MXC_GPIO->out_mode[PIN_CDC_LED_PORT] = out_mode; |
Pawel Zarembski |
0:01f31e923fe2 | 59 | |
Pawel Zarembski |
0:01f31e923fe2 | 60 | // Button input |
Pawel Zarembski |
0:01f31e923fe2 | 61 | out_mode = MXC_GPIO->out_mode[PIN_RESET_IN_NO_FWRD_PORT]; |
Pawel Zarembski |
0:01f31e923fe2 | 62 | out_mode &= ~(0xFU << (4 * PIN_RESET_IN_NO_FWRD_PIN)); |
Pawel Zarembski |
0:01f31e923fe2 | 63 | out_mode |= (MXC_V_GPIO_OUT_MODE_OPEN_DRAIN_WEAK_PULLUP << (4 * PIN_RESET_IN_NO_FWRD_PIN)); |
Pawel Zarembski |
0:01f31e923fe2 | 64 | MXC_GPIO->out_mode[PIN_RESET_IN_NO_FWRD_PORT] = out_mode; |
Pawel Zarembski |
0:01f31e923fe2 | 65 | MXC_GPIO->out_val[PIN_RESET_IN_NO_FWRD_PORT] |= (0x1 << PIN_RESET_IN_NO_FWRD_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 66 | } |
Pawel Zarembski |
0:01f31e923fe2 | 67 | |
Pawel Zarembski |
0:01f31e923fe2 | 68 | /******************************************************************************/ |
Pawel Zarembski |
0:01f31e923fe2 | 69 | void gpio_set_hid_led(gpio_led_state_t state) |
Pawel Zarembski |
0:01f31e923fe2 | 70 | { |
Pawel Zarembski |
0:01f31e923fe2 | 71 | if (state == GPIO_LED_ON) { |
Pawel Zarembski |
0:01f31e923fe2 | 72 | MXC_CLRBIT(&MXC_GPIO->out_val[PIN_DAP_LED_PORT], PIN_DAP_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 73 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 74 | MXC_SETBIT(&MXC_GPIO->out_val[PIN_DAP_LED_PORT], PIN_DAP_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 75 | } |
Pawel Zarembski |
0:01f31e923fe2 | 76 | } |
Pawel Zarembski |
0:01f31e923fe2 | 77 | |
Pawel Zarembski |
0:01f31e923fe2 | 78 | /******************************************************************************/ |
Pawel Zarembski |
0:01f31e923fe2 | 79 | void gpio_set_msc_led(gpio_led_state_t state) |
Pawel Zarembski |
0:01f31e923fe2 | 80 | { |
Pawel Zarembski |
0:01f31e923fe2 | 81 | if (state == GPIO_LED_ON) { |
Pawel Zarembski |
0:01f31e923fe2 | 82 | MXC_CLRBIT(&MXC_GPIO->out_val[PIN_MSD_LED_PORT], PIN_MSD_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 83 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 84 | MXC_SETBIT(&MXC_GPIO->out_val[PIN_MSD_LED_PORT], PIN_MSD_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 85 | } |
Pawel Zarembski |
0:01f31e923fe2 | 86 | } |
Pawel Zarembski |
0:01f31e923fe2 | 87 | |
Pawel Zarembski |
0:01f31e923fe2 | 88 | /******************************************************************************/ |
Pawel Zarembski |
0:01f31e923fe2 | 89 | void gpio_set_cdc_led(gpio_led_state_t state) |
Pawel Zarembski |
0:01f31e923fe2 | 90 | { |
Pawel Zarembski |
0:01f31e923fe2 | 91 | if (state == GPIO_LED_ON) { |
Pawel Zarembski |
0:01f31e923fe2 | 92 | MXC_CLRBIT(&MXC_GPIO->out_val[PIN_CDC_LED_PORT], PIN_CDC_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 93 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 94 | MXC_SETBIT(&MXC_GPIO->out_val[PIN_CDC_LED_PORT], PIN_CDC_LED_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 95 | } |
Pawel Zarembski |
0:01f31e923fe2 | 96 | } |
Pawel Zarembski |
0:01f31e923fe2 | 97 | |
Pawel Zarembski |
0:01f31e923fe2 | 98 | /******************************************************************************/ |
Pawel Zarembski |
0:01f31e923fe2 | 99 | uint8_t gpio_get_reset_btn_no_fwrd(void) |
Pawel Zarembski |
0:01f31e923fe2 | 100 | { |
Pawel Zarembski |
0:01f31e923fe2 | 101 | return !MXC_GETBIT(&MXC_GPIO->in_val[PIN_RESET_IN_NO_FWRD_PORT], PIN_RESET_IN_NO_FWRD_PIN); |
Pawel Zarembski |
0:01f31e923fe2 | 102 | } |
Pawel Zarembski |
0:01f31e923fe2 | 103 | |
Pawel Zarembski |
0:01f31e923fe2 | 104 | /******************************************************************************/ |
Pawel Zarembski |
0:01f31e923fe2 | 105 | uint8_t gpio_get_reset_btn_fwrd(void) |
Pawel Zarembski |
0:01f31e923fe2 | 106 | { |
Pawel Zarembski |
0:01f31e923fe2 | 107 | return 0; |
Pawel Zarembski |
0:01f31e923fe2 | 108 | } |
Pawel Zarembski |
0:01f31e923fe2 | 109 | |
Pawel Zarembski |
0:01f31e923fe2 | 110 | /******************************************************************************/ |
Pawel Zarembski |
0:01f31e923fe2 | 111 | void gpio_set_board_power(bool powerEnabled) |
Pawel Zarembski |
0:01f31e923fe2 | 112 | { |
Pawel Zarembski |
0:01f31e923fe2 | 113 | } |