Amit Gandhi / sensen_copy_2

Fork of mbed-dev by mbed official

Committer:
bogdanm
Date:
Thu Oct 01 15:25:22 2015 +0300
Revision:
0:9b334a45a8ff
Child:
144:ef7eb2e8f9f7
Initial commit on mbed-dev

Replaces mbed-src (now inactive)

Who changed what in which revision?

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