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

RTC-GPIO pin calculation incorrect #822

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions components/esp32/deep_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,24 @@ uint64_t esp_deep_sleep_get_ext1_wakeup_status()
}
uint32_t status = REG_GET_FIELD(RTC_CNTL_EXT_WAKEUP1_STATUS_REG, RTC_CNTL_EXT_WAKEUP1_STATUS);
// Translate bit map of RTC IO numbers into the bit map of GPIO numbers
uint64_t gpio_mask = 0;
for (int gpio = 0; gpio < GPIO_PIN_COUNT; ++gpio) {
uint64_t gpio_mask = 1;
uint64_t gpio_return = 0;
for (unsigned int gpio = 0; gpio < GPIO_PIN_COUNT; ++gpio) {

if(gpio > 0) {
gpio_mask <<= 0x1;
}

if (!RTC_GPIO_IS_VALID_GPIO(gpio)) {
continue;
}
int rtc_pin = rtc_gpio_desc[gpio].rtc_num;
if ((status & BIT(rtc_pin)) == 0) {
continue;
}
gpio_mask |= BIT(gpio);
Copy link
Member

@igrr igrr Jul 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be sufficient to replace this line with gpio_mask |= 1ULL << gpio; to fix the issue with GPIOs higher than 32?

Copy link
Contributor Author

@husigeza husigeza Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
According to my understanding the gpio_mask should show that which PIN caused the wakeup, with setting a relevant bit to 1. E.g.: the interrupt comes through GPIO Pin3, then gpio_mask (the return value) should look like: 0x0000000000001000, because 4th bit from the right (LSB) is associated with GPIO Pin 3. However with the current solution, the gpio_mask would look like the following: 0x0000000000001100. Is this the value the function should return ? If yes then sorry, I misunderstood the concept.
Even if I misunderstood the interpretation of the gpio_mask, a problem still exists with GPIO Pin 0: gpio_mask would be 0, even the interrupt has came through Pin 0, or even no interrupt came at all.

Cheers,
Geza

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If gpio = 0, BIT(0) = 1, and gpio_mask = 1. Are you sure you aren't misunderstanding the macro BIT? The patch does not seem like it would work. Igrr's suggestion seems right to fix gpio >= 32.

Copy link
Contributor Author

@husigeza husigeza Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, sorry I did not check what BIT() does when I replied to the first comment.
Actually my change exactly does the same what Igrr suggests just with an extra, unnecessary variable.
So in summary: I agree that the only change is necessary is which proposed by Igrr.

gpio_return |= gpio_mask;
}
return gpio_mask;
return gpio_return;
}

esp_deep_sleep_wakeup_cause_t esp_deep_sleep_get_wakeup_cause()
Expand Down