mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

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

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/

Initial version of drivers for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 /* mbed Microcontroller Library
mbed_official 579:53297373a894 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 579:53297373a894 3 *
mbed_official 579:53297373a894 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 579:53297373a894 5 * you may not use this file except in compliance with the License.
mbed_official 579:53297373a894 6 * You may obtain a copy of the License at
mbed_official 579:53297373a894 7 *
mbed_official 579:53297373a894 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 579:53297373a894 9 *
mbed_official 579:53297373a894 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 579:53297373a894 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 579:53297373a894 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 579:53297373a894 13 * See the License for the specific language governing permissions and
mbed_official 579:53297373a894 14 * limitations under the License.
mbed_official 579:53297373a894 15 */
mbed_official 579:53297373a894 16 #include "mbed_assert.h"
mbed_official 579:53297373a894 17 #include "PinNames.h"
mbed_official 579:53297373a894 18 #include "gpio_object.h"
mbed_official 579:53297373a894 19 #include "gpio_api.h"
mbed_official 579:53297373a894 20 #include "compiler.h"
mbed_official 579:53297373a894 21 #include "port.h"
mbed_official 579:53297373a894 22
mbed_official 579:53297373a894 23 uint32_t gpio_set(PinName pin)
mbed_official 579:53297373a894 24 {
mbed_official 579:53297373a894 25 MBED_ASSERT(pin != (PinName)NC);
mbed_official 579:53297373a894 26 return (1UL << (pin % 32));
mbed_official 579:53297373a894 27 }
mbed_official 579:53297373a894 28
mbed_official 579:53297373a894 29 void gpio_init(gpio_t *obj, PinName pin)
mbed_official 579:53297373a894 30 {
mbed_official 579:53297373a894 31 MBED_ASSERT(pin != (PinName)NC);
mbed_official 579:53297373a894 32 struct port_config pin_conf;
mbed_official 579:53297373a894 33 PortGroup *const port_base = (PortGroup*)port_get_group_from_gpio_pin(pin);
mbed_official 579:53297373a894 34
mbed_official 579:53297373a894 35 obj->pin = pin;
mbed_official 579:53297373a894 36 if (pin == (PinName)NC)
mbed_official 579:53297373a894 37 return;
mbed_official 579:53297373a894 38
mbed_official 579:53297373a894 39 obj->mask = gpio_set(pin);
mbed_official 579:53297373a894 40 port_get_config_defaults(&pin_conf);
mbed_official 579:53297373a894 41 obj->powersave = pin_conf.powersave;
mbed_official 579:53297373a894 42 obj->direction = PORT_PIN_DIR_INPUT;
mbed_official 579:53297373a894 43 obj->mode = PORT_PIN_PULL_UP;
mbed_official 579:53297373a894 44 port_pin_set_config(pin, &pin_conf);
mbed_official 579:53297373a894 45
mbed_official 579:53297373a894 46 obj->OUTCLR = &port_base->OUTCLR.reg;
mbed_official 579:53297373a894 47 obj->OUTSET = &port_base->OUTSET.reg;
mbed_official 579:53297373a894 48 obj->IN = &port_base->IN.reg;
mbed_official 579:53297373a894 49 obj->OUT = &port_base->OUT.reg;
mbed_official 579:53297373a894 50 }
mbed_official 579:53297373a894 51
mbed_official 579:53297373a894 52 void gpio_mode(gpio_t *obj, PinMode mode)
mbed_official 579:53297373a894 53 {
mbed_official 579:53297373a894 54 MBED_ASSERT(obj->pin != (PinName)NC);
mbed_official 579:53297373a894 55 struct port_config pin_conf;
mbed_official 579:53297373a894 56
mbed_official 579:53297373a894 57 obj->mode = mode;
mbed_official 579:53297373a894 58 pin_conf.direction = obj->direction;
mbed_official 579:53297373a894 59 pin_conf.powersave = obj->powersave;
mbed_official 579:53297373a894 60 switch (mode) {
mbed_official 579:53297373a894 61 case PullNone :
mbed_official 579:53297373a894 62 pin_conf.input_pull = PORT_PIN_PULL_NONE;
mbed_official 579:53297373a894 63 break;
mbed_official 579:53297373a894 64 case PullUp:
mbed_official 579:53297373a894 65 pin_conf.input_pull = PORT_PIN_PULL_UP;
mbed_official 579:53297373a894 66 break;
mbed_official 579:53297373a894 67 case PullDown:
mbed_official 579:53297373a894 68 pin_conf.input_pull = PORT_PIN_PULL_DOWN;
mbed_official 579:53297373a894 69 break;
mbed_official 579:53297373a894 70 }
mbed_official 579:53297373a894 71 port_pin_set_config(obj->pin, &pin_conf);
mbed_official 579:53297373a894 72 }
mbed_official 579:53297373a894 73
mbed_official 579:53297373a894 74 void gpio_dir(gpio_t *obj, PinDirection direction)
mbed_official 579:53297373a894 75 {
mbed_official 579:53297373a894 76 MBED_ASSERT(obj->pin != (PinName)NC);
mbed_official 579:53297373a894 77 struct port_config pin_conf;
mbed_official 579:53297373a894 78
mbed_official 579:53297373a894 79 obj->direction = direction;
mbed_official 579:53297373a894 80 pin_conf.input_pull = obj->mode;
mbed_official 579:53297373a894 81 pin_conf.powersave = obj->powersave;
mbed_official 579:53297373a894 82 switch (direction) {
mbed_official 579:53297373a894 83 case PIN_INPUT :
mbed_official 579:53297373a894 84 pin_conf.direction = PORT_PIN_DIR_INPUT;
mbed_official 579:53297373a894 85 break;
mbed_official 579:53297373a894 86 case PIN_OUTPUT:
mbed_official 579:53297373a894 87 pin_conf.direction = PORT_PIN_DIR_OUTPUT;
mbed_official 579:53297373a894 88 break;
mbed_official 579:53297373a894 89 case PIN_INPUT_OUTPUT:
mbed_official 579:53297373a894 90 pin_conf.direction = PORT_PIN_DIR_OUTPUT_WTH_READBACK;
mbed_official 579:53297373a894 91 break;
mbed_official 579:53297373a894 92 }
mbed_official 579:53297373a894 93 port_pin_set_config(obj->pin, &pin_conf);
mbed_official 579:53297373a894 94 }