RTC_DATA_ATTR and struct

hellraise007
Posts: 16
Joined: Tue Aug 06, 2019 6:18 am

RTC_DATA_ATTR and struct

Postby hellraise007 » Thu Aug 22, 2019 9:18 am

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;
};

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: RTC_DATA_ATTR and struct

Postby ESP_Sprite » Fri Aug 23, 2019 1:55 am

Yes.

hellraise007
Posts: 16
Joined: Tue Aug 06, 2019 6:18 am

Re: RTC_DATA_ATTR and struct

Postby hellraise007 » Fri Aug 23, 2019 10:26 am

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.

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: RTC_DATA_ATTR and struct

Postby ESP_Sprite » Mon Aug 26, 2019 3:56 am

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;

Who is online

Users browsing this forum: No registered users and 81 guests