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
gpio_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 "gpio_api.h" 00017 #include "pinmap.h" 00018 00019 uint32_t gpio_set(PinName pin) { 00020 int f = ((pin == P0_11) || 00021 (pin == P0_12) || 00022 (pin == P0_13) || 00023 (pin == P0_14)) ? (1) : (0); 00024 00025 pin_function(pin, f); 00026 00027 return (1 << ((int)pin & 0x1F)); 00028 } 00029 00030 void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) { 00031 if(pin == NC) return; 00032 00033 obj->pin = pin; 00034 obj->mask = gpio_set(pin); 00035 00036 unsigned int port = (unsigned int)pin >> PORT_SHIFT; 00037 00038 obj->reg_set = &LPC_GPIO->SET[port]; 00039 obj->reg_clr = &LPC_GPIO->CLR[port]; 00040 obj->reg_in = &LPC_GPIO->PIN[port]; 00041 obj->reg_dir = &LPC_GPIO->DIR[port]; 00042 00043 gpio_dir(obj, direction); 00044 switch (direction) { 00045 case PIN_OUTPUT: pin_mode(pin, PullNone); break; 00046 case PIN_INPUT : pin_mode(pin, PullDown); break; 00047 } 00048 } 00049 00050 void gpio_mode(gpio_t *obj, PinMode mode) { 00051 pin_mode(obj->pin, mode); 00052 } 00053 00054 void gpio_dir(gpio_t *obj, PinDirection direction) { 00055 switch (direction) { 00056 case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break; 00057 case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; 00058 } 00059 }
Generated on Tue Jul 12 2022 13:47:01 by 1.7.2