@@ -33,44 +33,46 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
33
33
34
34
ulPin = g_ADigitalPinMap [ulPin ];
35
35
36
+ NRF_GPIO_Type * port = nrf_gpio_pin_port_decode (& ulPin );
37
+
36
38
// Set pin mode according to chapter '22.6.3 I/O Pin Configuration'
37
39
switch ( ulMode )
38
40
{
39
41
case INPUT :
40
42
// Set pin to input mode
41
- * digitalPinCnfRegister ( ulPin ) = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
42
- | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
43
- | ((uint32_t )GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos )
44
- | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
45
- | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
46
- break ;
43
+ port -> PIN_CNF [ ulPin ] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
44
+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
45
+ | ((uint32_t )GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos )
46
+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
47
+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
48
+ break ;
47
49
48
50
case INPUT_PULLUP :
49
51
// Set pin to input mode with pull-up resistor enabled
50
- * digitalPinCnfRegister ( ulPin ) = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
51
- | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
52
- | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos )
53
- | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
54
- | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
55
- break ;
52
+ port -> PIN_CNF [ ulPin ] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
53
+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
54
+ | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos )
55
+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
56
+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
57
+ break ;
56
58
57
59
case INPUT_PULLDOWN :
58
60
// Set pin to input mode with pull-down resistor enabled
59
- * digitalPinCnfRegister ( ulPin ) = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
60
- | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
61
- | ((uint32_t )GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos )
62
- | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
63
- | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
64
- break ;
61
+ port -> PIN_CNF [ ulPin ] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
62
+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
63
+ | ((uint32_t )GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos )
64
+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
65
+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
66
+ break ;
65
67
66
68
case OUTPUT :
67
69
// Set pin to output mode
68
- * digitalPinCnfRegister ( ulPin ) = ((uint32_t )GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos )
69
- | ((uint32_t )GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos )
70
- | ((uint32_t )GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos )
71
- | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
72
- | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
73
- break ;
70
+ port -> PIN_CNF [ ulPin ] = ((uint32_t )GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos )
71
+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos )
72
+ | ((uint32_t )GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos )
73
+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
74
+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
75
+ break ;
74
76
75
77
default :
76
78
// do nothing
@@ -85,16 +87,17 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
85
87
}
86
88
87
89
ulPin = g_ADigitalPinMap [ulPin ];
88
- NRF_GPIO_Type * nrf_port = (NRF_GPIO_Type * ) digitalPinToPort (ulPin );
90
+
91
+ NRF_GPIO_Type * port = nrf_gpio_pin_port_decode (& ulPin );
89
92
90
93
switch ( ulVal )
91
94
{
92
95
case LOW :
93
- nrf_port -> OUTCLR = digitalPinToBitMask ( ulPin );
96
+ port -> OUTCLR = ( 1UL << ulPin );
94
97
break ;
95
98
96
99
default :
97
- nrf_port -> OUTSET = digitalPinToBitMask ( ulPin );
100
+ port -> OUTSET = ( 1UL << ulPin );
98
101
break ;
99
102
}
100
103
}
@@ -107,12 +110,11 @@ int digitalRead( uint32_t ulPin )
107
110
108
111
ulPin = g_ADigitalPinMap [ulPin ];
109
112
110
- // Return bit in OUT or IN depending on configured direction
111
- NRF_GPIO_Type * nrf_port = (NRF_GPIO_Type * ) digitalPinToPort (ulPin );
112
-
113
- if ( ulPin > 32 ) ulPin -= 32 ;
113
+ NRF_GPIO_Type * port = nrf_gpio_pin_port_decode (& ulPin );
114
+ uint32_t const bm = (1UL << ulPin );
114
115
115
- return bitRead (nrf_port -> DIR , ulPin ) ? bitRead (nrf_port -> OUT , ulPin ) : bitRead (nrf_port -> IN , ulPin );
116
+ // Return bit in OUT or IN depending on configured direction
117
+ return (bm & ((port -> DIR & bm ) ? port -> OUT : port -> IN )) ? 1 : 0 ;
116
118
}
117
119
118
120
void digitalToggle ( uint32_t pin )
0 commit comments