mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /* mbed Microcontroller Library
elessair 0:f269e3021894 2 * Copyright (c) 2006-2013 ARM Limited
elessair 0:f269e3021894 3 *
elessair 0:f269e3021894 4 * Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 5 * you may not use this file except in compliance with the License.
elessair 0:f269e3021894 6 * You may obtain a copy of the License at
elessair 0:f269e3021894 7 *
elessair 0:f269e3021894 8 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 9 *
elessair 0:f269e3021894 10 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 11 * distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 13 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 14 * limitations under the License.
elessair 0:f269e3021894 15 */
elessair 0:f269e3021894 16 #include "port_api.h"
elessair 0:f269e3021894 17
elessair 0:f269e3021894 18 namespace mbed {
elessair 0:f269e3021894 19
elessair 0:f269e3021894 20 PinName parse_pins(const char *str) {
elessair 0:f269e3021894 21 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
elessair 0:f269e3021894 22 static const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
elessair 0:f269e3021894 23 , p15, p16, p17, p18, p19, p20, p21, p22, p23
elessair 0:f269e3021894 24 , p24, p25, p26, p27, p28, p29, p30};
elessair 0:f269e3021894 25 #elif defined(TARGET_LPC1114)
elessair 0:f269e3021894 26 static const PinName pin_names[] = {dp1, dp2, dp4, dp5, dp6, dp9, dp10, dp11
elessair 0:f269e3021894 27 , dp13, dp14, dp15, dp16, dp17, dp18, dp23
elessair 0:f269e3021894 28 , dp24, dp25, dp26, dp27, dp28};
elessair 0:f269e3021894 29 #elif defined(TARGET_LPC4088)
elessair 0:f269e3021894 30 static const PinName pin_names[] = {NC, NC, NC, NC, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14
elessair 0:f269e3021894 31 , p15, p16, p17, p18, p19, p20, NC, NC, p23
elessair 0:f269e3021894 32 , p24, p25, p26, p27, p28, p29, p30, p31, p32
elessair 0:f269e3021894 33 , p33, p34, NC, NC, p37, p38, p39, NC, NC, NC, NC, NC, NC, NC};
elessair 0:f269e3021894 34 #elif defined(TARGET_LPC4088_DM)
elessair 0:f269e3021894 35 static const PinName pin_names[] = {p1, p2, p3, p4, NC, NC, p7, p8, p9, p10, p11, p12, p13, p14
elessair 0:f269e3021894 36 , p15, p16, p17, p18, p19, p20, p21, p22, p23
elessair 0:f269e3021894 37 , p24, p25, p26, NC, NC, p29, p30, NC, NC
elessair 0:f269e3021894 38 , NC, NC, NC, NC, NC, NC, NC, NC, p41, p42, p43, p44, p45, p46};
elessair 0:f269e3021894 39 #endif
elessair 0:f269e3021894 40
elessair 0:f269e3021894 41 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368) || defined(TARGET_LPC812) || defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) || defined(TARGET_LPC1114) || defined(TARGET_RZ_A1H) || defined(TARGET_VK_RZ_A1H)
elessair 0:f269e3021894 42 if (str[0] == 'P') { // Pn_n
elessair 0:f269e3021894 43 uint32_t port = str[1] - '0';
elessair 0:f269e3021894 44 uint32_t pin = str[3] - '0'; // Pn_n
elessair 0:f269e3021894 45 uint32_t pin2 = str[4] - '0'; // Pn_nn
elessair 0:f269e3021894 46 if (pin2 <= 9) {
elessair 0:f269e3021894 47 pin = pin * 10 + pin2;
elessair 0:f269e3021894 48 }
elessair 0:f269e3021894 49 return port_pin((PortName)port, pin);
elessair 0:f269e3021894 50
elessair 0:f269e3021894 51 #elif defined(TARGET_KL25Z) || defined(TARGET_KL27Z) || defined(TARGET_KL05Z) || defined(TARGET_KL46Z) || defined(TARGET_K22F) || defined(TARGET_K64F)
elessair 0:f269e3021894 52 if (str[0] == 'P' && str[1] == 'T') { // PTxn
elessair 0:f269e3021894 53 uint32_t port = str[2] - 'A';
elessair 0:f269e3021894 54 uint32_t pin = str[3] - '0'; // PTxn
elessair 0:f269e3021894 55 uint32_t pin2 = str[4] - '0'; // PTxnn
elessair 0:f269e3021894 56
elessair 0:f269e3021894 57 if (pin2 <= 9) {
elessair 0:f269e3021894 58 pin = pin * 10 + pin2;
elessair 0:f269e3021894 59 }
elessair 0:f269e3021894 60 return port_pin((PortName)port, pin);
elessair 0:f269e3021894 61
elessair 0:f269e3021894 62 #elif defined(TARGET_NUCLEO_F072RB) || defined(TARGET_NUCLEO_F303K8) || defined(TARGET_NUCLEO_F411RE)
elessair 0:f269e3021894 63 if (str[0] == 'P') { // PX_XX e.g.PA_2 PC_15
elessair 0:f269e3021894 64 uint32_t port = str[1] - 'A';
elessair 0:f269e3021894 65 uint32_t pin = str[3] - '0';
elessair 0:f269e3021894 66 uint32_t pin2 = str[4] - '0';
elessair 0:f269e3021894 67
elessair 0:f269e3021894 68 if (pin2 <= 9) {
elessair 0:f269e3021894 69 pin = pin * 10 + pin2;
elessair 0:f269e3021894 70 }
elessair 0:f269e3021894 71 return port_pin((PortName)port, pin);
elessair 0:f269e3021894 72
elessair 0:f269e3021894 73 #endif
elessair 0:f269e3021894 74
elessair 0:f269e3021894 75
elessair 0:f269e3021894 76
elessair 0:f269e3021894 77 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC2368)
elessair 0:f269e3021894 78 } else if (str[0] == 'p') { // pn
elessair 0:f269e3021894 79 uint32_t pin = str[1] - '0'; // pn
elessair 0:f269e3021894 80 uint32_t pin2 = str[2] - '0'; // pnn
elessair 0:f269e3021894 81 if (pin2 <= 9) {
elessair 0:f269e3021894 82 pin = pin * 10 + pin2;
elessair 0:f269e3021894 83 }
elessair 0:f269e3021894 84 if (pin < 5 || pin > 30) {
elessair 0:f269e3021894 85 return NC;
elessair 0:f269e3021894 86 }
elessair 0:f269e3021894 87 return pin_names[pin - 5];
elessair 0:f269e3021894 88 #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
elessair 0:f269e3021894 89 } else if (str[0] == 'p') { // pn
elessair 0:f269e3021894 90 uint32_t pin = str[1] - '0'; // pn
elessair 0:f269e3021894 91 uint32_t pin2 = str[2] - '0'; // pnn
elessair 0:f269e3021894 92 if (pin2 <= 9) {
elessair 0:f269e3021894 93 pin = pin * 10 + pin2;
elessair 0:f269e3021894 94 }
elessair 0:f269e3021894 95 if (pin < 1 || pin > 46) {
elessair 0:f269e3021894 96 return NC;
elessair 0:f269e3021894 97 }
elessair 0:f269e3021894 98 return pin_names[pin - 1];
elessair 0:f269e3021894 99 #endif
elessair 0:f269e3021894 100 } else if (str[0] == 'L') { // LEDn
elessair 0:f269e3021894 101 switch (str[3]) {
elessair 0:f269e3021894 102 case '1' : return LED1;
elessair 0:f269e3021894 103 case '2' : return LED2;
elessair 0:f269e3021894 104 case '3' : return LED3;
elessair 0:f269e3021894 105 case '4' : return LED4;
elessair 0:f269e3021894 106 }
elessair 0:f269e3021894 107
elessair 0:f269e3021894 108 } else if (str[0] == 'U') { // USB?X
elessair 0:f269e3021894 109 switch (str[3]) {
elessair 0:f269e3021894 110 case 'T' : return USBTX;
elessair 0:f269e3021894 111 case 'R' : return USBRX;
elessair 0:f269e3021894 112 }
elessair 0:f269e3021894 113 }
elessair 0:f269e3021894 114
elessair 0:f269e3021894 115 return NC;
elessair 0:f269e3021894 116 }
elessair 0:f269e3021894 117 }
elessair 0:f269e3021894 118
elessair 0:f269e3021894 119