USB Serial application
Fork of USBSerial_HelloWorld by
mbed-dev/targets/TARGET_WIZNET/TARGET_W7500x/pinmap.c@11:b3f2a8bdac4d, 2017-12-16 (annotated)
- Committer:
- Zaitsev
- Date:
- Sat Dec 16 10:26:48 2017 +0000
- Revision:
- 11:b3f2a8bdac4d
- Parent:
- 10:41552d038a69
A copy for D.S;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Zaitsev | 10:41552d038a69 | 1 | /* mbed Microcontroller Library |
Zaitsev | 10:41552d038a69 | 2 | ******************************************************************************* |
Zaitsev | 10:41552d038a69 | 3 | * Copyright (c) 2015 WIZnet Co.,Ltd. All rights reserved. |
Zaitsev | 10:41552d038a69 | 4 | * All rights reserved. |
Zaitsev | 10:41552d038a69 | 5 | * |
Zaitsev | 10:41552d038a69 | 6 | * Redistribution and use in source and binary forms, with or without |
Zaitsev | 10:41552d038a69 | 7 | * modification, are permitted provided that the following conditions are met: |
Zaitsev | 10:41552d038a69 | 8 | * |
Zaitsev | 10:41552d038a69 | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
Zaitsev | 10:41552d038a69 | 10 | * this list of conditions and the following disclaimer. |
Zaitsev | 10:41552d038a69 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Zaitsev | 10:41552d038a69 | 12 | * this list of conditions and the following disclaimer in the documentation |
Zaitsev | 10:41552d038a69 | 13 | * and/or other materials provided with the distribution. |
Zaitsev | 10:41552d038a69 | 14 | * 3. Neither the name of ARM Limited nor the names of its contributors |
Zaitsev | 10:41552d038a69 | 15 | * may be used to endorse or promote products derived from this software |
Zaitsev | 10:41552d038a69 | 16 | * without specific prior written permission. |
Zaitsev | 10:41552d038a69 | 17 | * |
Zaitsev | 10:41552d038a69 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Zaitsev | 10:41552d038a69 | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Zaitsev | 10:41552d038a69 | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Zaitsev | 10:41552d038a69 | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Zaitsev | 10:41552d038a69 | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Zaitsev | 10:41552d038a69 | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Zaitsev | 10:41552d038a69 | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Zaitsev | 10:41552d038a69 | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Zaitsev | 10:41552d038a69 | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Zaitsev | 10:41552d038a69 | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Zaitsev | 10:41552d038a69 | 28 | ******************************************************************************* |
Zaitsev | 10:41552d038a69 | 29 | */ |
Zaitsev | 10:41552d038a69 | 30 | |
Zaitsev | 10:41552d038a69 | 31 | #include "mbed_assert.h" |
Zaitsev | 10:41552d038a69 | 32 | #include "pinmap.h" |
Zaitsev | 10:41552d038a69 | 33 | #include "PortNames.h" |
Zaitsev | 10:41552d038a69 | 34 | #include "mbed_error.h" |
Zaitsev | 10:41552d038a69 | 35 | #include "W7500x.h" |
Zaitsev | 10:41552d038a69 | 36 | #include "W7500x_gpio.h" |
Zaitsev | 10:41552d038a69 | 37 | |
Zaitsev | 10:41552d038a69 | 38 | |
Zaitsev | 10:41552d038a69 | 39 | uint32_t Get_GPIO_BaseAddress(uint32_t port_idx) |
Zaitsev | 10:41552d038a69 | 40 | { |
Zaitsev | 10:41552d038a69 | 41 | uint32_t gpio_add = 0; |
Zaitsev | 10:41552d038a69 | 42 | switch(port_idx) { |
Zaitsev | 10:41552d038a69 | 43 | case PortA: |
Zaitsev | 10:41552d038a69 | 44 | gpio_add = GPIOA_BASE; |
Zaitsev | 10:41552d038a69 | 45 | break; |
Zaitsev | 10:41552d038a69 | 46 | case PortB: |
Zaitsev | 10:41552d038a69 | 47 | gpio_add = GPIOB_BASE; |
Zaitsev | 10:41552d038a69 | 48 | break; |
Zaitsev | 10:41552d038a69 | 49 | case PortC: |
Zaitsev | 10:41552d038a69 | 50 | gpio_add = GPIOC_BASE; |
Zaitsev | 10:41552d038a69 | 51 | break; |
Zaitsev | 10:41552d038a69 | 52 | case PortD: |
Zaitsev | 10:41552d038a69 | 53 | gpio_add = GPIOD_BASE; |
Zaitsev | 10:41552d038a69 | 54 | break; |
Zaitsev | 10:41552d038a69 | 55 | default: |
Zaitsev | 10:41552d038a69 | 56 | error("Pinmap error: wrong port number."); |
Zaitsev | 10:41552d038a69 | 57 | break; |
Zaitsev | 10:41552d038a69 | 58 | } |
Zaitsev | 10:41552d038a69 | 59 | return gpio_add; |
Zaitsev | 10:41552d038a69 | 60 | } |
Zaitsev | 10:41552d038a69 | 61 | |
Zaitsev | 10:41552d038a69 | 62 | /** |
Zaitsev | 10:41552d038a69 | 63 | * Configure pin (input, output, alternate function or analog) + output speed + AF |
Zaitsev | 10:41552d038a69 | 64 | */ |
Zaitsev | 10:41552d038a69 | 65 | |
Zaitsev | 10:41552d038a69 | 66 | void pin_function(PinName pin, int data) { |
Zaitsev | 10:41552d038a69 | 67 | MBED_ASSERT(pin != (PinName)NC); |
Zaitsev | 10:41552d038a69 | 68 | // Get the pin informations |
Zaitsev | 10:41552d038a69 | 69 | uint32_t mode = WIZ_PIN_MODE(data); |
Zaitsev | 10:41552d038a69 | 70 | uint32_t pupd = WIZ_PIN_PUPD(data); |
Zaitsev | 10:41552d038a69 | 71 | uint32_t afnum = WIZ_PIN_AFNUM(data); |
Zaitsev | 10:41552d038a69 | 72 | |
Zaitsev | 10:41552d038a69 | 73 | uint32_t port_num = WIZ_PORT(pin); |
Zaitsev | 10:41552d038a69 | 74 | uint32_t pin_index = WIZ_PIN_INDEX(pin); |
Zaitsev | 10:41552d038a69 | 75 | |
Zaitsev | 10:41552d038a69 | 76 | GPIO_TypeDef *gpio; |
Zaitsev | 10:41552d038a69 | 77 | |
Zaitsev | 10:41552d038a69 | 78 | // Configure Alternate Function |
Zaitsev | 10:41552d038a69 | 79 | // Warning: Must be done before the GPIO is initialized |
Zaitsev | 10:41552d038a69 | 80 | switch (afnum) { |
Zaitsev | 10:41552d038a69 | 81 | case 0: |
Zaitsev | 10:41552d038a69 | 82 | HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF0); |
Zaitsev | 10:41552d038a69 | 83 | break; |
Zaitsev | 10:41552d038a69 | 84 | case 1: |
Zaitsev | 10:41552d038a69 | 85 | HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF1); |
Zaitsev | 10:41552d038a69 | 86 | break; |
Zaitsev | 10:41552d038a69 | 87 | case 2: |
Zaitsev | 10:41552d038a69 | 88 | HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF2); |
Zaitsev | 10:41552d038a69 | 89 | break; |
Zaitsev | 10:41552d038a69 | 90 | case 3: |
Zaitsev | 10:41552d038a69 | 91 | HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF3); |
Zaitsev | 10:41552d038a69 | 92 | break; |
Zaitsev | 10:41552d038a69 | 93 | default: |
Zaitsev | 10:41552d038a69 | 94 | break; |
Zaitsev | 10:41552d038a69 | 95 | } |
Zaitsev | 10:41552d038a69 | 96 | |
Zaitsev | 10:41552d038a69 | 97 | if(mode == WIZ_MODE_AF) |
Zaitsev | 10:41552d038a69 | 98 | return; |
Zaitsev | 10:41552d038a69 | 99 | |
Zaitsev | 10:41552d038a69 | 100 | // Configure GPIO |
Zaitsev | 10:41552d038a69 | 101 | gpio = (GPIO_TypeDef *)Get_GPIO_BaseAddress(port_num); |
Zaitsev | 10:41552d038a69 | 102 | |
Zaitsev | 10:41552d038a69 | 103 | GPIO_InitTypeDef GPIO_InitStructure; |
Zaitsev | 10:41552d038a69 | 104 | GPIO_InitStructure.GPIO_Pin = pin_index; |
Zaitsev | 10:41552d038a69 | 105 | GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)mode; |
Zaitsev | 10:41552d038a69 | 106 | GPIO_InitStructure.GPIO_Pad = (GPIOPad_TypeDef)pupd; |
Zaitsev | 10:41552d038a69 | 107 | HAL_GPIO_Init(gpio, &GPIO_InitStructure); |
Zaitsev | 10:41552d038a69 | 108 | } |
Zaitsev | 10:41552d038a69 | 109 | |
Zaitsev | 10:41552d038a69 | 110 | /** |
Zaitsev | 10:41552d038a69 | 111 | * Configure pin pull-up/pull-down |
Zaitsev | 10:41552d038a69 | 112 | */ |
Zaitsev | 10:41552d038a69 | 113 | void pin_mode(PinName pin, PinMode pupd) |
Zaitsev | 10:41552d038a69 | 114 | { |
Zaitsev | 10:41552d038a69 | 115 | MBED_ASSERT(pin != (PinName)NC); |
Zaitsev | 10:41552d038a69 | 116 | |
Zaitsev | 10:41552d038a69 | 117 | uint32_t port_num = WIZ_PORT(pin); |
Zaitsev | 10:41552d038a69 | 118 | uint32_t pin_num = WIZ_PIN_NUM(pin); |
Zaitsev | 10:41552d038a69 | 119 | |
Zaitsev | 10:41552d038a69 | 120 | switch(port_num) { |
Zaitsev | 10:41552d038a69 | 121 | case PortA: |
Zaitsev | 10:41552d038a69 | 122 | PA_PCR->Port[pin_num] |= pupd; |
Zaitsev | 10:41552d038a69 | 123 | break; |
Zaitsev | 10:41552d038a69 | 124 | case PortB: |
Zaitsev | 10:41552d038a69 | 125 | PB_PCR->Port[pin_num] |= pupd; |
Zaitsev | 10:41552d038a69 | 126 | break; |
Zaitsev | 10:41552d038a69 | 127 | case PortC: |
Zaitsev | 10:41552d038a69 | 128 | PC_PCR->Port[pin_num] |= pupd; |
Zaitsev | 10:41552d038a69 | 129 | break; |
Zaitsev | 10:41552d038a69 | 130 | case PortD: |
Zaitsev | 10:41552d038a69 | 131 | PD_PCR->Port[pin_num] |= pupd; |
Zaitsev | 10:41552d038a69 | 132 | break; |
Zaitsev | 10:41552d038a69 | 133 | default: |
Zaitsev | 10:41552d038a69 | 134 | error("Pinmap error: wrong port number."); |
Zaitsev | 10:41552d038a69 | 135 | return; |
Zaitsev | 10:41552d038a69 | 136 | } |
Zaitsev | 10:41552d038a69 | 137 | } |