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