mbed-os
Fork of mbed-os by
targets/TARGET_NXP/TARGET_LPC81X/pinmap.c@1:3deb71413561, 2017-07-20 (annotated)
- Committer:
- xuaner
- Date:
- Thu Jul 20 14:26:57 2017 +0000
- Revision:
- 1:3deb71413561
- Parent:
- 0:f269e3021894
mbed_os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* mbed Microcontroller Library |
elessair | 0:f269e3021894 | 2 | * Copyright (c) 2006-2013 ARM Limited |
elessair | 0:f269e3021894 | 3 | * |
elessair | 0:f269e3021894 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
elessair | 0:f269e3021894 | 5 | * you may not use this file except in compliance with the License. |
elessair | 0:f269e3021894 | 6 | * You may obtain a copy of the License at |
elessair | 0:f269e3021894 | 7 | * |
elessair | 0:f269e3021894 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
elessair | 0:f269e3021894 | 9 | * |
elessair | 0:f269e3021894 | 10 | * Unless required by applicable law or agreed to in writing, software |
elessair | 0:f269e3021894 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
elessair | 0:f269e3021894 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elessair | 0:f269e3021894 | 13 | * See the License for the specific language governing permissions and |
elessair | 0:f269e3021894 | 14 | * limitations under the License. |
elessair | 0:f269e3021894 | 15 | */ |
elessair | 0:f269e3021894 | 16 | #include "mbed_assert.h" |
elessair | 0:f269e3021894 | 17 | #include "pinmap.h" |
elessair | 0:f269e3021894 | 18 | #include "mbed_error.h" |
elessair | 0:f269e3021894 | 19 | |
elessair | 0:f269e3021894 | 20 | __IO uint32_t* IOCON_REGISTERS[18] = { |
elessair | 0:f269e3021894 | 21 | &LPC_IOCON->PIO0_0 , &LPC_IOCON->PIO0_1 , &LPC_IOCON->PIO0_2 , |
elessair | 0:f269e3021894 | 22 | &LPC_IOCON->PIO0_3 , &LPC_IOCON->PIO0_4 , &LPC_IOCON->PIO0_5 , |
elessair | 0:f269e3021894 | 23 | &LPC_IOCON->PIO0_6 , &LPC_IOCON->PIO0_7 , &LPC_IOCON->PIO0_8 , |
elessair | 0:f269e3021894 | 24 | &LPC_IOCON->PIO0_9 , &LPC_IOCON->PIO0_10, &LPC_IOCON->PIO0_11, |
elessair | 0:f269e3021894 | 25 | &LPC_IOCON->PIO0_12, &LPC_IOCON->PIO0_13, &LPC_IOCON->PIO0_14, |
elessair | 0:f269e3021894 | 26 | &LPC_IOCON->PIO0_15, &LPC_IOCON->PIO0_16, &LPC_IOCON->PIO0_17, |
elessair | 0:f269e3021894 | 27 | }; |
elessair | 0:f269e3021894 | 28 | |
elessair | 0:f269e3021894 | 29 | void pin_function(PinName pin, int function) { |
elessair | 0:f269e3021894 | 30 | if (function == 0) { |
elessair | 0:f269e3021894 | 31 | // Disable initial fixed function for P0_2, P0_3 and P0_5 |
elessair | 0:f269e3021894 | 32 | uint32_t enable = 0; |
elessair | 0:f269e3021894 | 33 | if (pin == P0_2) |
elessair | 0:f269e3021894 | 34 | enable = 1 << 3; |
elessair | 0:f269e3021894 | 35 | else if (pin == P0_3) |
elessair | 0:f269e3021894 | 36 | enable = 1 << 2; |
elessair | 0:f269e3021894 | 37 | else if (pin == P0_5) |
elessair | 0:f269e3021894 | 38 | enable = 1 << 6; |
elessair | 0:f269e3021894 | 39 | LPC_SWM->PINENABLE0 |= enable; |
elessair | 0:f269e3021894 | 40 | } |
elessair | 0:f269e3021894 | 41 | } |
elessair | 0:f269e3021894 | 42 | |
elessair | 0:f269e3021894 | 43 | void pin_mode(PinName pin, PinMode mode) { |
elessair | 0:f269e3021894 | 44 | MBED_ASSERT(pin != (PinName)NC); |
elessair | 0:f269e3021894 | 45 | |
elessair | 0:f269e3021894 | 46 | if ((pin == 10) || (pin == 11)) { |
elessair | 0:f269e3021894 | 47 | // True open-drain pins can be configured for different I2C-bus speeds |
elessair | 0:f269e3021894 | 48 | return; |
elessair | 0:f269e3021894 | 49 | } |
elessair | 0:f269e3021894 | 50 | |
elessair | 0:f269e3021894 | 51 | __IO uint32_t *reg = IOCON_REGISTERS[pin]; |
elessair | 0:f269e3021894 | 52 | |
elessair | 0:f269e3021894 | 53 | if (mode == OpenDrain) { |
elessair | 0:f269e3021894 | 54 | *reg |= (1 << 10); |
elessair | 0:f269e3021894 | 55 | } else { |
elessair | 0:f269e3021894 | 56 | uint32_t tmp = *reg; |
elessair | 0:f269e3021894 | 57 | tmp &= ~(0x3 << 3); |
elessair | 0:f269e3021894 | 58 | tmp |= (mode & 0x3) << 3; |
elessair | 0:f269e3021894 | 59 | *reg = tmp; |
elessair | 0:f269e3021894 | 60 | } |
elessair | 0:f269e3021894 | 61 | } |