zain aftab / mbed-src3

Dependents:   RPC_Serial_V_mac

Committer:
mbed_official
Date:
Wed Jul 23 21:15:06 2014 +0100
Revision:
265:9632ea190e16
Synchronized with git revision 7a5896cba254ab45829b43f6cef5563706ebba2b

Full URL: https://github.com/mbedmicro/mbed/commit/7a5896cba254ab45829b43f6cef5563706ebba2b/

[MTS_GAMBIT] Add new target support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 265:9632ea190e16 1 /* mbed Microcontroller Library
mbed_official 265:9632ea190e16 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 265:9632ea190e16 3 *
mbed_official 265:9632ea190e16 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 265:9632ea190e16 5 * you may not use this file except in compliance with the License.
mbed_official 265:9632ea190e16 6 * You may obtain a copy of the License at
mbed_official 265:9632ea190e16 7 *
mbed_official 265:9632ea190e16 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 265:9632ea190e16 9 *
mbed_official 265:9632ea190e16 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 265:9632ea190e16 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 265:9632ea190e16 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 265:9632ea190e16 13 * See the License for the specific language governing permissions and
mbed_official 265:9632ea190e16 14 * limitations under the License.
mbed_official 265:9632ea190e16 15 */
mbed_official 265:9632ea190e16 16 #include "port_api.h"
mbed_official 265:9632ea190e16 17 #include "pinmap.h"
mbed_official 265:9632ea190e16 18 #include "gpio_api.h"
mbed_official 265:9632ea190e16 19
mbed_official 265:9632ea190e16 20 PinName port_pin(PortName port, int pin_n) {
mbed_official 265:9632ea190e16 21 return (PinName)((port << GPIO_PORT_SHIFT) | pin_n);
mbed_official 265:9632ea190e16 22 }
mbed_official 265:9632ea190e16 23
mbed_official 265:9632ea190e16 24 void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
mbed_official 265:9632ea190e16 25 obj->port = port;
mbed_official 265:9632ea190e16 26 obj->mask = mask;
mbed_official 265:9632ea190e16 27
mbed_official 265:9632ea190e16 28 // The function is set per pin: reuse gpio logic
mbed_official 265:9632ea190e16 29 for (uint32_t i = 0; i < 32; i++) {
mbed_official 265:9632ea190e16 30 if (obj->mask & (1 << i)) {
mbed_official 265:9632ea190e16 31 gpio_set(port_pin(obj->port, i));
mbed_official 265:9632ea190e16 32 }
mbed_official 265:9632ea190e16 33 }
mbed_official 265:9632ea190e16 34
mbed_official 265:9632ea190e16 35 port_dir(obj, dir);
mbed_official 265:9632ea190e16 36 }
mbed_official 265:9632ea190e16 37
mbed_official 265:9632ea190e16 38 void port_mode(port_t *obj, PinMode mode) {
mbed_official 265:9632ea190e16 39
mbed_official 265:9632ea190e16 40 // The mode is set per pin: reuse pinmap logic
mbed_official 265:9632ea190e16 41 for (uint32_t i = 0; i < 32; i++) {
mbed_official 265:9632ea190e16 42 if (obj->mask & (1 << i)) {
mbed_official 265:9632ea190e16 43 pin_mode(port_pin(obj->port, i), mode);
mbed_official 265:9632ea190e16 44 }
mbed_official 265:9632ea190e16 45 }
mbed_official 265:9632ea190e16 46 }
mbed_official 265:9632ea190e16 47
mbed_official 265:9632ea190e16 48 void port_dir(port_t *obj, PinDirection dir) {
mbed_official 265:9632ea190e16 49 uint32_t direction = gpio_hal_get_port_direction((uint32_t)obj->port);
mbed_official 265:9632ea190e16 50 switch (dir) {
mbed_official 265:9632ea190e16 51 case PIN_INPUT :
mbed_official 265:9632ea190e16 52 direction &= ~obj->mask;
mbed_official 265:9632ea190e16 53 gpio_hal_set_port_direction((uint32_t)obj->port, direction);
mbed_official 265:9632ea190e16 54 break;
mbed_official 265:9632ea190e16 55 case PIN_OUTPUT:
mbed_official 265:9632ea190e16 56 direction |= obj->mask;
mbed_official 265:9632ea190e16 57 gpio_hal_set_port_direction((uint32_t)obj->port, direction);
mbed_official 265:9632ea190e16 58 break;
mbed_official 265:9632ea190e16 59 }
mbed_official 265:9632ea190e16 60 }
mbed_official 265:9632ea190e16 61
mbed_official 265:9632ea190e16 62 void port_write(port_t *obj, int value) {
mbed_official 265:9632ea190e16 63 uint32_t input = gpio_hal_read_port_input((uint32_t)obj->port) & ~obj->mask;
mbed_official 265:9632ea190e16 64 gpio_hal_write_port_output((uint32_t)obj->port, input | (uint32_t)(value & obj->mask));
mbed_official 265:9632ea190e16 65 }
mbed_official 265:9632ea190e16 66
mbed_official 265:9632ea190e16 67 int port_read(port_t *obj) {
mbed_official 265:9632ea190e16 68 return (int)(gpio_hal_read_port_input((uint32_t)obj->port) & obj->mask);
mbed_official 265:9632ea190e16 69 }