add SPI ethernet

This commit is contained in:
Philippe G
2021-10-31 14:45:35 -07:00
parent f4615462c7
commit 4f6dcc2cc7
4 changed files with 91 additions and 36 deletions

View File

@@ -25,10 +25,10 @@
#define CONFIG_AIRPLAY_NAME "ESP32-AirPlay"
#endif
typedef struct {
static EXT_RAM_ATTR struct raop_cb_s {
raop_cmd_vcb_t cmd;
raop_data_cb_t data;
} raop_cb_t;
} raop_cbs;
log_level raop_loglevel = lINFO;
log_level util_loglevel;
@@ -204,10 +204,8 @@ static bool raop_sink_start(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
* 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)) {
if (raop_sink_start(raop_cbs.cmd, raop_cbs.data)) {
xTimerDelete(xTimer, portMAX_DELAY);
free(cbs);
}
}
@@ -216,10 +214,9 @@ static void raop_start_handler( TimerHandle_t xTimer ) {
*/
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);
raop_cbs.cmd = cmd_cb;
raop_cbs.data = data_cb;
TimerHandle_t timer = xTimerCreate("raopStart", 5000 / portTICK_RATE_MS, pdTRUE, NULL, raop_start_handler);
xTimerStart(timer, portMAX_DELAY);
LOG_INFO( "delaying AirPlay start");
}

View File

@@ -118,7 +118,7 @@ static void set_i2s_pin(char *config, i2s_pin_config_t *pin_config) {
* Get i2s config structure from config string
*/
const i2s_platform_config_t * config_get_i2s_from_str(char * dac_config ){
static i2s_platform_config_t i2s_dac_pin = {
static EXT_RAM_ATTR i2s_platform_config_t i2s_dac_pin = {
.i2c_addr = -1,
.sda= -1,
.scl = -1,
@@ -146,16 +146,26 @@ const i2s_platform_config_t * config_get_i2s_from_str(char * dac_config ){
* 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,
static EXT_RAM_ATTR eth_config_t eth_pin = {
.rmii = false,
.model = "",
};
char * p=NULL;
if ((p = strcasestr(eth_config, "model")) != NULL) sscanf(p, "%*[^=]=%15[^,]", eth_pin.model);
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);
if ((p = strcasestr(eth_config, "mosi")) != NULL) eth_pin.mosi = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(eth_config, "miso")) != NULL) eth_pin.miso = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(eth_config, "intr")) != NULL) eth_pin.intr = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(eth_config, "cs")) != NULL) eth_pin.cs = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(eth_config, "speed")) != NULL) eth_pin.speed = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(eth_config, "clk")) != NULL) eth_pin.clk = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(eth_config, "host")) != NULL) eth_pin.host = atoi(strchr(p, '=') + 1);
if (strcasestr(eth_pin.model, "lan8720")) eth_pin.rmii = true;
return &eth_pin;
}
@@ -164,7 +174,7 @@ const eth_config_t * config_get_eth_from_str(char * eth_config ){
*/
const i2s_platform_config_t * config_spdif_get( ){
char * spdif_config = config_spdif_get_string();
static i2s_platform_config_t i2s_dac_config;
static EXT_RAM_ATTR i2s_platform_config_t i2s_dac_config;
memcpy(&i2s_dac_config, config_get_i2s_from_str(spdif_config), sizeof(i2s_dac_config));
free(spdif_config);
return &i2s_dac_config;
@@ -175,7 +185,7 @@ const i2s_platform_config_t * config_spdif_get( ){
*/
const i2s_platform_config_t * config_dac_get(){
char * spdif_config = get_dac_config_string();
static i2s_platform_config_t i2s_dac_config;
static EXT_RAM_ATTR i2s_platform_config_t i2s_dac_config;
memcpy(&i2s_dac_config, config_get_i2s_from_str(spdif_config), sizeof(i2s_dac_config));
free(spdif_config);
return &i2s_dac_config;
@@ -185,9 +195,19 @@ const i2s_platform_config_t * config_dac_get(){
* 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;
char * config = config_alloc_get_str("eth_config", CONFIG_ETH_CONFIG, "rst=" STR(CONFIG_ETH_PHY_RST_IO)
#if defined(CONFIG_ETH_LAN8720)
",model=lan8720"
#elif defined(CONFIG_ETH_DM9051)
",model=dm9051"
#endif
",mdc=" STR(CONFIG_ETH_MDC_IO) ",mdio=" STR(CONFIG_ETH_MDIO_IO)
",host=" STR(CONFIG_ETH_SPI_HOST) ",cs=" STR(CONFIG_ETH_SPI_CS_IO)
",mosi=" STR(CONFIG_ETH_SPI_MOSI_IO) ",miso=" STR(CONFIG_ETH_SPI_MISO_IO)
",intr=" STR(CONFIG_ETH_SPI_INTR_IO)
",clk=" STR(CONFIG_ETH_SPI_CLK_IO) ",speed=" STR(CONFIG_ETH_SPI_SPEED) );
static EXT_RAM_ATTR eth_config_t eth_config;
ESP_LOGD(TAG, "Ethernet config string %s", config);
memcpy(&eth_config, config_get_eth_from_str(config), sizeof(eth_config));
free(config);
return &eth_config;

View File

@@ -31,9 +31,13 @@ typedef struct {
} display_config_t;
typedef struct {
int mdc;
int mdio;
bool rmii;
char model[16];
int rst;
int mdc, mdio;
int host;
int cs, mosi, miso, intr, clk;
int speed;
} eth_config_t;
typedef struct {