Ethernet + AirPlay fixes

This commit is contained in:
Philippe G
2021-10-30 12:05:46 -07:00
parent 1e45348e4a
commit a98b1d00b0
6 changed files with 131 additions and 6 deletions

View File

@@ -25,6 +25,11 @@
#define CONFIG_AIRPLAY_NAME "ESP32-AirPlay"
#endif
typedef struct {
raop_cmd_vcb_t cmd;
raop_data_cb_t data;
} raop_cb_t;
log_level raop_loglevel = lINFO;
log_level util_loglevel;
@@ -150,17 +155,27 @@ void raop_sink_deinit(void) {
}
/****************************************************************************************
* Airplay sink initialization
* Airplay sink startup
*/
void raop_sink_init(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
const char *hostname;
static bool raop_sink_start(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
const char *hostname = NULL;
char sink_name[64-6] = CONFIG_AIRPLAY_NAME;
tcpip_adapter_ip_info_t ipInfo;
tcpip_adapter_ip_info_t ipInfo = { };
struct in_addr host;
tcpip_adapter_if_t ifs[] = { TCPIP_ADAPTER_IF_ETH, TCPIP_ADAPTER_IF_STA, TCPIP_ADAPTER_IF_AP };
// get various IP info
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname);
for (int i = 0; i < sizeof(ifs) / sizeof(tcpip_adapter_if_t); i++)
if (tcpip_adapter_get_ip_info(ifs[i], &ipInfo) == ESP_OK && ipInfo.ip.addr != IPADDR_ANY) {
tcpip_adapter_get_hostname(ifs[i], &hostname);
break;
}
if (!hostname) {
LOG_INFO( "no hostname/IP found, can't start AirPlay");
return false;
}
host.s_addr = ipInfo.ip.addr;
// initialize mDNS
@@ -181,6 +196,33 @@ void raop_sink_init(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
esp_read_mac(mac, ESP_MAC_WIFI_STA);
cmd_handler_chain = cmd_cb;
raop = raop_create(host, sink_name, mac, 0, cmd_handler, data_cb);
return true;
}
/****************************************************************************************
* Airplay sink timer handler
*/
static void raop_start_handler( TimerHandle_t xTimer ) {
raop_cb_t *cbs = (raop_cb_t*) pvTimerGetTimerID (xTimer);
if (raop_sink_start(cbs->cmd, cbs->data)) {
xTimerDelete(xTimer, portMAX_DELAY);
free(cbs);
}
}
/****************************************************************************************
* Airplay sink initialization
*/
void raop_sink_init(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
if (!raop_sink_start(cmd_cb, data_cb)) {
raop_cb_t *cbs = (raop_cb_t*) malloc(sizeof(raop_cb_t));
cbs->cmd = cmd_cb;
cbs->data = data_cb;
TimerHandle_t timer = xTimerCreate("raopStart", 1000 / portTICK_RATE_MS, pdTRUE, cbs, raop_start_handler);
xTimerStart(timer, portMAX_DELAY);
LOG_INFO( "delaying AirPlay start");
}
}
/****************************************************************************************

View File

@@ -142,6 +142,23 @@ const i2s_platform_config_t * config_get_i2s_from_str(char * dac_config ){
return &i2s_dac_pin;
}
/****************************************************************************************
* Get eth config structure from config string
*/
const eth_config_t * config_get_eth_from_str(char * eth_config ){
static eth_config_t eth_pin = {
.mdc = -1,
.mdio = -1,
.rst = -1,
};
char * p=NULL;
if ((p = strcasestr(eth_config, "mdc")) != NULL) eth_pin.mdc = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(eth_config, "mdio")) != NULL) eth_pin.mdio = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(eth_config, "rst")) != NULL) eth_pin.rst = atoi(strchr(p, '=') + 1);
return &eth_pin;
}
/****************************************************************************************
* Get spdif config structure
*/
@@ -164,6 +181,18 @@ const i2s_platform_config_t * config_dac_get(){
return &i2s_dac_config;
}
/****************************************************************************************
* Get ethernet config structure
*/
const eth_config_t * config_eth_get( ){
char * config = config_alloc_get_str("eth_config", CONFIG_ETH_CONFIG, "mdc=" STR(CONFIG_MDC_IO)
",mdio=" STR(CONFIG_MDIO_IO) ",do=" STR(CONFIG_PHY_RST_IO));
static eth_config_t eth_config;
memcpy(&eth_config, config_get_eth_from_str(config), sizeof(eth_config));
free(config);
return &eth_config;
}
/****************************************************************************************
*
*/

View File

@@ -30,6 +30,12 @@ typedef struct {
bool rotate;
} display_config_t;
typedef struct {
int mdc;
int mdio;
int rst;
} eth_config_t;
typedef struct {
i2s_pin_config_t pin;
char model[32];
@@ -75,6 +81,7 @@ typedef struct {
} gpio_entry_t;
const display_config_t * config_display_get();
const eth_config_t * config_eth_get( );
esp_err_t config_display_set(const display_config_t * config);
esp_err_t config_i2c_set(const i2c_config_t * config, int port);
esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_name);