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