forked from sle118/squeezelite-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,181 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
idf_component_register(SRC_DIRS . | ||
INCLUDE_DIRS . | ||
PRIV_REQUIRES freertos pthread squeezelite services codecs tools display wifi-manager | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <ctype.h> | ||
#include <stdlib.h> | ||
|
||
#include "nvs.h" | ||
#include "esp_netif.h" | ||
#include "esp_log.h" | ||
#include "esp_console.h" | ||
#include "esp_pthread.h" | ||
#include "esp_system.h" | ||
#include "freertos/timers.h" | ||
#include "platform_config.h" | ||
#include "input_i2s.h" | ||
//#include "audio_controls.h" | ||
#include "display.h" | ||
#include "accessors.h" | ||
#include "network_services.h" | ||
|
||
static EXT_RAM_ATTR struct adc_cb_s { | ||
adc_cmd_vcb_t cmd; | ||
adc_data_cb_t data; | ||
} adc_cbs; | ||
|
||
static const char TAG[] = "adc_sink"; | ||
|
||
static struct adc_ctx_s *adc_i2s; | ||
static adc_cmd_vcb_t cmd_handler_chain; | ||
|
||
void adc_linein_start(uint16_t sample_rate) { | ||
ESP_LOGI(TAG, "ADC Start (setup)"); | ||
adc_cmd(adc_i2s, ADC_SETUP, sample_rate); | ||
ESP_LOGI(TAG, "ADC Start (play)"); | ||
adc_cmd(adc_i2s, ADC_PLAY, NULL); | ||
ESP_LOGI(TAG, "ADC Start (done)"); | ||
|
||
} | ||
|
||
/**************************************************************************************** | ||
* Command handler | ||
*/ | ||
static bool cmd_handler(adc_event_t event, ...) { | ||
va_list args; | ||
|
||
va_start(args, event); | ||
|
||
// handle audio event and stop if forbidden | ||
if (!cmd_handler_chain(event, args)) { | ||
va_end(args); | ||
return false; | ||
} | ||
|
||
// now handle events for display | ||
switch(event) { | ||
case ADC_SETUP: | ||
ESP_LOGI(TAG, "ADC Setup"); | ||
displayer_control(DISPLAYER_ACTIVATE, "ADC INPUT ACTIVE", true); | ||
displayer_artwork(NULL); | ||
break; | ||
case ADC_PLAY: | ||
ESP_LOGI(TAG, "ADC Play"); | ||
// control it internally | ||
//displayer_control(DISPLAYER_TIMER_RUN); | ||
displayer_control(DISPLAYER_SHUTDOWN); // hand back to lms | ||
break; | ||
case ADC_STALLED: | ||
ESP_LOGI(TAG, "ADC Stalled"); | ||
adc_abort(adc_i2s); | ||
displayer_control(DISPLAYER_SHUTDOWN); | ||
break; | ||
|
||
default: | ||
ESP_LOGI(TAG, "ADC Unknown: %d", event); | ||
break; | ||
} | ||
|
||
va_end(args); | ||
|
||
return true; | ||
} | ||
|
||
/**************************************************************************************** | ||
* Airplay sink de-initialization | ||
*/ | ||
void adc_sink_deinit(void) { | ||
adc_delete(adc_i2s); | ||
ESP_LOGI(TAG, "deinit ADC"); | ||
} | ||
|
||
/**************************************************************************************** | ||
* ADC sink startup | ||
*/ | ||
static void adc_sink_start(nm_state_t state_id, int sub_state) { | ||
const char *hostname; | ||
|
||
cmd_handler_chain = adc_cbs.cmd; | ||
network_get_hostname(&hostname); | ||
|
||
ESP_LOGI(TAG, "starting ADC on host %s", hostname); | ||
|
||
adc_i2s = adc_create(cmd_handler, adc_cbs.data); | ||
} | ||
|
||
/**************************************************************************************** | ||
* ADC sink initialization | ||
*/ | ||
void adc_sink_init(adc_cmd_vcb_t cmd_cb, adc_data_cb_t data_cb) { | ||
adc_cbs.cmd = cmd_cb; | ||
adc_cbs.data = data_cb; | ||
|
||
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE, WIFI_CONNECTED_STATE, "adc_sink_start", adc_sink_start); | ||
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE, ETH_ACTIVE_CONNECTED_STATE, "adc_sink_start", adc_sink_start); | ||
} | ||
|
||
/**************************************************************************************** | ||
* ADC forced disconnection | ||
*/ | ||
void adc_disconnect(void) { | ||
ESP_LOGI(TAG, "forced disconnection"); | ||
displayer_control(DISPLAYER_SHUTDOWN); | ||
adc_cmd(adc_i2s, ADC_CLOSE, NULL); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
This example code is in the Public Domain (or CC0 licensed, at your option.) | ||
Unless required by applicable law or agreed to in writing, this | ||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
CONDITIONS OF ANY KIND, either express or implied. | ||
*/ | ||
|
||
#ifndef ADC_SINK_H | ||
#define ADC_SINK_H | ||
|
||
#include <stdint.h> | ||
#include <stdarg.h> | ||
|
||
|
||
typedef enum { ADC_SETUP, ADC_STREAM, ADC_PLAY, ADC_FLUSH, ADC_STOP, ADC_STALLED, | ||
ADC_TOGGLE, ADC_CLOSE, ADC_METADATA, ADC_GAIN } adc_event_t ; // , ADC_VOLUME_UP, ADC_VOLUME_DOWN, | ||
|
||
typedef bool (*adc_cmd_cb_t)(adc_event_t event, ...); | ||
typedef bool (*adc_cmd_vcb_t)(adc_event_t event, va_list args); | ||
typedef void (*adc_data_cb_t)(const uint8_t *data, size_t len); | ||
|
||
/** | ||
* @brief init sink mode (need to be provided) | ||
*/ | ||
void adc_sink_init(adc_cmd_vcb_t cmd_cb, adc_data_cb_t data_cb); | ||
|
||
/** | ||
* @brief deinit sink mode (need to be provided) | ||
*/ | ||
void adc_sink_deinit(void); | ||
|
||
/** | ||
* @brief force disconnection | ||
*/ | ||
void adc_disconnect(void); | ||
void adc_linein_start(uint16_t sample_rate); | ||
|
||
#endif /* ADC_SINK_H*/ |
Oops, something went wrong.