mothercup/mcm-ddc-ble/inc/app_params.h

64 lines
2.1 KiB
C

/**
* @file app_params.h
* @brief Application parameter record stored in the APP_DATA flash region
* (0x01006000, 8KB reserved). Structured access only: parameters are
* read/modified by name through the "param" CLI command (UART and the
* BLE CLI read/write characteristic); no raw region access is exposed.
*/
#ifndef __APP_PARAMS_H__
#define __APP_PARAMS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/* Parameter record layout (stored at CAIIC_APP_DATA_ADDR) */
#define CAIIC_PARAMS_MAGIC 0xCA12DA7Au
#define CAIIC_PARAMS_LAYOUT_VER 1u
#define PARAM_LED1_BLINK_MS_MIN 50u
#define PARAM_LED1_BLINK_MS_MAX 10000u
#define PARAM_LED1_BLINK_MS_DEF 500u
#define PARAM_PWM_DUTY_PCT_MAX 100u
typedef struct
{
uint32_t magic; /* CAIIC_PARAMS_MAGIC */
uint32_t layout_ver; /* parameter layout version */
uint16_t led1_blink_ms; /* LED1 blink half period in ms */
uint16_t flags; /* reserved */
uint32_t pwm_duty_pct; /* PWM duty 0..100, stored only (no PWM output yet) */
uint32_t reserved[8]; /* future parameters */
uint32_t crc32; /* IEEE CRC32 over all fields above this one */
} caiic_params_t;
/**
* @brief Load the parameter record from flash; fall back to defaults in RAM
* when the record is missing/invalid (flash is left untouched until
* the first "param set"/"param save").
*/
void app_params_init(void);
/** Current RAM copy of the parameters (always valid after init). */
const caiic_params_t* app_params_get(void);
/** 1 when the on-flash record passed magic+CRC validation at init. */
uint8_t app_params_is_valid(void);
/** Restore factory defaults and program them to flash; 0 on success. */
uint8_t app_params_restore_defaults(void);
/** "appget": dump all parameters + record state (registered in cli_core.c). */
void AppParams_CmdAppget(int argc, char* argv[]);
/** "appset <led|pwm> <val>": modify one parameter and save it to flash. */
void AppParams_CmdAppset(int argc, char* argv[]);
#ifdef __cplusplus
}
#endif
#endif /* __APP_PARAMS_H__ */