Skip to content

Commit

Permalink
Merge pull request #9534 from Sola85/nordic-use-sense-for-pinalarm
Browse files Browse the repository at this point in the history
nordic: reduce sleep current by using SENSE feature for PinAlarm when possible
  • Loading branch information
tannewt authored Aug 19, 2024
2 parents c53a0cb + 4955379 commit 5e4cecd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ports/nordic/common-hal/alarm/pin/PinAlarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,16 @@ void alarm_pin_pinalarm_reset(void) {
static void configure_pins_for_sleep(void) {
_pinhandler_gpiote_count = 0;

int n_pin_alarms = __builtin_popcountll(high_alarms) + __builtin_popcountll(low_alarms);
const int MAX_N_PIN_ALARMS_FOR_SENSE_FEATURE = 2;

nrfx_gpiote_in_config_t cfg = {
.sense = NRF_GPIOTE_POLARITY_TOGGLE,
.pull = NRF_GPIO_PIN_PULLUP,
.is_watcher = false,
.hi_accuracy = true,
// hi_accuracy = False reduces sleep current by a factor of ~10x by using the SENSE feature,
// but only works if not more than MAX_N_PIN_ALARMS_FOR_SENSE_FEATURE pin alarms are used.
.hi_accuracy = (n_pin_alarms > MAX_N_PIN_ALARMS_FOR_SENSE_FEATURE),
.skip_gpio_setup = false
};
for (size_t i = 0; i < 64; ++i) {
Expand Down

0 comments on commit 5e4cecd

Please sign in to comment.