1 /* mbed Microcontroller Library
2 * Copyright (c) 2013 Nordic Semiconductor
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.
20 PinName
port_pin(PortName port
, int pin_n
)
22 return (PinName
)(pin_n
);
25 void port_init(port_t
*obj
, PortName port
, int mask
, PinDirection dir
)
30 obj
->reg_out
= &NRF_GPIO
->OUT
;
31 obj
->reg_in
= &NRF_GPIO
->IN
;
32 obj
->reg_cnf
= NRF_GPIO
->PIN_CNF
;
37 void port_mode(port_t
*obj
, PinMode mode
)
40 // The mode is set per pin: reuse pinmap logic
41 for (i
= 0; i
<31; i
++) {
42 if (obj
->mask
& (1 << i
)) {
43 pin_mode(port_pin(obj
->port
, i
), mode
);
48 void port_dir(port_t
*obj
, PinDirection dir
)
53 for (i
= 0; i
<31; i
++) {
54 if (obj
->mask
& (1 << i
)) {
55 obj
->reg_cnf
[i
] = (GPIO_PIN_CNF_SENSE_Disabled
<< GPIO_PIN_CNF_SENSE_Pos
)
56 | (GPIO_PIN_CNF_DRIVE_S0S1
<< GPIO_PIN_CNF_DRIVE_Pos
)
57 | (GPIO_PIN_CNF_INPUT_Connect
<< GPIO_PIN_CNF_INPUT_Pos
)
58 | (GPIO_PIN_CNF_DIR_Input
<< GPIO_PIN_CNF_DIR_Pos
);
63 for (i
= 0; i
<31; i
++) {
64 if (obj
->mask
& (1 << i
)) {
65 obj
->reg_cnf
[i
] = (GPIO_PIN_CNF_SENSE_Disabled
<< GPIO_PIN_CNF_SENSE_Pos
)
66 | (GPIO_PIN_CNF_DRIVE_S0S1
<< GPIO_PIN_CNF_DRIVE_Pos
)
67 | (GPIO_PIN_CNF_PULL_Disabled
<< GPIO_PIN_CNF_PULL_Pos
)
68 | (GPIO_PIN_CNF_INPUT_Connect
<< GPIO_PIN_CNF_INPUT_Pos
)
69 | (GPIO_PIN_CNF_DIR_Output
<< GPIO_PIN_CNF_DIR_Pos
);
76 void port_write(port_t
*obj
, int value
)
78 *obj
->reg_out
= value
;
81 int port_read(port_t
*obj
)
83 return (*obj
->reg_in
);