Skip to content

Commit 7e4000f

Browse files
committed
Better code to shut down pins we do not use
1 parent 0b8f145 commit 7e4000f

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

variants/preonic/variant.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@ const uint32_t g_ADigitalPinMap[] =
6767
19, // D31 is P0.19 is PGOOD
6868
};
6969

70-
71-
void disableUnusedPin(uint8_t pin) {
72-
NRF_GPIO->PIN_CNF[pin] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) |
73-
(GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) |
74-
(GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos);
70+
void disableUnusedPin(NRF_GPIO_Type *port, uint8_t pin) {
71+
// Configure for lowest power consumption
72+
port->PIN_CNF[pin] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
73+
| ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
74+
| ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
75+
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
76+
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
7577
}
7678

7779

80+
81+
7882
void initVariant()
7983
{
8084
// Enable DC/DC converter for better power efficiency
@@ -89,23 +93,22 @@ void initVariant()
8993
// nrf_gpio_cfg_input(18, NRF_GPIO_PIN_PULLDOWN); // P0.18
9094

9195

92-
// Configure unused P0.xx pins
93-
disableUnusedPin(9); // P0.09
94-
disableUnusedPin(10); // P0.10
95-
disableUnusedPin(13); // P0.13
96-
disableUnusedPin(14); // P0.14
97-
disableUnusedPin(15); // P0.15
98-
disableUnusedPin(16); // P0.16
99-
disableUnusedPin(17); // P0.17
100-
disableUnusedPin(20); // P0.20
101-
102-
// Configure unused P1.xx pins
103-
disableUnusedPin(P1_BANK + 0); // P1.00
104-
disableUnusedPin(P1_BANK + 1); // P1.01
105-
disableUnusedPin(P1_BANK + 3); // P1.03
106-
disableUnusedPin(P1_BANK + 4); // P1.04
107-
disableUnusedPin(P1_BANK + 6); // P1.06
108-
96+
// Configure unused P0.xx pins
97+
disableUnusedPin(NRF_P0, 9); // P0.09
98+
disableUnusedPin(NRF_P0, 10); // P0.10
99+
disableUnusedPin(NRF_P0, 13); // P0.13
100+
disableUnusedPin(NRF_P0, 14); // P0.14
101+
disableUnusedPin(NRF_P0, 15); // P0.15
102+
disableUnusedPin(NRF_P0, 16); // P0.16
103+
disableUnusedPin(NRF_P0, 17); // P0.17
104+
disableUnusedPin(NRF_P0, 20); // P0.20
105+
106+
// Configure unused P1.xx pins
107+
disableUnusedPin(NRF_P1, 0); // P1.00
108+
disableUnusedPin(NRF_P1, 1); // P1.01
109+
disableUnusedPin(NRF_P1, 3); // P1.03
110+
disableUnusedPin(NRF_P1, 4); // P1.04
111+
disableUnusedPin(NRF_P1, 6); // P1.06
109112
// Disable debug interface if not actively debugging
110113
NRF_CLOCK->TRACECONFIG = 0;
111114

0 commit comments

Comments
 (0)