mbed RPC for none LPC_xxx platform
Dependents: mbed_controller_demo
Fork of mbed-rpc by
parse_pins.cpp@9:75a49e903ad8, 2015-03-25 (annotated)
- Committer:
- hillkim7
- Date:
- Wed Mar 25 21:51:23 2015 +0000
- Revision:
- 9:75a49e903ad8
- Parent:
- 8:fece2d5e8d96
- Child:
- 10:6c26f367f70d
Add support for TARGET_ARCH_MAX.
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 | 4:9f88f495e549 | 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}; |
bogdanm | 5:4490a0d9cb2a | 25 | #elif defined(TARGET_LPC1114) |
bogdanm | 5:4490a0d9cb2a | 26 | static const PinName pin_names[] = {dp1, dp2, dp4, dp5, dp6, dp9, dp10, dp11 |
bogdanm | 5:4490a0d9cb2a | 27 | , dp13, dp14, dp15, dp16, dp17, dp18, dp23 |
bogdanm | 5:4490a0d9cb2a | 28 | , dp24, dp25, dp26, dp27, dp28}; |
mbed_official | 7:2a26fd6a2b36 | 29 | #elif defined(TARGET_LPC4088) |
mbed_official | 8:fece2d5e8d96 | 30 | static const PinName pin_names[] = {NC, NC, NC, NC, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14 |
emilmont | 4:9f88f495e549 | 31 | , p15, p16, p17, p18, p19, p20, NC, NC, p23 |
emilmont | 4:9f88f495e549 | 32 | , p24, p25, p26, p27, p28, p29, p30, p31, p32 |
mbed_official | 8:fece2d5e8d96 | 33 | , p33, p34, NC, NC, p37, p38, p39, NC, NC, NC, NC, NC, NC, NC}; |
mbed_official | 8:fece2d5e8d96 | 34 | #elif defined(TARGET_LPC4088_DM) |
mbed_official | 8:fece2d5e8d96 | 35 | static const PinName pin_names[] = {p1, p2, p3, p4, NC, NC, p7, p8, p9, p10, p11, p12, p13, p14 |
mbed_official | 8:fece2d5e8d96 | 36 | , p15, p16, p17, p18, p19, p20, p21, p22, p23 |
mbed_official | 8:fece2d5e8d96 | 37 | , p24, p25, p26, NC, NC, p29, p30, NC, NC |
mbed_official | 8:fece2d5e8d96 | 38 | , NC, NC, NC, NC, NC, NC, NC, NC, p41, p42, p43, p44, p45, p46}; |
hillkim7 | 9:75a49e903ad8 | 39 | #elif defined(TARGET_ARCH_MAX) |
hillkim7 | 9:75a49e903ad8 | 40 | // Arduino pinmap mapping |
hillkim7 | 9:75a49e903ad8 | 41 | static const PinName A_pin_names[] = {A0, A1, A2, A3, A4, A5, A6, A7}; |
hillkim7 | 9:75a49e903ad8 | 42 | static const PinName D_pin_names[] = {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15}; |
emilmont | 1:6919289a5946 | 43 | #endif |
emilmont | 1:6919289a5946 | 44 | |
mbed_official | 8:fece2d5e8d96 | 45 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812) || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC1114) |
emilmont | 1:6919289a5946 | 46 | if (str[0] == 'P') { // Pn_n |
emilmont | 1:6919289a5946 | 47 | uint32_t port = str[1] - '0'; |
emilmont | 1:6919289a5946 | 48 | uint32_t pin = str[3] - '0'; // Pn_n |
emilmont | 1:6919289a5946 | 49 | uint32_t pin2 = str[4] - '0'; // Pn_nn |
emilmont | 1:6919289a5946 | 50 | if (pin2 <= 9) { |
emilmont | 1:6919289a5946 | 51 | pin = pin * 10 + pin2; |
emilmont | 1:6919289a5946 | 52 | } |
emilmont | 1:6919289a5946 | 53 | return port_pin((PortName)port, pin); |
emilmont | 1:6919289a5946 | 54 | |
mbed_official | 7:2a26fd6a2b36 | 55 | #elif defined(TARGET_KL25Z) || defined(TARGET_KL05Z) || defined(TARGET_KL46Z) || defined(TARGET_K64F) |
mbed_official | 7:2a26fd6a2b36 | 56 | if (str[0] == 'P' && str[1] == 'T') { // PTxn |
mbed_official | 7:2a26fd6a2b36 | 57 | uint32_t port = str[2] - 'A'; |
mbed_official | 7:2a26fd6a2b36 | 58 | uint32_t pin = str[3] - '0'; // PTxn |
mbed_official | 7:2a26fd6a2b36 | 59 | uint32_t pin2 = str[4] - '0'; // PTxnn |
emilmont | 1:6919289a5946 | 60 | |
mbed_official | 7:2a26fd6a2b36 | 61 | if (pin2 <= 9) { |
mbed_official | 7:2a26fd6a2b36 | 62 | pin = pin * 10 + pin2; |
mbed_official | 7:2a26fd6a2b36 | 63 | } |
mbed_official | 7:2a26fd6a2b36 | 64 | return port_pin((PortName)port, pin); |
emilmont | 1:6919289a5946 | 65 | #endif |
emilmont | 1:6919289a5946 | 66 | |
mbed_official | 7:2a26fd6a2b36 | 67 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) |
emilmont | 1:6919289a5946 | 68 | } else if (str[0] == 'p') { // pn |
emilmont | 1:6919289a5946 | 69 | uint32_t pin = str[1] - '0'; // pn |
emilmont | 1:6919289a5946 | 70 | uint32_t pin2 = str[2] - '0'; // pnn |
emilmont | 1:6919289a5946 | 71 | if (pin2 <= 9) { |
emilmont | 1:6919289a5946 | 72 | pin = pin * 10 + pin2; |
emilmont | 1:6919289a5946 | 73 | } |
emilmont | 1:6919289a5946 | 74 | if (pin < 5 || pin > 30) { |
emilmont | 1:6919289a5946 | 75 | return NC; |
emilmont | 1:6919289a5946 | 76 | } |
emilmont | 1:6919289a5946 | 77 | return pin_names[pin - 5]; |
mbed_official | 8:fece2d5e8d96 | 78 | #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) |
emilmont | 4:9f88f495e549 | 79 | } else if (str[0] == 'p') { // pn |
emilmont | 4:9f88f495e549 | 80 | uint32_t pin = str[1] - '0'; // pn |
emilmont | 4:9f88f495e549 | 81 | uint32_t pin2 = str[2] - '0'; // pnn |
emilmont | 4:9f88f495e549 | 82 | if (pin2 <= 9) { |
emilmont | 4:9f88f495e549 | 83 | pin = pin * 10 + pin2; |
emilmont | 4:9f88f495e549 | 84 | } |
mbed_official | 8:fece2d5e8d96 | 85 | if (pin < 1 || pin > 46) { |
emilmont | 4:9f88f495e549 | 86 | return NC; |
emilmont | 4:9f88f495e549 | 87 | } |
mbed_official | 8:fece2d5e8d96 | 88 | return pin_names[pin - 1]; |
hillkim7 | 9:75a49e903ad8 | 89 | } |
emilmont | 1:6919289a5946 | 90 | #endif |
emilmont | 1:6919289a5946 | 91 | |
hillkim7 | 9:75a49e903ad8 | 92 | #if defined(TARGET_ARCH_MAX) |
hillkim7 | 9:75a49e903ad8 | 93 | if (str[0] == 'D') { // D0~D15 |
hillkim7 | 9:75a49e903ad8 | 94 | uint32_t pin = str[1] - '0'; |
hillkim7 | 9:75a49e903ad8 | 95 | uint32_t pin2 = str[2] - '0'; |
hillkim7 | 9:75a49e903ad8 | 96 | if (pin2 <= 9) { |
hillkim7 | 9:75a49e903ad8 | 97 | pin = pin * 10 + pin2; |
hillkim7 | 9:75a49e903ad8 | 98 | } |
hillkim7 | 9:75a49e903ad8 | 99 | if (pin <= sizeof(D_pin_names)/sizeof(D_pin_names[0])) |
hillkim7 | 9:75a49e903ad8 | 100 | return D_pin_names[pin]; |
hillkim7 | 9:75a49e903ad8 | 101 | else |
hillkim7 | 9:75a49e903ad8 | 102 | return NC; |
hillkim7 | 9:75a49e903ad8 | 103 | } else if (str[0] == 'A') { // A0~A7 |
hillkim7 | 9:75a49e903ad8 | 104 | uint32_t pin = str[1] - '0'; |
hillkim7 | 9:75a49e903ad8 | 105 | if (pin <= sizeof(A_pin_names)/sizeof(A_pin_names[0])) |
hillkim7 | 9:75a49e903ad8 | 106 | return A_pin_names[pin]; |
hillkim7 | 9:75a49e903ad8 | 107 | else |
hillkim7 | 9:75a49e903ad8 | 108 | return NC; |
hillkim7 | 9:75a49e903ad8 | 109 | } |
hillkim7 | 9:75a49e903ad8 | 110 | #endif |
hillkim7 | 9:75a49e903ad8 | 111 | |
hillkim7 | 9:75a49e903ad8 | 112 | if (str[0] == 'L') { // LEDn |
emilmont | 1:6919289a5946 | 113 | switch (str[3]) { |
emilmont | 1:6919289a5946 | 114 | case '1' : return LED1; |
emilmont | 1:6919289a5946 | 115 | case '2' : return LED2; |
emilmont | 1:6919289a5946 | 116 | case '3' : return LED3; |
emilmont | 1:6919289a5946 | 117 | case '4' : return LED4; |
emilmont | 1:6919289a5946 | 118 | } |
emilmont | 1:6919289a5946 | 119 | |
emilmont | 1:6919289a5946 | 120 | } else if (str[0] == 'U') { // USB?X |
emilmont | 1:6919289a5946 | 121 | switch (str[3]) { |
emilmont | 1:6919289a5946 | 122 | case 'T' : return USBTX; |
emilmont | 1:6919289a5946 | 123 | case 'R' : return USBRX; |
emilmont | 1:6919289a5946 | 124 | } |
emilmont | 1:6919289a5946 | 125 | } |
emilmont | 1:6919289a5946 | 126 | |
emilmont | 1:6919289a5946 | 127 | return NC; |
emilmont | 1:6919289a5946 | 128 | } |
emilmont | 1:6919289a5946 | 129 | |
emilmont | 1:6919289a5946 | 130 | } |