]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/gpio_api.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_NORDIC / TARGET_MCU_NRF51822 / gpio_api.c
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 "mbed_assert.h"
17 #include "gpio_api.h"
18 #include "pinmap.h"
19
20 void gpio_init(gpio_t *obj, PinName pin)
21 {
22 obj->pin = pin;
23 if (pin == (PinName)NC) {
24 return;
25 }
26
27 obj->mask = (1ul << pin);
28
29 obj->reg_set = &NRF_GPIO->OUTSET;
30 obj->reg_clr = &NRF_GPIO->OUTCLR;
31 obj->reg_in = &NRF_GPIO->IN;
32 obj->reg_dir = &NRF_GPIO->DIR;
33 }
34
35 void gpio_mode(gpio_t *obj, PinMode mode)
36 {
37 pin_mode(obj->pin, mode);
38 }
39
40 void gpio_dir(gpio_t *obj, PinDirection direction)
41 {
42 MBED_ASSERT(obj->pin != (PinName)NC);
43 switch (direction) {
44 case PIN_INPUT:
45 NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
46 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
47 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
48 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
49 break;
50 case PIN_OUTPUT:
51 NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
52 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
53 | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
54 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
55 | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
56 break;
57 }
58 }
Imprint / Impressum