Skip to content

Commit 4955379

Browse files
committed
nordic: use SENSE feature for PinAlarm when possible
1 parent 830294e commit 4955379

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ports/nordic/common-hal/alarm/pin/PinAlarm.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,16 @@ void alarm_pin_pinalarm_reset(void) {
123123
static void configure_pins_for_sleep(void) {
124124
_pinhandler_gpiote_count = 0;
125125

126+
int n_pin_alarms = __builtin_popcountll(high_alarms) + __builtin_popcountll(low_alarms);
127+
const int MAX_N_PIN_ALARMS_FOR_SENSE_FEATURE = 2;
128+
126129
nrfx_gpiote_in_config_t cfg = {
127130
.sense = NRF_GPIOTE_POLARITY_TOGGLE,
128131
.pull = NRF_GPIO_PIN_PULLUP,
129132
.is_watcher = false,
130-
.hi_accuracy = true,
133+
// hi_accuracy = False reduces sleep current by a factor of ~10x by using the SENSE feature,
134+
// but only works if not more than MAX_N_PIN_ALARMS_FOR_SENSE_FEATURE pin alarms are used.
135+
.hi_accuracy = (n_pin_alarms > MAX_N_PIN_ALARMS_FOR_SENSE_FEATURE),
131136
.skip_gpio_setup = false
132137
};
133138
for (size_t i = 0; i < 64; ++i) {

0 commit comments

Comments
 (0)