The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_WIZWIKI_W7500P/TARGET_WIZNET/TARGET_W7500x/gpio_object.h@108:34e6b704fe68
mbed library. Release version 164

Who changed what in which revision?

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