You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. namespace mbed {
  18. PinName parse_pins(const char *str) {
  19. #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
  20. static const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
  21. , p15, p16, p17, p18, p19, p20, p21, p22, p23
  22. , p24, p25, p26, p27, p28, p29, p30};
  23. #elif defined(TARGET_LPC1114)
  24. static const PinName pin_names[] = {dp1, dp2, dp4, dp5, dp6, dp9, dp10, dp11
  25. , dp13, dp14, dp15, dp16, dp17, dp18, dp23
  26. , dp24, dp25, dp26, dp27, dp28};
  27. #elif defined(TARGET_LPC4088)
  28. static const PinName pin_names[] = {NC, NC, NC, NC, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
  29. , p15, p16, p17, p18, p19, p20, NC, NC, p23
  30. , p24, p25, p26, p27, p28, p29, p30, p31, p32
  31. , p33, p34, NC, NC, p37, p38, p39, NC, NC, NC, NC, NC, NC, NC};
  32. #elif defined(TARGET_LPC4088_DM)
  33. static const PinName pin_names[] = {p1, p2, p3, p4, NC, NC, p7, p8, p9, p10, p11, p12, p13, p14
  34. , p15, p16, p17, p18, p19, p20, p21, p22, p23
  35. , p24, p25, p26, NC, NC, p29, p30, NC, NC
  36. , NC, NC, NC, NC, NC, NC, NC, NC, p41, p42, p43, p44, p45, p46};
  37. #endif
  38. #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812) || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC1114)
  39. if (str[0] == 'P') { // Pn_n
  40. uint32_t port = str[1] - '0';
  41. uint32_t pin = str[3] - '0'; // Pn_n
  42. uint32_t pin2 = str[4] - '0'; // Pn_nn
  43. if (pin2 <= 9) {
  44. pin = pin * 10 + pin2;
  45. }
  46. return port_pin((PortName)port, pin);
  47. #elif defined(TARGET_KL25Z) || defined(TARGET_KL05Z) || defined(TARGET_KL46Z) || defined(TARGET_K64F)
  48. if (str[0] == 'P' && str[1] == 'T') { // PTxn
  49. uint32_t port = str[2] - 'A';
  50. uint32_t pin = str[3] - '0'; // PTxn
  51. uint32_t pin2 = str[4] - '0'; // PTxnn
  52. if (pin2 <= 9) {
  53. pin = pin * 10 + pin2;
  54. }
  55. return port_pin((PortName)port, pin);
  56. #endif
  57. #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
  58. } else if (str[0] == 'p') { // pn
  59. uint32_t pin = str[1] - '0'; // pn
  60. uint32_t pin2 = str[2] - '0'; // pnn
  61. if (pin2 <= 9) {
  62. pin = pin * 10 + pin2;
  63. }
  64. if (pin < 5 || pin > 30) {
  65. return NC;
  66. }
  67. return pin_names[pin - 5];
  68. #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
  69. } else if (str[0] == 'p') { // pn
  70. uint32_t pin = str[1] - '0'; // pn
  71. uint32_t pin2 = str[2] - '0'; // pnn
  72. if (pin2 <= 9) {
  73. pin = pin * 10 + pin2;
  74. }
  75. if (pin < 1 || pin > 46) {
  76. return NC;
  77. }
  78. return pin_names[pin - 1];
  79. #endif
  80. } else if (str[0] == 'L') { // LEDn
  81. switch (str[3]) {
  82. case '1' : return LED1;
  83. case '2' : return LED2;
  84. case '3' : return LED3;
  85. case '4' : return LED4;
  86. }
  87. } else if (str[0] == 'U') { // USB?X
  88. switch (str[3]) {
  89. case 'T' : return USBTX;
  90. case 'R' : return USBRX;
  91. }
  92. }
  93. return NC;
  94. }
  95. }