2024-07-31 15:36:57 -04:00
|
|
|
#ifndef __CONFIGULATOR_H__
|
|
|
|
#define __CONFIGULATOR_H__
|
|
|
|
|
2024-07-31 15:51:12 -04:00
|
|
|
#include <stdint.h>
|
2024-07-31 15:36:57 -04:00
|
|
|
|
|
|
|
#define CFGLR_BACKENDS_MAX (04)
|
|
|
|
#define CFGLR_ELEMENTS_MAX (04)
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CFGLR_DATATYPE_U8,
|
|
|
|
CFGLR_DATATYPE_I8,
|
|
|
|
CFGLR_DATATYPE_U16,
|
|
|
|
CFGLR_DATATYPE_I16,
|
|
|
|
CFGLR_DATATYPE_U32,
|
|
|
|
CFGLR_DATATYPE_I32,
|
|
|
|
CFGLR_DATATYPE_U64,
|
|
|
|
CFGLR_DATATYPE_I64,
|
|
|
|
CFGLR_DATATYPE_STR,
|
|
|
|
CFGLR_DATATYPE_BIN,
|
|
|
|
} cfglr_datatype_e;
|
|
|
|
|
|
|
|
typedef void (*cfglr_read_callback)(const char *key, void *out);
|
2024-07-31 15:51:12 -04:00
|
|
|
typedef void (*cfglr_write_callback)(const char *key, void *valoue, uint8_t length);
|
2024-07-31 15:36:57 -04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
cfglr_read_callback read;
|
|
|
|
cfglr_write_callback write;
|
|
|
|
} cfglr_data_handler_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *key;
|
2024-07-31 15:51:12 -04:00
|
|
|
uint8_t dirty;
|
2024-07-31 15:36:57 -04:00
|
|
|
cfglr_datatype_e datatype;
|
|
|
|
void *default_data;
|
|
|
|
void *data;
|
|
|
|
} cfglr_element_t;
|
|
|
|
|
|
|
|
#define CFGLR_ELEMENT(KEY, TYPE, DEFAULT) (cfglr_element_t){\
|
|
|
|
.key = KEY,\
|
|
|
|
.dirty = 1,\
|
|
|
|
.default_data = (void*)DEFAULT,\
|
|
|
|
.datatype = TYPE\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CFGLR_ELEMENT_U8(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_U8, DEFAULT)
|
|
|
|
|
|
|
|
typedef struct cfglr_backend cfglr_backend_t;
|
|
|
|
typedef struct cfglr_handle_struct cfglr_handle_t;
|
|
|
|
|
|
|
|
typedef void (*cfglr_backend_open_t)(cfglr_backend_t *backend, cfglr_handle_t *handle);
|
|
|
|
typedef void (*cfglr_backend_close_t)(cfglr_backend_t *backend, cfglr_handle_t *handle);
|
|
|
|
typedef void (*cfglr_backend_get_t)(cfglr_backend_t *backend, cfglr_element_t *element, cfglr_handle_t *handle);
|
|
|
|
|
|
|
|
struct cfglr_backend {
|
|
|
|
cfglr_backend_open_t open;
|
|
|
|
cfglr_backend_close_t close;
|
|
|
|
cfglr_backend_get_t get;
|
2024-07-31 15:51:12 -04:00
|
|
|
void *handle;
|
2024-07-31 15:36:57 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CFGLR_BACKEND(OPEN, CLOSE) {\
|
|
|
|
.open = OPEN,\
|
|
|
|
.close = CLOSE,\
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cfglr_handle_struct {
|
|
|
|
const char *namespace;
|
2024-07-31 15:51:12 -04:00
|
|
|
uint8_t store_defaults;
|
2024-07-31 15:36:57 -04:00
|
|
|
cfglr_backend_t backends[CFGLR_BACKENDS_MAX];
|
|
|
|
cfglr_element_t elements[CFGLR_ELEMENTS_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
uint8_t cfglr_init(cfglr_handle_t *handle);
|
|
|
|
uint8_t cfglr_fetch_data(cfglr_backend_t *backend, cfglr_element_t *element, cfglr_handle_t *handler);
|
|
|
|
|
2024-07-31 15:51:12 -04:00
|
|
|
#include "cfglr_nvs.h"
|
|
|
|
|
2024-07-31 15:36:57 -04:00
|
|
|
#endif//__CONFIGULATOR_H__
|