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:
Fri Sep 15 14:46:57 2017 +0100
Revision:
151:675da3299148
Parent:
93:e188a91d3eaa
Release 151 of the mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 87:6213f644d804 1 /* mbed Microcontroller Library
bogdanm 87:6213f644d804 2 * Copyright (c) 2006-2013 ARM Limited
bogdanm 87:6213f644d804 3 *
bogdanm 87:6213f644d804 4 * Licensed under the Apache License, Version 2.0 (the "License");
bogdanm 87:6213f644d804 5 * you may not use this file except in compliance with the License.
bogdanm 87:6213f644d804 6 * You may obtain a copy of the License at
bogdanm 87:6213f644d804 7 *
bogdanm 87:6213f644d804 8 * http://www.apache.org/licenses/LICENSE-2.0
bogdanm 87:6213f644d804 9 *
bogdanm 87:6213f644d804 10 * Unless required by applicable law or agreed to in writing, software
bogdanm 87:6213f644d804 11 * distributed under the License is distributed on an "AS IS" BASIS,
bogdanm 87:6213f644d804 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bogdanm 87:6213f644d804 13 * See the License for the specific language governing permissions and
bogdanm 87:6213f644d804 14 * limitations under the License.
bogdanm 87:6213f644d804 15 */
bogdanm 87:6213f644d804 16 #ifndef MBED_GPIO_OBJECT_H
bogdanm 87:6213f644d804 17 #define MBED_GPIO_OBJECT_H
bogdanm 87:6213f644d804 18
bogdanm 87:6213f644d804 19 #include "mbed_assert.h"
bogdanm 87:6213f644d804 20
bogdanm 87:6213f644d804 21 #ifdef __cplusplus
bogdanm 87:6213f644d804 22 extern "C" {
bogdanm 87:6213f644d804 23 #endif
bogdanm 87:6213f644d804 24
bogdanm 87:6213f644d804 25 typedef struct {
bogdanm 87:6213f644d804 26 PinName pin;
bogdanm 87:6213f644d804 27 uint32_t mask;
bogdanm 87:6213f644d804 28
bogdanm 87:6213f644d804 29 __IO uint32_t *reg_dir;
bogdanm 87:6213f644d804 30 __IO uint32_t *reg_set;
bogdanm 87:6213f644d804 31 __IO uint32_t *reg_clr;
bogdanm 87:6213f644d804 32 __I uint32_t *reg_in;
bogdanm 87:6213f644d804 33 } gpio_t;
bogdanm 87:6213f644d804 34
bogdanm 87:6213f644d804 35 static inline void gpio_write(gpio_t *obj, int value) {
bogdanm 87:6213f644d804 36 MBED_ASSERT(obj->pin != (PinName)NC);
bogdanm 87:6213f644d804 37 if (value)
bogdanm 87:6213f644d804 38 *obj->reg_set = obj->mask;
bogdanm 87:6213f644d804 39 else
bogdanm 87:6213f644d804 40 *obj->reg_clr = obj->mask;
bogdanm 87:6213f644d804 41 }
bogdanm 87:6213f644d804 42
bogdanm 87:6213f644d804 43 static inline int gpio_read(gpio_t *obj) {
bogdanm 87:6213f644d804 44 MBED_ASSERT(obj->pin != (PinName)NC);
bogdanm 87:6213f644d804 45 return ((*obj->reg_in & obj->mask) ? 1 : 0);
bogdanm 87:6213f644d804 46 }
bogdanm 87:6213f644d804 47
Kojto 93:e188a91d3eaa 48 static inline int gpio_is_connected(const gpio_t *obj) {
Kojto 93:e188a91d3eaa 49 return obj->pin != (PinName)NC;
Kojto 93:e188a91d3eaa 50 }
Kojto 93:e188a91d3eaa 51
bogdanm 87:6213f644d804 52 #ifdef __cplusplus
bogdanm 87:6213f644d804 53 }
bogdanm 87:6213f644d804 54 #endif
bogdanm 87:6213f644d804 55
bogdanm 87:6213f644d804 56 #endif