Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-rpc by
parse_pins.cpp@1:6919289a5946, 2013-04-22 (annotated)
- Committer:
- emilmont
- Date:
- Mon Apr 22 17:50:11 2013 +0100
- Revision:
- 1:6919289a5946
- Child:
- 2:65228c367483
Update license
Add "parse_pins" function removed from the mbed library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:6919289a5946 | 1 | /* mbed Microcontroller Library |
emilmont | 1:6919289a5946 | 2 | * Copyright (c) 2006-2013 ARM Limited |
emilmont | 1:6919289a5946 | 3 | * |
emilmont | 1:6919289a5946 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
emilmont | 1:6919289a5946 | 5 | * you may not use this file except in compliance with the License. |
emilmont | 1:6919289a5946 | 6 | * You may obtain a copy of the License at |
emilmont | 1:6919289a5946 | 7 | * |
emilmont | 1:6919289a5946 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
emilmont | 1:6919289a5946 | 9 | * |
emilmont | 1:6919289a5946 | 10 | * Unless required by applicable law or agreed to in writing, software |
emilmont | 1:6919289a5946 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
emilmont | 1:6919289a5946 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
emilmont | 1:6919289a5946 | 13 | * See the License for the specific language governing permissions and |
emilmont | 1:6919289a5946 | 14 | * limitations under the License. |
emilmont | 1:6919289a5946 | 15 | */ |
emilmont | 1:6919289a5946 | 16 | #include "port_api.h" |
emilmont | 1:6919289a5946 | 17 | |
emilmont | 1:6919289a5946 | 18 | namespace mbed { |
emilmont | 1:6919289a5946 | 19 | |
emilmont | 1:6919289a5946 | 20 | PinName parse_pins(const char *str) { |
emilmont | 1:6919289a5946 | 21 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) |
emilmont | 1:6919289a5946 | 22 | static const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14 |
emilmont | 1:6919289a5946 | 23 | , p15, p16, p17, p18, p19, p20, p21, p22, p23 |
emilmont | 1:6919289a5946 | 24 | , p24, p25, p26, p27, p28, p29, p30}; |
emilmont | 1:6919289a5946 | 25 | #endif |
emilmont | 1:6919289a5946 | 26 | |
emilmont | 1:6919289a5946 | 27 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812) |
emilmont | 1:6919289a5946 | 28 | if (str[0] == 'P') { // Pn_n |
emilmont | 1:6919289a5946 | 29 | uint32_t port = str[1] - '0'; |
emilmont | 1:6919289a5946 | 30 | uint32_t pin = str[3] - '0'; // Pn_n |
emilmont | 1:6919289a5946 | 31 | uint32_t pin2 = str[4] - '0'; // Pn_nn |
emilmont | 1:6919289a5946 | 32 | if (pin2 <= 9) { |
emilmont | 1:6919289a5946 | 33 | pin = pin * 10 + pin2; |
emilmont | 1:6919289a5946 | 34 | } |
emilmont | 1:6919289a5946 | 35 | return port_pin((PortName)port, pin); |
emilmont | 1:6919289a5946 | 36 | |
emilmont | 1:6919289a5946 | 37 | #elif defined(LTARGET_KL25Z) |
emilmont | 1:6919289a5946 | 38 | if (str[0] == 'P' && str[1] == 'T') { // PTx_n |
emilmont | 1:6919289a5946 | 39 | uint32_t port = str[2] - 'A'; |
emilmont | 1:6919289a5946 | 40 | uint32_t pin = str[3] - '0'; // PTxn |
emilmont | 1:6919289a5946 | 41 | uint32_t pin2 = str[4] - '0'; // PTxnn |
emilmont | 1:6919289a5946 | 42 | |
emilmont | 1:6919289a5946 | 43 | if (pin2 <= 9) { |
emilmont | 1:6919289a5946 | 44 | pin = pin * 10 + pin2; |
emilmont | 1:6919289a5946 | 45 | } |
emilmont | 1:6919289a5946 | 46 | return port_pin((PortName)port, pin); |
emilmont | 1:6919289a5946 | 47 | #endif |
emilmont | 1:6919289a5946 | 48 | |
emilmont | 1:6919289a5946 | 49 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) |
emilmont | 1:6919289a5946 | 50 | } else if (str[0] == 'p') { // pn |
emilmont | 1:6919289a5946 | 51 | uint32_t pin = str[1] - '0'; // pn |
emilmont | 1:6919289a5946 | 52 | uint32_t pin2 = str[2] - '0'; // pnn |
emilmont | 1:6919289a5946 | 53 | if (pin2 <= 9) { |
emilmont | 1:6919289a5946 | 54 | pin = pin * 10 + pin2; |
emilmont | 1:6919289a5946 | 55 | } |
emilmont | 1:6919289a5946 | 56 | if (pin < 5 || pin > 30) { |
emilmont | 1:6919289a5946 | 57 | return NC; |
emilmont | 1:6919289a5946 | 58 | } |
emilmont | 1:6919289a5946 | 59 | return pin_names[pin - 5]; |
emilmont | 1:6919289a5946 | 60 | #endif |
emilmont | 1:6919289a5946 | 61 | |
emilmont | 1:6919289a5946 | 62 | } else if (str[0] == 'L') { // LEDn |
emilmont | 1:6919289a5946 | 63 | switch (str[3]) { |
emilmont | 1:6919289a5946 | 64 | case '1' : return LED1; |
emilmont | 1:6919289a5946 | 65 | case '2' : return LED2; |
emilmont | 1:6919289a5946 | 66 | case '3' : return LED3; |
emilmont | 1:6919289a5946 | 67 | case '4' : return LED4; |
emilmont | 1:6919289a5946 | 68 | } |
emilmont | 1:6919289a5946 | 69 | |
emilmont | 1:6919289a5946 | 70 | } else if (str[0] == 'U') { // USB?X |
emilmont | 1:6919289a5946 | 71 | switch (str[3]) { |
emilmont | 1:6919289a5946 | 72 | case 'T' : return USBTX; |
emilmont | 1:6919289a5946 | 73 | case 'R' : return USBRX; |
emilmont | 1:6919289a5946 | 74 | } |
emilmont | 1:6919289a5946 | 75 | } |
emilmont | 1:6919289a5946 | 76 | |
emilmont | 1:6919289a5946 | 77 | return NC; |
emilmont | 1:6919289a5946 | 78 | } |
emilmont | 1:6919289a5946 | 79 | |
emilmont | 1:6919289a5946 | 80 | } |