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@619:034e698bc035, 2015-09-04 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Sep 04 09:30:10 2015 +0100
- Revision:
- 619:034e698bc035
- Parent:
- 567:a97fd0eca828
Synchronized with git revision 92d1bfad30082571776c810a56fd471d30514ccf
Full URL: https://github.com/mbedmicro/mbed/commit/92d1bfad30082571776c810a56fd471d30514ccf/
Change directory structure and move files.
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 | 567:a97fd0eca828 | 34 | #include "mbed_error.h" |
mbed_official | 619:034e698bc035 | 35 | #include "W7500x.h" |
mbed_official | 619:034e698bc035 | 36 | #include "W7500x_gpio.h" |
mbed_official | 558:0880f51c4036 | 37 | |
mbed_official | 558:0880f51c4036 | 38 | |
mbed_official | 558:0880f51c4036 | 39 | uint32_t Get_GPIO_BaseAddress(uint32_t port_idx) |
mbed_official | 558:0880f51c4036 | 40 | { |
mbed_official | 558:0880f51c4036 | 41 | uint32_t gpio_add = 0; |
mbed_official | 558:0880f51c4036 | 42 | switch(port_idx) { |
mbed_official | 558:0880f51c4036 | 43 | case PortA: |
mbed_official | 558:0880f51c4036 | 44 | gpio_add = GPIOA_BASE; |
mbed_official | 558:0880f51c4036 | 45 | break; |
mbed_official | 558:0880f51c4036 | 46 | case PortB: |
mbed_official | 558:0880f51c4036 | 47 | gpio_add = GPIOB_BASE; |
mbed_official | 558:0880f51c4036 | 48 | break; |
mbed_official | 558:0880f51c4036 | 49 | case PortC: |
mbed_official | 558:0880f51c4036 | 50 | gpio_add = GPIOC_BASE; |
mbed_official | 558:0880f51c4036 | 51 | break; |
mbed_official | 558:0880f51c4036 | 52 | case PortD: |
mbed_official | 558:0880f51c4036 | 53 | gpio_add = GPIOD_BASE; |
mbed_official | 558:0880f51c4036 | 54 | break; |
mbed_official | 558:0880f51c4036 | 55 | default: |
mbed_official | 558:0880f51c4036 | 56 | error("Pinmap error: wrong port number."); |
mbed_official | 558:0880f51c4036 | 57 | break; |
mbed_official | 558:0880f51c4036 | 58 | } |
mbed_official | 558:0880f51c4036 | 59 | return gpio_add; |
mbed_official | 558:0880f51c4036 | 60 | } |
mbed_official | 558:0880f51c4036 | 61 | |
mbed_official | 558:0880f51c4036 | 62 | /** |
mbed_official | 558:0880f51c4036 | 63 | * Configure pin (input, output, alternate function or analog) + output speed + AF |
mbed_official | 558:0880f51c4036 | 64 | */ |
mbed_official | 558:0880f51c4036 | 65 | |
mbed_official | 558:0880f51c4036 | 66 | void pin_function(PinName pin, int data) { |
mbed_official | 558:0880f51c4036 | 67 | MBED_ASSERT(pin != (PinName)NC); |
mbed_official | 558:0880f51c4036 | 68 | // Get the pin informations |
mbed_official | 558:0880f51c4036 | 69 | uint32_t mode = WIZ_PIN_MODE(data); |
mbed_official | 558:0880f51c4036 | 70 | uint32_t pupd = WIZ_PIN_PUPD(data); |
mbed_official | 567:a97fd0eca828 | 71 | uint32_t afnum = WIZ_PIN_AFNUM(data); |
mbed_official | 567:a97fd0eca828 | 72 | |
mbed_official | 567:a97fd0eca828 | 73 | uint32_t port_num = WIZ_PORT(pin); |
mbed_official | 567:a97fd0eca828 | 74 | uint32_t pin_index = WIZ_PIN_INDEX(pin); |
mbed_official | 567:a97fd0eca828 | 75 | |
mbed_official | 567:a97fd0eca828 | 76 | GPIO_TypeDef *gpio; |
mbed_official | 558:0880f51c4036 | 77 | |
mbed_official | 558:0880f51c4036 | 78 | // Configure Alternate Function |
mbed_official | 558:0880f51c4036 | 79 | // Warning: Must be done before the GPIO is initialized |
mbed_official | 558:0880f51c4036 | 80 | switch (afnum) { |
mbed_official | 558:0880f51c4036 | 81 | case 0: |
mbed_official | 567:a97fd0eca828 | 82 | HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF0); |
mbed_official | 558:0880f51c4036 | 83 | break; |
mbed_official | 558:0880f51c4036 | 84 | case 1: |
mbed_official | 567:a97fd0eca828 | 85 | HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF1); |
mbed_official | 558:0880f51c4036 | 86 | break; |
mbed_official | 558:0880f51c4036 | 87 | case 2: |
mbed_official | 567:a97fd0eca828 | 88 | HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF2); |
mbed_official | 558:0880f51c4036 | 89 | break; |
mbed_official | 558:0880f51c4036 | 90 | case 3: |
mbed_official | 567:a97fd0eca828 | 91 | HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF3); |
mbed_official | 558:0880f51c4036 | 92 | break; |
mbed_official | 558:0880f51c4036 | 93 | default: |
mbed_official | 558:0880f51c4036 | 94 | break; |
mbed_official | 558:0880f51c4036 | 95 | } |
mbed_official | 558:0880f51c4036 | 96 | |
mbed_official | 558:0880f51c4036 | 97 | if(mode == WIZ_MODE_AF) |
mbed_official | 558:0880f51c4036 | 98 | return; |
mbed_official | 558:0880f51c4036 | 99 | |
mbed_official | 558:0880f51c4036 | 100 | // Configure GPIO |
mbed_official | 567:a97fd0eca828 | 101 | gpio = (GPIO_TypeDef *)Get_GPIO_BaseAddress(port_num); |
mbed_official | 567:a97fd0eca828 | 102 | |
mbed_official | 558:0880f51c4036 | 103 | GPIO_InitTypeDef GPIO_InitStructure; |
mbed_official | 567:a97fd0eca828 | 104 | GPIO_InitStructure.GPIO_Pin = pin_index; |
mbed_official | 567:a97fd0eca828 | 105 | GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)mode; |
mbed_official | 567:a97fd0eca828 | 106 | GPIO_InitStructure.GPIO_Pad = (GPIOPad_TypeDef)pupd; |
mbed_official | 558:0880f51c4036 | 107 | HAL_GPIO_Init(gpio, &GPIO_InitStructure); |
mbed_official | 558:0880f51c4036 | 108 | } |
mbed_official | 558:0880f51c4036 | 109 | |
mbed_official | 558:0880f51c4036 | 110 | /** |
mbed_official | 558:0880f51c4036 | 111 | * Configure pin pull-up/pull-down |
mbed_official | 558:0880f51c4036 | 112 | */ |
mbed_official | 558:0880f51c4036 | 113 | void pin_mode(PinName pin, PinMode pupd) |
mbed_official | 558:0880f51c4036 | 114 | { |
mbed_official | 558:0880f51c4036 | 115 | MBED_ASSERT(pin != (PinName)NC); |
mbed_official | 567:a97fd0eca828 | 116 | |
mbed_official | 567:a97fd0eca828 | 117 | uint32_t port_num = WIZ_PORT(pin); |
mbed_official | 567:a97fd0eca828 | 118 | uint32_t pin_num = WIZ_PIN_NUM(pin); |
mbed_official | 558:0880f51c4036 | 119 | |
mbed_official | 567:a97fd0eca828 | 120 | switch(port_num) { |
mbed_official | 558:0880f51c4036 | 121 | case PortA: |
mbed_official | 567:a97fd0eca828 | 122 | PA_PCR->Port[pin_num] |= pupd; |
mbed_official | 558:0880f51c4036 | 123 | break; |
mbed_official | 558:0880f51c4036 | 124 | case PortB: |
mbed_official | 567:a97fd0eca828 | 125 | PB_PCR->Port[pin_num] |= pupd; |
mbed_official | 558:0880f51c4036 | 126 | break; |
mbed_official | 558:0880f51c4036 | 127 | case PortC: |
mbed_official | 567:a97fd0eca828 | 128 | PC_PCR->Port[pin_num] |= pupd; |
mbed_official | 558:0880f51c4036 | 129 | break; |
mbed_official | 558:0880f51c4036 | 130 | case PortD: |
mbed_official | 567:a97fd0eca828 | 131 | PD_PCR->Port[pin_num] |= pupd; |
mbed_official | 558:0880f51c4036 | 132 | break; |
mbed_official | 558:0880f51c4036 | 133 | default: |
mbed_official | 567:a97fd0eca828 | 134 | error("Pinmap error: wrong port number."); |
mbed_official | 558:0880f51c4036 | 135 | return; |
mbed_official | 558:0880f51c4036 | 136 | } |
mbed_official | 558:0880f51c4036 | 137 | } |