Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
targets/hal/TARGET_Freescale/TARGET_KLXX/gpio_api.c@636:a11c0372f0ba, 2015-09-30 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Sep 30 17:00:09 2015 +0100
- Revision:
- 636:a11c0372f0ba
- Parent:
- 363:12a245e5c745
Synchronized with git revision d29c98dae61be0946ddf3a3c641c7726056f9452
Full URL: https://github.com/mbedmicro/mbed/commit/d29c98dae61be0946ddf3a3c641c7726056f9452/
Added support for SAMW25
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_official | 82:0b31dbcd4769 | 1 | /* mbed Microcontroller Library |
| mbed_official | 82:0b31dbcd4769 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| mbed_official | 82:0b31dbcd4769 | 3 | * |
| mbed_official | 82:0b31dbcd4769 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| mbed_official | 82:0b31dbcd4769 | 5 | * you may not use this file except in compliance with the License. |
| mbed_official | 82:0b31dbcd4769 | 6 | * You may obtain a copy of the License at |
| mbed_official | 82:0b31dbcd4769 | 7 | * |
| mbed_official | 82:0b31dbcd4769 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| mbed_official | 82:0b31dbcd4769 | 9 | * |
| mbed_official | 82:0b31dbcd4769 | 10 | * Unless required by applicable law or agreed to in writing, software |
| mbed_official | 82:0b31dbcd4769 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| mbed_official | 82:0b31dbcd4769 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| mbed_official | 82:0b31dbcd4769 | 13 | * See the License for the specific language governing permissions and |
| mbed_official | 82:0b31dbcd4769 | 14 | * limitations under the License. |
| mbed_official | 82:0b31dbcd4769 | 15 | */ |
| mbed_official | 227:7bd0639b8911 | 16 | #include "mbed_assert.h" |
| mbed_official | 82:0b31dbcd4769 | 17 | #include "gpio_api.h" |
| mbed_official | 82:0b31dbcd4769 | 18 | #include "pinmap.h" |
| mbed_official | 82:0b31dbcd4769 | 19 | |
| mbed_official | 82:0b31dbcd4769 | 20 | uint32_t gpio_set(PinName pin) { |
| mbed_official | 227:7bd0639b8911 | 21 | MBED_ASSERT(pin != (PinName)NC); |
| mbed_official | 82:0b31dbcd4769 | 22 | pin_function(pin, 1); |
| mbed_official | 82:0b31dbcd4769 | 23 | return 1 << ((pin & 0x7F) >> 2); |
| mbed_official | 82:0b31dbcd4769 | 24 | } |
| mbed_official | 82:0b31dbcd4769 | 25 | |
| mbed_official | 113:65a335a675de | 26 | void gpio_init(gpio_t *obj, PinName pin) { |
| mbed_official | 227:7bd0639b8911 | 27 | obj->pin = pin; |
| mbed_official | 227:7bd0639b8911 | 28 | if (pin == (PinName)NC) |
| mbed_official | 227:7bd0639b8911 | 29 | return; |
| mbed_official | 82:0b31dbcd4769 | 30 | |
| mbed_official | 82:0b31dbcd4769 | 31 | obj->mask = gpio_set(pin); |
| mbed_official | 82:0b31dbcd4769 | 32 | |
| mbed_official | 82:0b31dbcd4769 | 33 | unsigned int port = (unsigned int)pin >> PORT_SHIFT; |
| mbed_official | 82:0b31dbcd4769 | 34 | |
| mbed_official | 363:12a245e5c745 | 35 | #if defined(TARGET_KL43Z) |
| mbed_official | 363:12a245e5c745 | 36 | GPIO_Type *reg = (GPIO_Type *)(GPIOA_BASE + port * 0x40); |
| mbed_official | 363:12a245e5c745 | 37 | #else |
| mbed_official | 82:0b31dbcd4769 | 38 | FGPIO_Type *reg = (FGPIO_Type *)(FPTA_BASE + port * 0x40); |
| mbed_official | 363:12a245e5c745 | 39 | #endif |
| mbed_official | 82:0b31dbcd4769 | 40 | obj->reg_set = ®->PSOR; |
| mbed_official | 82:0b31dbcd4769 | 41 | obj->reg_clr = ®->PCOR; |
| mbed_official | 82:0b31dbcd4769 | 42 | obj->reg_in = ®->PDIR; |
| mbed_official | 82:0b31dbcd4769 | 43 | obj->reg_dir = ®->PDDR; |
| mbed_official | 82:0b31dbcd4769 | 44 | } |
| mbed_official | 82:0b31dbcd4769 | 45 | |
| mbed_official | 82:0b31dbcd4769 | 46 | void gpio_mode(gpio_t *obj, PinMode mode) { |
| mbed_official | 82:0b31dbcd4769 | 47 | pin_mode(obj->pin, mode); |
| mbed_official | 82:0b31dbcd4769 | 48 | } |
| mbed_official | 82:0b31dbcd4769 | 49 | |
| mbed_official | 82:0b31dbcd4769 | 50 | void gpio_dir(gpio_t *obj, PinDirection direction) { |
| mbed_official | 227:7bd0639b8911 | 51 | MBED_ASSERT(obj->pin != (PinName)NC); |
| mbed_official | 82:0b31dbcd4769 | 52 | switch (direction) { |
| mbed_official | 227:7bd0639b8911 | 53 | case PIN_INPUT : |
| mbed_official | 227:7bd0639b8911 | 54 | *obj->reg_dir &= ~obj->mask; |
| mbed_official | 227:7bd0639b8911 | 55 | break; |
| mbed_official | 227:7bd0639b8911 | 56 | case PIN_OUTPUT: |
| mbed_official | 227:7bd0639b8911 | 57 | *obj->reg_dir |= obj->mask; |
| mbed_official | 227:7bd0639b8911 | 58 | break; |
| mbed_official | 82:0b31dbcd4769 | 59 | } |
| mbed_official | 82:0b31dbcd4769 | 60 | } |