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 /***************************************************************************//**
elessair 0:f269e3021894 2 * @file pinmap.c
elessair 0:f269e3021894 3 *******************************************************************************
elessair 0:f269e3021894 4 * @section License
elessair 0:f269e3021894 5 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
elessair 0:f269e3021894 6 *******************************************************************************
elessair 0:f269e3021894 7 *
elessair 0:f269e3021894 8 * SPDX-License-Identifier: Apache-2.0
elessair 0:f269e3021894 9 *
elessair 0:f269e3021894 10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
elessair 0:f269e3021894 11 * not use this file except in compliance with the License.
elessair 0:f269e3021894 12 * You may obtain a copy of the License at
elessair 0:f269e3021894 13 *
elessair 0:f269e3021894 14 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 15 *
elessair 0:f269e3021894 16 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
elessair 0:f269e3021894 18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 19 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 20 * limitations under the License.
elessair 0:f269e3021894 21 *
elessair 0:f269e3021894 22 ******************************************************************************/
elessair 0:f269e3021894 23
elessair 0:f269e3021894 24 #include "pinmap.h"
elessair 0:f269e3021894 25 #include "em_gpio.h"
elessair 0:f269e3021894 26 #include "em_cmu.h"
elessair 0:f269e3021894 27 #include "mbed_assert.h"
elessair 0:f269e3021894 28
elessair 0:f269e3021894 29 static int gpio_clock_inited = 0;
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31 void pin_function(PinName pin, int function)
elessair 0:f269e3021894 32 {
elessair 0:f269e3021894 33 //Intentionally left empty. We have repurposed the function field.
elessair 0:f269e3021894 34 }
elessair 0:f269e3021894 35
elessair 0:f269e3021894 36 void pin_mode(PinName pin, PinMode mode)
elessair 0:f269e3021894 37 {
elessair 0:f269e3021894 38 MBED_ASSERT((0xFFFFFF00 |pin) != NC);
elessair 0:f269e3021894 39
elessair 0:f269e3021894 40 /* Enable GPIO clock if not already done */
elessair 0:f269e3021894 41 if (!gpio_clock_inited) {
elessair 0:f269e3021894 42 CMU_ClockEnable(cmuClock_GPIO, true);
elessair 0:f269e3021894 43 gpio_clock_inited = 1;
elessair 0:f269e3021894 44 }
elessair 0:f269e3021894 45
elessair 0:f269e3021894 46 /* Pin and port index encoded in one uint32.
elessair 0:f269e3021894 47 * First four bits represent the pin number
elessair 0:f269e3021894 48 * The remaining bits represent the port number */
elessair 0:f269e3021894 49 uint32_t pin_number = (uint32_t) pin;
elessair 0:f269e3021894 50 int pin_index = (pin_number & 0xF);
elessair 0:f269e3021894 51 int port_index = pin_number >> 4;
elessair 0:f269e3021894 52
elessair 0:f269e3021894 53 GPIO_PinModeSet(port_index, pin_index, mode & 0xF, GPIO_PinOutGet(port_index, pin_index & 0xF));
elessair 0:f269e3021894 54 }
elessair 0:f269e3021894 55
elessair 0:f269e3021894 56 // TODO_LP get pin_mode to be able to store previous settings