]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/rpc/parse_pins.cpp
Change .gitignore for ChibiOS
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / rpc / parse_pins.cpp
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "port_api.h"
17
18 namespace mbed {
19
20 PinName parse_pins(const char *str) {
21 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
22 static const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
23 , p15, p16, p17, p18, p19, p20, p21, p22, p23
24 , p24, p25, p26, p27, p28, p29, p30};
25 #elif defined(TARGET_LPC1114)
26 static const PinName pin_names[] = {dp1, dp2, dp4, dp5, dp6, dp9, dp10, dp11
27 , dp13, dp14, dp15, dp16, dp17, dp18, dp23
28 , dp24, dp25, dp26, dp27, dp28};
29 #elif defined(TARGET_LPC4088)
30 static const PinName pin_names[] = {NC, NC, NC, NC, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
31 , p15, p16, p17, p18, p19, p20, NC, NC, p23
32 , p24, p25, p26, p27, p28, p29, p30, p31, p32
33 , p33, p34, NC, NC, p37, p38, p39, NC, NC, NC, NC, NC, NC, NC};
34 #elif defined(TARGET_LPC4088_DM)
35 static const PinName pin_names[] = {p1, p2, p3, p4, NC, NC, p7, p8, p9, p10, p11, p12, p13, p14
36 , p15, p16, p17, p18, p19, p20, p21, p22, p23
37 , p24, p25, p26, NC, NC, p29, p30, NC, NC
38 , NC, NC, NC, NC, NC, NC, NC, NC, p41, p42, p43, p44, p45, p46};
39 #endif
40
41 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812) || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC1114)
42 if (str[0] == 'P') { // Pn_n
43 uint32_t port = str[1] - '0';
44 uint32_t pin = str[3] - '0'; // Pn_n
45 uint32_t pin2 = str[4] - '0'; // Pn_nn
46 if (pin2 <= 9) {
47 pin = pin * 10 + pin2;
48 }
49 return port_pin((PortName)port, pin);
50
51 #elif defined(TARGET_KL25Z) || defined(TARGET_KL05Z) || defined(TARGET_KL46Z) || defined(TARGET_K64F)
52 if (str[0] == 'P' && str[1] == 'T') { // PTxn
53 uint32_t port = str[2] - 'A';
54 uint32_t pin = str[3] - '0'; // PTxn
55 uint32_t pin2 = str[4] - '0'; // PTxnn
56
57 if (pin2 <= 9) {
58 pin = pin * 10 + pin2;
59 }
60 return port_pin((PortName)port, pin);
61 #endif
62
63 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
64 } else if (str[0] == 'p') { // pn
65 uint32_t pin = str[1] - '0'; // pn
66 uint32_t pin2 = str[2] - '0'; // pnn
67 if (pin2 <= 9) {
68 pin = pin * 10 + pin2;
69 }
70 if (pin < 5 || pin > 30) {
71 return NC;
72 }
73 return pin_names[pin - 5];
74 #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
75 } else if (str[0] == 'p') { // pn
76 uint32_t pin = str[1] - '0'; // pn
77 uint32_t pin2 = str[2] - '0'; // pnn
78 if (pin2 <= 9) {
79 pin = pin * 10 + pin2;
80 }
81 if (pin < 1 || pin > 46) {
82 return NC;
83 }
84 return pin_names[pin - 1];
85 #endif
86
87 } else if (str[0] == 'L') { // LEDn
88 switch (str[3]) {
89 case '1' : return LED1;
90 case '2' : return LED2;
91 case '3' : return LED3;
92 case '4' : return LED4;
93 }
94
95 } else if (str[0] == 'U') { // USB?X
96 switch (str[3]) {
97 case 'T' : return USBTX;
98 case 'R' : return USBRX;
99 }
100 }
101
102 return NC;
103 }
104
105 }
Imprint / Impressum