Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
targets/TARGET_WIZNET/TARGET_W7500x/gpio_object.h@0:098463de4c5d, 2017-01-25 (annotated)
- Committer:
- group-onsemi
- Date:
- Wed Jan 25 20:34:15 2017 +0000
- Revision:
- 0:098463de4c5d
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-onsemi | 0:098463de4c5d | 1 | /* mbed Microcontroller Library |
group-onsemi | 0:098463de4c5d | 2 | ******************************************************************************* |
group-onsemi | 0:098463de4c5d | 3 | * Copyright (c) 2015 WIZnet Co.,Ltd. All rights reserved. |
group-onsemi | 0:098463de4c5d | 4 | * All rights reserved. |
group-onsemi | 0:098463de4c5d | 5 | * |
group-onsemi | 0:098463de4c5d | 6 | * Redistribution and use in source and binary forms, with or without |
group-onsemi | 0:098463de4c5d | 7 | * modification, are permitted provided that the following conditions are met: |
group-onsemi | 0:098463de4c5d | 8 | * |
group-onsemi | 0:098463de4c5d | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
group-onsemi | 0:098463de4c5d | 10 | * this list of conditions and the following disclaimer. |
group-onsemi | 0:098463de4c5d | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
group-onsemi | 0:098463de4c5d | 12 | * this list of conditions and the following disclaimer in the documentation |
group-onsemi | 0:098463de4c5d | 13 | * and/or other materials provided with the distribution. |
group-onsemi | 0:098463de4c5d | 14 | * 3. Neither the name of ARM Limited nor the names of its contributors |
group-onsemi | 0:098463de4c5d | 15 | * may be used to endorse or promote products derived from this software |
group-onsemi | 0:098463de4c5d | 16 | * without specific prior written permission. |
group-onsemi | 0:098463de4c5d | 17 | * |
group-onsemi | 0:098463de4c5d | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
group-onsemi | 0:098463de4c5d | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
group-onsemi | 0:098463de4c5d | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
group-onsemi | 0:098463de4c5d | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
group-onsemi | 0:098463de4c5d | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
group-onsemi | 0:098463de4c5d | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
group-onsemi | 0:098463de4c5d | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
group-onsemi | 0:098463de4c5d | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
group-onsemi | 0:098463de4c5d | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
group-onsemi | 0:098463de4c5d | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
group-onsemi | 0:098463de4c5d | 28 | ******************************************************************************* |
group-onsemi | 0:098463de4c5d | 29 | */ |
group-onsemi | 0:098463de4c5d | 30 | |
group-onsemi | 0:098463de4c5d | 31 | #ifndef MBED_GPIO_OBJECT_H |
group-onsemi | 0:098463de4c5d | 32 | #define MBED_GPIO_OBJECT_H |
group-onsemi | 0:098463de4c5d | 33 | |
group-onsemi | 0:098463de4c5d | 34 | #include "mbed_assert.h" |
group-onsemi | 0:098463de4c5d | 35 | #include "W7500x_gpio.h" |
group-onsemi | 0:098463de4c5d | 36 | |
group-onsemi | 0:098463de4c5d | 37 | #ifdef __cplusplus |
group-onsemi | 0:098463de4c5d | 38 | extern "C" { |
group-onsemi | 0:098463de4c5d | 39 | #endif |
group-onsemi | 0:098463de4c5d | 40 | |
group-onsemi | 0:098463de4c5d | 41 | typedef struct { |
group-onsemi | 0:098463de4c5d | 42 | PinName pin; |
group-onsemi | 0:098463de4c5d | 43 | uint32_t pin_index; |
group-onsemi | 0:098463de4c5d | 44 | uint32_t port_num; |
group-onsemi | 0:098463de4c5d | 45 | uint32_t direction; |
group-onsemi | 0:098463de4c5d | 46 | uint32_t mode; |
group-onsemi | 0:098463de4c5d | 47 | __IO uint32_t *reg_data_in; |
group-onsemi | 0:098463de4c5d | 48 | } gpio_t; |
group-onsemi | 0:098463de4c5d | 49 | |
group-onsemi | 0:098463de4c5d | 50 | |
group-onsemi | 0:098463de4c5d | 51 | extern uint32_t Get_GPIO_BaseAddress(uint32_t port_idx); |
group-onsemi | 0:098463de4c5d | 52 | |
group-onsemi | 0:098463de4c5d | 53 | |
group-onsemi | 0:098463de4c5d | 54 | static inline void gpio_write(gpio_t *obj, int value) { |
group-onsemi | 0:098463de4c5d | 55 | MBED_ASSERT(obj->pin != (PinName)NC); |
group-onsemi | 0:098463de4c5d | 56 | |
group-onsemi | 0:098463de4c5d | 57 | uint32_t port_num = WIZ_PORT(obj->pin); |
group-onsemi | 0:098463de4c5d | 58 | uint32_t pin_index = WIZ_PIN_INDEX(obj->pin); |
group-onsemi | 0:098463de4c5d | 59 | |
group-onsemi | 0:098463de4c5d | 60 | GPIO_TypeDef *gpio = (GPIO_TypeDef *)Get_GPIO_BaseAddress(port_num); |
group-onsemi | 0:098463de4c5d | 61 | |
group-onsemi | 0:098463de4c5d | 62 | |
group-onsemi | 0:098463de4c5d | 63 | if (value) |
group-onsemi | 0:098463de4c5d | 64 | { |
group-onsemi | 0:098463de4c5d | 65 | HAL_GPIO_SetBits(gpio, pin_index); |
group-onsemi | 0:098463de4c5d | 66 | } |
group-onsemi | 0:098463de4c5d | 67 | else |
group-onsemi | 0:098463de4c5d | 68 | { |
group-onsemi | 0:098463de4c5d | 69 | HAL_GPIO_ResetBits(gpio, pin_index); |
group-onsemi | 0:098463de4c5d | 70 | } |
group-onsemi | 0:098463de4c5d | 71 | } |
group-onsemi | 0:098463de4c5d | 72 | |
group-onsemi | 0:098463de4c5d | 73 | static inline int gpio_read(gpio_t *obj) { |
group-onsemi | 0:098463de4c5d | 74 | int ret; |
group-onsemi | 0:098463de4c5d | 75 | |
group-onsemi | 0:098463de4c5d | 76 | MBED_ASSERT(obj->pin != (PinName)NC); |
group-onsemi | 0:098463de4c5d | 77 | |
group-onsemi | 0:098463de4c5d | 78 | uint32_t port_num = WIZ_PORT(obj->pin); |
group-onsemi | 0:098463de4c5d | 79 | |
group-onsemi | 0:098463de4c5d | 80 | GPIO_TypeDef *gpio = (GPIO_TypeDef *)Get_GPIO_BaseAddress(port_num); |
group-onsemi | 0:098463de4c5d | 81 | |
group-onsemi | 0:098463de4c5d | 82 | if(obj->direction == PIN_OUTPUT) |
group-onsemi | 0:098463de4c5d | 83 | { |
group-onsemi | 0:098463de4c5d | 84 | ret = ( HAL_GPIO_ReadOutputData(gpio) & obj->pin_index ) ? 1 : 0; |
group-onsemi | 0:098463de4c5d | 85 | } |
group-onsemi | 0:098463de4c5d | 86 | else |
group-onsemi | 0:098463de4c5d | 87 | { |
group-onsemi | 0:098463de4c5d | 88 | ret = ((*obj->reg_data_in & obj->pin_index) ? 1 : 0); |
group-onsemi | 0:098463de4c5d | 89 | } |
group-onsemi | 0:098463de4c5d | 90 | |
group-onsemi | 0:098463de4c5d | 91 | return ret; |
group-onsemi | 0:098463de4c5d | 92 | } |
group-onsemi | 0:098463de4c5d | 93 | |
group-onsemi | 0:098463de4c5d | 94 | static inline int gpio_is_connected(const gpio_t *obj) { |
group-onsemi | 0:098463de4c5d | 95 | return obj->pin != (PinName)NC; |
group-onsemi | 0:098463de4c5d | 96 | } |
group-onsemi | 0:098463de4c5d | 97 | |
group-onsemi | 0:098463de4c5d | 98 | #ifdef __cplusplus |
group-onsemi | 0:098463de4c5d | 99 | } |
group-onsemi | 0:098463de4c5d | 100 | #endif |
group-onsemi | 0:098463de4c5d | 101 | |
group-onsemi | 0:098463de4c5d | 102 | #endif |