t
Fork of mbed-dev by
targets/TARGET_Atmel/TARGET_SAM_CortexM0P/gpio_api.c@178:c26431f84b0d, 2017-11-09 (annotated)
- Committer:
- amithy
- Date:
- Thu Nov 09 22:14:37 2017 +0000
- Revision:
- 178:c26431f84b0d
- Parent:
- 149:156823d33999
test export
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 "mbed_assert.h" |
mbed_official | 15:a81a8d6c1dfe | 17 | #include "PinNames.h" |
mbed_official | 15:a81a8d6c1dfe | 18 | #include "gpio_object.h" |
mbed_official | 15:a81a8d6c1dfe | 19 | #include "gpio_api.h" |
mbed_official | 15:a81a8d6c1dfe | 20 | #include "compiler.h" |
mbed_official | 15:a81a8d6c1dfe | 21 | #include "port.h" |
mbed_official | 15:a81a8d6c1dfe | 22 | |
mbed_official | 15:a81a8d6c1dfe | 23 | uint32_t gpio_set(PinName pin) |
mbed_official | 15:a81a8d6c1dfe | 24 | { |
mbed_official | 15:a81a8d6c1dfe | 25 | MBED_ASSERT(pin != (PinName)NC); |
mbed_official | 15:a81a8d6c1dfe | 26 | return (1UL << (pin % 32)); |
mbed_official | 15:a81a8d6c1dfe | 27 | } |
mbed_official | 15:a81a8d6c1dfe | 28 | |
mbed_official | 15:a81a8d6c1dfe | 29 | void gpio_init(gpio_t *obj, PinName pin) |
mbed_official | 15:a81a8d6c1dfe | 30 | { |
mbed_official | 15:a81a8d6c1dfe | 31 | MBED_ASSERT(pin != (PinName)NC); |
mbed_official | 15:a81a8d6c1dfe | 32 | struct port_config pin_conf; |
mbed_official | 15:a81a8d6c1dfe | 33 | PortGroup *const port_base = (PortGroup*)port_get_group_from_gpio_pin(pin); |
mbed_official | 15:a81a8d6c1dfe | 34 | |
mbed_official | 15:a81a8d6c1dfe | 35 | obj->pin = pin; |
mbed_official | 15:a81a8d6c1dfe | 36 | if (pin == (PinName)NC) |
mbed_official | 15:a81a8d6c1dfe | 37 | return; |
mbed_official | 15:a81a8d6c1dfe | 38 | |
mbed_official | 15:a81a8d6c1dfe | 39 | obj->mask = gpio_set(pin); |
mbed_official | 15:a81a8d6c1dfe | 40 | port_get_config_defaults(&pin_conf); |
mbed_official | 15:a81a8d6c1dfe | 41 | obj->powersave = pin_conf.powersave; |
mbed_official | 15:a81a8d6c1dfe | 42 | obj->direction = PORT_PIN_DIR_INPUT; |
mbed_official | 15:a81a8d6c1dfe | 43 | obj->mode = PORT_PIN_PULL_UP; |
mbed_official | 15:a81a8d6c1dfe | 44 | port_pin_set_config(pin, &pin_conf); |
mbed_official | 15:a81a8d6c1dfe | 45 | |
mbed_official | 15:a81a8d6c1dfe | 46 | obj->OUTCLR = &port_base->OUTCLR.reg; |
mbed_official | 15:a81a8d6c1dfe | 47 | obj->OUTSET = &port_base->OUTSET.reg; |
mbed_official | 15:a81a8d6c1dfe | 48 | obj->IN = &port_base->IN.reg; |
mbed_official | 15:a81a8d6c1dfe | 49 | obj->OUT = &port_base->OUT.reg; |
mbed_official | 15:a81a8d6c1dfe | 50 | } |
mbed_official | 15:a81a8d6c1dfe | 51 | |
mbed_official | 15:a81a8d6c1dfe | 52 | void gpio_mode(gpio_t *obj, PinMode mode) |
mbed_official | 15:a81a8d6c1dfe | 53 | { |
mbed_official | 15:a81a8d6c1dfe | 54 | MBED_ASSERT(obj->pin != (PinName)NC); |
mbed_official | 15:a81a8d6c1dfe | 55 | struct port_config pin_conf; |
mbed_official | 15:a81a8d6c1dfe | 56 | |
mbed_official | 15:a81a8d6c1dfe | 57 | obj->mode = mode; |
mbed_official | 64:41a834223ea3 | 58 | pin_conf.direction = (enum port_pin_dir)obj->direction; |
mbed_official | 15:a81a8d6c1dfe | 59 | pin_conf.powersave = obj->powersave; |
mbed_official | 15:a81a8d6c1dfe | 60 | switch (mode) { |
mbed_official | 15:a81a8d6c1dfe | 61 | case PullNone : |
mbed_official | 15:a81a8d6c1dfe | 62 | pin_conf.input_pull = PORT_PIN_PULL_NONE; |
mbed_official | 15:a81a8d6c1dfe | 63 | break; |
mbed_official | 15:a81a8d6c1dfe | 64 | case PullUp: |
mbed_official | 15:a81a8d6c1dfe | 65 | pin_conf.input_pull = PORT_PIN_PULL_UP; |
mbed_official | 15:a81a8d6c1dfe | 66 | break; |
mbed_official | 15:a81a8d6c1dfe | 67 | case PullDown: |
mbed_official | 15:a81a8d6c1dfe | 68 | pin_conf.input_pull = PORT_PIN_PULL_DOWN; |
mbed_official | 15:a81a8d6c1dfe | 69 | break; |
mbed_official | 15:a81a8d6c1dfe | 70 | } |
mbed_official | 15:a81a8d6c1dfe | 71 | port_pin_set_config(obj->pin, &pin_conf); |
mbed_official | 15:a81a8d6c1dfe | 72 | } |
mbed_official | 15:a81a8d6c1dfe | 73 | |
mbed_official | 15:a81a8d6c1dfe | 74 | void gpio_dir(gpio_t *obj, PinDirection direction) |
mbed_official | 15:a81a8d6c1dfe | 75 | { |
mbed_official | 15:a81a8d6c1dfe | 76 | MBED_ASSERT(obj->pin != (PinName)NC); |
mbed_official | 15:a81a8d6c1dfe | 77 | struct port_config pin_conf; |
mbed_official | 15:a81a8d6c1dfe | 78 | obj->direction = direction; |
mbed_official | 64:41a834223ea3 | 79 | pin_conf.input_pull = (enum port_pin_pull)obj->mode; |
mbed_official | 15:a81a8d6c1dfe | 80 | pin_conf.powersave = obj->powersave; |
mbed_official | 15:a81a8d6c1dfe | 81 | switch (direction) { |
mbed_official | 15:a81a8d6c1dfe | 82 | case PIN_INPUT : |
mbed_official | 15:a81a8d6c1dfe | 83 | pin_conf.direction = PORT_PIN_DIR_INPUT; |
mbed_official | 15:a81a8d6c1dfe | 84 | break; |
mbed_official | 15:a81a8d6c1dfe | 85 | case PIN_OUTPUT: |
mbed_official | 15:a81a8d6c1dfe | 86 | pin_conf.direction = PORT_PIN_DIR_OUTPUT; |
mbed_official | 15:a81a8d6c1dfe | 87 | break; |
mbed_official | 15:a81a8d6c1dfe | 88 | case PIN_INPUT_OUTPUT: |
mbed_official | 15:a81a8d6c1dfe | 89 | pin_conf.direction = PORT_PIN_DIR_OUTPUT_WTH_READBACK; |
mbed_official | 15:a81a8d6c1dfe | 90 | break; |
mbed_official | 15:a81a8d6c1dfe | 91 | } |
mbed_official | 15:a81a8d6c1dfe | 92 | port_pin_set_config(obj->pin, &pin_conf); |
mbed_official | 15:a81a8d6c1dfe | 93 | } |