diff --git a/README.md b/README.md index 74077d9b..a570c0a4 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ But squeezelite-esp32 is highly extensible and you can add - Buttons and Rotary Encoder and map/combine them to various functions (play, pause, volume, next ...) - IR receiver (no pullup resistor or capacitor needed, just the 38kHz receiver) - Monochrome, GrayScale or Color displays using SPI or I2C (supported drivers are SH1106, SSD1306, SSD1322, SSD1326/7, SSD1351, ST7735, ST7789 and ILI9341). +- Ethernet using a LAN6270 with RMII interface Other features include @@ -370,6 +371,25 @@ The benefit of the "raw" mode is that you can build a player which is as close a There is no good or bad option, it's your choice. Use the NVS parameter "lms_ctrls_raw" to change that option **Note that gpio 36 and 39 are input only and cannot use interrupt. When using them for a button, a 100ms polling is started which is expensive. Long press is also likely to not work very well** +### Ethernet (coming soon) +Wired ethernet is supported by esp32 with various options but squeezelite is only supporting a LAN8270 with a RMII interface like [this](https://www.aliexpress.com/item/32858432526.html). The esp32 has a strict set of wires required to use the RMII interface. + +- RMII PHY wiring is fixed and can not be changed + +| GPIO | RMII Signal | Notes | +| ------ | ----------- | ------------ | +| GPIO21 | TX_EN | EMAC_TX_EN | +| GPIO19 | TX0 | EMAC_TXD0 | +| GPIO22 | TX1 | EMAC_TXD1 | +| GPIO25 | RX0 | EMAC_RXD0 | +| GPIO26 | RX1 | EMAC_RXD1 | +| GPIO27 | CRS_DV | EMAC_RX_DRV | + +- SMI (Serial Management Interface) wiring is not fixed and you can change it either in the configuration or using "ethernet_config" parameter with the following syntax: +``` +MDC=,MDIO=[,RST=gpio>] +``` +** THIS IS NOT AVAILABLE YET, SO MORE TO COME ON HOW TO USE WIRED ETHERNET*** ### Battery / ADC The NVS parameter "bat_config" sets the ADC1 channel used to measure battery/DC voltage. The "atten" value attenuates the input voltage to the ADC input (the read value maintains a 0-1V rage) where: 0=no attenuation(0..800mV), 1=2.5dB attenuation(0..1.1V), 2=6dB attenuation(0..1.35V), 3=11dB attenuation(0..2.6V). Scale is a float ratio applied to every sample of the 12 bits ADC. A measure is taken every 10s and an average is made every 5 minutes (not a sliding window). Syntax is ``` diff --git a/components/raop/raop_sink.c b/components/raop/raop_sink.c index 767dc526..e654f112 100644 --- a/components/raop/raop_sink.c +++ b/components/raop/raop_sink.c @@ -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"); + } } /**************************************************************************************** diff --git a/components/services/accessors.c b/components/services/accessors.c index af847304..ac7ab5d2 100644 --- a/components/services/accessors.c +++ b/components/services/accessors.c @@ -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 ð_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(ð_config, config_get_eth_from_str(config), sizeof(eth_config)); + free(config); + return ð_config; +} + /**************************************************************************************** * */ diff --git a/components/services/accessors.h b/components/services/accessors.h index eba65c98..6cf59a2c 100644 --- a/components/services/accessors.h +++ b/components/services/accessors.h @@ -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); diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index fea336a1..f408318d 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -96,12 +96,36 @@ menu "Squeezelite-ESP32" string default "SPI,driver=ST7789,width=240,height=240,cs=5,back=12,speed=16000000,HFlip,VFlip" if TWATCH2020 default "" + config ETH_CONFIG + string + default "" config DAC_CONTROLSET string default "{ \"init\": [ {\"reg\":41, \"val\":128}, {\"reg\":18, \"val\":255} ], \"poweron\": [ {\"reg\":18, \"val\":64, \"mode\":\"or\"} ], \"poweroff\": [ {\"reg\":18, \"val\":191, \"mode\":\"and\"} ] }" if TWATCH2020 default "" # AGGREGATES - end endmenu + + menu "Ethernet Options" + visible if BASIC_I2C_BT && ETH_USE_ESP32_EMAC + config ETH_MDC_IO + int "SMI MDC GPIO number" + default 23 + help + Set the GPIO number used by SMI MDC. + config ETH_MDIO_IO + int "SMI MDIO GPIO number" + default 18 + help + Set the GPIO number used by SMI MDIO. + config ETH_PHY_RST_IO + int "PHY Reset GPIO number" + default 4 + help + Set the GPIO number used to reset PHY chip. + Set to -1 to disable PHY chip hardware reset. + endmenu + menu "Audio settings" menu "DAC settings" visible if BASIC_I2C_BT diff --git a/main/esp_app_main.c b/main/esp_app_main.c index 4a4d95d7..02e1a384 100644 --- a/main/esp_app_main.c +++ b/main/esp_app_main.c @@ -366,6 +366,9 @@ void register_default_nvs(){ ESP_LOGD(TAG,"Registering default value for key %s, value %s", "display_config", CONFIG_DISPLAY_CONFIG); config_set_default(NVS_TYPE_STR, "display_config", CONFIG_DISPLAY_CONFIG, 0); + ESP_LOGD(TAG,"Registering default value for key %s, value %s", "eth_config", CONFIG_ETH_CONFIG); + config_set_default(NVS_TYPE_STR, "eth_config", CONFIG_ETH_CONFIG, 0); + ESP_LOGD(TAG,"Registering default value for key %s, value %s", "i2c_config", CONFIG_I2C_CONFIG); config_set_default(NVS_TYPE_STR, "i2c_config", CONFIG_I2C_CONFIG, 0);