make targets "loadable"

This commit is contained in:
Philippe G
2022-01-20 17:30:36 -08:00
parent 964b94fa1e
commit dbdd0739db
10 changed files with 72 additions and 30 deletions

View File

@@ -1,13 +1,4 @@
# This should be made a pure CMake component but as CMake is even
# more shitty under Windows, backslash in path screws it all
if(CONFIG_MUSE)
message("Compiling for MUSE")
set(src_dirs "muse")
else()
set(src_dirs ".")
endif()
idf_component_register( SRC_DIRS ${src_dirs}
idf_component_register( SRC_DIRS . muse
INCLUDE_DIRS .
PRIV_REQUIRES services
)

View File

@@ -1,3 +0,0 @@
// weak should do the job but it does not...
__attribute__((weak)) void target_init(void) {
}

View File

@@ -10,6 +10,7 @@
//#include <driver/adc.h>
#include "driver/rmt.h"
#include "monitor.h"
#include "targets.h"
/////////////////////////////////////////////////////////////////
//*********************** NeoPixels ***************************
@@ -44,11 +45,15 @@ static const char TAG[] = "muse";
static void (*battery_handler_chain)(float value);
static void battery_svc(float value);
static bool init(void);
void target_init(void) {
const struct target_s target_muse = { "muse", init };
static bool init(void) {
battery_handler_chain = battery_handler_svc;
battery_handler_svc = battery_svc;
ESP_LOGI(TAG, "Initializing for Muse");
return true;
}
static void battery_svc(float value) {

View File

@@ -0,0 +1,11 @@
#include "string.h"
#include "targets.h"
const struct target_s *target_set[] = { &target_muse, NULL };
void target_init(char *target) {
for (int i = 0; target_set[i]; i++) if (strcasestr(target_set[i]->model, target)) {
target_set[i]->init();
break;
}
}

View File

@@ -0,0 +1,22 @@
/*
* Squeezelite for esp32
*
* (c) Sebastien 2019
* Philippe G. 2019, philippe_44@outlook.com
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*
*/
#pragma once
#include "stddef.h"
#include "stdbool.h"
struct target_s {
char *model;
bool (*init)(void);
};
extern const struct target_s target_muse;