resolve some type problems

This commit is contained in:
Karl Osterseher
2025-01-18 22:09:07 +01:00
Unverified
parent d9afc3038b
commit 3c27108520
6 changed files with 102 additions and 89 deletions

View File

@@ -29,6 +29,7 @@
#include "audio_volume.h"
#include "board.h"
#include "esp_log.h"
#include "freertos/projdefs.h"
#include "i2c_bus.h"
#include "tas5805m_reg_cfg.h"
@@ -95,7 +96,7 @@ static esp_err_t tas5805m_transmit_registers(const tas5805m_cfg_reg_t *conf_buf,
// Used in legacy applications. Ignored here.
break;
case CFG_META_DELAY:
vTaskDelay(conf_buf[i].value / portTICK_RATE_MS);
vTaskDelay(pdMS_TO_TICKS(conf_buf[i].value));
break;
case CFG_META_BURST:
ret = i2c_bus_write_bytes(i2c_handler, TAS5805M_ADDR,
@@ -135,9 +136,9 @@ esp_err_t tas5805m_init(audio_hal_codec_config_t *codec_cfg) {
io_conf.intr_type = GPIO_INTR_DISABLE;
gpio_config(&io_conf);
gpio_set_level(TAS5805M_RST_GPIO, 0);
vTaskDelay(20 / portTICK_RATE_MS);
vTaskDelay(pdMS_TO_TICKS(20));
gpio_set_level(TAS5805M_RST_GPIO, 1);
vTaskDelay(200 / portTICK_RATE_MS);
vTaskDelay(pdMS_TO_TICKS(200));
ret = get_i2c_pins(I2C_NUM_0, &i2c_cfg);
i2c_handler = i2c_bus_create(I2C_NUM_0, &i2c_cfg);

View File

@@ -156,7 +156,7 @@ typedef struct audio_hal {
esp_err_t (*audio_codec_set_volume)(int volume); /*!< set codec volume */
esp_err_t (*audio_codec_get_volume)(int *volume); /*!< get codec volume */
esp_err_t (*audio_codec_enable_pa)(bool enable); /*!< enable pa */
xSemaphoreHandle audio_hal_lock; /*!< semaphore of codec */
SemaphoreHandle_t audio_hal_lock; /*!< semaphore of codec */
void *handle; /*!< handle of audio codec */
} audio_hal_func_t;

View File

@@ -33,6 +33,7 @@
#include "audio_mutex.h"
#include "driver/i2c.h"
#include "esp_log.h"
#include "freertos/projdefs.h"
#define ESP_INTR_FLG_DEFAULT (0)
#define ESP_I2C_MASTER_BUF_LEN (0)
@@ -45,10 +46,10 @@
}
typedef struct {
i2c_config_t i2c_conf; /*!<I2C bus parameters*/
i2c_port_t i2c_port; /*!<I2C port number */
int ref_count; /*!<Reference Count for multiple client */
xSemaphoreHandle bus_lock; /*!<Lock for bus */
i2c_config_t i2c_conf; /*!<I2C bus parameters*/
i2c_port_t i2c_port; /*!<I2C port number */
int ref_count; /*!<Reference Count for multiple client */
SemaphoreHandle_t bus_lock; /*!<Lock for bus */
} i2c_bus_t;
static const char *TAG = "I2C_BUS";
@@ -116,7 +117,7 @@ esp_err_t i2c_bus_write_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg,
ret |= i2c_master_write(cmd, reg, regLen, I2C_ACK_CHECK_EN);
ret |= i2c_master_write(cmd, data, datalen, I2C_ACK_CHECK_EN);
ret |= i2c_master_stop(cmd);
ret |= i2c_master_cmd_begin(p_bus->i2c_port, cmd, 1000 / portTICK_RATE_MS);
ret |= i2c_master_cmd_begin(p_bus->i2c_port, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
mutex_unlock(p_bus->bus_lock);
I2C_BUS_CHECK(ret == 0, "I2C Bus WriteReg Error", ESP_FAIL);
@@ -136,7 +137,7 @@ esp_err_t i2c_bus_write_data(i2c_bus_handle_t bus, int addr, uint8_t *data,
ret |= i2c_master_write_byte(cmd, addr, 1);
ret |= i2c_master_write(cmd, data, datalen, I2C_ACK_CHECK_EN);
ret |= i2c_master_stop(cmd);
ret |= i2c_master_cmd_begin(p_bus->i2c_port, cmd, 1000 / portTICK_RATE_MS);
ret |= i2c_master_cmd_begin(p_bus->i2c_port, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
mutex_unlock(p_bus->bus_lock);
I2C_BUS_CHECK(ret == 0, "I2C Bus WriteReg Error", ESP_FAIL);
@@ -158,7 +159,7 @@ esp_err_t i2c_bus_read_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg,
ret |= i2c_master_write_byte(cmd, addr, I2C_ACK_CHECK_EN);
ret |= i2c_master_write(cmd, reg, reglen, I2C_ACK_CHECK_EN);
ret |= i2c_master_stop(cmd);
ret |= i2c_master_cmd_begin(p_bus->i2c_port, cmd, 1000 / portTICK_RATE_MS);
ret |= i2c_master_cmd_begin(p_bus->i2c_port, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
cmd = i2c_cmd_link_create();
@@ -171,7 +172,7 @@ esp_err_t i2c_bus_read_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg,
ret |= i2c_master_read_byte(cmd, &outdata[datalen - 1], 1);
ret |= i2c_master_stop(cmd);
ret |= i2c_master_cmd_begin(p_bus->i2c_port, cmd, 1000 / portTICK_RATE_MS);
ret |= i2c_master_cmd_begin(p_bus->i2c_port, cmd, pdMS_TO_TICKS(1000));
i2c_cmd_link_delete(cmd);
mutex_unlock(p_bus->bus_lock);

View File

@@ -1,7 +1,8 @@
if(CONFIG_SNAPCLIENT_ENABLE_ETHERNET)
idf_component_register(SRCS "eth_interface.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES driver esp_eth esp_netif)
else()
idf_component_register()
endif()
#if(CONFIG_SNAPCLIENT_ENABLE_ETHERNET)
idf_component_register(SRCS "eth_interface.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES driver esp_eth esp_netif)
#else()
# idf_component_register()
#endif()

View File

@@ -10,22 +10,26 @@
#include <string.h>
#include "driver/gpio.h"
#if CONFIG_ETH_USE_SPI_ETHERNET
#include "driver/spi_master.h"
#endif // CONFIG_ETH_USE_SPI_ETHERNET
#include "esp_eth.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_mac.h"
#include "esp_netif.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "freertos/task.h"
// #include "sdkconfig.h"
#include "sdkconfig.h"
#if CONFIG_ETH_USE_SPI_ETHERNET
#include "driver/spi_master.h"
#endif // CONFIG_ETH_USE_SPI_ETHERNET
static const char *TAG = "ETH";
static esp_eth_handle_t s_eth_handle = NULL;
static esp_eth_mac_t *s_mac = NULL;
static esp_eth_phy_t *s_phy = NULL;
static esp_eth_netif_glue_handle_t s_eth_glue = NULL;
/* The event group allows multiple bits for each event, but we only care about
* two events:
* - we are connected to the AP with an IP
@@ -88,42 +92,41 @@ void eth_init(void) {
ESP_ERROR_CHECK(esp_netif_init());
// Create default event loop that running in background
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
esp_netif_t *eth_netif = esp_netif_new(&cfg);
// Set default handlers to process TCP/IP stuffs
ESP_ERROR_CHECK(esp_eth_set_default_handlers(eth_netif));
// Register user defined event handers
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID,
&eth_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP,
&got_ip_event_handler, NULL));
esp_netif_inherent_config_t esp_netif_config =
ESP_NETIF_INHERENT_DEFAULT_ETH();
// Warning: the interface desc is used in tests to capture actual connection
// details (IP, gw, mask)
esp_netif_config.if_desc = "eth";
esp_netif_config.route_prio = 64;
esp_netif_config_t netif_config = {.base = &esp_netif_config,
.stack = ESP_NETIF_NETSTACK_DEFAULT_ETH};
esp_netif_t *netif = esp_netif_new(&netif_config);
assert(netif);
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
mac_config.rx_task_stack_size = 2048;
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
phy_config.phy_addr = CONFIG_SNAPCLIENT_ETH_PHY_ADDR;
phy_config.reset_gpio_num = CONFIG_SNAPCLIENT_ETH_PHY_RST_GPIO;
// phy_config.reset_timeout_ms = 500;
// mac_config.sw_reset_timeout_ms = 500;
#if CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET
mac_config.smi_mdc_gpio_num = CONFIG_SNAPCLIENT_ETH_MDC_GPIO;
mac_config.smi_mdio_gpio_num = CONFIG_SNAPCLIENT_ETH_MDIO_GPIO;
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
esp32_emac_config.smi_mdc_gpio_num = CONFIG_SNAPCLIENT_ETH_MDC_GPIO;
esp32_emac_config.smi_mdio_gpio_num = CONFIG_SNAPCLIENT_ETH_MDIO_GPIO;
s_mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config);
#if CONFIG_SNAPCLIENT_ETH_PHY_IP101
esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config);
s_phy = esp_eth_phy_new_ip101(&phy_config);
#elif CONFIG_SNAPCLIENT_ETH_PHY_RTL8201
esp_eth_phy_t *phy = esp_eth_phy_new_rtl8201(&phy_config);
s_phy = esp_eth_phy_new_rtl8201(&phy_config);
#elif CONFIG_SNAPCLIENT_ETH_PHY_LAN8720
esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
s_phy = esp_eth_phy_new_lan87xx(&phy_config);
#elif CONFIG_SNAPCLIENT_ETH_PHY_DP83848
esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config);
s_phy = esp_eth_phy_new_dp83848(&phy_config);
#elif CONFIG_SNAPCLIENT_ETH_PHY_KSZ8041
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8041(&phy_config);
s_phy = esp_eth_phy_new_ksz80xx(&phy_config);
#endif
#elif CONFIG_ETH_USE_SPI_ETHERNET
#elif CONFIG_SNAPCLIENT_USE_SPI_ETHERNET
gpio_install_isr_service(0);
spi_device_handle_t spi_handle = NULL;
spi_bus_config_t buscfg = {
.miso_io_num = CONFIG_SNAPCLIENT_ETH_SPI_MISO_GPIO,
.mosi_io_num = CONFIG_SNAPCLIENT_ETH_SPI_MOSI_GPIO,
@@ -131,57 +134,64 @@ void eth_init(void) {
.quadwp_io_num = -1,
.quadhd_io_num = -1,
};
ESP_ERROR_CHECK(
spi_bus_initialize(CONFIG_SNAPCLIENT_ETH_SPI_HOST, &buscfg, 1));
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_SNAPCLIENT_ETH_SPI_HOST, &buscfg,
SPI_DMA_CH_AUTO));
spi_device_interface_config_t spi_devcfg = {
.mode = 0,
.clock_speed_hz = CONFIG_SNAPCLIENT_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
.spics_io_num = CONFIG_SNAPCLIENT_ETH_SPI_CS_GPIO,
.queue_size = 20};
#if CONFIG_SNAPCLIENT_USE_DM9051
spi_device_interface_config_t devcfg = {
.command_bits = 1,
.address_bits = 7,
.mode = 0,
.clock_speed_hz = CONFIG_SNAPCLIENT_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
.spics_io_num = CONFIG_SNAPCLIENT_ETH_SPI_CS_GPIO,
.queue_size = 20};
ESP_ERROR_CHECK(
spi_bus_add_device(CONFIG_SNAPCLIENT_ETH_SPI_HOST, &devcfg, &spi_handle));
/* dm9051 ethernet driver is based on spi driver */
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
eth_dm9051_config_t dm9051_config =
ETH_DM9051_DEFAULT_CONFIG(CONFIG_SNAPCLIENT_ETH_SPI_HOST, &spi_devcfg);
dm9051_config.int_gpio_num = CONFIG_SNAPCLIENT_ETH_SPI_INT_GPIO;
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
s_mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
s_phy = esp_eth_phy_new_dm9051(&phy_config);
#elif CONFIG_SNAPCLIENT_USE_W5500
spi_device_interface_config_t devcfg = {
.command_bits = 16, // Actually it's the address phase in W5500 SPI frame
.address_bits = 8, // Actually it's the control phase in W5500 SPI frame
.mode = 0,
.clock_speed_hz = CONFIG_SNAPCLIENT_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
.spics_io_num = CONFIG_SNAPCLIENT_ETH_SPI_CS_GPIO,
.queue_size = 20};
ESP_ERROR_CHECK(
spi_bus_add_device(CONFIG_SNAPCLIENT_ETH_SPI_HOST, &devcfg, &spi_handle));
/* w5500 ethernet driver is based on spi driver */
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
eth_w5500_config_t w5500_config =
ETH_W5500_DEFAULT_CONFIG(CONFIG_SNAPCLIENT_ETH_SPI_HOST, &spi_devcfg);
w5500_config.int_gpio_num = CONFIG_SNAPCLIENT_ETH_SPI_INT_GPIO;
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);
s_mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
s_phy = esp_eth_phy_new_w5500(&phy_config);
#endif
#endif // CONFIG_ETH_USE_SPI_ETHERNET
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
esp_eth_handle_t eth_handle = NULL;
ESP_ERROR_CHECK(esp_eth_driver_install(&config, &eth_handle));
#elif CONFIG_SNAPCLIENT_USE_OPENETH
phy_config.autonego_timeout_ms = 100;
s_mac = esp_eth_mac_new_openeth(&mac_config);
s_phy = esp_eth_phy_new_dp83848(&phy_config);
#endif
// Install Ethernet driver
esp_eth_config_t config = ETH_DEFAULT_CONFIG(s_mac, s_phy);
ESP_ERROR_CHECK(esp_eth_driver_install(&config, &s_eth_handle));
#if !CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET
/* The SPI Ethernet module might doesn't have a burned factory MAC address, we
cat to set it manually. 02:00:00 is a Locally Administered OUI range so
should not be used except when testing on a LAN under your control.
cat to set it manually. We set the ESP_MAC_ETH mac address as the default,
if you want to use ESP_MAC_EFUSE_CUSTOM mac address, please enable the
configuration: `ESP_MAC_USE_CUSTOM_MAC_AS_BASE_MAC`
*/
ESP_ERROR_CHECK(
esp_eth_ioctl(eth_handle, ETH_CMD_S_MAC_ADDR,
(uint8_t[]){0x02, 0x00, 0x00, 0x12, 0x34, 0x56}));
uint8_t eth_mac[6] = {0};
ESP_ERROR_CHECK(esp_read_mac(eth_mac, ESP_MAC_ETH));
ESP_ERROR_CHECK(esp_eth_ioctl(s_eth_handle, ETH_CMD_S_MAC_ADDR, eth_mac));
#endif
/* attach Ethernet driver to TCP/IP stack */
ESP_ERROR_CHECK(
esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
/* start Ethernet driver state machine */
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
// combine driver with netif
s_eth_glue = esp_eth_new_netif_glue(s_eth_handle);
esp_netif_attach(netif, s_eth_glue);
// Register user defined event handers
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID,
&eth_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP,
&got_ip_event_handler, NULL));
#ifdef CONFIG_SNAPCLIENT_CONNECT_IPV6
ESP_ERROR_CHECK(esp_event_handler_register(
ETH_EVENT, ETHERNET_EVENT_CONNECTED, &on_eth_event, netif));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6,
&eth_on_got_ipv6, NULL));
#endif
esp_eth_start(s_eth_handle);
/* Waiting until either the connection is established (ETH_CONNECTED_BIT) or
* connection failed for the maximum number of re-tries (ETH_FAIL_BIT). The

View File

@@ -20,7 +20,7 @@
#include "ota_server.h"
#include "player.h"
extern xTaskHandle t_http_get_task;
extern TaskHandle_t t_http_get_task;
const int OTA_CONNECTED_BIT = BIT0;
static const char *TAG = "OTA";