mbed_controller / mbed-rpc

Dependents:   mbed_controller_demo

Fork of mbed-rpc by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers parse_pins.cpp Source File

parse_pins.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "port_api.h"
00017 
00018 namespace mbed {
00019 
00020 PinName parse_pins(const char *str) {
00021 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
00022     static const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
00023                                 , p15, p16, p17, p18, p19, p20, p21, p22, p23
00024                                 , p24, p25, p26, p27, p28, p29, p30};
00025 #elif defined(TARGET_LPC1114)
00026     static const PinName pin_names[] = {dp1, dp2, dp4, dp5, dp6, dp9, dp10, dp11
00027                                 , dp13, dp14, dp15, dp16, dp17, dp18, dp23
00028                                 , dp24, dp25, dp26, dp27, dp28};
00029 #elif defined(TARGET_LPC4088)
00030     static const PinName pin_names[] = {NC, NC, NC, NC, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
00031                                 , p15, p16, p17, p18, p19, p20, NC, NC, p23
00032                                 , p24, p25, p26, p27, p28, p29, p30, p31, p32
00033                                 , p33, p34, NC, NC, p37, p38, p39, NC, NC, NC, NC, NC, NC, NC};
00034 #elif defined(TARGET_LPC4088_DM)
00035     static const PinName pin_names[] = {p1, p2, p3, p4, NC, NC, p7, p8, p9, p10, p11, p12, p13, p14
00036                                 , p15, p16, p17, p18, p19, p20, p21, p22, p23
00037                                 , p24, p25, p26, NC, NC, p29, p30, NC, NC
00038                                 , NC, NC, NC, NC, NC, NC, NC, NC, p41, p42, p43, p44, p45, p46};
00039 #elif defined(TARGET_ARCH_MAX)
00040     // Arduino pinmap mapping
00041     static const PinName A_pin_names[] = {A0, A1, A2, A3, A4, A5, A6, A7};
00042     static const PinName D_pin_names[] = {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15};
00043 #endif
00044 
00045 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812) || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC1114)
00046     if (str[0] == 'P') {              // Pn_n
00047         uint32_t port = str[1] - '0';
00048         uint32_t pin  = str[3] - '0'; // Pn_n
00049         uint32_t pin2 = str[4] - '0'; // Pn_nn
00050         if (pin2 <= 9) {
00051             pin = pin * 10 + pin2;
00052         }
00053         return port_pin((PortName)port, pin);
00054 
00055 #elif defined(TARGET_KL25Z) || defined(TARGET_KL05Z) || defined(TARGET_KL46Z) || defined(TARGET_K64F)
00056     if (str[0] == 'P' && str[1] == 'T') {   // PTxn
00057         uint32_t port = str[2] - 'A';
00058         uint32_t pin  = str[3] - '0';       // PTxn
00059         uint32_t pin2 = str[4] - '0';       // PTxnn
00060 
00061         if (pin2 <= 9) {
00062             pin = pin * 10 + pin2;
00063         }
00064         return port_pin((PortName)port, pin);
00065 #endif
00066 
00067 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
00068     } else if (str[0] == 'p') {       // pn
00069         uint32_t pin  = str[1] - '0'; // pn
00070         uint32_t pin2 = str[2] - '0'; // pnn
00071         if (pin2 <= 9) {
00072             pin = pin * 10 + pin2;
00073         }
00074         if (pin < 5 || pin > 30) {
00075             return NC;
00076         }
00077         return pin_names[pin - 5];
00078 #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
00079     } else if (str[0] == 'p') {       // pn
00080         uint32_t pin  = str[1] - '0'; // pn
00081         uint32_t pin2 = str[2] - '0'; // pnn
00082         if (pin2 <= 9) {
00083             pin = pin * 10 + pin2;
00084         }
00085         if (pin < 1 || pin > 46) {
00086             return NC;
00087         }
00088         return pin_names[pin - 1];
00089     }
00090 #endif
00091 
00092 #if defined(TARGET_ARCH_MAX)
00093     if (str[0] == 'D') {       // D0~D15
00094         uint32_t pin  = str[1] - '0';
00095         uint32_t pin2 = str[2] - '0';
00096         if (pin2 <= 9) {
00097             pin = pin * 10 + pin2;
00098         }
00099         if (pin < sizeof(D_pin_names)/sizeof(D_pin_names[0]))
00100             return D_pin_names[pin];
00101         else
00102             return NC;
00103     } else if (str[0] == 'A') {       // A0~A7
00104         uint32_t pin  = str[1] - '0';
00105         if (pin < sizeof(A_pin_names)/sizeof(A_pin_names[0]))
00106             return A_pin_names[pin];
00107         else
00108             return NC;
00109     }
00110 #else
00111 }
00112 #endif
00113 
00114     if (str[0] == 'L') {  // LEDn
00115         switch (str[3]) {
00116             case '1' : return LED1;
00117             case '2' : return LED2;
00118             case '3' : return LED3;
00119             case '4' : return LED4;
00120         }
00121 
00122     } else if (str[0] == 'U') {  // USB?X
00123         switch (str[3]) {
00124             case 'T' : return USBTX;
00125             case 'R' : return USBRX;
00126         }
00127     }
00128 
00129     return NC;
00130 }
00131 
00132 }