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
pinmap.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 "pinmap.h" 00017 #include "error.h" 00018 00019 #define LPC_IOCON0_BASE (LPC_IOCON_BASE) 00020 #define LPC_IOCON1_BASE (LPC_IOCON_BASE + 0x60) 00021 00022 void pin_function(PinName pin, int function) { 00023 if (pin == (uint32_t)NC) return; 00024 00025 uint32_t pin_number = (uint32_t)pin; 00026 00027 __IO uint32_t *reg = (pin_number < 32) ? 00028 (__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) : 00029 (__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32)); 00030 00031 // pin function bits: [2:0] -> 111 = (0x7) 00032 *reg = (*reg & ~0x7) | (function & 0x7); 00033 } 00034 00035 void pin_mode(PinName pin, PinMode mode) { 00036 if (pin == (uint32_t)NC) { return; } 00037 00038 uint32_t pin_number = (uint32_t)pin; 00039 uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2; 00040 00041 __IO uint32_t *reg = (pin_number < 32) ? 00042 (__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) : 00043 (__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32)); 00044 uint32_t tmp = *reg; 00045 00046 // pin mode bits: [4:3] -> 11000 = (0x3 << 3) 00047 tmp &= ~(0x3 << 3); 00048 tmp |= (mode & 0x3) << 3; 00049 00050 // drain 00051 tmp &= ~(0x1 << 10); 00052 tmp |= drain << 10; 00053 00054 *reg = tmp; 00055 }
Generated on Tue Jul 12 2022 13:47:01 by 1.7.2