Skip to content

Commit 31c36c6

Browse files
committed
pbio/sys/storage_settings: Use bit flags instead of bit fields.
Bit fields are not guaranteed to have the same order if we write them to disk and read them back with another firmware build.
1 parent 7887e97 commit 31c36c6

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

lib/pbio/include/pbsys/storage_settings.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@
1919
#include <pbsys/config.h>
2020

2121
/**
22-
* System settings. All data types are little-endian.
22+
* System setting flags
2323
*/
24-
typedef struct _pbsys_storage_settings_t {
25-
#if PBSYS_CONFIG_BLUETOOTH_TOGGLE
24+
typedef enum {
2625
/**
27-
* User has enabled Bluetooth Low Energy.
26+
* Bluetooth is enabled by the user (defaults to true).
2827
*/
29-
bool bluetooth_ble_user_enabled : 1;
30-
#endif // PBSYS_CONFIG_BLUETOOTH_TOGGLE
28+
PBSYS_STORAGE_SETTINGS_FLAGS_BLUETOOTH_ENABLED = (1 << 0),
29+
} pbsys_storage_settings_flags_t;
30+
31+
/**
32+
* System settings. All data types are little-endian.
33+
*/
34+
typedef struct _pbsys_storage_settings_t {
35+
uint32_t flags;
3136
} pbsys_storage_settings_t;
3237

3338
#if PBSYS_CONFIG_STORAGE

lib/pbio/sys/storage_settings.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
void pbsys_storage_set_default_settings(pbsys_storage_settings_t *settings) {
2727
#if PBSYS_CONFIG_BLUETOOTH_TOGGLE
28-
settings->bluetooth_ble_user_enabled = true;
28+
settings->flags |= PBSYS_STORAGE_SETTINGS_FLAGS_BLUETOOTH_ENABLED;
2929
#endif
3030
}
3131

@@ -35,7 +35,7 @@ bool pbsys_storage_settings_bluetooth_enabled(void) {
3535
if (!settings) {
3636
return true;
3737
}
38-
return settings->bluetooth_ble_user_enabled;
38+
return settings->flags & PBSYS_STORAGE_SETTINGS_FLAGS_BLUETOOTH_ENABLED;
3939
#else
4040
return true;
4141
#endif // PBSYS_CONFIG_BLUETOOTH_TOGGLE
@@ -55,13 +55,13 @@ void pbsys_storage_settings_bluetooth_enabled_request_toggle(void) {
5555
|| pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_LE)
5656
|| pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_PERIPHERAL)
5757
// Ignore if last request not yet finished processing.
58-
|| settings->bluetooth_ble_user_enabled != pbdrv_bluetooth_is_ready()
58+
|| pbsys_storage_settings_bluetooth_enabled() != pbdrv_bluetooth_is_ready()
5959
) {
6060
return;
6161
}
6262

6363
// Toggle the user enabled state and poll process to take action.
64-
settings->bluetooth_ble_user_enabled = !settings->bluetooth_ble_user_enabled;
64+
settings->flags ^= PBSYS_STORAGE_SETTINGS_FLAGS_BLUETOOTH_ENABLED;
6565
pbsys_storage_request_write();
6666
pbsys_bluetooth_process_poll();
6767
#endif

0 commit comments

Comments
 (0)