TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Sat Feb 25 00:23:53 2017 +0000
Revision:
2:5acdd8565d02
Parent:
1:d0dfbce63a89
Ready to show

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elmot 1:d0dfbce63a89 1 /* mbed Microcontroller Library
elmot 1:d0dfbce63a89 2 *******************************************************************************
elmot 1:d0dfbce63a89 3 * Copyright (c) 2016, STMicroelectronics
elmot 1:d0dfbce63a89 4 * All rights reserved.
elmot 1:d0dfbce63a89 5 *
elmot 1:d0dfbce63a89 6 * Redistribution and use in source and binary forms, with or without
elmot 1:d0dfbce63a89 7 * modification, are permitted provided that the following conditions are met:
elmot 1:d0dfbce63a89 8 *
elmot 1:d0dfbce63a89 9 * 1. Redistributions of source code must retain the above copyright notice,
elmot 1:d0dfbce63a89 10 * this list of conditions and the following disclaimer.
elmot 1:d0dfbce63a89 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
elmot 1:d0dfbce63a89 12 * this list of conditions and the following disclaimer in the documentation
elmot 1:d0dfbce63a89 13 * and/or other materials provided with the distribution.
elmot 1:d0dfbce63a89 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
elmot 1:d0dfbce63a89 15 * may be used to endorse or promote products derived from this software
elmot 1:d0dfbce63a89 16 * without specific prior written permission.
elmot 1:d0dfbce63a89 17 *
elmot 1:d0dfbce63a89 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
elmot 1:d0dfbce63a89 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
elmot 1:d0dfbce63a89 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
elmot 1:d0dfbce63a89 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
elmot 1:d0dfbce63a89 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
elmot 1:d0dfbce63a89 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
elmot 1:d0dfbce63a89 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
elmot 1:d0dfbce63a89 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
elmot 1:d0dfbce63a89 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
elmot 1:d0dfbce63a89 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
elmot 1:d0dfbce63a89 28 *******************************************************************************
elmot 1:d0dfbce63a89 29 */
elmot 1:d0dfbce63a89 30 #ifndef MBED_GPIO_OBJECT_H
elmot 1:d0dfbce63a89 31 #define MBED_GPIO_OBJECT_H
elmot 1:d0dfbce63a89 32
elmot 1:d0dfbce63a89 33 #include "mbed_assert.h"
elmot 1:d0dfbce63a89 34 #include "cmsis.h"
elmot 1:d0dfbce63a89 35 #include "PortNames.h"
elmot 1:d0dfbce63a89 36 #include "PeripheralNames.h"
elmot 1:d0dfbce63a89 37 #include "PinNames.h"
elmot 1:d0dfbce63a89 38
elmot 1:d0dfbce63a89 39 #ifdef __cplusplus
elmot 1:d0dfbce63a89 40 extern "C" {
elmot 1:d0dfbce63a89 41 #endif
elmot 1:d0dfbce63a89 42
elmot 1:d0dfbce63a89 43 /*
elmot 1:d0dfbce63a89 44 * Note: reg_clr might actually be same as reg_set.
elmot 1:d0dfbce63a89 45 * Depends on family whether BRR is available on top of BSRR
elmot 1:d0dfbce63a89 46 * if BRR does not exist, family shall define GPIO_DOES_NOT_HAVE_BRR
elmot 1:d0dfbce63a89 47 */
elmot 1:d0dfbce63a89 48 typedef struct {
elmot 1:d0dfbce63a89 49 PinName pin;
elmot 1:d0dfbce63a89 50 uint32_t mask;
elmot 1:d0dfbce63a89 51 __IO uint32_t *reg_in;
elmot 1:d0dfbce63a89 52 __IO uint32_t *reg_set;
elmot 1:d0dfbce63a89 53 __IO uint32_t *reg_clr;
elmot 1:d0dfbce63a89 54 } gpio_t;
elmot 1:d0dfbce63a89 55
elmot 1:d0dfbce63a89 56 static inline void gpio_write(gpio_t *obj, int value)
elmot 1:d0dfbce63a89 57 {
elmot 1:d0dfbce63a89 58 MBED_ASSERT(obj->pin != (PinName)NC);
elmot 1:d0dfbce63a89 59 if (value) {
elmot 1:d0dfbce63a89 60 *obj->reg_set = obj->mask;
elmot 1:d0dfbce63a89 61 } else {
elmot 1:d0dfbce63a89 62 #ifdef GPIO_IP_WITHOUT_BRR
elmot 1:d0dfbce63a89 63 *obj->reg_clr = obj->mask << 16;
elmot 1:d0dfbce63a89 64 #else
elmot 1:d0dfbce63a89 65 *obj->reg_clr = obj->mask;
elmot 1:d0dfbce63a89 66 #endif
elmot 1:d0dfbce63a89 67 }
elmot 1:d0dfbce63a89 68 }
elmot 1:d0dfbce63a89 69
elmot 1:d0dfbce63a89 70 static inline int gpio_read(gpio_t *obj)
elmot 1:d0dfbce63a89 71 {
elmot 1:d0dfbce63a89 72 MBED_ASSERT(obj->pin != (PinName)NC);
elmot 1:d0dfbce63a89 73 return ((*obj->reg_in & obj->mask) ? 1 : 0);
elmot 1:d0dfbce63a89 74 }
elmot 1:d0dfbce63a89 75
elmot 1:d0dfbce63a89 76 static inline int gpio_is_connected(const gpio_t *obj)
elmot 1:d0dfbce63a89 77 {
elmot 1:d0dfbce63a89 78 return obj->pin != (PinName)NC;
elmot 1:d0dfbce63a89 79 }
elmot 1:d0dfbce63a89 80
elmot 1:d0dfbce63a89 81 #ifdef __cplusplus
elmot 1:d0dfbce63a89 82 }
elmot 1:d0dfbce63a89 83 #endif
elmot 1:d0dfbce63a89 84
elmot 1:d0dfbce63a89 85 #endif