Is there a reason bool and float aren't supported in nvs_flash?

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Is there a reason bool and float aren't supported in nvs_flash?

Postby gtjoseph » Mon Jan 23, 2023 2:14 am

There doesn't seem to be an implementation for either bool or float in the nvs_flash component. Is there a reason?

bool is easy to represent as an integer of course but having a specific type for it is handy on read because you can translate the value to a 'true" or "false" string.

I added the necessary code in nvs_flash and it seemed to be trivial once I figured out that the enum values in nvs_type_t actually have special meanings (they tell nvs_page whether it's signed or unsigned, and the length).

Did I miss something that might cause problems?

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: Is there a reason bool and float aren't supported in nvs_flash?

Postby mbratch » Mon Jan 23, 2023 4:29 pm

It does seem a little arbitrary. Maybe the developers considered the integer types as being the most common (?).

I chased down various predefined functions and it seems that, under the hood, it ultimately treats each as a small binary object (bsob? haha) whose length is sizeof(T) where T is the type as determined by a generically defined function. So for bool or floats, as long as you are establishing the size of the data type properly, you should be fine.

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Re: Is there a reason bool and float aren't supported in nvs_flash?

Postby gtjoseph » Mon Jan 23, 2023 6:05 pm

The template for "is_integral" in nvs_handle.hpp needed to be split out to 3 separate cases because float isn't integral and even though bool is, the way the logic works it'd be resolved to signed-no, length 1 (0x01) NVS_TYPE_U8 .

Who is online

Users browsing this forum: No registered users and 115 guests