Skip to content

Commit 57c40ff

Browse files
authored
Refactoring Settings enumeration to be dynamically generated (#2135)
* Generate Settings data from py * Joining Make with the settings generator * Add to linking * WiP on editing settings * Fill out settings pages * Inject Settings packing * cpp guard settings.h * Format * Update settings.yaml
1 parent 5aa6515 commit 57c40ff

21 files changed

Lines changed: 2001 additions & 98 deletions

.github/workflows/push.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: apk add --no-cache gcc-riscv-none-elf g++-riscv-none-elf gcc-arm-none-eabi g++-arm-none-eabi newlib-riscv-none-elf newlib-arm-none-eabi findutils python3 py3-pip make git bash
3636

3737
- name: Install dependencies (python)
38-
run: python3 -m pip install --break-system-packages bdflib
38+
run: python3 -m pip install --break-system-packages bdflib pyyaml
3939

4040
- uses: actions/checkout@v6
4141
with:
@@ -82,8 +82,7 @@ jobs:
8282
- name: Install dependencies (apk)
8383
run: apk add --no-cache gcc-riscv-none-elf g++-riscv-none-elf gcc-arm-none-eabi g++-arm-none-eabi newlib-riscv-none-elf newlib-arm-none-eabi findutils python3 py3-pip make git bash musl-dev
8484
- name: Install dependencies (python)
85-
run: python3 -m pip install --break-system-packages bdflib
86-
85+
run: python3 -m pip install --break-system-packages bdflib pyyaml
8786
- uses: actions/checkout@v6
8887
with:
8988
submodules: true
@@ -149,7 +148,7 @@ jobs:
149148
submodules: true
150149

151150
- name: Install dependencies (python)
152-
run: python3 -m pip install --break-system-packages bdflib
151+
run: python3 -m pip install --break-system-packages bdflib pyyaml
153152

154153
- name: Run python tests
155154
run: ./Translations/make_translation_test.py
@@ -196,7 +195,7 @@ jobs:
196195
submodules: true
197196

198197
- name: Install dependencies (python)
199-
run: python3 -m pip install --break-system-packages bdflib flake8
198+
run: python3 -m pip install --break-system-packages bdflib pyyaml flake8
200199

201200
- name: Check python formatting with black
202201
run: black --diff --check Translations

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ DOCKER_FILE=$(CURDIR)/scripts/IronOS.Dockerfile
4646
DOCKER_DEPS=$(DOCKER_YML) $(DOCKER_FILE)
4747

4848
# compose docker-compose command
49-
DOCKER_CMD=$(DOCKER_BIN) -f $(DOCKER_YML) run --rm builder
49+
DOCKER_CMD=$(DOCKER_BIN) -f $(DOCKER_YML) run --rm builder
5050

5151
# MkDocs config
5252
MKDOCS_YML=$(CURDIR)/scripts/IronOS-mkdocs.yml

scripts/IronOS.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ARG APK_MISC="findutils make git diffutils zip"
2121
ARG APK_DEV="musl-dev clang bash clang-extra-tools shellcheck"
2222

2323
# PIP packages to check & test Python code, and generate docs
24-
ARG PIP_PKGS='bdflib flake8 pymdown-extensions mkdocs mkdocs-autolinks-plugin mkdocs-awesome-pages-plugin mkdocs-git-revision-date-plugin'
24+
ARG PIP_PKGS='bdflib flake8 pymdown-extensions mkdocs mkdocs-autolinks-plugin mkdocs-awesome-pages-plugin mkdocs-git-revision-date-plugin pyyaml'
2525

2626
# Install system packages using alpine package manager
2727
RUN apk add --no-cache ${APK_COMPS} ${APK_PYTHON} ${APK_MISC} ${APK_DEV}

source/Core/Inc/Settings.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define CORE_SETTINGS_H_
1414
#include <stdbool.h>
1515
#include <stdint.h>
16+
#ifdef __cplusplus
1617
#ifdef MODEL_Pinecilv2
1718
// Required settings reset for PR #1916
1819
#define SETTINGSVERSION (0x55AB) // This number is frozen, do not edit
@@ -81,6 +82,27 @@ enum SettingsOptions {
8182
SettingsOptionsLength = 56, // End marker
8283
};
8384

85+
// For every setting we need to store the min/max/increment values
86+
typedef struct {
87+
const uint16_t min; // Inclusive minimum value
88+
const uint16_t max; // Inclusive maximum value
89+
const uint16_t increment; // Standard increment
90+
const uint16_t defaultValue; // Default vaue after reset
91+
} SettingConstants;
92+
extern const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOptionsLength];
93+
/*
94+
* This struct must be a multiple of 2 bytes as it is saved / restored from
95+
* flash in uint16_t chunks
96+
*/
97+
typedef struct {
98+
uint16_t versionMarker;
99+
uint16_t length; // Length of valid bytes following
100+
uint16_t settingsValues[SettingsOptionsLength];
101+
// used to make this nicely "good enough" aligned to 32 bytes to make driver code trivial
102+
uint32_t padding;
103+
104+
} systemSettingsType;
105+
84106
typedef enum {
85107
OFF = 0, // Off (disabled)
86108
SLOW = 1, //
@@ -170,12 +192,14 @@ bool isLastSettingValue(const enum SettingsOptions option);
170192
void setSettingValue(const enum SettingsOptions option, const uint16_t newValue);
171193

172194
// Special access helpers, to reduce logic duplication
173-
uint8_t lookupVoltageLevel();
174-
uint16_t lookupHallEffectThreshold();
195+
uint8_t lookupVoltageLevel();
196+
uint16_t lookupHallEffectThreshold();
175197
#ifdef TIP_TYPE_SUPPORT
176198
const char *lookupTipName(); // Get the name string for the current soldering tip
177-
#endif /* TIP_TYPE_SUPPORT */
199+
#endif /* TIP_TYPE_SUPPORT */
178200
#ifdef BLE_ENABLED
179201
void setBluetoothLE(void);
180202
#endif /* BLE_ENABLED */
203+
#endif // c++ guard
204+
181205
#endif /* SETTINGS_H_ */

source/Core/Src/Settings.cpp

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -26,94 +26,9 @@ bool sanitiseSettings();
2626
#define QC_VOLTAGE_MAX 140
2727
#endif /* POW_QC_20V */
2828

29-
/*
30-
* This struct must be a multiple of 2 bytes as it is saved / restored from
31-
* flash in uint16_t chunks
32-
*/
33-
typedef struct {
34-
uint16_t versionMarker;
35-
uint16_t length; // Length of valid bytes following
36-
uint16_t settingsValues[SettingsOptionsLength];
37-
// used to make this nicely "good enough" aligned to 32 bytes to make driver code trivial
38-
uint32_t padding;
39-
40-
} systemSettingsType;
41-
42-
//~1024 is common programming size, setting threshold to be lower so we have warning
43-
static_assert(sizeof(systemSettingsType) < 512);
44-
4529
// char (*__kaboom)[sizeof(systemSettingsType)] = 1; // Uncomment to print size at compile time
4630
volatile systemSettingsType systemSettings;
4731

48-
// For every setting we need to store the min/max/increment values
49-
typedef struct {
50-
const uint16_t min; // Inclusive minimum value
51-
const uint16_t max; // Inclusive maximum value
52-
const uint16_t increment; // Standard increment
53-
const uint16_t defaultValue; // Default vaue after reset
54-
} SettingConstants;
55-
56-
static const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOptionsLength] = {
57-
//{ min, max, increment, default}
58-
{ MIN_TEMP_C, MAX_TEMP_F, 5, SOLDERING_TEMP}, // SolderingTemp
59-
{ MIN_TEMP_C, MAX_TEMP_F, 5, 150}, // SleepTemp
60-
{ 0, 15, 1, SLEEP_TIME}, // SleepTime
61-
{ 0, 4, 1, CUT_OUT_SETTING}, // MinDCVoltageCells
62-
{ 24, 38, 1, RECOM_VOL_CELL}, // MinVoltageCells
63-
{ 90, QC_VOLTAGE_MAX, 2, 90}, // QCIdealVoltage
64-
{ 0, MAX_ORIENTATION_MODE, 1, ORIENTATION_MODE}, // OrientationMode
65-
{ 0, 9, 1, SENSITIVITY}, // Sensitivity
66-
{ 0, 1, 1, ANIMATION_LOOP}, // AnimationLoop
67-
{ 0, settingOffSpeed_t::MAX_VALUE - 1, 1, ANIMATION_SPEED}, // AnimationSpeed
68-
{ 0, 3, 1, AUTO_START_MODE}, // AutoStartMode
69-
{ 0, 60, 1, SHUTDOWN_TIME}, // ShutdownTime
70-
{ 0, 1, 1, COOLING_TEMP_BLINK}, // CoolingTempBlink
71-
{ 0, 1, 1, DETAILED_IDLE}, // DetailedIDLE
72-
{ 0, 1, 1, DETAILED_SOLDERING}, // DetailedSoldering
73-
{ 0, (uint16_t)(HasFahrenheit ? 1 : 0), 1, TEMPERATURE_INF}, // TemperatureInF
74-
{ 0, 1, 1, DESCRIPTION_SCROLL_SPEED}, // DescriptionScrollSpeed
75-
{ 0, 2, 1, LOCKING_MODE}, // LockingMode
76-
{ 0, 99, 1, POWER_PULSE_DEFAULT}, // KeepAwakePulse
77-
{ 1, POWER_PULSE_WAIT_MAX, 1, POWER_PULSE_WAIT_DEFAULT}, // KeepAwakePulseWait
78-
{ 1, POWER_PULSE_DURATION_MAX, 1, POWER_PULSE_DURATION_DEFAULT}, // KeepAwakePulseDuration
79-
{ 360, 900, 1, VOLTAGE_DIV}, // VoltageDiv
80-
{ 0, MAX_TEMP_F, 10, BOOST_TEMP}, // BoostTemp
81-
{MIN_CALIBRATION_OFFSET, 2500, 1, CALIBRATION_OFFSET}, // CalibrationOffset
82-
{ 0, MAX_POWER_LIMIT, POWER_LIMIT_STEPS, POWER_LIMIT}, // PowerLimit
83-
{ 0, 1, 1, REVERSE_BUTTON_TEMP_CHANGE}, // ReverseButtonTempChangeEnabled
84-
{ 5, TEMP_CHANGE_LONG_STEP_MAX, 5, TEMP_CHANGE_LONG_STEP}, // TempChangeLongStep
85-
{ 1, TEMP_CHANGE_SHORT_STEP_MAX, 1, TEMP_CHANGE_SHORT_STEP}, // TempChangeShortStep
86-
{ 0, 9, 1, 7}, // HallEffectSensitivity
87-
{ 0, 9, 1, 0}, // AccelMissingWarningCounter
88-
{ 0, 9, 1, 0}, // PDMissingWarningCounter
89-
{ 0, 0xFFFF, 0, 41431 /*EN*/}, // UILanguage
90-
{ 0, 50, 1, 20}, // PDNegTimeout
91-
{ 0, 1, 1, 0}, // OLEDInversion
92-
{ MIN_BRIGHTNESS, MAX_BRIGHTNESS, BRIGHTNESS_STEP, DEFAULT_BRIGHTNESS}, // OLEDBrightness
93-
{ 0, 6, 1, 1}, // LOGOTime
94-
{ 0, 1, 1, 0}, // CalibrateCJC
95-
{ 0, 2, 1, 0}, // BluetoothLE
96-
{ 0, 2, 1, 0}, // USBPDMode
97-
{ 1, 5, 1, 4}, // ProfilePhases
98-
{ MIN_TEMP_C, MAX_TEMP_F, 5, 90}, // ProfilePreheatTemp
99-
{ 1, 10, 1, 1}, // ProfilePreheatSpeed
100-
{ MIN_TEMP_C, MAX_TEMP_F, 5, 130}, // ProfilePhase1Temp
101-
{ 10, 180, 5, 90}, // ProfilePhase1Duration
102-
{ MIN_TEMP_C, MAX_TEMP_F, 5, 140}, // ProfilePhase2Temp
103-
{ 10, 180, 5, 30}, // ProfilePhase2Duration
104-
{ MIN_TEMP_C, MAX_TEMP_F, 5, 165}, // ProfilePhase3Temp
105-
{ 10, 180, 5, 30}, // ProfilePhase3Duration
106-
{ MIN_TEMP_C, MAX_TEMP_F, 5, 140}, // ProfilePhase4Temp
107-
{ 10, 180, 5, 30}, // ProfilePhase4Duration
108-
{ MIN_TEMP_C, MAX_TEMP_F, 5, 90}, // ProfilePhase5Temp
109-
{ 10, 180, 5, 30}, // ProfilePhase5Duration
110-
{ 1, 10, 1, 2}, // ProfileCooldownSpeed
111-
{ 0, 12, 1, 0}, // HallEffectSleepTime
112-
{ 0, (tipType_t::TIP_TYPE_MAX - 1) > 0 ? (tipType_t::TIP_TYPE_MAX - 1) : 0, 1, 0}, // SolderingTipType
113-
{ 0, 1, 1, 0}, // ReverseButtonSettings
114-
};
115-
static_assert((sizeof(settingsConstants) / sizeof(SettingConstants)) == ((int)SettingsOptions::SettingsOptionsLength));
116-
11732
#ifdef BLE_ENABLED
11833
static int16_t bleValueOnEntry = -1;
11934

0 commit comments

Comments
 (0)