supported STM32
Fork of mbed-rpc by
parse_pins.cpp@12:ac3570c18083, 2016-02-19 (annotated)
- Committer:
- dll7
- Date:
- Fri Feb 19 20:37:14 2016 +0000
- Revision:
- 12:ac3570c18083
- Parent:
- 5:4490a0d9cb2a
STM32
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 | 1:6919289a5946 | 21 | |
dll7 | 12:ac3570c18083 | 22 | static const PinName pin_digital[] = {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15}; |
dll7 | 12:ac3570c18083 | 23 | static const PinName pin_analog[] = {A0, A1, A2, A3, A4, A5}; |
dll7 | 12:ac3570c18083 | 24 | |
dll7 | 12:ac3570c18083 | 25 | if (str[0] == 'D') { // Dn |
dll7 | 12:ac3570c18083 | 26 | uint32_t pin = str[1] - '0'; // Dn |
dll7 | 12:ac3570c18083 | 27 | uint32_t pin2 = str[2] - '0'; // Dnn |
emilmont | 1:6919289a5946 | 28 | if (pin2 <= 9) { |
emilmont | 1:6919289a5946 | 29 | pin = pin * 10 + pin2; |
emilmont | 1:6919289a5946 | 30 | } |
dll7 | 12:ac3570c18083 | 31 | if (pin < 0 || pin > 15) { |
dll7 | 12:ac3570c18083 | 32 | return NC; |
dll7 | 12:ac3570c18083 | 33 | } |
dll7 | 12:ac3570c18083 | 34 | return pin_digital[pin]; |
dll7 | 12:ac3570c18083 | 35 | } else if (str[0] == 'A') { // An |
dll7 | 12:ac3570c18083 | 36 | uint32_t pin = str[1] - '0'; // An |
dll7 | 12:ac3570c18083 | 37 | uint32_t pin2 = str[2] - '0'; // Ann |
emilmont | 1:6919289a5946 | 38 | if (pin2 <= 9) { |
emilmont | 1:6919289a5946 | 39 | pin = pin * 10 + pin2; |
emilmont | 1:6919289a5946 | 40 | } |
dll7 | 12:ac3570c18083 | 41 | if (pin < 0 || pin > 5) { |
emilmont | 1:6919289a5946 | 42 | return NC; |
emilmont | 1:6919289a5946 | 43 | } |
dll7 | 12:ac3570c18083 | 44 | return pin_analog[pin]; |
emilmont | 1:6919289a5946 | 45 | } else if (str[0] == 'L') { // LEDn |
emilmont | 1:6919289a5946 | 46 | switch (str[3]) { |
emilmont | 1:6919289a5946 | 47 | case '1' : return LED1; |
emilmont | 1:6919289a5946 | 48 | case '2' : return LED2; |
emilmont | 1:6919289a5946 | 49 | case '3' : return LED3; |
emilmont | 1:6919289a5946 | 50 | case '4' : return LED4; |
emilmont | 1:6919289a5946 | 51 | } |
emilmont | 1:6919289a5946 | 52 | |
emilmont | 1:6919289a5946 | 53 | } else if (str[0] == 'U') { // USB?X |
emilmont | 1:6919289a5946 | 54 | switch (str[3]) { |
emilmont | 1:6919289a5946 | 55 | case 'T' : return USBTX; |
emilmont | 1:6919289a5946 | 56 | case 'R' : return USBRX; |
emilmont | 1:6919289a5946 | 57 | } |
emilmont | 1:6919289a5946 | 58 | } |
emilmont | 1:6919289a5946 | 59 | |
emilmont | 1:6919289a5946 | 60 | return NC; |
emilmont | 1:6919289a5946 | 61 | } |
emilmont | 1:6919289a5946 | 62 | |
emilmont | 1:6919289a5946 | 63 | } |