Skip to content

Commit

Permalink
driver: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
redchenjs committed Feb 11, 2021
1 parent d5d06c6 commit dfa889f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions main/src/chip/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void bt_init(void)
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE));
#endif

esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));
esp_bt_controller_config_t btc_conf = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_bt_controller_init(&btc_conf));
ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BTDM));
ESP_ERROR_CHECK(esp_bluedroid_init());
ESP_ERROR_CHECK(esp_bluedroid_enable());
Expand Down
42 changes: 21 additions & 21 deletions main/src/chip/i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define I2S0_TAG "i2s-0"
#define I2S1_TAG "i2s-1"

static i2s_config_t i2s_output_config = {
static i2s_config_t output_conf = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX
#if (CONFIG_AUDIO_OUTPUT_I2S_NUM == CONFIG_AUDIO_INPUT_I2S_NUM)
| I2S_MODE_RX
Expand All @@ -29,7 +29,7 @@ static i2s_config_t i2s_output_config = {
};

#if !defined(CONFIG_AUDIO_INPUT_NONE) && (CONFIG_AUDIO_OUTPUT_I2S_NUM != CONFIG_AUDIO_INPUT_I2S_NUM)
static i2s_config_t i2s_input_config = {
static i2s_config_t input_conf = {
.mode = I2S_MODE_MASTER | I2S_MODE_RX
#ifdef CONFIG_AUDIO_INPUT_PDM
| I2S_MODE_PDM
Expand All @@ -49,12 +49,12 @@ static i2s_config_t i2s_input_config = {
static void i2s0_init(void)
{
#if (CONFIG_AUDIO_OUTPUT_I2S_NUM == 0)
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_0, &i2s_output_config, 0, NULL));
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_0, &output_conf, 0, NULL));
#else
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_0, &i2s_input_config, 0, NULL));
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_0, &input_conf, 0, NULL));
#endif

i2s_pin_config_t pin_config = {
i2s_pin_config_t pin_conf = {
#ifndef CONFIG_AUDIO_INPUT_PDM
.bck_io_num = CONFIG_I2S0_BCLK_PIN,
.ws_io_num = CONFIG_I2S0_LRCK_PIN,
Expand All @@ -75,13 +75,13 @@ static void i2s0_init(void)
.data_in_num = CONFIG_PDM_DIN_PIN
#endif
};
ESP_ERROR_CHECK(i2s_set_pin(I2S_NUM_0, &pin_config));
ESP_ERROR_CHECK(i2s_set_pin(I2S_NUM_0, &pin_conf));

ESP_LOGI(I2S0_TAG, "initialized, bck: %d, ws: %d, dout: %d, din: %d",
pin_config.bck_io_num,
pin_config.ws_io_num,
pin_config.data_out_num,
pin_config.data_in_num
pin_conf.bck_io_num,
pin_conf.ws_io_num,
pin_conf.data_out_num,
pin_conf.data_in_num
);
}

Expand All @@ -97,12 +97,12 @@ static void i2s0_deinit(void)
static void i2s1_init(void)
{
#if (CONFIG_AUDIO_OUTPUT_I2S_NUM == 1)
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_1, &i2s_output_config, 0, NULL));
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_1, &output_conf, 0, NULL));
#else
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_1, &i2s_input_config, 0, NULL));
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_1, &input_conf, 0, NULL));
#endif

i2s_pin_config_t pin_config = {
i2s_pin_config_t pin_conf = {
.bck_io_num = CONFIG_I2S1_BCLK_PIN,
.ws_io_num = CONFIG_I2S1_LRCK_PIN,
#ifdef CONFIG_AUDIO_OUTPUT_I2S1
Expand All @@ -116,13 +116,13 @@ static void i2s1_init(void)
.data_in_num = -1
#endif
};
ESP_ERROR_CHECK(i2s_set_pin(I2S_NUM_1, &pin_config));
ESP_ERROR_CHECK(i2s_set_pin(I2S_NUM_1, &pin_conf));

ESP_LOGI(I2S1_TAG, "initialized, bck: %d, ws: %d, dout: %d, din: %d",
pin_config.bck_io_num,
pin_config.ws_io_num,
pin_config.data_out_num,
pin_config.data_in_num
pin_conf.bck_io_num,
pin_conf.ws_io_num,
pin_conf.data_out_num,
pin_conf.data_in_num
);
}

Expand Down Expand Up @@ -154,10 +154,10 @@ void i2s_output_deinit(void)

void i2s_output_set_sample_rate(unsigned int sample_rate)
{
if (sample_rate != i2s_output_config.sample_rate) {
i2s_output_config.sample_rate = sample_rate;
if (sample_rate != output_conf.sample_rate) {
output_conf.sample_rate = sample_rate;
i2s_zero_dma_buffer(CONFIG_AUDIO_OUTPUT_I2S_NUM);
i2s_set_sample_rates(CONFIG_AUDIO_OUTPUT_I2S_NUM, i2s_output_config.sample_rate);
i2s_set_sample_rates(CONFIG_AUDIO_OUTPUT_I2S_NUM, output_conf.sample_rate);
}
}

Expand Down
16 changes: 8 additions & 8 deletions main/src/chip/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spi_device_handle_t hspi;

void hspi_init(void)
{
spi_bus_config_t buscfg = {
spi_bus_config_t bus_conf = {
.miso_io_num = -1,
.mosi_io_num = CONFIG_SPI_MOSI_PIN,
.sclk_io_num = CONFIG_SPI_SCLK_PIN,
Expand All @@ -34,9 +34,9 @@ void hspi_init(void)
.max_transfer_sz = CUBE0414_X * CUBE0414_Y * CUBE0414_Z * 3
#endif
};
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &buscfg, 1));
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &bus_conf, 1));

spi_device_interface_config_t devcfg = {
spi_device_interface_config_t dev_conf = {
.mode = 0, // SPI mode 0
.spics_io_num = CONFIG_SPI_CS_PIN, // CS pin
#ifdef CONFIG_VFX_OUTPUT_ST7735
Expand All @@ -52,13 +52,13 @@ void hspi_init(void)
.queue_size = 2, // we want to be able to queue 2 transactions at a time
.flags = SPI_DEVICE_3WIRE | SPI_DEVICE_HALFDUPLEX
};
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &devcfg, &hspi));
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_conf, &hspi));

ESP_LOGI(HSPI_TAG, "initialized, sclk: %d, mosi: %d, miso: %d, cs: %d",
buscfg.sclk_io_num,
buscfg.mosi_io_num,
buscfg.miso_io_num,
devcfg.spics_io_num
bus_conf.sclk_io_num,
bus_conf.mosi_io_num,
bus_conf.miso_io_num,
dev_conf.spics_io_num
);
}
#endif

0 comments on commit dfa889f

Please sign in to comment.