1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "mbed_assert.h"
20 void gpio_init(gpio_t
*obj
, PinName pin
)
23 if (pin
== (PinName
)NC
) {
27 obj
->mask
= (1ul << pin
);
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;
35 void gpio_mode(gpio_t
*obj
, PinMode mode
)
37 pin_mode(obj
->pin
, mode
);
40 void gpio_dir(gpio_t
*obj
, PinDirection direction
)
42 MBED_ASSERT(obj
->pin
!= (PinName
)NC
);
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
);
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
);