@@ -31,45 +31,46 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
31
31
return ;
32
32
}
33
33
34
- ulPin = g_ADigitalPinMap [ulPin ];
34
+ NRF_GPIO_Type * port = digitalPinToPort (ulPin );
35
+ uint32_t pin = digitalPinToPin (ulPin );
35
36
36
37
// Set pin mode according to chapter '22.6.3 I/O Pin Configuration'
37
38
switch ( ulMode )
38
39
{
39
40
case INPUT :
40
41
// Set pin to input mode
41
- NRF_GPIO -> PIN_CNF [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 );
42
+ port -> PIN_CNF [pin ] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
43
+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
44
+ | ((uint32_t )GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos )
45
+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
46
+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
46
47
break ;
47
48
48
49
case INPUT_PULLUP :
49
50
// Set pin to input mode with pull-up resistor enabled
50
- NRF_GPIO -> PIN_CNF [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 );
51
+ port -> PIN_CNF [pin ] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
52
+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
53
+ | ((uint32_t )GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos )
54
+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
55
+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
55
56
break ;
56
57
57
58
case INPUT_PULLDOWN :
58
59
// Set pin to input mode with pull-down resistor enabled
59
- NRF_GPIO -> PIN_CNF [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 );
60
+ port -> PIN_CNF [pin ] = ((uint32_t )GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos )
61
+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos )
62
+ | ((uint32_t )GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos )
63
+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
64
+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
64
65
break ;
65
66
66
67
case OUTPUT :
67
68
// Set pin to output mode
68
- NRF_GPIO -> PIN_CNF [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 );
69
+ port -> PIN_CNF [pin ] = ((uint32_t )GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos )
70
+ | ((uint32_t )GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos )
71
+ | ((uint32_t )GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos )
72
+ | ((uint32_t )GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos )
73
+ | ((uint32_t )GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos );
73
74
break ;
74
75
75
76
default :
@@ -84,16 +85,17 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
84
85
return ;
85
86
}
86
87
87
- ulPin = g_ADigitalPinMap [ulPin ];
88
+ NRF_GPIO_Type * port = digitalPinToPort (ulPin );
89
+ uint32_t mask = digitalPinToBitMask (ulPin );
88
90
89
91
switch ( ulVal )
90
92
{
91
93
case LOW :
92
- NRF_GPIO -> OUTCLR = ( 1UL << ulPin ) ;
94
+ port -> OUTCLR = mask ;
93
95
break ;
94
96
95
97
default :
96
- NRF_GPIO -> OUTSET = ( 1UL << ulPin ) ;
98
+ port -> OUTSET = mask ;
97
99
break ;
98
100
}
99
101
@@ -106,9 +108,10 @@ int digitalRead( uint32_t ulPin )
106
108
return 0 ;
107
109
}
108
110
109
- ulPin = g_ADigitalPinMap [ulPin ];
111
+ NRF_GPIO_Type * port = digitalPinToPort (ulPin );
112
+ uint32_t pin = digitalPinToPin (ulPin );
110
113
111
- return ((NRF_GPIO -> IN >> ulPin ) & 1UL ) ? HIGH : LOW ;
114
+ return ((port -> IN >> pin ) & 1UL ) ? HIGH : LOW ;
112
115
}
113
116
114
117
#ifdef __cplusplus
0 commit comments