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)
|
2024-11-15 14:41:07 -05:00
|
|
|
#define CFGLR_ELEMENTS_MAX (12)
|
2024-08-01 16:34:38 -04:00
|
|
|
#define CFGLR_SIGNALERS_MAX (04)
|
2024-07-31 15:36:57 -04:00
|
|
|
|
|
|
|
typedef enum {
|
2024-08-01 16:34:38 -04:00
|
|
|
CFGLR_SIGNAL_LOADED = 0,
|
|
|
|
CFGLR_SIGNAL_CHANGE,
|
|
|
|
CFGLR_SIGNAL_DELETE,
|
|
|
|
} cfglr_signal_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CFGLR_DATATYPE_U8 = 0,
|
2024-07-31 15:36:57 -04:00
|
|
|
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;
|
|
|
|
|
2024-08-01 16:34:38 -04:00
|
|
|
#define CFGLR_DATATYPE_COUNT (uint8_t)(CFGLR_DATATYPE_BIN - CFGLR_DATATYPE_U8)
|
2024-07-31 15:36:57 -04:00
|
|
|
|
2024-08-01 16:34:38 -04:00
|
|
|
typedef struct cfglr_signaler cfglr_signaler_t;
|
|
|
|
typedef struct cfglr_handle_struct cfglr_handle_t;
|
2024-11-15 14:41:07 -05:00
|
|
|
typedef struct cfglr_element cfglr_element_t;
|
2024-08-01 16:34:38 -04:00
|
|
|
|
2024-11-15 14:41:07 -05:00
|
|
|
typedef void (*cfglr_signaler_init_t)(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_handle_t *handle);
|
2024-08-01 16:34:38 -04:00
|
|
|
typedef void (*cfglr_signaler_dispatch_t)(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig);
|
|
|
|
|
|
|
|
struct cfglr_signaler {
|
2024-11-15 14:41:07 -05:00
|
|
|
const char *key;
|
2024-08-01 16:34:38 -04:00
|
|
|
cfglr_signaler_dispatch_t dispatch;
|
|
|
|
cfglr_signaler_init_t init;
|
|
|
|
void *handle;
|
|
|
|
};
|
|
|
|
|
2024-11-15 14:41:07 -05:00
|
|
|
struct cfglr_element {
|
|
|
|
const char *key;
|
|
|
|
uint8_t dirty;
|
|
|
|
uint8_t signaler_count;
|
|
|
|
cfglr_datatype_e datatype;
|
|
|
|
// TODO precalcualte sizes in an array and use datatype enum to look up
|
|
|
|
uint8_t datatype_size;
|
|
|
|
void *data;
|
|
|
|
void *default_data;
|
|
|
|
cfglr_handle_t *handle;
|
|
|
|
cfglr_signaler_t signalers[CFGLR_SIGNALERS_MAX];
|
|
|
|
};
|
|
|
|
|
2024-08-01 16:34:38 -04:00
|
|
|
#define CFGLR_ELEMENT(KEY, TYPE, DEFAULT, SIZE) (cfglr_element_t){\
|
2024-07-31 15:36:57 -04:00
|
|
|
.key = KEY,\
|
2024-08-01 16:34:38 -04:00
|
|
|
.datatype = TYPE,\
|
|
|
|
.datatype_size = SIZE,\
|
2024-07-31 15:36:57 -04:00
|
|
|
.default_data = (void*)DEFAULT,\
|
|
|
|
}
|
|
|
|
|
2024-08-01 16:34:38 -04:00
|
|
|
#define CFGLR_ELEMENT_U8(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_U8, DEFAULT, sizeof(uint8_t))
|
|
|
|
#define CFGLR_ELEMENT_I8(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_I8, DEFAULT, sizeof(int8_t))
|
2024-11-15 14:41:07 -05:00
|
|
|
#define CFGLR_ELEMENT_U16(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_U16, DEFAULT, sizeof(uint16_t))
|
|
|
|
#define CFGLR_ELEMENT_I16(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_I16, DEFAULT, sizeof(int16_t))
|
|
|
|
#define CFGLR_ELEMENT_U32(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_U32, DEFAULT, sizeof(uint32_t))
|
|
|
|
#define CFGLR_ELEMENT_I32(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_I32, DEFAULT, sizeof(int32_t))
|
2024-08-01 16:34:38 -04:00
|
|
|
#define CFGLR_ELEMENT_U64(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_U64, DEFAULT, sizeof(uint64_t))
|
|
|
|
#define CFGLR_ELEMENT_I64(KEY, DEFAULT) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_I64, DEFAULT, sizeof(int64_t))
|
2024-07-31 15:36:57 -04:00
|
|
|
|
|
|
|
typedef struct cfglr_backend cfglr_backend_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);
|
2024-08-01 16:34:38 -04:00
|
|
|
typedef uint16_t (*cfglr_backend_get_t)(cfglr_backend_t *backend, cfglr_element_t *element, cfglr_handle_t *handle);
|
|
|
|
typedef uint16_t (*cfglr_backend_set_t)(cfglr_backend_t *backend, cfglr_element_t *element, cfglr_handle_t *handle);
|
|
|
|
|
2024-11-15 14:41:07 -05:00
|
|
|
uint16_t cfglr_commit(cfglr_element_t *element);
|
2024-08-01 16:34:38 -04:00
|
|
|
uint16_t cfglr_commit_data(cfglr_backend_t *backend, cfglr_element_t *element, cfglr_handle_t *handle);
|
2024-07-31 15:36:57 -04:00
|
|
|
|
|
|
|
struct cfglr_backend {
|
|
|
|
cfglr_backend_open_t open;
|
|
|
|
cfglr_backend_close_t close;
|
|
|
|
cfglr_backend_get_t get;
|
2024-08-01 16:34:38 -04:00
|
|
|
cfglr_backend_set_t set;
|
2024-07-31 15:51:12 -04:00
|
|
|
void *handle;
|
2024-07-31 15:36:57 -04:00
|
|
|
};
|
|
|
|
|
2024-08-01 16:34:38 -04:00
|
|
|
#define CFGLR_BACKEND(OPEN, CLOSE, GET, SET) {\
|
2024-07-31 15:36:57 -04:00
|
|
|
.open = OPEN,\
|
|
|
|
.close = CLOSE,\
|
2024-08-01 16:34:38 -04:00
|
|
|
.get = GET,\
|
|
|
|
.set = SET,\
|
2024-07-31 15:36:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct cfglr_handle_struct {
|
|
|
|
const char *namespace;
|
2024-08-01 16:34:38 -04:00
|
|
|
uint8_t store_default;
|
|
|
|
uint8_t backend_count;
|
|
|
|
uint8_t element_count;
|
2024-11-15 14:41:07 -05:00
|
|
|
cfglr_backend_t backend;
|
2024-07-31 15:36:57 -04:00
|
|
|
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-08-01 16:34:38 -04:00
|
|
|
#include "cfglr_signaler_idf_event.h"
|
2024-11-15 14:41:07 -05:00
|
|
|
#include "cfglr_signaler_lvgl.h"
|
2024-07-31 15:51:12 -04:00
|
|
|
|
2024-07-31 15:36:57 -04:00
|
|
|
#endif//__CONFIGULATOR_H__
|