mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Jul 17 09:15:10 2015 +0100
Revision:
592:a274ee790e56
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6

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

More API implementation for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 592:a274ee790e56 1 /* mbed Microcontroller Library
mbed_official 592:a274ee790e56 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 592:a274ee790e56 3 *
mbed_official 592:a274ee790e56 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 592:a274ee790e56 5 * you may not use this file except in compliance with the License.
mbed_official 592:a274ee790e56 6 * You may obtain a copy of the License at
mbed_official 592:a274ee790e56 7 *
mbed_official 592:a274ee790e56 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 592:a274ee790e56 9 *
mbed_official 592:a274ee790e56 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 592:a274ee790e56 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 592:a274ee790e56 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 592:a274ee790e56 13 * See the License for the specific language governing permissions and
mbed_official 592:a274ee790e56 14 * limitations under the License.
mbed_official 592:a274ee790e56 15 */
mbed_official 592:a274ee790e56 16 #include <stddef.h>
mbed_official 592:a274ee790e56 17 #include "us_ticker_api.h"
mbed_official 592:a274ee790e56 18 #include "cmsis.h"
mbed_official 592:a274ee790e56 19 #include "mbed_assert.h"
mbed_official 592:a274ee790e56 20 #include "ins_gclk.h"
mbed_official 592:a274ee790e56 21 #include "compiler.h"
mbed_official 592:a274ee790e56 22 #include "system.h"
mbed_official 592:a274ee790e56 23
mbed_official 592:a274ee790e56 24 #include "pinmux.h"
mbed_official 592:a274ee790e56 25 #include "pinmap.h"
mbed_official 592:a274ee790e56 26
mbed_official 592:a274ee790e56 27 extern uint8_t g_sys_init;
mbed_official 592:a274ee790e56 28
mbed_official 592:a274ee790e56 29
mbed_official 592:a274ee790e56 30 static inline void pinmux_get_current_config(PinName pin, struct system_pinmux_config *const config)
mbed_official 592:a274ee790e56 31 {
mbed_official 592:a274ee790e56 32 MBED_ASSERT(pin != (PinName)NC);
mbed_official 592:a274ee790e56 33 uint32_t pin_index = pin % 32;
mbed_official 592:a274ee790e56 34 uint32_t pin_mask = (uint32_t)(1UL << pin_index);
mbed_official 592:a274ee790e56 35
mbed_official 592:a274ee790e56 36 PortGroup *const port = system_pinmux_get_group_from_gpio_pin(pin);
mbed_official 592:a274ee790e56 37 MBED_ASSERT(port);
mbed_official 592:a274ee790e56 38
mbed_official 592:a274ee790e56 39 config->mux_position = system_pinmux_pin_get_mux_position(pin);
mbed_official 592:a274ee790e56 40
mbed_official 592:a274ee790e56 41 if (port->PINCFG[pin_index].reg & PORT_PINCFG_INEN) {
mbed_official 592:a274ee790e56 42 if (port->DIR.reg & pin_mask) {
mbed_official 592:a274ee790e56 43 config->direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK;
mbed_official 592:a274ee790e56 44 config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
mbed_official 592:a274ee790e56 45 } else {
mbed_official 592:a274ee790e56 46 config->direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
mbed_official 592:a274ee790e56 47 if (port->PINCFG[pin_index].reg & PORT_PINCFG_PULLEN) {
mbed_official 592:a274ee790e56 48 if (port->OUT.reg & pin_mask) {
mbed_official 592:a274ee790e56 49 config->input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
mbed_official 592:a274ee790e56 50 } else {
mbed_official 592:a274ee790e56 51 config->input_pull = SYSTEM_PINMUX_PIN_PULL_DOWN;
mbed_official 592:a274ee790e56 52 }
mbed_official 592:a274ee790e56 53 } else {
mbed_official 592:a274ee790e56 54 config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
mbed_official 592:a274ee790e56 55 }
mbed_official 592:a274ee790e56 56 }
mbed_official 592:a274ee790e56 57 } else {
mbed_official 592:a274ee790e56 58 config->input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
mbed_official 592:a274ee790e56 59 config->direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
mbed_official 592:a274ee790e56 60 }
mbed_official 592:a274ee790e56 61
mbed_official 592:a274ee790e56 62 /* Not relevant for now */
mbed_official 592:a274ee790e56 63 config->powersave = false;
mbed_official 592:a274ee790e56 64 }
mbed_official 592:a274ee790e56 65
mbed_official 592:a274ee790e56 66 /** Change the MUX padding of input pin
mbed_official 592:a274ee790e56 67 *
mbed_official 592:a274ee790e56 68 * Configure the pin for specific module
mbed_official 592:a274ee790e56 69 * @param[in] pin Pin name whose MUX padding is to be changed
mbed_official 592:a274ee790e56 70 * @param[in] function The MUX mode to be selected
mbed_official 592:a274ee790e56 71 * @return void
mbed_official 592:a274ee790e56 72 */
mbed_official 592:a274ee790e56 73 void pin_function(PinName pin, int function)
mbed_official 592:a274ee790e56 74 {
mbed_official 592:a274ee790e56 75 MBED_ASSERT(pin != (PinName)NC);
mbed_official 592:a274ee790e56 76
mbed_official 592:a274ee790e56 77 struct system_pinmux_config pin_conf;
mbed_official 592:a274ee790e56 78
mbed_official 592:a274ee790e56 79 pinmux_get_current_config(pin, &pin_conf);
mbed_official 592:a274ee790e56 80 pin_conf.mux_position = function;
mbed_official 592:a274ee790e56 81
mbed_official 592:a274ee790e56 82 system_pinmux_pin_set_config(pin, &pin_conf);
mbed_official 592:a274ee790e56 83 }
mbed_official 592:a274ee790e56 84
mbed_official 592:a274ee790e56 85 /** Change the pin pull mode
mbed_official 592:a274ee790e56 86 *
mbed_official 592:a274ee790e56 87 * Configure the pin pull mode
mbed_official 592:a274ee790e56 88 * @param[in] pin Pin name whose MUX padding is to be changed
mbed_official 592:a274ee790e56 89 * @param[in] mode Pin pull mode to be set
mbed_official 592:a274ee790e56 90 * @return void
mbed_official 592:a274ee790e56 91 */
mbed_official 592:a274ee790e56 92 void pin_mode(PinName pin, PinMode mode)
mbed_official 592:a274ee790e56 93 {
mbed_official 592:a274ee790e56 94 MBED_ASSERT(pin != (PinName)NC);
mbed_official 592:a274ee790e56 95
mbed_official 592:a274ee790e56 96 struct system_pinmux_config pin_conf;
mbed_official 592:a274ee790e56 97
mbed_official 592:a274ee790e56 98 pinmux_get_current_config(pin, &pin_conf);
mbed_official 592:a274ee790e56 99 if (mode == PullUp) {
mbed_official 592:a274ee790e56 100 pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
mbed_official 592:a274ee790e56 101 } else if (mode == PullDown) {
mbed_official 592:a274ee790e56 102 pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_DOWN;
mbed_official 592:a274ee790e56 103 } else {
mbed_official 592:a274ee790e56 104 pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
mbed_official 592:a274ee790e56 105 }
mbed_official 592:a274ee790e56 106
mbed_official 592:a274ee790e56 107 system_pinmux_pin_set_config(pin, &pin_conf);
mbed_official 592:a274ee790e56 108 }