fix for mbed lib issue 3 (i2c problem) see also https://mbed.org/users/mbed_official/code/mbed/issues/3 affected implementations: LPC812, LPC11U24, LPC1768, LPC2368, LPC4088

Fork of mbed-src by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers port_api.c Source File

port_api.c

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "port_api.h"
00017 #include "pinmap.h"
00018 #include "gpio_api.h"
00019 
00020 PinName port_pin(PortName port, int pin_n) {
00021     return (PinName)((port << PORT_SHIFT) | pin_n);
00022 }
00023 
00024 void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
00025     obj->port = port;
00026     obj->mask = mask;
00027     
00028     LPC_GPIO->MASK[port] = ~mask;
00029     
00030     obj->reg_mpin = &LPC_GPIO->MPIN[port];
00031     obj->reg_dir = &LPC_GPIO->DIR[port];
00032     
00033     uint32_t i;
00034     // The function is set per pin: reuse gpio logic
00035     for (i=0; i<32; i++) {
00036         if (obj->mask & (1<<i)) {
00037             gpio_set(port_pin(obj->port, i));
00038         }
00039     }
00040     
00041     port_dir(obj, dir);
00042 }
00043 
00044 void port_mode(port_t *obj, PinMode mode) {
00045     uint32_t i;
00046     // The mode is set per pin: reuse pinmap logic
00047     for (i=0; i<32; i++) {
00048         if (obj->mask & (1<<i)) {
00049             pin_mode(port_pin(obj->port, i), mode);
00050         }
00051     }
00052 }
00053 
00054 void port_dir(port_t *obj, PinDirection dir) {
00055     switch (dir) {
00056         case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
00057         case PIN_OUTPUT: *obj->reg_dir |=  obj->mask; break;
00058     }
00059 }
00060 
00061 void port_write(port_t *obj, int value) {
00062     *obj->reg_mpin = value;
00063 }
00064 
00065 int port_read(port_t *obj) {
00066     return (*obj->reg_mpin);
00067 }