Modified version of the mbed library for use with the Nucleo boards.
Dependents: EEPROMWrite Full-Project
Fork of mbed-src by
targets/hal/TARGET_WIZNET/TARGET_W7500x/pinmap.c@558:0880f51c4036, 2015-06-03 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Jun 03 09:00:09 2015 +0100
- Revision:
- 558:0880f51c4036
- Child:
- 567:a97fd0eca828
Synchronized with git revision 927c31ab8457cfef0ee8a8316117b7a41fd79133
Full URL: https://github.com/mbedmicro/mbed/commit/927c31ab8457cfef0ee8a8316117b7a41fd79133/
Add WIZwiki-W7500
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 558:0880f51c4036 | 1 | /* mbed Microcontroller Library |
mbed_official | 558:0880f51c4036 | 2 | ******************************************************************************* |
mbed_official | 558:0880f51c4036 | 3 | * Copyright (c) 2015 WIZnet Co.,Ltd. All rights reserved. |
mbed_official | 558:0880f51c4036 | 4 | * All rights reserved. |
mbed_official | 558:0880f51c4036 | 5 | * |
mbed_official | 558:0880f51c4036 | 6 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 558:0880f51c4036 | 7 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 558:0880f51c4036 | 8 | * |
mbed_official | 558:0880f51c4036 | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 558:0880f51c4036 | 10 | * this list of conditions and the following disclaimer. |
mbed_official | 558:0880f51c4036 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 558:0880f51c4036 | 12 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 558:0880f51c4036 | 13 | * and/or other materials provided with the distribution. |
mbed_official | 558:0880f51c4036 | 14 | * 3. Neither the name of ARM Limited nor the names of its contributors |
mbed_official | 558:0880f51c4036 | 15 | * may be used to endorse or promote products derived from this software |
mbed_official | 558:0880f51c4036 | 16 | * without specific prior written permission. |
mbed_official | 558:0880f51c4036 | 17 | * |
mbed_official | 558:0880f51c4036 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 558:0880f51c4036 | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 558:0880f51c4036 | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 558:0880f51c4036 | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 558:0880f51c4036 | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 558:0880f51c4036 | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 558:0880f51c4036 | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 558:0880f51c4036 | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 558:0880f51c4036 | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 558:0880f51c4036 | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 558:0880f51c4036 | 28 | ******************************************************************************* |
mbed_official | 558:0880f51c4036 | 29 | */ |
mbed_official | 558:0880f51c4036 | 30 | |
mbed_official | 558:0880f51c4036 | 31 | #include "mbed_assert.h" |
mbed_official | 558:0880f51c4036 | 32 | #include "pinmap.h" |
mbed_official | 558:0880f51c4036 | 33 | #include "PortNames.h" |
mbed_official | 558:0880f51c4036 | 34 | |
mbed_official | 558:0880f51c4036 | 35 | |
mbed_official | 558:0880f51c4036 | 36 | // GPIO mode look-up table |
mbed_official | 558:0880f51c4036 | 37 | // It have to same with PinMode index in "PinNames.h" |
mbed_official | 558:0880f51c4036 | 38 | static const uint32_t gpio_pupd[4] = { |
mbed_official | 558:0880f51c4036 | 39 | GPIO_NO_PUPD, // PullNone |
mbed_official | 558:0880f51c4036 | 40 | GPIO_PuPd_DOWN, // PullDown |
mbed_official | 558:0880f51c4036 | 41 | GPIO_PuPd_UP, // PullUp |
mbed_official | 558:0880f51c4036 | 42 | GPIO_OD // OpenDrain |
mbed_official | 558:0880f51c4036 | 43 | }; |
mbed_official | 558:0880f51c4036 | 44 | |
mbed_official | 558:0880f51c4036 | 45 | uint32_t Get_GPIO_BaseAddress(uint32_t port_idx) |
mbed_official | 558:0880f51c4036 | 46 | { |
mbed_official | 558:0880f51c4036 | 47 | uint32_t gpio_add = 0; |
mbed_official | 558:0880f51c4036 | 48 | switch(port_idx) { |
mbed_official | 558:0880f51c4036 | 49 | case PortA: |
mbed_official | 558:0880f51c4036 | 50 | gpio_add = GPIOA_BASE; |
mbed_official | 558:0880f51c4036 | 51 | break; |
mbed_official | 558:0880f51c4036 | 52 | case PortB: |
mbed_official | 558:0880f51c4036 | 53 | gpio_add = GPIOB_BASE; |
mbed_official | 558:0880f51c4036 | 54 | break; |
mbed_official | 558:0880f51c4036 | 55 | case PortC: |
mbed_official | 558:0880f51c4036 | 56 | gpio_add = GPIOC_BASE; |
mbed_official | 558:0880f51c4036 | 57 | break; |
mbed_official | 558:0880f51c4036 | 58 | case PortD: |
mbed_official | 558:0880f51c4036 | 59 | gpio_add = GPIOD_BASE; |
mbed_official | 558:0880f51c4036 | 60 | break; |
mbed_official | 558:0880f51c4036 | 61 | default: |
mbed_official | 558:0880f51c4036 | 62 | error("Pinmap error: wrong port number."); |
mbed_official | 558:0880f51c4036 | 63 | break; |
mbed_official | 558:0880f51c4036 | 64 | } |
mbed_official | 558:0880f51c4036 | 65 | return gpio_add; |
mbed_official | 558:0880f51c4036 | 66 | } |
mbed_official | 558:0880f51c4036 | 67 | |
mbed_official | 558:0880f51c4036 | 68 | |
mbed_official | 558:0880f51c4036 | 69 | /** |
mbed_official | 558:0880f51c4036 | 70 | * Configure pin (input, output, alternate function or analog) + output speed + AF |
mbed_official | 558:0880f51c4036 | 71 | */ |
mbed_official | 558:0880f51c4036 | 72 | |
mbed_official | 558:0880f51c4036 | 73 | void pin_function(PinName pin, int data) { |
mbed_official | 558:0880f51c4036 | 74 | MBED_ASSERT(pin != (PinName)NC); |
mbed_official | 558:0880f51c4036 | 75 | // Get the pin informations |
mbed_official | 558:0880f51c4036 | 76 | uint32_t mode = WIZ_PIN_MODE(data); |
mbed_official | 558:0880f51c4036 | 77 | uint32_t pupd = WIZ_PIN_PUPD(data); |
mbed_official | 558:0880f51c4036 | 78 | uint32_t afnum; |
mbed_official | 558:0880f51c4036 | 79 | |
mbed_official | 558:0880f51c4036 | 80 | if( mode == WIZ_MODE_AF ) |
mbed_official | 558:0880f51c4036 | 81 | afnum = WIZ_PIN_AFNUM(data); |
mbed_official | 558:0880f51c4036 | 82 | else |
mbed_official | 558:0880f51c4036 | 83 | afnum = WIZ_AFNUM(pin); |
mbed_official | 558:0880f51c4036 | 84 | |
mbed_official | 558:0880f51c4036 | 85 | uint32_t port_index = WIZ_PORT(pin); |
mbed_official | 558:0880f51c4036 | 86 | uint32_t pin_index = WIZ_PIN(pin); |
mbed_official | 558:0880f51c4036 | 87 | |
mbed_official | 558:0880f51c4036 | 88 | |
mbed_official | 558:0880f51c4036 | 89 | uint32_t gpio_add = Get_GPIO_BaseAddress(port_index); |
mbed_official | 558:0880f51c4036 | 90 | GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add; |
mbed_official | 558:0880f51c4036 | 91 | |
mbed_official | 558:0880f51c4036 | 92 | // Configure Alternate Function |
mbed_official | 558:0880f51c4036 | 93 | // Warning: Must be done before the GPIO is initialized |
mbed_official | 558:0880f51c4036 | 94 | switch (afnum) { |
mbed_official | 558:0880f51c4036 | 95 | case 0: |
mbed_official | 558:0880f51c4036 | 96 | HAL_PAD_AFConfig(port_index,(uint32_t)(1 << pin_index),Px_AFSR_AF0); |
mbed_official | 558:0880f51c4036 | 97 | break; |
mbed_official | 558:0880f51c4036 | 98 | case 1: |
mbed_official | 558:0880f51c4036 | 99 | HAL_PAD_AFConfig(port_index,(uint32_t)(1 << pin_index),Px_AFSR_AF1); |
mbed_official | 558:0880f51c4036 | 100 | break; |
mbed_official | 558:0880f51c4036 | 101 | case 2: |
mbed_official | 558:0880f51c4036 | 102 | HAL_PAD_AFConfig(port_index,(uint32_t)(1 << pin_index),Px_AFSR_AF2); |
mbed_official | 558:0880f51c4036 | 103 | break; |
mbed_official | 558:0880f51c4036 | 104 | case 3: |
mbed_official | 558:0880f51c4036 | 105 | HAL_PAD_AFConfig(port_index,(uint32_t)(1 << pin_index),Px_AFSR_AF3); |
mbed_official | 558:0880f51c4036 | 106 | break; |
mbed_official | 558:0880f51c4036 | 107 | default: |
mbed_official | 558:0880f51c4036 | 108 | break; |
mbed_official | 558:0880f51c4036 | 109 | } |
mbed_official | 558:0880f51c4036 | 110 | |
mbed_official | 558:0880f51c4036 | 111 | if(mode == WIZ_MODE_AF) |
mbed_official | 558:0880f51c4036 | 112 | return; |
mbed_official | 558:0880f51c4036 | 113 | |
mbed_official | 558:0880f51c4036 | 114 | // Configure GPIO |
mbed_official | 558:0880f51c4036 | 115 | GPIO_InitTypeDef GPIO_InitStructure; |
mbed_official | 558:0880f51c4036 | 116 | GPIO_InitStructure.GPIO_Pin = (uint32_t)(1 << pin_index); |
mbed_official | 558:0880f51c4036 | 117 | GPIO_InitStructure.GPIO_Mode = mode; |
mbed_official | 558:0880f51c4036 | 118 | GPIO_InitStructure.GPIO_Pad = gpio_pupd[pupd]; |
mbed_official | 558:0880f51c4036 | 119 | HAL_GPIO_Init(gpio, &GPIO_InitStructure); |
mbed_official | 558:0880f51c4036 | 120 | } |
mbed_official | 558:0880f51c4036 | 121 | |
mbed_official | 558:0880f51c4036 | 122 | /** |
mbed_official | 558:0880f51c4036 | 123 | * Configure pin pull-up/pull-down |
mbed_official | 558:0880f51c4036 | 124 | */ |
mbed_official | 558:0880f51c4036 | 125 | void pin_mode(PinName pin, PinMode pupd) |
mbed_official | 558:0880f51c4036 | 126 | { |
mbed_official | 558:0880f51c4036 | 127 | MBED_ASSERT(pin != (PinName)NC); |
mbed_official | 558:0880f51c4036 | 128 | |
mbed_official | 558:0880f51c4036 | 129 | P_Port_Def *px_pcr; |
mbed_official | 558:0880f51c4036 | 130 | |
mbed_official | 558:0880f51c4036 | 131 | uint32_t port_index = WIZ_PORT(pin); |
mbed_official | 558:0880f51c4036 | 132 | |
mbed_official | 558:0880f51c4036 | 133 | switch(port_index) { |
mbed_official | 558:0880f51c4036 | 134 | case PortA: |
mbed_official | 558:0880f51c4036 | 135 | px_pcr = PA_PCR; |
mbed_official | 558:0880f51c4036 | 136 | break; |
mbed_official | 558:0880f51c4036 | 137 | case PortB: |
mbed_official | 558:0880f51c4036 | 138 | px_pcr = PB_PCR; |
mbed_official | 558:0880f51c4036 | 139 | break; |
mbed_official | 558:0880f51c4036 | 140 | case PortC: |
mbed_official | 558:0880f51c4036 | 141 | px_pcr = PC_PCR; |
mbed_official | 558:0880f51c4036 | 142 | break; |
mbed_official | 558:0880f51c4036 | 143 | case PortD: |
mbed_official | 558:0880f51c4036 | 144 | px_pcr = (P_Port_Def*)PD_PCR; |
mbed_official | 558:0880f51c4036 | 145 | break; |
mbed_official | 558:0880f51c4036 | 146 | default: |
mbed_official | 558:0880f51c4036 | 147 | error("Pinmap error: wrong port number."); |
mbed_official | 558:0880f51c4036 | 148 | return; |
mbed_official | 558:0880f51c4036 | 149 | } |
mbed_official | 558:0880f51c4036 | 150 | |
mbed_official | 558:0880f51c4036 | 151 | px_pcr->Port[port_index] &= ~(Px_PCR_PUPD_DOWN|Px_PCR_PUPD_UP|Px_PCR_DS_HIGH| \ |
mbed_official | 558:0880f51c4036 | 152 | Px_PCR_OD | Px_PCR_IE | Px_PCR_CS_SUMMIT); |
mbed_official | 558:0880f51c4036 | 153 | px_pcr->Port[port_index] |= gpio_pupd[pupd]; |
mbed_official | 558:0880f51c4036 | 154 | } |