Page 1 of 1

RTC_DATA_ATTR and struct

Posted: Thu Aug 22, 2019 9:18 am
by hellraise007
Is it possible to store data under struct like the one below in RTC memory so I can retain the values of all the objects on wake up

Code: Select all

struct Button {
  const uint8_t PIN;
  volatile uint32_t numberKeyPresses;
  volatile bool pressed;
};

Re: RTC_DATA_ATTR and struct

Posted: Fri Aug 23, 2019 1:55 am
by ESP_Sprite
Yes.

Re: RTC_DATA_ATTR and struct

Posted: Fri Aug 23, 2019 10:26 am
by hellraise007
ESP_Sprite wrote:
Fri Aug 23, 2019 1:55 am
Yes.
Thanks for the reply. What is the correct syntax for this. This is illegal

Code: Select all

RTC_DATA_ATTR struct Button {
  const uint8_t PIN;
  volatile uint32_t numberKeyPresses;
  volatile bool pressed;
};

Code: Select all

struct Button {
  RTC_DATA_ATTR const uint8_t PIN;
  RTC_DATA_ATTR volatile uint32_t numberKeyPresses;
  RTC_DATA_ATTR volatile bool pressed;
};
I am not quite familiar with attributes.

Re: RTC_DATA_ATTR and struct

Posted: Mon Aug 26, 2019 3:56 am
by ESP_Sprite
Do it where you actually allocate memory for your data. Something like this (untested):

Code: Select all

struct Button {
  const uint8_t PIN;
  volatile uint32_t numberKeyPresses;
  volatile bool pressed;
};

RTC_DATA_ATTR  struct Button my_button;