add buttons/rotary/ir/BT sink in sleep + battery low-voltage

This commit is contained in:
philippe44
2023-09-16 17:55:41 -07:00
parent f4c0a91e84
commit bb185d76dc
10 changed files with 199 additions and 71 deletions

View File

@@ -103,11 +103,11 @@ const struct adac_s *adac = &dac_external;
static log_level loglevel;
static uint32_t stopped_time;
static uint32_t i2s_idle_since;
static void (*pseudo_idle_chain)(uint32_t);
static bool (*slimp_handler_chain)(u8_t *data, int len);
static bool jack_mutes_amp;
static bool running, isI2SStarted, ended, i2s_stats;
static bool running, isI2SStarted, ended;
static i2s_config_t i2s_config;
static u8_t *obuf;
static frames_t oframes;
@@ -128,7 +128,7 @@ DECLARE_ALL_MIN_MAX;
static int _i2s_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, u8_t flags,
s32_t cross_gain_in, s32_t cross_gain_out, ISAMPLE_T **cross_ptr);
static void output_thread_i2s(void *arg);
static void i2s_idle(uint32_t now);
static void i2s_stats(uint32_t now);
static void spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, size_t *count);
static void (*jack_handler_chain)(bool inserted);
@@ -202,6 +202,13 @@ static void set_amp_gpio(int gpio, char *value) {
}
#endif
/****************************************************************************************
* Get inactivity callback
*/
static uint32_t i2s_idle_callback(void) {
return output.state <= OUTPUT_STOPPED ? pdTICKS_TO_MS(xTaskGetTickCount()) - i2s_idle_since : 0;
}
/****************************************************************************************
* Set pin from config string
*/
@@ -418,11 +425,15 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
// do we want stats
p = config_alloc_get_default(NVS_TYPE_STR, "stats", "n", 0);
i2s_stats = p && (*p == '1' || *p == 'Y' || *p == 'y');
if (p && (*p == '1' || *p == 'Y' || *p == 'y')) {
pseudo_idle_chain = pseudo_idle_svc;
pseudo_idle_svc = i2s_stats;
}
free(p);
pseudo_idle_chain = pseudo_idle_svc;
pseudo_idle_svc = i2s_idle;
// register a callback for inactivity
i2s_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
services_sleep_setsleeper(i2s_idle_callback);
// create task as a FreeRTOS task but uses stack in internal RAM
{
@@ -433,7 +444,6 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
}
}
/****************************************************************************************
* Terminate DAC output
*/
@@ -497,8 +507,7 @@ static void output_thread_i2s(void *arg) {
uint32_t fullness = gettime_ms();
bool synced;
output_state state = OUTPUT_OFF - 1;
stopped_time = pdMS_TO_TICKS(xTaskGetTickCount());
while (running) {
TIME_MEASUREMENT_START(timer_start);
@@ -513,7 +522,7 @@ static void output_thread_i2s(void *arg) {
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) {
stopped_time = pdMS_TO_TICKS(xTaskGetTickCount());
i2s_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
adac->speaker(false);
led_blink(LED_GREEN, 200, 1000);
} else if (output.state == OUTPUT_RUNNING) {
@@ -640,17 +649,14 @@ static void output_thread_i2s(void *arg) {
/****************************************************************************************
* stats output callback
*/
static void i2s_idle(uint32_t now) {
static void i2s_stats(uint32_t now) {
static uint32_t last;
// first chain to next handler
if (pseudo_idle_chain) pseudo_idle_chain(now);
// call the sleep mamanger
if (output.state <= OUTPUT_STOPPED) services_sleep_callback(now - stopped_time);
// then see if we need to act
if (!i2s_stats || output.state <= OUTPUT_STOPPED || now < last + STATS_PERIOD_MS) return;
if (output.state <= OUTPUT_STOPPED || now < last + STATS_PERIOD_MS) return;
last = now;
LOG_INFO( "Output State: %d, current sample rate: %d, bytes per frame: %d", output.state, output.current_sample_rate, BYTES_PER_FRAME);