Skip to content

Commit 1cfac4c

Browse files
committed
Add parse_pins function removed from the mbed library
1 parent 36ee7d9 commit 1cfac4c

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

libraries/mbed/rpc/Arguments.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define ARGUMENTS_H
1818

1919
#include "platform.h"
20+
#include "parse_pins.h"
2021

2122
namespace mbed {
2223

libraries/mbed/rpc/parse_pins.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
#endif
26+
27+
#if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812)
28+
if (str[0] == 'P') { // Pn_n
29+
uint32_t port = str[1] - '0';
30+
uint32_t pin = str[3] - '0'; // Pn_n
31+
uint32_t pin2 = str[4] - '0'; // Pn_nn
32+
if (pin2 <= 9) {
33+
pin = pin * 10 + pin2;
34+
}
35+
return port_pin((PortName)port, pin);
36+
37+
#elif defined(LTARGET_KL25Z)
38+
if (str[0] == 'P' && str[1] == 'T') { // PTx_n
39+
uint32_t port = str[2] - 'A';
40+
uint32_t pin = str[3] - '0'; // PTxn
41+
uint32_t pin2 = str[4] - '0'; // PTxnn
42+
43+
if (pin2 <= 9) {
44+
pin = pin * 10 + pin2;
45+
}
46+
return port_pin((PortName)port, pin);
47+
#endif
48+
49+
#if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
50+
} else if (str[0] == 'p') { // pn
51+
uint32_t pin = str[1] - '0'; // pn
52+
uint32_t pin2 = str[2] - '0'; // pnn
53+
if (pin2 <= 9) {
54+
pin = pin * 10 + pin2;
55+
}
56+
if (pin < 5 || pin > 30) {
57+
return NC;
58+
}
59+
return pin_names[pin - 5];
60+
#endif
61+
62+
} else if (str[0] == 'L') { // LEDn
63+
switch (str[3]) {
64+
case '1' : return LED1;
65+
case '2' : return LED2;
66+
case '3' : return LED3;
67+
case '4' : return LED4;
68+
}
69+
70+
} else if (str[0] == 'U') { // USB?X
71+
switch (str[3]) {
72+
case 'T' : return USBTX;
73+
case 'R' : return USBRX;
74+
}
75+
}
76+
77+
return NC;
78+
}
79+
80+
}

libraries/mbed/rpc/parse_pins.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#ifndef MBED_PINMAP_H
17+
#define MBED_PINMAP_H
18+
19+
#include "PinNames.h"
20+
21+
namespace mbed {
22+
23+
PinName parse_pins(const char *str);
24+
25+
}
26+
27+
#endif

0 commit comments

Comments
 (0)