Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nordic: reduce sleep current by using SENSE feature for PinAlarm when possible #9534

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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