mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 12:07:09 +03:00
big merge
This commit is contained in:
@@ -43,6 +43,7 @@ sure that using rate_delay would fix that
|
||||
#include "led.h"
|
||||
#include "monitor.h"
|
||||
#include "platform_config.h"
|
||||
#include "gpio_exp.h"
|
||||
#include "accessors.h"
|
||||
#include "equalizer.h"
|
||||
#include "globdefs.h"
|
||||
@@ -129,8 +130,13 @@ static bool handler(u8_t *data, int len){
|
||||
jack_mutes_amp = pkt->config == 0;
|
||||
config_set_value(NVS_TYPE_STR, "jack_mutes_amp", jack_mutes_amp ? "y" : "n");
|
||||
|
||||
if (jack_mutes_amp && jack_inserted_svc()) adac->speaker(false);
|
||||
else adac->speaker(true);
|
||||
if (jack_mutes_amp && jack_inserted_svc()) {
|
||||
adac->speaker(false);
|
||||
if (amp_control.gpio != -1) gpio_set_level_x(amp_control.gpio, !amp_control.active);
|
||||
} else {
|
||||
adac->speaker(true);
|
||||
if (amp_control.gpio != -1) gpio_set_level_x(amp_control.gpio, amp_control.active);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO("got AUDO %02x", pkt->config);
|
||||
@@ -151,13 +157,12 @@ static void jack_handler(bool inserted) {
|
||||
// jack detection bounces a bit but that seems fine
|
||||
if (jack_mutes_amp) {
|
||||
LOG_INFO("switching amplifier %s", inserted ? "OFF" : "ON");
|
||||
if (inserted) adac->speaker(false);
|
||||
else adac->speaker(true);
|
||||
adac->speaker(!inserted);
|
||||
if (amp_control.gpio != -1) gpio_set_level_x(amp_control.gpio, inserted ? !amp_control.active : amp_control.active);
|
||||
}
|
||||
|
||||
// activate headset
|
||||
if (inserted) adac->headset(true);
|
||||
else adac->headset(false);
|
||||
adac->headset(inserted);
|
||||
|
||||
// and chain if any
|
||||
if (jack_handler_chain) (jack_handler_chain)(inserted);
|
||||
@@ -173,9 +178,9 @@ static void set_amp_gpio(int gpio, char *value) {
|
||||
amp_control.gpio = gpio;
|
||||
if ((p = strchr(value, ':')) != NULL) amp_control.active = atoi(p + 1);
|
||||
|
||||
gpio_pad_select_gpio(amp_control.gpio);
|
||||
gpio_set_direction(amp_control.gpio, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(amp_control.gpio, !amp_control.active);
|
||||
gpio_pad_select_gpio_x(amp_control.gpio);
|
||||
gpio_set_direction_x(amp_control.gpio, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level_x(amp_control.gpio, !amp_control.active);
|
||||
|
||||
LOG_INFO("setting amplifier GPIO %d (active:%d)", amp_control.gpio, amp_control.active);
|
||||
}
|
||||
@@ -185,11 +190,10 @@ static void set_amp_gpio(int gpio, char *value) {
|
||||
* Set pin from config string
|
||||
*/
|
||||
static void set_i2s_pin(char *config, i2s_pin_config_t *pin_config) {
|
||||
char *p;
|
||||
pin_config->bck_io_num = pin_config->ws_io_num = pin_config->data_out_num = pin_config->data_in_num = -1;
|
||||
if ((p = strcasestr(config, "bck")) != NULL) pin_config->bck_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "ws")) != NULL) pin_config->ws_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(config, "do")) != NULL) pin_config->data_out_num = atoi(strchr(p, '=') + 1);
|
||||
PARSE_PARAM(config, "bck", '=', pin_config->bck_io_num);
|
||||
PARSE_PARAM(config, "ws", '=', pin_config->ws_io_num);
|
||||
PARSE_PARAM(config, "do", '=', pin_config->data_out_num);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
@@ -343,12 +347,13 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
||||
jack_handler_chain = jack_handler_svc;
|
||||
jack_handler_svc = jack_handler;
|
||||
|
||||
parse_set_GPIO(set_amp_gpio);
|
||||
|
||||
if (jack_mutes_amp && jack_inserted_svc()) adac->speaker(false);
|
||||
else adac->speaker(true);
|
||||
|
||||
adac->headset(jack_inserted_svc());
|
||||
|
||||
parse_set_GPIO(set_amp_gpio);
|
||||
|
||||
// create task as a FreeRTOS task but uses stack in internal RAM
|
||||
{
|
||||
@@ -365,10 +370,11 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
||||
|
||||
// memory still used but at least task is not created
|
||||
if (stats) {
|
||||
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
|
||||
// we allocate TCB but stack is static to avoid SPIRAM fragmentation
|
||||
StaticTask_t* xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
static EXT_RAM_ATTR StackType_t xStack[STAT_STACK_SIZE] __attribute__ ((aligned (4)));
|
||||
stats_task = xTaskCreateStatic( (TaskFunction_t) output_thread_i2s_stats, "output_i2s_sts", STAT_STACK_SIZE,
|
||||
NULL, ESP_TASK_PRIO_MIN, xStack, &xTaskBuffer);
|
||||
NULL, ESP_TASK_PRIO_MIN, xStack, xTaskBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,13 +455,16 @@ static void output_thread_i2s(void *arg) {
|
||||
LOG_INFO("Output state is %d", output.state);
|
||||
if (output.state == OUTPUT_OFF) {
|
||||
led_blink(LED_GREEN, 100, 2500);
|
||||
if (amp_control.gpio != -1) gpio_set_level(amp_control.gpio, !amp_control.active);
|
||||
if (amp_control.gpio != -1) gpio_set_level_x(amp_control.gpio, !amp_control.active);
|
||||
LOG_INFO("switching off amp GPIO %d", amp_control.gpio);
|
||||
} else if (output.state == OUTPUT_STOPPED) {
|
||||
adac->speaker(false);
|
||||
led_blink(LED_GREEN, 200, 1000);
|
||||
} else if (output.state == OUTPUT_RUNNING) {
|
||||
if (!jack_mutes_amp || !jack_inserted_svc()) adac->speaker(true);
|
||||
if (!jack_mutes_amp || !jack_inserted_svc()) {
|
||||
if (amp_control.gpio != -1) gpio_set_level_x(amp_control.gpio, amp_control.active);
|
||||
adac->speaker(true);
|
||||
}
|
||||
led_on(LED_GREEN);
|
||||
}
|
||||
}
|
||||
@@ -513,7 +522,6 @@ static void output_thread_i2s(void *arg) {
|
||||
i2s_zero_dma_buffer(CONFIG_I2S_NUM);
|
||||
i2s_start(CONFIG_I2S_NUM);
|
||||
adac->power(ADAC_ON);
|
||||
if (amp_control.gpio != -1) gpio_set_level(amp_control.gpio, amp_control.active);
|
||||
}
|
||||
|
||||
// this does not work well as set_sample_rates resets the fifos (and it's too early)
|
||||
|
||||
Reference in New Issue
Block a user