supported STM32

Fork of mbed-rpc by Mbed

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 
00022     static const PinName pin_digital[] = {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15};
00023     static const PinName pin_analog[] = {A0, A1, A2, A3, A4, A5};
00024     
00025     if (str[0] == 'D') { // Dn
00026         uint32_t pin  = str[1] - '0'; // Dn
00027         uint32_t pin2 = str[2] - '0'; // Dnn
00028         if (pin2 <= 9) {
00029             pin = pin * 10 + pin2;
00030         }
00031         if (pin < 0 || pin > 15) {
00032             return NC;
00033         }
00034         return pin_digital[pin];
00035     } else if (str[0] == 'A') { // An
00036         uint32_t pin  = str[1] - '0'; // An
00037         uint32_t pin2 = str[2] - '0'; // Ann
00038         if (pin2 <= 9) {
00039             pin = pin * 10 + pin2;
00040         }
00041         if (pin < 0 || pin > 5) {
00042             return NC;
00043         }
00044         return pin_analog[pin];
00045     } else if (str[0] == 'L') {  // LEDn
00046         switch (str[3]) {
00047             case '1' : return LED1;
00048             case '2' : return LED2;
00049             case '3' : return LED3;
00050             case '4' : return LED4;
00051         }
00052 
00053     } else if (str[0] == 'U') {  // USB?X
00054         switch (str[3]) {
00055             case 'T' : return USBTX;
00056             case 'R' : return USBRX;
00057         }
00058     }
00059 
00060     return NC;
00061 }
00062 
00063 }