diff --git a/components/esp_lcd/include/esp_lcd_panel_io.h b/components/esp_lcd/include/esp_lcd_panel_io.h index 6505a10127..7fe5bc9747 100644 --- a/components/esp_lcd/include/esp_lcd_panel_io.h +++ b/components/esp_lcd/include/esp_lcd_panel_io.h @@ -44,7 +44,6 @@ typedef struct { esp_lcd_panel_io_color_trans_done_cb_t on_color_trans_done; /*!< Callback invoked when color data transfer has finished */ } esp_lcd_panel_io_callbacks_t; - /** * @brief Transmit LCD command and receive corresponding parameters * diff --git a/components/esp_lcd/src/esp_lcd_panel_io_i2c_v1.c b/components/esp_lcd/src/esp_lcd_panel_io_i2c_v1.c index 6ad986cee8..ba7731b2dc 100644 --- a/components/esp_lcd/src/esp_lcd_panel_io_i2c_v1.c +++ b/components/esp_lcd/src/esp_lcd_panel_io_i2c_v1.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -94,7 +94,7 @@ static esp_err_t panel_io_i2c_register_event_callbacks(esp_lcd_panel_io_handle_t { lcd_panel_io_i2c_t *i2c_panel_io = __containerof(io, lcd_panel_io_i2c_t, base); - if(i2c_panel_io->on_color_trans_done != NULL) { + if (i2c_panel_io->on_color_trans_done != NULL) { ESP_LOGW(TAG, "Callback on_color_trans_done was already set and now it was owerwritten!"); } @@ -117,7 +117,7 @@ static esp_err_t panel_io_i2c_rx_buffer(esp_lcd_panel_io_t *io, int lcd_cmd, voi if (send_param) { if (i2c_panel_io->control_phase_enabled) { ESP_GOTO_ON_ERROR(i2c_master_write_byte(cmd_link, i2c_panel_io->control_phase_cmd, true), - err, TAG, "write control phase failed"); // control phase + err, TAG, "write control phase failed"); // control phase } uint8_t cmds[4] = {BYTESHIFT(lcd_cmd, 3), BYTESHIFT(lcd_cmd, 2), BYTESHIFT(lcd_cmd, 1), BYTESHIFT(lcd_cmd, 0)}; size_t cmds_size = i2c_panel_io->lcd_cmd_bits / 8; @@ -157,12 +157,11 @@ static esp_err_t panel_io_i2c_tx_buffer(esp_lcd_panel_io_t *io, int lcd_cmd, con ESP_GOTO_ON_ERROR(i2c_master_write_byte(cmd_link, (i2c_panel_io->dev_addr << 1) | I2C_MASTER_WRITE, true), err, TAG, "write address failed"); // address phase if (i2c_panel_io->control_phase_enabled) { ESP_GOTO_ON_ERROR(i2c_master_write_byte(cmd_link, is_param ? i2c_panel_io->control_phase_cmd : i2c_panel_io->control_phase_data, true), - err, TAG, "write control phase failed"); // control phase + err, TAG, "write control phase failed"); // control phase } // some displays don't want any additional commands on data transfers - if (send_param) - { + if (send_param) { uint8_t cmds[4] = {BYTESHIFT(lcd_cmd, 3), BYTESHIFT(lcd_cmd, 2), BYTESHIFT(lcd_cmd, 1), BYTESHIFT(lcd_cmd, 0)}; size_t cmds_size = i2c_panel_io->lcd_cmd_bits / 8; if (cmds_size > 0 && cmds_size <= sizeof(cmds)) { diff --git a/components/esp_lcd/src/esp_lcd_panel_io_i2c_v2.c b/components/esp_lcd/src/esp_lcd_panel_io_i2c_v2.c index 3bab7b8329..fa2c834adc 100644 --- a/components/esp_lcd/src/esp_lcd_panel_io_i2c_v2.c +++ b/components/esp_lcd/src/esp_lcd_panel_io_i2c_v2.c @@ -105,7 +105,7 @@ static esp_err_t panel_io_i2c_register_event_callbacks(esp_lcd_panel_io_handle_t { lcd_panel_io_i2c_t *i2c_panel_io = __containerof(io, lcd_panel_io_i2c_t, base); - if(i2c_panel_io->on_color_trans_done != NULL) { + if (i2c_panel_io->on_color_trans_done != NULL) { ESP_LOGW(TAG, "Callback on_color_trans_done was already set and now it was owerwritten!"); } @@ -159,8 +159,7 @@ static esp_err_t panel_io_i2c_tx_buffer(esp_lcd_panel_io_t *io, int lcd_cmd, con } // some displays don't want any additional commands on data transfers - if (send_param) - { + if (send_param) { uint8_t cmds[4] = {BYTESHIFT(lcd_cmd, 3), BYTESHIFT(lcd_cmd, 2), BYTESHIFT(lcd_cmd, 1), BYTESHIFT(lcd_cmd, 0)}; size_t cmds_size = i2c_panel_io->lcd_cmd_bits / 8; if (cmds_size > 0 && cmds_size <= sizeof(cmds)) { diff --git a/components/esp_lcd/src/esp_lcd_panel_io_i80.c b/components/esp_lcd/src/esp_lcd_panel_io_i80.c index db86c75f03..d90d57fe36 100644 --- a/components/esp_lcd/src/esp_lcd_panel_io_i80.c +++ b/components/esp_lcd/src/esp_lcd_panel_io_i80.c @@ -425,8 +425,8 @@ static esp_err_t panel_io_i80_tx_param(esp_lcd_panel_io_t *io, int lcd_cmd, cons // wait all pending transaction in the queue to finish size_t num_trans_inflight = next_device->num_trans_inflight; for (size_t i = 0; i < num_trans_inflight; i++) { - ESP_RETURN_ON_FALSE( xQueueReceive(next_device->done_queue, &trans_desc, portMAX_DELAY) == pdTRUE, - ESP_FAIL, TAG, "recycle inflight transactions failed"); + ESP_RETURN_ON_FALSE(xQueueReceive(next_device->done_queue, &trans_desc, portMAX_DELAY) == pdTRUE, + ESP_FAIL, TAG, "recycle inflight transactions failed"); next_device->num_trans_inflight--; } diff --git a/components/esp_lcd/src/esp_lcd_panel_io_spi.c b/components/esp_lcd/src/esp_lcd_panel_io_spi.c index 7c731451ba..663e3f2a62 100644 --- a/components/esp_lcd/src/esp_lcd_panel_io_spi.c +++ b/components/esp_lcd/src/esp_lcd_panel_io_spi.c @@ -330,7 +330,7 @@ static esp_err_t panel_io_spi_tx_color(esp_lcd_panel_io_t *io, int lcd_cmd, cons lcd_trans->flags.dc_gpio_level = !spi_panel_io->flags.dc_data_level; // set D/C line to command mode lcd_trans->base.length = spi_panel_io->lcd_cmd_bits; lcd_trans->base.tx_buffer = &lcd_cmd; - if(color && color_size) { + if (color && color_size) { lcd_trans->base.flags |= SPI_TRANS_CS_KEEP_ACTIVE; } if (spi_panel_io->flags.octal_mode) { diff --git a/components/esp_lcd/src/esp_lcd_panel_ssd1306.c b/components/esp_lcd/src/esp_lcd_panel_ssd1306.c index 0520146c10..d2a94aefb1 100644 --- a/components/esp_lcd/src/esp_lcd_panel_ssd1306.c +++ b/components/esp_lcd/src/esp_lcd_panel_ssd1306.c @@ -141,10 +141,10 @@ static esp_err_t panel_ssd1306_init(esp_lcd_panel_t *panel) ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, SSD1306_CMD_DISP_OFF, NULL, 0), TAG, "io tx param SSD1306_CMD_DISP_OFF failed"); ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, SSD1306_CMD_SET_MEMORY_ADDR_MODE, (uint8_t[]) { - 0x00 // horizontal addressing mode + 0x00 // horizontal addressing mode }, 1), TAG, "io tx param SSD1306_CMD_SET_MEMORY_ADDR_MODE failed"); ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, SSD1306_CMD_SET_CHARGE_PUMP, (uint8_t[]) { - 0x14 // enable charge pump + 0x14 // enable charge pump }, 1), TAG, "io tx param SSD1306_CMD_SET_CHARGE_PUMP failed"); ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, SSD1306_CMD_MIRROR_X_OFF, NULL, 0), TAG, "io tx param SSD1306_CMD_MIRROR_X_OFF failed"); diff --git a/components/esp_lcd/src/esp_lcd_panel_st7789.c b/components/esp_lcd/src/esp_lcd_panel_st7789.c index fb3f7349f4..36c39110bf 100644 --- a/components/esp_lcd/src/esp_lcd_panel_st7789.c +++ b/components/esp_lcd/src/esp_lcd_panel_st7789.c @@ -106,7 +106,7 @@ esp_lcd_new_panel_st7789(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel st7789->ramctl_val_1 = 0x00; st7789->ramctl_val_2 = 0xf0; // Use big endian by default - if((panel_dev_config->data_endian) == LCD_RGB_DATA_ENDIAN_LITTLE) { + if ((panel_dev_config->data_endian) == LCD_RGB_DATA_ENDIAN_LITTLE) { // Use little endian st7789->ramctl_val_2 |= ST7789_DATA_LITTLE_ENDIAN_BIT; } diff --git a/components/esp_lcd/test_apps/i80_lcd/main/test_i80_lcd_panel.c b/components/esp_lcd/test_apps/i80_lcd/main/test_i80_lcd_panel.c index 7f18e14c86..e2f6e2cf18 100644 --- a/components/esp_lcd/test_apps/i80_lcd/main/test_i80_lcd_panel.c +++ b/components/esp_lcd/test_apps/i80_lcd/main/test_i80_lcd_panel.c @@ -43,7 +43,6 @@ TEST_CASE("i80_and_i2s_driver_co-existence", "[lcd][i2s]") }; TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus)); - i2s_chan_handle_t tx_handle = NULL; i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER); // I2S driver won't be installed as the same I2S port has been used by LCD diff --git a/components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c b/components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c index 5923da521c..4e1eb3edd3 100644 --- a/components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c +++ b/components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c @@ -26,7 +26,7 @@ #define TEST_IMG_SIZE (100 * 100 * sizeof(uint16_t)) static esp_lcd_panel_handle_t test_rgb_panel_initialization(size_t data_width, size_t bpp, size_t bb_pixels, bool refresh_on_demand, - esp_lcd_rgb_panel_vsync_cb_t vsync_cb, void *user_data) + esp_lcd_rgb_panel_vsync_cb_t vsync_cb, void *user_data) { esp_lcd_panel_handle_t panel_handle = NULL; esp_lcd_rgb_panel_config_t panel_config = { diff --git a/examples/peripherals/adc/continuous_read/main/continuous_read_main.c b/examples/peripherals/adc/continuous_read/main/continuous_read_main.c index 35a95d1486..307b8da979 100644 --- a/examples/peripherals/adc/continuous_read/main/continuous_read_main.c +++ b/examples/peripherals/adc/continuous_read/main/continuous_read_main.c @@ -41,7 +41,6 @@ static adc_channel_t channel[2] = {ADC_CHANNEL_2, ADC_CHANNEL_3}; static TaskHandle_t s_task_handle; static const char *TAG = "EXAMPLE"; - static bool IRAM_ATTR s_conv_done_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data) { BaseType_t mustYield = pdFALSE; @@ -103,7 +102,7 @@ void app_main(void) ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(handle, &cbs, NULL)); ESP_ERROR_CHECK(adc_continuous_start(handle)); - while(1) { + while (1) { /** * This is to show you the way to use the ADC continuous mode driver event callback. diff --git a/examples/peripherals/adc/oneshot_read/main/oneshot_read_main.c b/examples/peripherals/adc/oneshot_read/main/oneshot_read_main.c index 25ffc14d8b..1183d0fddf 100644 --- a/examples/peripherals/adc/oneshot_read/main/oneshot_read_main.c +++ b/examples/peripherals/adc/oneshot_read/main/oneshot_read_main.c @@ -52,7 +52,6 @@ static int voltage[2][10]; static bool example_adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_atten_t atten, adc_cali_handle_t *out_handle); static void example_adc_calibration_deinit(adc_cali_handle_t handle); - void app_main(void) { //-------------ADC1 Init---------------// @@ -76,7 +75,6 @@ void app_main(void) bool do_calibration1_chan0 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC1_CHAN0, EXAMPLE_ADC_ATTEN, &adc1_cali_chan0_handle); bool do_calibration1_chan1 = example_adc_calibration_init(ADC_UNIT_1, EXAMPLE_ADC1_CHAN1, EXAMPLE_ADC_ATTEN, &adc1_cali_chan1_handle); - #if EXAMPLE_USE_ADC2 //-------------ADC2 Init---------------// adc_oneshot_unit_handle_t adc2_handle; @@ -139,7 +137,6 @@ void app_main(void) #endif //#if EXAMPLE_USE_ADC2 } - /*--------------------------------------------------------------- ADC Calibration ---------------------------------------------------------------*/ diff --git a/examples/peripherals/analog_comparator/main/ana_cmpr_example_intr.c b/examples/peripherals/analog_comparator/main/ana_cmpr_example_intr.c index 78fec3e9bc..29e1e45304 100644 --- a/examples/peripherals/analog_comparator/main/ana_cmpr_example_intr.c +++ b/examples/peripherals/analog_comparator/main/ana_cmpr_example_intr.c @@ -15,8 +15,8 @@ static const char *TAG = "ana_cmpr_example"; static bool example_ana_cmpr_on_cross_callback(ana_cmpr_handle_t cmpr, - const ana_cmpr_cross_event_data_t *edata, - void *user_ctx) + const ana_cmpr_cross_event_data_t *edata, + void *user_ctx) { #if CONFIG_EXAMPLE_HYSTERESIS_COMPARATOR static ana_cmpr_internal_ref_config_t ref_cfg = { @@ -70,7 +70,7 @@ void example_init_analog_comparator_intr(void) }; ESP_ERROR_CHECK(ana_cmpr_set_internal_reference(cmpr, &ref_cfg)); #else - /* Step 1: Allocate the new analog comparator unit */ + /* Step 1: Allocate the new analog comparator unit */ ana_cmpr_config_t config = { .unit = EXAMPLE_ANA_CMPR_UNIT, .clk_src = ANA_CMPR_CLK_SRC_DEFAULT, diff --git a/examples/peripherals/dac/dac_continuous/dac_audio/main/dac_audio_example_main.c b/examples/peripherals/dac/dac_continuous/dac_audio/main/dac_audio_example_main.c index cc1cf9d0f6..b0ceb64c1b 100644 --- a/examples/peripherals/dac/dac_continuous/dac_audio/main/dac_audio_example_main.c +++ b/examples/peripherals/dac/dac_continuous/dac_audio/main/dac_audio_example_main.c @@ -43,7 +43,7 @@ static void dac_write_data_asynchronously(dac_continuous_handle_t handle, QueueH xQueueReceive(que, &evt_data, portMAX_DELAY); size_t loaded_bytes = 0; ESP_ERROR_CHECK(dac_continuous_write_asynchronously(handle, evt_data.buf, evt_data.buf_size, - data + byte_written, data_size - byte_written, &loaded_bytes)); + data + byte_written, data_size - byte_written, &loaded_bytes)); byte_written += loaded_bytes; } /* Clear the legacy data in DMA, clear times equal to the 'dac_continuous_config_t::desc_num' */ diff --git a/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_dma.c b/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_dma.c index f96f6403e9..fe3fa3eb65 100644 --- a/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_dma.c +++ b/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_dma.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -32,20 +32,20 @@ static void dac_dma_write_task(void *args) while (1) { /* The wave in the buffer will be converted cyclically */ switch (wav_sel) { - case DAC_SINE_WAVE: - ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)sin_wav, buf_len, NULL)); - break; - case DAC_TRIANGLE_WAVE: - ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)tri_wav, buf_len, NULL)); - break; - case DAC_SAWTOOTH_WAVE: - ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)saw_wav, buf_len, NULL)); - break; - case DAC_SQUARE_WAVE: - ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)squ_wav, buf_len, NULL)); - break; - default: - break; + case DAC_SINE_WAVE: + ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)sin_wav, buf_len, NULL)); + break; + case DAC_TRIANGLE_WAVE: + ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)tri_wav, buf_len, NULL)); + break; + case DAC_SAWTOOTH_WAVE: + ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)saw_wav, buf_len, NULL)); + break; + case DAC_SQUARE_WAVE: + ESP_ERROR_CHECK(dac_continuous_write_cyclically(handle, (uint8_t *)squ_wav, buf_len, NULL)); + break; + default: + break; } /* Switch wave every CONFIG_EXAMPLE_WAVE_PERIOD_SEC seconds */ vTaskDelay(pdMS_TO_TICKS(CONFIG_EXAMPLE_WAVE_PERIOD_SEC * 1000)); diff --git a/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_main.c b/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_main.c index d182850f4e..a20c65e939 100644 --- a/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_main.c +++ b/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_main.c @@ -54,7 +54,7 @@ static void example_generate_wave(void) uint32_t pnt_num = EXAMPLE_ARRAY_LEN; for (int i = 0; i < pnt_num; i ++) { - sin_wav[i] = (uint8_t)((sin( i * CONST_PERIOD_2_PI / pnt_num) + 1) * (double)(EXAMPLE_DAC_AMPLITUDE) / 2 + 0.5); + sin_wav[i] = (uint8_t)((sin(i * CONST_PERIOD_2_PI / pnt_num) + 1) * (double)(EXAMPLE_DAC_AMPLITUDE) / 2 + 0.5); tri_wav[i] = (i > (pnt_num / 2)) ? (2 * EXAMPLE_DAC_AMPLITUDE * (pnt_num - i) / pnt_num) : (2 * EXAMPLE_DAC_AMPLITUDE * i / pnt_num); saw_wav[i] = (i == pnt_num) ? 0 : (i * EXAMPLE_DAC_AMPLITUDE / pnt_num); squ_wav[i] = (i < (pnt_num / 2)) ? EXAMPLE_DAC_AMPLITUDE : 0; diff --git a/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_timer.c b/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_timer.c index 821ae8860e..ae6402dddb 100644 --- a/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_timer.c +++ b/examples/peripherals/dac/dac_continuous/signal_generator/main/dac_continuous_example_timer.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -42,24 +42,24 @@ static bool IRAM_ATTR on_timer_alarm_cb(gptimer_handle_t timer, const gptimer_al // Switch wave every CONFIG_EXAMPLE_WAVE_PERIOD_SEC second if (point_cnt < EXAMPLE_CONVERT_FREQ_HZ * CONFIG_EXAMPLE_WAVE_PERIOD_SEC) { switch (wav_sel) { - case DAC_SINE_WAVE: - ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, sin_wav[index])); - ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, sin_wav[index])); - break; - case DAC_TRIANGLE_WAVE: - ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, tri_wav[index])); - ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, tri_wav[index])); - break; - case DAC_SAWTOOTH_WAVE: - ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, saw_wav[index])); - ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, saw_wav[index])); - break; - case DAC_SQUARE_WAVE: - ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, squ_wav[index])); - ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, squ_wav[index])); - break; - default: - break; + case DAC_SINE_WAVE: + ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, sin_wav[index])); + ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, sin_wav[index])); + break; + case DAC_TRIANGLE_WAVE: + ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, tri_wav[index])); + ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, tri_wav[index])); + break; + case DAC_SAWTOOTH_WAVE: + ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, saw_wav[index])); + ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, saw_wav[index])); + break; + case DAC_SQUARE_WAVE: + ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan0_handle, squ_wav[index])); + ESP_ERROR_CHECK(dac_oneshot_output_voltage(chan1_handle, squ_wav[index])); + break; + default: + break; } point_cnt++; index++; diff --git a/examples/peripherals/dedicated_gpio/soft_i2c/components/soft_i2c_master/include/soft_i2c_master.h b/examples/peripherals/dedicated_gpio/soft_i2c/components/soft_i2c_master/include/soft_i2c_master.h index fb28aeec9e..c7f3df6084 100644 --- a/examples/peripherals/dedicated_gpio/soft_i2c/components/soft_i2c_master/include/soft_i2c_master.h +++ b/examples/peripherals/dedicated_gpio/soft_i2c/components/soft_i2c_master/include/soft_i2c_master.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -23,7 +23,6 @@ typedef enum { SOFT_I2C_FREQ_END } soft_i2c_master_freq_t; - /** * @brief Structure defining the configuration for the software I2C master bus */ @@ -33,13 +32,11 @@ typedef struct { soft_i2c_master_freq_t freq; } soft_i2c_master_config_t; - /** * @brief Abstract type representing a software I2C bus. */ typedef struct i2c_master_bus_impl_t* soft_i2c_master_bus_t; - /** * @brief Create and configure the software I2C bus. * @@ -50,7 +47,6 @@ typedef struct i2c_master_bus_impl_t* soft_i2c_master_bus_t; */ esp_err_t soft_i2c_master_new(soft_i2c_master_config_t *config, soft_i2c_master_bus_t *bus); - /** * @brief Delete a previously initialized I2C software bus. * @@ -60,7 +56,6 @@ esp_err_t soft_i2c_master_new(soft_i2c_master_config_t *config, soft_i2c_master_ */ esp_err_t soft_i2c_master_del(soft_i2c_master_bus_t bus); - /** * @brief Perform a write to the given device on the software I2C bus. * @@ -75,7 +70,6 @@ esp_err_t soft_i2c_master_write(soft_i2c_master_bus_t bus, uint8_t device_address, const uint8_t* write_buffer, size_t write_size); - /** * @brief Perform a read from the given device on the software I2C bus. * @@ -90,7 +84,6 @@ esp_err_t soft_i2c_master_read(soft_i2c_master_bus_t bus, uint8_t device_address, uint8_t* read_buffer, size_t read_size); - /** * @brief Perform a write followed by a read to the given device on the software I2C bus. * diff --git a/examples/peripherals/dedicated_gpio/soft_i2c/components/soft_i2c_master/soft_i2c_master.c b/examples/peripherals/dedicated_gpio/soft_i2c/components/soft_i2c_master/soft_i2c_master.c index 9ddff9b11b..cf283c9800 100644 --- a/examples/peripherals/dedicated_gpio/soft_i2c/components/soft_i2c_master/soft_i2c_master.c +++ b/examples/peripherals/dedicated_gpio/soft_i2c/components/soft_i2c_master/soft_i2c_master.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -24,10 +24,9 @@ /* Forward declaration of static functions */ static uint32_t freq_to_delay(soft_i2c_master_freq_t freq); static esp_err_t emulate_i2c_transfer(uint8_t device_address, - const uint8_t* write_buffer, uint32_t write_size, - uint8_t* read_buffer, uint32_t read_size, - soft_i2c_master_bus_t bus); - + const uint8_t* write_buffer, uint32_t write_size, + uint8_t* read_buffer, uint32_t read_size, + soft_i2c_master_bus_t bus); /* Mutex required to enter critical sections */ static portMUX_TYPE g_lock = portMUX_INITIALIZER_UNLOCKED; @@ -42,7 +41,6 @@ struct i2c_master_bus_impl_t { dedic_gpio_bundle_handle_t bundle; }; - esp_err_t soft_i2c_master_new(soft_i2c_master_config_t *config, soft_i2c_master_bus_t *bus) { esp_err_t ret; @@ -103,7 +101,6 @@ error: return ret; } - esp_err_t soft_i2c_master_del(soft_i2c_master_bus_t bus) { esp_err_t ret; @@ -117,7 +114,6 @@ error: return ret; } - esp_err_t soft_i2c_master_write(soft_i2c_master_bus_t bus, uint8_t device_address, const uint8_t* write_buffer, size_t write_size) @@ -159,7 +155,6 @@ error: return ret; } - esp_err_t soft_i2c_master_write_read(soft_i2c_master_bus_t bus, uint8_t device_address, const uint8_t* write_buffer, size_t write_size, @@ -184,18 +179,17 @@ error: return ret; } - /***** Private implementation *****/ static uint32_t freq_to_delay(soft_i2c_master_freq_t freq) { - switch(freq) { - case SOFT_I2C_100KHZ: return 3; - case SOFT_I2C_200KHZ: return 2; - case SOFT_I2C_300KHZ: return 1; - default: - assert(false); - return 0; + switch (freq) { + case SOFT_I2C_100KHZ: return 3; + case SOFT_I2C_200KHZ: return 2; + case SOFT_I2C_300KHZ: return 1; + default: + assert(false); + return 0; } } @@ -232,7 +226,6 @@ static inline void emulate_start(soft_i2c_master_bus_t bus) set_sda(bidir_bundle, 0, delay); } - static inline void emulate_stop(soft_i2c_master_bus_t bus) { dedic_gpio_bundle_handle_t bidir_bundle = bus->bundle; @@ -287,8 +280,7 @@ static inline uint8_t emulate_read_byte(soft_i2c_master_bus_t bus, int send_ack) set_scl(bidir_bundle, 0, delay); set_sda(bidir_bundle, 1, delay); - for (int i = 7; i >= 0; i--) - { + for (int i = 7; i >= 0; i--) { /* Set SCL to low */ set_scl(bidir_bundle, 0, delay); /* Get SDA value now and store it in the final result */ diff --git a/examples/peripherals/dedicated_gpio/soft_spi/components/soft_spi/include/soft_spi.h b/examples/peripherals/dedicated_gpio/soft_spi/components/soft_spi/include/soft_spi.h index ecf5f1c9ab..e6c9f83870 100644 --- a/examples/peripherals/dedicated_gpio/soft_spi/components/soft_spi/include/soft_spi.h +++ b/examples/peripherals/dedicated_gpio/soft_spi/components/soft_spi/include/soft_spi.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -23,13 +23,11 @@ typedef struct { uint32_t cs_pin; } soft_spi_config_t; - /** * @brief Abstract type representing a software SPI bus. */ typedef struct soft_spi_bus_impl_t* soft_spi_bus_t; - /** * @brief Create and configure the software SPI bus. * @@ -40,7 +38,6 @@ typedef struct soft_spi_bus_impl_t* soft_spi_bus_t; */ esp_err_t soft_spi_new(soft_spi_config_t *config, soft_spi_bus_t *bus); - /** * @brief Delete a previously initialized software SPI bus. * @@ -50,7 +47,6 @@ esp_err_t soft_spi_new(soft_spi_config_t *config, soft_spi_bus_t *bus); */ esp_err_t soft_spi_del(soft_spi_bus_t bus); - /** * @brief Send the given bytes on the software SPI bus. * @@ -65,7 +61,6 @@ esp_err_t soft_spi_transfer(soft_spi_bus_t bus, const uint8_t* write_buffer, uint8_t* read_buffer, size_t buf_size); - #ifdef __cplusplus } #endif diff --git a/examples/peripherals/dedicated_gpio/soft_spi/components/soft_spi/soft_spi.c b/examples/peripherals/dedicated_gpio/soft_spi/components/soft_spi/soft_spi.c index 25b081d59e..2171fb11cd 100644 --- a/examples/peripherals/dedicated_gpio/soft_spi/components/soft_spi/soft_spi.c +++ b/examples/peripherals/dedicated_gpio/soft_spi/components/soft_spi/soft_spi.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -31,7 +31,6 @@ static portMUX_TYPE g_lock = portMUX_INITIALIZER_UNLOCKED; const char* __attribute__((used)) SOFT_SPI_TAG = "soft_spi"; - struct soft_spi_bus_impl_t { uint32_t clk_bit; uint32_t mosi_bit; @@ -41,7 +40,6 @@ struct soft_spi_bus_impl_t { dedic_gpio_bundle_handle_t in_bundle; }; - esp_err_t soft_spi_new(soft_spi_config_t *config, soft_spi_bus_t *bus) { esp_err_t ret; @@ -121,7 +119,6 @@ error: return ret; } - esp_err_t soft_spi_del(soft_spi_bus_t bus) { esp_err_t ret; @@ -135,7 +132,6 @@ error: return ret; } - esp_err_t soft_spi_transfer(soft_spi_bus_t bus, const uint8_t* write_buffer, uint8_t* read_buffer, size_t buf_size) { esp_err_t ret = ESP_OK; @@ -145,9 +141,9 @@ esp_err_t soft_spi_transfer(soft_spi_bus_t bus, const uint8_t* write_buffer, uin portENTER_CRITICAL(&g_lock); asm_emulate_spi_shift_byte(write_buffer, read_buffer, buf_size, - /* Provide the offset in special dedicated GPIO register for Clock, MOSI and Clock - * respectively */ - bus->clk_bit, bus->mosi_bit, bus->cs_bit, bus->miso_bit); + /* Provide the offset in special dedicated GPIO register for Clock, MOSI and Clock + * respectively */ + bus->clk_bit, bus->mosi_bit, bus->cs_bit, bus->miso_bit); portEXIT_CRITICAL(&g_lock); error: diff --git a/examples/peripherals/dedicated_gpio/soft_uart/components/soft_uart/include/soft_uart.h b/examples/peripherals/dedicated_gpio/soft_uart/components/soft_uart/include/soft_uart.h index d35dc6362f..0ff0221cd8 100644 --- a/examples/peripherals/dedicated_gpio/soft_uart/components/soft_uart/include/soft_uart.h +++ b/examples/peripherals/dedicated_gpio/soft_uart/components/soft_uart/include/soft_uart.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -24,7 +24,6 @@ typedef enum { SOFT_UART_BAUD_END } soft_uart_baudrate_t; - /** * @brief Structure defining the configuration for the software UART port */ @@ -34,13 +33,11 @@ typedef struct { soft_uart_baudrate_t baudrate; } soft_uart_config_t; - /** * @brief Abstract type representing a software UART port. */ typedef struct soft_uart_port_impl_t* soft_uart_port_t; - /** * @brief Create and configure the software UART port. * @@ -51,7 +48,6 @@ typedef struct soft_uart_port_impl_t* soft_uart_port_t; */ esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port); - /** * @brief Delete a previously initialized software UART port. * @@ -61,7 +57,6 @@ esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port); */ esp_err_t soft_uart_del(soft_uart_port_t port); - /** * @brief Send the given bytes on the software UART port. * diff --git a/examples/peripherals/dedicated_gpio/soft_uart/components/soft_uart/soft_uart.c b/examples/peripherals/dedicated_gpio/soft_uart/components/soft_uart/soft_uart.c index 2b0a70912a..c214ca2436 100644 --- a/examples/peripherals/dedicated_gpio/soft_uart/components/soft_uart/soft_uart.c +++ b/examples/peripherals/dedicated_gpio/soft_uart/components/soft_uart/soft_uart.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -33,7 +33,6 @@ struct soft_uart_port_impl_t { dedic_gpio_bundle_handle_t rx_bundle; }; - esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port) { esp_err_t ret; @@ -82,7 +81,6 @@ esp_err_t soft_uart_new(soft_uart_config_t *config, soft_uart_port_t *port) } }; - /* Allocate the master port structure now that we need it */ port_impl = malloc(sizeof(struct soft_uart_port_impl_t)); ESP_GOTO_ON_FALSE(port_impl != NULL, ESP_ERR_NO_MEM, error, SOFT_UART_TAG, "No more memory available in the system"); @@ -118,7 +116,6 @@ error: return ret; } - esp_err_t soft_uart_del(soft_uart_port_t port) { esp_err_t ret; @@ -132,7 +129,6 @@ error: return ret; } - esp_err_t soft_uart_send(soft_uart_port_t port, const uint8_t* write_buffer, size_t write_size) { esp_err_t ret = ESP_OK; @@ -172,17 +168,17 @@ static uint32_t baudrate_to_cycles(soft_uart_baudrate_t baudrate) * For each delay, subtract a small amount of clock cycles which compensate for the instructions * used to prepare the next bits (loop, shifts, logic...). */ - switch(baudrate) { - case SOFT_UART_115200: // 115200, 8.63us per bit - return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 863)/100 - 20); - case SOFT_UART_230400: // 4.34us per bit - return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 434)/100 - 24); - case SOFT_UART_460800: // 2.17us per bit - return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 217)/100 - 20); - case SOFT_UART_921600: // 1.085us per bit - return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 108)/100 - 23); - default: - assert(false); - return 0; + switch (baudrate) { + case SOFT_UART_115200: // 115200, 8.63us per bit + return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 863) / 100 - 20); + case SOFT_UART_230400: // 4.34us per bit + return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 434) / 100 - 24); + case SOFT_UART_460800: // 2.17us per bit + return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 217) / 100 - 20); + case SOFT_UART_921600: // 1.085us per bit + return ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 108) / 100 - 23); + default: + assert(false); + return 0; } } diff --git a/examples/peripherals/gpio/generic_gpio/main/gpio_example_main.c b/examples/peripherals/gpio/generic_gpio/main/gpio_example_main.c index 1ef2491e6e..27b22cdaa4 100644 --- a/examples/peripherals/gpio/generic_gpio/main/gpio_example_main.c +++ b/examples/peripherals/gpio/generic_gpio/main/gpio_example_main.c @@ -68,8 +68,8 @@ static void IRAM_ATTR gpio_isr_handler(void* arg) static void gpio_task_example(void* arg) { uint32_t io_num; - for(;;) { - if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) { + for (;;) { + if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) { printf("GPIO[%"PRIu32"] intr, val: %d\n", io_num, gpio_get_level(io_num)); } } @@ -125,7 +125,7 @@ void app_main(void) printf("Minimum free heap size: %"PRIu32" bytes\n", esp_get_minimum_free_heap_size()); int cnt = 0; - while(1) { + while (1) { printf("cnt: %d\n", cnt++); vTaskDelay(1000 / portTICK_PERIOD_MS); gpio_set_level(GPIO_OUTPUT_IO_0, cnt % 2); diff --git a/examples/peripherals/gpio/matrix_keyboard/components/matrix_keyboard/src/matrix_keyboard.c b/examples/peripherals/gpio/matrix_keyboard/components/matrix_keyboard/src/matrix_keyboard.c index b19d4eea71..daf1b6a341 100644 --- a/examples/peripherals/gpio/matrix_keyboard/components/matrix_keyboard/src/matrix_keyboard.c +++ b/examples/peripherals/gpio/matrix_keyboard/components/matrix_keyboard/src/matrix_keyboard.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -86,7 +86,7 @@ static void matrix_kbd_debounce_timer_callback(TimerHandle_t xTimer) // col lines set to low level dedic_gpio_bundle_write(mkbd->col_bundle, (1 << mkbd->nr_col_gpios) - 1, 0); dedic_gpio_bundle_set_interrupt_and_callback(mkbd->row_bundle, (1 << mkbd->nr_row_gpios) - 1, - DEDIC_GPIO_INTR_BOTH_EDGE, matrix_kbd_row_isr_callback, mkbd); + DEDIC_GPIO_INTR_BOTH_EDGE, matrix_kbd_row_isr_callback, mkbd); } esp_err_t matrix_kbd_install(const matrix_kbd_config_t *config, matrix_kbd_handle_t *mkbd_handle) @@ -145,9 +145,9 @@ esp_err_t matrix_kbd_install(const matrix_kbd_config_t *config, matrix_kbd_handl // Disable interrupt dedic_gpio_bundle_set_interrupt_and_callback(mkbd->row_bundle, (1 << config->nr_row_gpios) - 1, - DEDIC_GPIO_INTR_NONE, NULL, NULL); + DEDIC_GPIO_INTR_NONE, NULL, NULL); dedic_gpio_bundle_set_interrupt_and_callback(mkbd->col_bundle, (1 << config->nr_col_gpios) - 1, - DEDIC_GPIO_INTR_NONE, NULL, NULL); + DEDIC_GPIO_INTR_NONE, NULL, NULL); // Create a ont-shot os timer, used for key debounce mkbd->debounce_timer = xTimerCreate("kb_debounce", pdMS_TO_TICKS(config->debounce_ms), pdFALSE, mkbd, matrix_kbd_debounce_timer_callback); @@ -200,7 +200,7 @@ esp_err_t matrix_kbd_start(matrix_kbd_handle_t mkbd_handle) // only enable row line interrupt dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->row_bundle, (1 << mkbd_handle->nr_row_gpios) - 1, - DEDIC_GPIO_INTR_BOTH_EDGE, matrix_kbd_row_isr_callback, mkbd_handle); + DEDIC_GPIO_INTR_BOTH_EDGE, matrix_kbd_row_isr_callback, mkbd_handle); return ESP_OK; err: @@ -216,9 +216,9 @@ esp_err_t matrix_kbd_stop(matrix_kbd_handle_t mkbd_handle) // Disable interrupt dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->row_bundle, (1 << mkbd_handle->nr_row_gpios) - 1, - DEDIC_GPIO_INTR_NONE, NULL, NULL); + DEDIC_GPIO_INTR_NONE, NULL, NULL); dedic_gpio_bundle_set_interrupt_and_callback(mkbd_handle->col_bundle, (1 << mkbd_handle->nr_col_gpios) - 1, - DEDIC_GPIO_INTR_NONE, NULL, NULL); + DEDIC_GPIO_INTR_NONE, NULL, NULL); return ESP_OK; err: diff --git a/examples/peripherals/i2c/i2c_eeprom/main/i2c_eeprom_main.c b/examples/peripherals/i2c/i2c_eeprom/main/i2c_eeprom_main.c index 1b925ad22c..cab8d281a6 100644 --- a/examples/peripherals/i2c/i2c_eeprom/main/i2c_eeprom_main.c +++ b/examples/peripherals/i2c/i2c_eeprom/main/i2c_eeprom_main.c @@ -23,7 +23,7 @@ static void disp_buf(uint8_t *buf, int len) int i; for (i = 0; i < len; i++) { printf("%02x ", buf[i]); - if (( i + 1 ) % 16 == 0) { + if ((i + 1) % 16 == 0) { printf("\n"); } } @@ -59,7 +59,7 @@ void app_main(void) uint8_t read_buf[LENGTH]; ESP_ERROR_CHECK(i2c_eeprom_init(bus_handle, &eeprom_config, &eeprom_handle)); - while(1) { + while (1) { ESP_ERROR_CHECK(i2c_eeprom_write(eeprom_handle, block_addr, buf, LENGTH)); // Needs wait for eeprom hardware done, referring from datasheet i2c_eeprom_wait_idle(eeprom_handle); diff --git a/examples/peripherals/i2c/i2c_self_test/main/i2c_example_main.c b/examples/peripherals/i2c/i2c_self_test/main/i2c_example_main.c index d9629ba09a..993548c479 100644 --- a/examples/peripherals/i2c/i2c_self_test/main/i2c_example_main.c +++ b/examples/peripherals/i2c/i2c_self_test/main/i2c_example_main.c @@ -31,12 +31,12 @@ static const char *TAG = "i2c-example"; #define DELAY_TIME_BETWEEN_ITEMS_MS 1000 /*!< delay time between different test items */ #if SOC_I2C_NUM > 1 - #define I2C_SLAVE_SCL_IO CONFIG_I2C_SLAVE_SCL /*!< gpio number for i2c slave clock */ - #define I2C_SLAVE_SDA_IO CONFIG_I2C_SLAVE_SDA /*!< gpio number for i2c slave data */ - #define I2C_SLAVE_NUM I2C_NUMBER(CONFIG_I2C_SLAVE_PORT_NUM) /*!< I2C port number for slave dev */ - #define I2C_SLAVE_TX_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave tx buffer size */ - #define I2C_SLAVE_RX_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave rx buffer size */ - #define ESP_SLAVE_ADDR CONFIG_I2C_SLAVE_ADDRESS /*!< ESP32 slave address, you can set any 7bit value */ +#define I2C_SLAVE_SCL_IO CONFIG_I2C_SLAVE_SCL /*!< gpio number for i2c slave clock */ +#define I2C_SLAVE_SDA_IO CONFIG_I2C_SLAVE_SDA /*!< gpio number for i2c slave data */ +#define I2C_SLAVE_NUM I2C_NUMBER(CONFIG_I2C_SLAVE_PORT_NUM) /*!< I2C port number for slave dev */ +#define I2C_SLAVE_TX_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave tx buffer size */ +#define I2C_SLAVE_RX_BUF_LEN (2 * DATA_LENGTH) /*!< I2C slave rx buffer size */ +#define ESP_SLAVE_ADDR CONFIG_I2C_SLAVE_ADDRESS /*!< ESP32 slave address, you can set any 7bit value */ #endif #define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL /*!< gpio number for I2C master clock */ @@ -280,7 +280,7 @@ static void i2c_test_task(void *arg) ret = i2c_master_write_slave(I2C_MASTER_NUM, data_wr, RW_TEST_LENGTH); if (ret == ESP_OK) { size = i2c_slave_read_buffer(I2C_SLAVE_NUM, data, RW_TEST_LENGTH, 1000 / portTICK_PERIOD_MS); - } + } if (ret == ESP_ERR_TIMEOUT) { ESP_LOGE(TAG, "I2C Timeout"); } else if (ret == ESP_OK) { diff --git a/examples/peripherals/i2c/i2c_simple/main/i2c_simple_main.c b/examples/peripherals/i2c/i2c_simple/main/i2c_simple_main.c index 6e63a361b1..e95b38cf16 100644 --- a/examples/peripherals/i2c/i2c_simple/main/i2c_simple_main.c +++ b/examples/peripherals/i2c/i2c_simple/main/i2c_simple_main.c @@ -78,7 +78,6 @@ static esp_err_t i2c_master_init(void) return i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0); } - void app_main(void) { uint8_t data[2]; diff --git a/examples/peripherals/i2s/i2s_basic/i2s_pdm/main/i2s_pdm_rx.c b/examples/peripherals/i2s/i2s_basic/i2s_pdm/main/i2s_pdm_rx.c index 08f091b41d..174c37a370 100644 --- a/examples/peripherals/i2s/i2s_basic/i2s_pdm/main/i2s_pdm_rx.c +++ b/examples/peripherals/i2s/i2s_basic/i2s_pdm/main/i2s_pdm_rx.c @@ -24,7 +24,6 @@ #define EXAMPLE_PDM_RX_FREQ_HZ 16000 // I2S PDM RX frequency - static i2s_chan_handle_t i2s_example_init_pdm_rx(void) { i2s_chan_handle_t rx_chan; // I2S rx channel handler @@ -72,7 +71,6 @@ static i2s_chan_handle_t i2s_example_init_pdm_rx(void) return rx_chan; } - void i2s_example_pdm_rx_task(void *args) { int16_t *r_buf = (int16_t *)calloc(1, EXAMPLE_BUFF_SIZE); diff --git a/examples/peripherals/i2s/i2s_basic/i2s_pdm/main/i2s_pdm_tx.c b/examples/peripherals/i2s/i2s_basic/i2s_pdm/main/i2s_pdm_tx.c index 5bee1954b3..332fed0e3e 100644 --- a/examples/peripherals/i2s/i2s_basic/i2s_pdm/main/i2s_pdm_tx.c +++ b/examples/peripherals/i2s/i2s_basic/i2s_pdm/main/i2s_pdm_tx.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -25,14 +25,17 @@ #define EXAMPLE_BYTE_NUM_EVERY_TONE (EXAMPLE_TONE_LAST_TIME_MS * EXAMPLE_PDM_TX_FREQ_HZ / 1000) /* The frequency of tones: do, re, mi, fa, so, la, si, in Hz. */ -static const uint32_t tone[3][7] = {{262, 294, 330, 349, 392, 440, 494}, // bass - {523, 587, 659, 698, 784, 880, 988}, // alto - {1046, 1175, 1318, 1397, 1568, 1760, 1976}}; // treble +static const uint32_t tone[3][7] = { + {262, 294, 330, 349, 392, 440, 494}, // bass + {523, 587, 659, 698, 784, 880, 988}, // alto + {1046, 1175, 1318, 1397, 1568, 1760, 1976}, // treble +}; /* Numbered musical notation of 'twinkle twinkle little star' */ static const uint8_t song[28] = {1, 1, 5, 5, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1, 5, 5, 4, 4, 3, 3, 2, - 5, 5, 4, 4, 3, 3, 2}; + 5, 5, 4, 4, 3, 3, 2 + }; /* Rhythm of 'twinkle twinkle little star', it's repeated in four sections */ static const uint8_t rhythm[7] = {1, 1, 1, 1, 1, 1, 2}; @@ -92,10 +95,10 @@ void i2s_example_pdm_tx_task(void *args) printf("Playing %s `twinkle twinkle little star`\n", tone_name[tone_select]); while (1) { - int tone_point = EXAMPLE_SINE_WAVE_LEN(tone[tone_select][song[cnt]-1]); + int tone_point = EXAMPLE_SINE_WAVE_LEN(tone[tone_select][song[cnt] - 1]); /* Generate the tone buffer */ for (int i = 0; i < tone_point; i++) { - w_buf[i] = (int16_t)((sin(2 * (float)i * CONST_PI / tone_point)) * EXAMPLE_WAVE_AMPLITUDE); + w_buf[i] = (int16_t)((sin(2 * (float)i * CONST_PI / tone_point)) * EXAMPLE_WAVE_AMPLITUDE); } for (int tot_bytes = 0; tot_bytes < EXAMPLE_BYTE_NUM_EVERY_TONE * rhythm[cnt % 7]; tot_bytes += w_bytes) { /* Play the tone */ diff --git a/examples/peripherals/i2s/i2s_basic/i2s_std/main/i2s_std_example_main.c b/examples/peripherals/i2s/i2s_basic/i2s_std/main/i2s_std_example_main.c index 8276022983..ac3caade60 100644 --- a/examples/peripherals/i2s/i2s_basic/i2s_std/main/i2s_std_example_main.c +++ b/examples/peripherals/i2s/i2s_basic/i2s_std/main/i2s_std_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -20,27 +20,27 @@ #define EXAMPLE_I2S_DUPLEX_MODE CONFIG_USE_DUPLEX #if CONFIG_IDF_TARGET_ESP32 - #define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_4 // I2S bit clock io number - #define EXAMPLE_STD_WS_IO1 GPIO_NUM_5 // I2S word select io number - #define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_18 // I2S data out io number - #define EXAMPLE_STD_DIN_IO1 GPIO_NUM_19 // I2S data in io number - #if !EXAMPLE_I2S_DUPLEX_MODE - #define EXAMPLE_STD_BCLK_IO2 GPIO_NUM_22 // I2S bit clock io number - #define EXAMPLE_STD_WS_IO2 GPIO_NUM_23 // I2S word select io number - #define EXAMPLE_STD_DOUT_IO2 GPIO_NUM_25 // I2S data out io number - #define EXAMPLE_STD_DIN_IO2 GPIO_NUM_26 // I2S data in io number - #endif +#define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_4 // I2S bit clock io number +#define EXAMPLE_STD_WS_IO1 GPIO_NUM_5 // I2S word select io number +#define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_18 // I2S data out io number +#define EXAMPLE_STD_DIN_IO1 GPIO_NUM_19 // I2S data in io number +#if !EXAMPLE_I2S_DUPLEX_MODE +#define EXAMPLE_STD_BCLK_IO2 GPIO_NUM_22 // I2S bit clock io number +#define EXAMPLE_STD_WS_IO2 GPIO_NUM_23 // I2S word select io number +#define EXAMPLE_STD_DOUT_IO2 GPIO_NUM_25 // I2S data out io number +#define EXAMPLE_STD_DIN_IO2 GPIO_NUM_26 // I2S data in io number +#endif #else - #define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_2 // I2S bit clock io number - #define EXAMPLE_STD_WS_IO1 GPIO_NUM_3 // I2S word select io number - #define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_4 // I2S data out io number - #define EXAMPLE_STD_DIN_IO1 GPIO_NUM_5 // I2S data in io number - #if !EXAMPLE_I2S_DUPLEX_MODE - #define EXAMPLE_STD_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number - #define EXAMPLE_STD_WS_IO2 GPIO_NUM_7 // I2S word select io number - #define EXAMPLE_STD_DOUT_IO2 GPIO_NUM_8 // I2S data out io number - #define EXAMPLE_STD_DIN_IO2 GPIO_NUM_9 // I2S data in io number - #endif +#define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_2 // I2S bit clock io number +#define EXAMPLE_STD_WS_IO1 GPIO_NUM_3 // I2S word select io number +#define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_4 // I2S data out io number +#define EXAMPLE_STD_DIN_IO1 GPIO_NUM_5 // I2S data in io number +#if !EXAMPLE_I2S_DUPLEX_MODE +#define EXAMPLE_STD_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number +#define EXAMPLE_STD_WS_IO2 GPIO_NUM_7 // I2S word select io number +#define EXAMPLE_STD_DOUT_IO2 GPIO_NUM_8 // I2S data out io number +#define EXAMPLE_STD_DIN_IO2 GPIO_NUM_9 // I2S data in io number +#endif #endif #define EXAMPLE_BUFF_SIZE 2048 diff --git a/examples/peripherals/i2s/i2s_basic/i2s_tdm/main/i2s_tdm_example_main.c b/examples/peripherals/i2s/i2s_basic/i2s_tdm/main/i2s_tdm_example_main.c index 38a132a1df..ad09af1e78 100644 --- a/examples/peripherals/i2s/i2s_basic/i2s_tdm/main/i2s_tdm_example_main.c +++ b/examples/peripherals/i2s/i2s_basic/i2s_tdm/main/i2s_tdm_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -22,10 +22,10 @@ #define EXAMPLE_TDM_DOUT_IO1 GPIO_NUM_4 // I2S data out io number #define EXAMPLE_TDM_DIN_IO1 GPIO_NUM_5 // I2S data in io number #if !EXAMPLE_I2S_DUPLEX_MODE - #define EXAMPLE_TDM_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number - #define EXAMPLE_TDM_WS_IO2 GPIO_NUM_7 // I2S word select io number - #define EXAMPLE_TDM_DOUT_IO2 GPIO_NUM_8 // I2S data out io number - #define EXAMPLE_TDM_DIN_IO2 GPIO_NUM_9 // I2S data in io number +#define EXAMPLE_TDM_BCLK_IO2 GPIO_NUM_6 // I2S bit clock io number +#define EXAMPLE_TDM_WS_IO2 GPIO_NUM_7 // I2S word select io number +#define EXAMPLE_TDM_DOUT_IO2 GPIO_NUM_8 // I2S data out io number +#define EXAMPLE_TDM_DIN_IO2 GPIO_NUM_9 // I2S data in io number #endif #define EXAMPLE_BUFF_SIZE 2048 diff --git a/examples/peripherals/i2s/i2s_codec/i2s_es7210_tdm/main/i2s_es7210_record_example.c b/examples/peripherals/i2s/i2s_codec/i2s_es7210_tdm/main/i2s_es7210_record_example.c index 9bd65e93a7..bdc10b366c 100644 --- a/examples/peripherals/i2s/i2s_codec/i2s_es7210_tdm/main/i2s_es7210_record_example.c +++ b/examples/peripherals/i2s/i2s_codec/i2s_es7210_tdm/main/i2s_es7210_record_example.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -71,7 +71,6 @@ static const char *TAG = "example"; - static i2s_chan_handle_t es7210_i2s_init(void) { i2s_chan_handle_t i2s_rx_chan = NULL; @@ -151,8 +150,8 @@ sdmmc_card_t * mount_sdcard(void) } ESP_LOGI(TAG, "Card size: %lluMB, speed: %dMHz", - (((uint64_t)sdmmc_card->csd.capacity) * sdmmc_card->csd.sector_size) >> 20, - sdmmc_card->max_freq_khz / 1000); + (((uint64_t)sdmmc_card->csd.capacity) * sdmmc_card->csd.sector_size) >> 20, + sdmmc_card->max_freq_khz / 1000); return sdmmc_card; } @@ -217,13 +216,13 @@ static esp_err_t record_wav(i2s_chan_handle_t i2s_rx_chan) static int16_t i2s_readraw_buff[4096]; ESP_GOTO_ON_ERROR(i2s_channel_enable(i2s_rx_chan), err, TAG, "error while starting i2s rx channel"); while (wav_written < wav_size) { - if(wav_written % byte_rate < sizeof(i2s_readraw_buff)) { - ESP_LOGI(TAG, "Recording: %"PRIu32"/%ds", wav_written/byte_rate + 1, EXAMPLE_RECORD_TIME_SEC); + if (wav_written % byte_rate < sizeof(i2s_readraw_buff)) { + ESP_LOGI(TAG, "Recording: %"PRIu32"/%ds", wav_written / byte_rate + 1, EXAMPLE_RECORD_TIME_SEC); } size_t bytes_read = 0; /* Read RAW samples from ES7210 */ ESP_GOTO_ON_ERROR(i2s_channel_read(i2s_rx_chan, i2s_readraw_buff, sizeof(i2s_readraw_buff), &bytes_read, - pdMS_TO_TICKS(1000)), err, TAG, "error while reading samples from i2s"); + pdMS_TO_TICKS(1000)), err, TAG, "error while reading samples from i2s"); /* Write the samples to the WAV file */ ESP_GOTO_ON_FALSE(fwrite(i2s_readraw_buff, bytes_read, 1, f), ESP_FAIL, err, TAG, "error while writing samples to wav file"); @@ -250,9 +249,9 @@ void app_main(void) esp_err_t err = record_wav(i2s_rx_chan); /* Unmount SD card */ esp_vfs_fat_sdcard_unmount(EXAMPLE_SD_MOUNT_POINT, sdmmc_card); - if(err == ESP_OK) { + if (err == ESP_OK) { ESP_LOGI(TAG, "Audio was successfully recorded into "EXAMPLE_RECORD_FILE_PATH - ". You can now remove the SD card safely"); + ". You can now remove the SD card safely"); } else { ESP_LOGE(TAG, "Record failed, "EXAMPLE_RECORD_FILE_PATH" on SD card may not be playable."); } diff --git a/examples/peripherals/i2s/i2s_codec/i2s_es8311/main/example_config.h b/examples/peripherals/i2s/i2s_codec/i2s_es8311/main/example_config.h index 72835af592..afab7b4408 100644 --- a/examples/peripherals/i2s/i2s_codec/i2s_es8311/main/example_config.h +++ b/examples/peripherals/i2s/i2s_codec/i2s_es8311/main/example_config.h @@ -18,7 +18,6 @@ #define EXAMPLE_MIC_GAIN CONFIG_EXAMPLE_MIC_GAIN #endif - #if !defined(CONFIG_EXAMPLE_BSP) /* I2C port and GPIOs */ @@ -47,7 +46,6 @@ #define I2S_DI_IO (GPIO_NUM_3) #endif - #else // CONFIG_EXAMPLE_BSP #include "bsp/esp-bsp.h" #define I2C_NUM BSP_I2C_NUM diff --git a/examples/peripherals/i2s/i2s_codec/i2s_es8311/main/i2s_es8311_example.c b/examples/peripherals/i2s/i2s_codec/i2s_es8311/main/i2s_es8311_example.c index 66012e47b1..3abbb23efd 100644 --- a/examples/peripherals/i2s/i2s_codec/i2s_es8311/main/i2s_es8311_example.c +++ b/examples/peripherals/i2s/i2s_codec/i2s_es8311/main/i2s_es8311_example.c @@ -15,7 +15,6 @@ #include "es8311.h" #include "example_config.h" - static const char *TAG = "i2s_es8311"; static const char err_reason[][30] = {"input param is invalid", "operation timeout" diff --git a/examples/peripherals/lcd/tjpgd/main/pretty_effect.c b/examples/peripherals/lcd/tjpgd/main/pretty_effect.c index b7e557f990..d12c52bcc1 100644 --- a/examples/peripherals/lcd/tjpgd/main/pretty_effect.c +++ b/examples/peripherals/lcd/tjpgd/main/pretty_effect.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -15,11 +15,11 @@ uint16_t *pixels; static inline uint16_t get_bgnd_pixel(int x, int y) { //Get color of the pixel on x,y coords - return (uint16_t) *(pixels + (y * IMAGE_W) + x); + return (uint16_t) * (pixels + (y * IMAGE_W) + x); } //This variable is used to detect the next frame. -static int prev_frame=-1; +static int prev_frame = -1; //Instead of calculating the offsets for each pixel we grab, we pre-calculate the valueswhenever a frame changes, then re-use //these as we go through all the pixels in the frame. This is much, much faster. @@ -31,23 +31,30 @@ static int8_t xcomp[320], ycomp[240]; //is displayed; this is used to go to the next frame of animation. void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect) { - if (frame!=prev_frame) { + if (frame != prev_frame) { //We need to calculate a new set of offset coefficients. Take some random sines as offsets to make everything //look pretty and fluid-y. - for (int x=0; x<320; x++) xofs[x]=sin(frame*0.15+x*0.06)*4; - for (int y=0; y<240; y++) yofs[y]=sin(frame*0.1+y*0.05)*4; - for (int x=0; x<320; x++) xcomp[x]=sin(frame*0.11+x*0.12)*4; - for (int y=0; y<240; y++) ycomp[y]=sin(frame*0.07+y*0.15)*4; - prev_frame=frame; + for (int x = 0; x < 320; x++) { + xofs[x] = sin(frame * 0.15 + x * 0.06) * 4; + } + for (int y = 0; y < 240; y++) { + yofs[y] = sin(frame * 0.1 + y * 0.05) * 4; + } + for (int x = 0; x < 320; x++) { + xcomp[x] = sin(frame * 0.11 + x * 0.12) * 4; + } + for (int y = 0; y < 240; y++) { + ycomp[y] = sin(frame * 0.07 + y * 0.15) * 4; + } + prev_frame = frame; } - for (int y=line; y #include "esp_err.h" - /** * @brief Calculate the effect for a bunch of lines. * @@ -19,7 +18,6 @@ */ void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect); - /** * @brief Initialize the effect * diff --git a/examples/peripherals/ledc/ledc_fade/main/ledc_fade_example_main.c b/examples/peripherals/ledc/ledc_fade/main/ledc_fade_example_main.c index 6c961959aa..ada11d47bb 100644 --- a/examples/peripherals/ledc/ledc_fade/main/ledc_fade_example_main.c +++ b/examples/peripherals/ledc/ledc_fade/main/ledc_fade_example_main.c @@ -195,9 +195,9 @@ void app_main(void) printf("1. LEDC fade up to duty = %d\n", LEDC_TEST_DUTY); for (ch = 0; ch < LEDC_TEST_CH_NUM; ch++) { ledc_set_fade_with_time(ledc_channel[ch].speed_mode, - ledc_channel[ch].channel, LEDC_TEST_DUTY, LEDC_TEST_FADE_TIME); + ledc_channel[ch].channel, LEDC_TEST_DUTY, LEDC_TEST_FADE_TIME); ledc_fade_start(ledc_channel[ch].speed_mode, - ledc_channel[ch].channel, LEDC_FADE_NO_WAIT); + ledc_channel[ch].channel, LEDC_FADE_NO_WAIT); } for (int i = 0; i < LEDC_TEST_CH_NUM; i++) { @@ -207,9 +207,9 @@ void app_main(void) printf("2. LEDC fade down to duty = 0\n"); for (ch = 0; ch < LEDC_TEST_CH_NUM; ch++) { ledc_set_fade_with_time(ledc_channel[ch].speed_mode, - ledc_channel[ch].channel, 0, LEDC_TEST_FADE_TIME); + ledc_channel[ch].channel, 0, LEDC_TEST_FADE_TIME); ledc_fade_start(ledc_channel[ch].speed_mode, - ledc_channel[ch].channel, LEDC_FADE_NO_WAIT); + ledc_channel[ch].channel, LEDC_FADE_NO_WAIT); } for (int i = 0; i < LEDC_TEST_CH_NUM; i++) { diff --git a/examples/peripherals/ledc/ledc_gamma_curve_fade/main/ledc_gamma_curve_fade_example_main.c b/examples/peripherals/ledc/ledc_gamma_curve_fade/main/ledc_gamma_curve_fade_example_main.c index 24cc72fb7d..9277866e8e 100644 --- a/examples/peripherals/ledc/ledc_gamma_curve_fade/main/ledc_gamma_curve_fade_example_main.c +++ b/examples/peripherals/ledc/ledc_gamma_curve_fade/main/ledc_gamma_curve_fade_example_main.c @@ -64,7 +64,6 @@ static rgb_channel_config_t rgb_led_2_channels = { .blue_channel = LEDC_CHANNEL_GAMMA_BLUE, }; - // Define some colors R, G, B channel PWM duty cycles #define RGB_TO_DUTY(x) (x * (1 << LEDC_DUTY_RES) / 255) @@ -126,7 +125,6 @@ static rgb_channel_config_t rgb_led_2_channels = { #define BLUEISH_PURPLE_G RGB_TO_DUTY(102) #define BLUEISH_PURPLE_B RGB_TO_DUTY(255) - #if CONFIG_GAMMA_CORRECTION_WITH_LUT // Brightness 0 - 100% gamma correction look up table (gamma = 2.6) // Y = B ^ 2.6 @@ -158,7 +156,6 @@ static uint32_t gamma_correction_calculator(uint32_t duty) } #endif // CONFIG_GAMMA_CORRECTION_WITH_LUT - static void rgb_set_duty_and_update(rgb_channel_config_t rgb_channels, uint32_t target_r_duty, uint32_t target_g_duty, uint32_t target_b_duty) { diff --git a/examples/peripherals/mcpwm/mcpwm_bldc_hall_control/main/mcpwm_bldc_hall_control_example_main.c b/examples/peripherals/mcpwm/mcpwm_bldc_hall_control/main/mcpwm_bldc_hall_control_example_main.c index d437c72421..a0726322f3 100644 --- a/examples/peripherals/mcpwm/mcpwm_bldc_hall_control/main/mcpwm_bldc_hall_control_example_main.c +++ b/examples/peripherals/mcpwm/mcpwm_bldc_hall_control/main/mcpwm_bldc_hall_control_example_main.c @@ -1,6 +1,6 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -261,22 +261,22 @@ void app_main(void) // we will use the dead time module to add edge delay, also make gen_high and gen_low complementary for (int i = 0; i < 3; i++) { ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH], - MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH))); + MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH))); ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH], - MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW))); + MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW))); ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH], - MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW))); + MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW))); ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_HIGH], - MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW))); + MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW))); ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW], - MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH))); + MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH))); ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW], - MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW))); + MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW))); ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW], - MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW))); + MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW))); ESP_ERROR_CHECK(mcpwm_generator_set_action_on_brake_event(generators[i][BLDC_MCPWM_GEN_INDEX_LOW], - MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW))); + MCPWM_GEN_BRAKE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_OPER_BRAKE_MODE_CBC, MCPWM_GEN_ACTION_LOW))); } ESP_LOGI(TAG, "Setup deadtime"); diff --git a/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/app_main.c b/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/app_main.c index 1e6f14e5df..e21301adf1 100644 --- a/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/app_main.c +++ b/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/app_main.c @@ -51,12 +51,11 @@ static const char *TAG = "example_foc"; #define EXAMPLE_FOC_WAVE_FREQ 10 // 50Hz 3 phase AC wave #define EXAMPLE_FOC_WAVE_AMPL 100 // Wave amplitude, Use up-down timer mode, max value should be (EXAMPLE_FOC_MCPWM_PERIOD/2) - void bsp_bridge_driver_init(void) { gpio_config_t drv_en_config = { - .pin_bit_mask = 1ULL << EXAMPLE_FOC_DRV_EN_GPIO, .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = 1ULL << EXAMPLE_FOC_DRV_EN_GPIO, }; ESP_ERROR_CHECK(gpio_config(&drv_en_config)); } diff --git a/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/foc/esp_foc.c b/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/foc/esp_foc.c index 10ce368440..ab70f12158 100644 --- a/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/foc/esp_foc.c +++ b/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/foc/esp_foc.c @@ -5,12 +5,11 @@ */ #include "esp_foc.h" - /** * alpha = u - (v + w)sin(30) * (2/3), (2/3): Equal amplitude transformation const * beta = (v - w)cos(30) * (2/3) */ -void foc_clarke_transform (const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab) +void foc_clarke_transform(const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab) { const _iq foc_clark_k1_iq = _IQ(2.0 / 3.0); const _iq foc_clark_k2_iq = _IQ(1.0 / 3.0); @@ -20,14 +19,14 @@ void foc_clarke_transform (const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab) v_ab->beta = _IQmpy(v_uvw->v - v_uvw->w, foc_clark_k3_iq); } -void foc_inverse_clarke_transform (const foc_ab_coord_t *v_ab, foc_uvw_coord_t *v_uvw) +void foc_inverse_clarke_transform(const foc_ab_coord_t *v_ab, foc_uvw_coord_t *v_uvw) { v_uvw->u = v_ab->alpha; v_uvw->v = _IQdiv2(_IQmpy(v_ab->beta, _IQ(M_SQRT3)) - v_ab->alpha); v_uvw->w = -v_uvw->u - v_uvw->v; } -void foc_park_transform (_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord_t *v_dq) +void foc_park_transform(_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord_t *v_dq) { _iq sin = _IQsin(theta_rad); _iq cos = _IQcos(theta_rad); @@ -36,7 +35,7 @@ void foc_park_transform (_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord v_dq->q = _IQmpy(v_ab->beta, cos) - _IQmpy(v_ab->alpha, sin); } -void foc_inverse_park_transform (_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ab_coord_t *v_ab) +void foc_inverse_park_transform(_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ab_coord_t *v_ab) { _iq sin = _IQsin(theta_rad); _iq cos = _IQcos(theta_rad); diff --git a/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/foc/esp_foc.h b/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/foc/esp_foc.h index c478a80d66..2bd1952768 100644 --- a/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/foc/esp_foc.h +++ b/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/foc/esp_foc.h @@ -10,7 +10,6 @@ #define GLOBAL_IQ 18 #include "IQmathLib.h" - // 3-phase uvw coord data type typedef struct foc_uvw_coord { _iq u; // U phase data in IQ type @@ -36,7 +35,7 @@ typedef struct foc_dq_coord { * @param[in] v_uvw data in 3-phase coord to be transformed * @param[out] v_ab output data in alpha-beta coord */ -void foc_clarke_transform (const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab); +void foc_clarke_transform(const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab); /** * @brief inverse clark transform, to transform value in alpha_beta system to 3phase uvw system @@ -44,7 +43,7 @@ void foc_clarke_transform (const foc_uvw_coord_t *v_uvw, foc_ab_coord_t *v_ab); * @param[in] v_ab data in alpha-beta coord to be transformed * @param[out] v_uvw output data in 3-phase coord */ -void foc_inverse_clarke_transform (const foc_ab_coord_t *v_ab, foc_uvw_coord_t *v_uvw); +void foc_inverse_clarke_transform(const foc_ab_coord_t *v_ab, foc_uvw_coord_t *v_uvw); /** * @brief park transform, to transform value in static alpha_beta system to rotate d-q system @@ -53,7 +52,7 @@ void foc_inverse_clarke_transform (const foc_ab_coord_t *v_ab, foc_uvw_coord_t * * @param[in] v_ab data in alpha-beta coord to be transformed * @param[out] v_dq output data in dq coord */ -void foc_park_transform (_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord_t *v_dq); +void foc_park_transform(_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord_t *v_dq); /** * @brief inverse park transform, to transform value in rotate d-q system to alpha_beta system @@ -62,7 +61,7 @@ void foc_park_transform (_iq theta_rad, const foc_ab_coord_t *v_ab, foc_dq_coord * @param[in] v_dq data in dq coord to be transformed * @param[out] v_ab output data in alpha-beta coord */ -void foc_inverse_park_transform (_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ab_coord_t *v_ab); +void foc_inverse_park_transform(_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ab_coord_t *v_ab); /** * @brief 7-segment svpwm modulation @@ -70,4 +69,4 @@ void foc_inverse_park_transform (_iq theta_rad, const foc_dq_coord_t *v_dq, foc_ * @param v_ab[in] input value in alpha-beta coord * @param out_uvw[out] output modulated pwm duty in IQ type */ -void foc_svpwm_duty_calculate (const foc_ab_coord_t *v_ab, foc_uvw_coord_t *out_uvw); +void foc_svpwm_duty_calculate(const foc_ab_coord_t *v_ab, foc_uvw_coord_t *out_uvw); diff --git a/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/svpwm/esp_svpwm.c b/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/svpwm/esp_svpwm.c index f05a1643f3..ee0887bc5f 100644 --- a/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/svpwm/esp_svpwm.c +++ b/examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop/main/svpwm/esp_svpwm.c @@ -18,7 +18,6 @@ typedef struct mcpwm_svpwm_ctx { mcpwm_gen_handle_t generators[3][2]; } mcpwm_svpwm_ctx_t; - esp_err_t svpwm_new_inverter(const inverter_config_t *config, inverter_handle_t *ret_inverter) { esp_err_t ret; @@ -51,9 +50,9 @@ esp_err_t svpwm_new_inverter(const inverter_config_t *config, inverter_handle_t for (int i = 0; i < 3; i++) { ESP_GOTO_ON_ERROR(mcpwm_generator_set_actions_on_compare_event(svpwm_dev->generators[i][0], - MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, svpwm_dev->comparators[i], MCPWM_GEN_ACTION_LOW), - MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_DOWN, svpwm_dev->comparators[i], MCPWM_GEN_ACTION_HIGH), - MCPWM_GEN_COMPARE_EVENT_ACTION_END()), err, TAG, "Set generator actions failed"); + MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, svpwm_dev->comparators[i], MCPWM_GEN_ACTION_LOW), + MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_DOWN, svpwm_dev->comparators[i], MCPWM_GEN_ACTION_HIGH), + MCPWM_GEN_COMPARE_EVENT_ACTION_END()), err, TAG, "Set generator actions failed"); } for (int i = 0; i < 3; i++) { diff --git a/examples/peripherals/mcpwm/mcpwm_servo_control/main/mcpwm_servo_control_example_main.c b/examples/peripherals/mcpwm/mcpwm_servo_control/main/mcpwm_servo_control_example_main.c index 7440cfa1dd..47dc4b2990 100644 --- a/examples/peripherals/mcpwm/mcpwm_servo_control/main/mcpwm_servo_control_example_main.c +++ b/examples/peripherals/mcpwm/mcpwm_servo_control/main/mcpwm_servo_control_example_main.c @@ -67,10 +67,10 @@ void app_main(void) ESP_LOGI(TAG, "Set generator action on timer and compare event"); // go high on counter empty ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generator, - MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH))); + MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH))); // go low on compare threshold ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generator, - MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparator, MCPWM_GEN_ACTION_LOW))); + MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparator, MCPWM_GEN_ACTION_LOW))); ESP_LOGI(TAG, "Enable and start timer"); ESP_ERROR_CHECK(mcpwm_timer_enable(timer)); diff --git a/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c b/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c index 60b6a1c06f..c05aa0e000 100644 --- a/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c +++ b/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c @@ -176,11 +176,11 @@ void app_main(void) ESP_LOGI(TAG, "Set generator actions on timer and compare event"); for (int i = 0; i < 3; i++) { ESP_ERROR_CHECK(mcpwm_generator_set_action_on_timer_event(generators[i], - // when the timer value is zero, and is counting up, set output to high - MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH))); + // when the timer value is zero, and is counting up, set output to high + MCPWM_GEN_TIMER_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, MCPWM_TIMER_EVENT_EMPTY, MCPWM_GEN_ACTION_HIGH))); ESP_ERROR_CHECK(mcpwm_generator_set_action_on_compare_event(generators[i], - // when compare event happens, and timer is counting up, set output to low - MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW))); + // when compare event happens, and timer is counting up, set output to low + MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comparators[i], MCPWM_GEN_ACTION_LOW))); } ESP_LOGI(TAG, "Start timers one by one, so they are not synced"); diff --git a/examples/peripherals/rmt/led_strip/main/led_strip_example_main.c b/examples/peripherals/rmt/led_strip/main/led_strip_example_main.c index 65cb57e066..ccfbb383b4 100644 --- a/examples/peripherals/rmt/led_strip/main/led_strip_example_main.c +++ b/examples/peripherals/rmt/led_strip/main/led_strip_example_main.c @@ -10,7 +10,6 @@ #include "driver/rmt_tx.h" #include "led_strip_encoder.h" - #define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution) #define RMT_LED_STRIP_GPIO_NUM 0 diff --git a/examples/peripherals/sdio/host/main/app_main.c b/examples/peripherals/sdio/host/main/app_main.c index 0676d6da94..f9542ac01e 100644 --- a/examples/peripherals/sdio/host/main/app_main.c +++ b/examples/peripherals/sdio/host/main/app_main.c @@ -28,7 +28,6 @@ #include "sdkconfig.h" #include "sdmmc_cmd.h" - #define TIMEOUT_MAX UINT32_MAX #define GPIO_B1 21 @@ -55,7 +54,6 @@ #define PIN_D3 SDMMC_SLOT1_IOMUX_PIN_NUM_D3 #endif - /* sdio host example. @@ -298,7 +296,6 @@ esp_err_t slave_init(essl_handle_t* handle) return ret; } - void slave_power_on(void) { #ifdef SLAVE_PWR_GPIO @@ -338,9 +335,13 @@ static esp_err_t get_intr(essl_handle_t handle, uint32_t* out_raw, uint32_t* out #endif ret = essl_get_intr(handle, out_raw, out_st, TIMEOUT_MAX); - if (ret != ESP_OK) return ret; + if (ret != ESP_OK) { + return ret; + } ret = essl_clear_intr(handle, *out_raw, TIMEOUT_MAX); - if (ret != ESP_OK) return ret; + if (ret != ESP_OK) { + return ret; + } ESP_LOGD(TAG, "intr: %08"PRIX32, *out_raw); return ESP_OK; } diff --git a/examples/peripherals/sdio/slave/main/app_main.c b/examples/peripherals/sdio/slave/main/app_main.c index f78ad91070..607f3af21b 100644 --- a/examples/peripherals/sdio/slave/main/app_main.c +++ b/examples/peripherals/sdio/slave/main/app_main.c @@ -75,8 +75,8 @@ typedef enum { static const char TAG[] = "example_slave"; static int s_job = JOB_IDLE; -DMA_ATTR uint8_t data_to_send[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33 ,0x22, 0x11, 0x00 }; -DMA_ATTR uint8_t data_to_recv[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33 ,0x22, 0x11, 0x00 }; +DMA_ATTR uint8_t data_to_send[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 }; +DMA_ATTR uint8_t data_to_recv[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 }; static const char job_desc[][32] = { "JOB_IDLE", @@ -85,22 +85,27 @@ static const char job_desc[][32] = { "JOB_WRITE_REG", }; - //reset counters of the slave hardware, and clean the receive buffer (normally they should be sent back to the host) static esp_err_t slave_reset(void) { esp_err_t ret; sdio_slave_stop(); ret = sdio_slave_reset(); - if (ret != ESP_OK) return ret; + if (ret != ESP_OK) { + return ret; + } ret = sdio_slave_start(); - if (ret != ESP_OK) return ret; + if (ret != ESP_OK) { + return ret; + } //Since the buffer will not be sent any more, we return them back to receving driver - while(1) { + while (1) { sdio_slave_buf_handle_t handle; ret = sdio_slave_send_get_finished(&handle, 0); - if (ret != ESP_OK) break; + if (ret != ESP_OK) { + break; + } ret = sdio_slave_recv_load_buf(handle); ESP_ERROR_CHECK(ret); } @@ -110,12 +115,14 @@ static esp_err_t slave_reset(void) //sent interrupts to the host in turns static esp_err_t task_hostint(void) { - for(int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) { ESP_LOGV(TAG, "send intr: %d", i); sdio_slave_send_host_int(i); //check reset for quick response to RESET signal - if (s_job & JOB_RESET) break; - vTaskDelay(500/portTICK_PERIOD_MS); + if (s_job & JOB_RESET) { + break; + } + vTaskDelay(500 / portTICK_PERIOD_MS); } return ESP_OK; } @@ -127,7 +134,7 @@ static esp_err_t task_write_reg(void) //the host write REG1, the slave should write its registers according to value of REG1 uint8_t read = sdio_slave_read_reg(1); for (int i = 0; i < 60; i++) { - sdio_slave_write_reg(SLAVE_ADDR(i), read + 3*i); + sdio_slave_write_reg(SLAVE_ADDR(i), read + 3 * i); } uint8_t reg[60] = {0}; for (int i = 0; i < 60; i++) { @@ -144,11 +151,11 @@ static esp_err_t task_write_reg(void) static void event_cb(uint8_t pos) { ESP_EARLY_LOGD(TAG, "event: %d", pos); - switch(pos) { - case 0: - s_job = sdio_slave_read_reg(0); - sdio_slave_write_reg(0, JOB_IDLE); - break; + switch (pos) { + case 0: + s_job = sdio_slave_read_reg(0); + sdio_slave_write_reg(0, JOB_IDLE); + break; } } @@ -185,7 +192,7 @@ void app_main(void) sdio_slave_write_reg(0, JOB_IDLE); - for(int i = 0; i < BUFFER_NUM; i++) { + for (int i = 0; i < BUFFER_NUM; i++) { sdio_slave_buf_handle_t handle = sdio_slave_recv_register_buf(buffer[i]); assert(handle != NULL); @@ -194,21 +201,21 @@ void app_main(void) } sdio_slave_set_host_intena(SDIO_SLAVE_HOSTINT_SEND_NEW_PACKET | - SDIO_SLAVE_HOSTINT_BIT0 | - SDIO_SLAVE_HOSTINT_BIT1 | - SDIO_SLAVE_HOSTINT_BIT2 | - SDIO_SLAVE_HOSTINT_BIT3 | - SDIO_SLAVE_HOSTINT_BIT4 | - SDIO_SLAVE_HOSTINT_BIT5 | - SDIO_SLAVE_HOSTINT_BIT6 | - SDIO_SLAVE_HOSTINT_BIT7 - ); + SDIO_SLAVE_HOSTINT_BIT0 | + SDIO_SLAVE_HOSTINT_BIT1 | + SDIO_SLAVE_HOSTINT_BIT2 | + SDIO_SLAVE_HOSTINT_BIT3 | + SDIO_SLAVE_HOSTINT_BIT4 | + SDIO_SLAVE_HOSTINT_BIT5 | + SDIO_SLAVE_HOSTINT_BIT6 | + SDIO_SLAVE_HOSTINT_BIT7 + ); sdio_slave_start(); ESP_LOGI(TAG, EV_STR("slave ready")); - for(;;) { + for (;;) { const TickType_t non_blocking = 0, blocking = portMAX_DELAY; sdio_slave_buf_handle_t recv_queue[BUFFER_NUM]; int packet_size = 0; @@ -266,7 +273,7 @@ void app_main(void) } // if there's finished sending desc, return the buffer to receiving driver - for(;;){ + for (;;) { void* send_args = NULL; ret = sdio_slave_send_get_finished(&send_args, 0); @@ -281,12 +288,12 @@ void app_main(void) } if (s_job != 0) { - for(int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) { if (s_job & BIT(i)) { - ESP_LOGI(TAG, EV_STR("%s"), job_desc[i+1]); + ESP_LOGI(TAG, EV_STR("%s"), job_desc[i + 1]); s_job &= ~BIT(i); - switch(BIT(i)) { + switch (BIT(i)) { case JOB_SEND_INT: ret = task_hostint(); ESP_ERROR_CHECK(ret); diff --git a/examples/peripherals/secure_element/atecc608_ecdsa/main/ecdsa_example_main.c b/examples/peripherals/secure_element/atecc608_ecdsa/main/ecdsa_example_main.c index 4f0ad17a42..516a03c929 100644 --- a/examples/peripherals/secure_element/atecc608_ecdsa/main/ecdsa_example_main.c +++ b/examples/peripherals/secure_element/atecc608_ecdsa/main/ecdsa_example_main.c @@ -5,7 +5,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * SPDX-FileContributor: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileContributor: 2015-2023 Espressif Systems (Shanghai) CO LTD */ /* This is mbedtls boilerplate for library configuration */ @@ -46,7 +46,7 @@ static int configure_mbedtls_rng(void) mbedtls_entropy_init(&entropy); ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, - (const unsigned char *)seed, strlen(seed)); + (const unsigned char *)seed, strlen(seed)); if (ret != 0) { ESP_LOGI(TAG, " failed ! mbedtls_ctr_drbg_seed returned %d", ret); } else { @@ -108,7 +108,7 @@ static int atca_ecdsa_test(void) #ifdef MBEDTLS_ECDSA_SIGN_ALT /* Convert to an mbedtls key */ - ESP_LOGI(TAG, " Using a hardware private key ..." ); + ESP_LOGI(TAG, " Using a hardware private key ..."); ret = atca_mbedtls_pk_init(&pkey, 0); if (ret != 0) { ESP_LOGI(TAG, " failed ! atca_mbedtls_pk_init returned %02x", ret); @@ -116,20 +116,20 @@ static int atca_ecdsa_test(void) } ESP_LOGI(TAG, " ok"); #else - ESP_LOGI(TAG, " Generating a software private key ..." ); + ESP_LOGI(TAG, " Generating a software private key ..."); mbedtls_pk_init(&pkey); ret = mbedtls_pk_setup(&pkey, - mbedtls_pk_info_from_type( MBEDTLS_PK_ECDSA )); + mbedtls_pk_info_from_type(MBEDTLS_PK_ECDSA)); if (ret != 0) { - ESP_LOGI(TAG, " failed ! mbedtls_pk_setup returned -0x%04x", -ret ); + ESP_LOGI(TAG, " failed ! mbedtls_pk_setup returned -0x%04x", -ret); goto exit; } - ret = mbedtls_ecp_gen_key( MBEDTLS_ECP_DP_SECP256R1, - mbedtls_pk_ec( pkey ), - mbedtls_ctr_drbg_random, &ctr_drbg ); + ret = mbedtls_ecp_gen_key(MBEDTLS_ECP_DP_SECP256R1, + mbedtls_pk_ec(pkey), + mbedtls_ctr_drbg_random, &ctr_drbg); if (ret != 0) { - ESP_LOGI(TAG, " failed ! mbedtls_ecp_gen_key returned -0x%04x", -ret ); + ESP_LOGI(TAG, " failed ! mbedtls_ecp_gen_key returned -0x%04x", -ret); goto exit; } ESP_LOGI(TAG, " ok"); @@ -137,7 +137,7 @@ static int atca_ecdsa_test(void) ESP_LOGI(TAG, " Generating ECDSA Signature..."); ret = mbedtls_pk_sign(&pkey, MBEDTLS_MD_SHA256, hash, 0, buf, MBEDTLS_MPI_MAX_SIZE, &olen, - mbedtls_ctr_drbg_random, &ctr_drbg); + mbedtls_ctr_drbg_random, &ctr_drbg); if (ret != 0) { ESP_LOGI(TAG, " failed ! mbedtls_pk_sign returned -0x%04x", -ret); goto exit; @@ -146,7 +146,7 @@ static int atca_ecdsa_test(void) ESP_LOGI(TAG, " Verifying ECDSA Signature..."); ret = mbedtls_pk_verify(&pkey, MBEDTLS_MD_SHA256, hash, 0, - buf, olen); + buf, olen); if (ret != 0) { ESP_LOGI(TAG, " failed ! mbedtls_pk_verify returned -0x%04x", -ret); goto exit; diff --git a/examples/peripherals/spi_master/hd_eeprom/components/eeprom/spi_eeprom.c b/examples/peripherals/spi_master/hd_eeprom/components/eeprom/spi_eeprom.c index 0c4f488c44..4d01482397 100644 --- a/examples/peripherals/spi_master/hd_eeprom/components/eeprom/spi_eeprom.c +++ b/examples/peripherals/spi_master/hd_eeprom/components/eeprom/spi_eeprom.c @@ -19,7 +19,6 @@ #include #include "sdkconfig.h" - #define EEPROM_BUSY_TIMEOUT_MS 5 #define EEPROM_CLK_FREQ (1*1000*1000) //When powered by 3.3V, EEPROM max freq is 1MHz @@ -42,7 +41,7 @@ #define ADD_EWEN 0x60 /// Context (config and data) of the spi_eeprom -struct eeprom_context_t{ +struct eeprom_context_t { eeprom_config_t cfg; ///< Configuration by the caller. spi_device_handle_t spi; ///< SPI device handle SemaphoreHandle_t ready_sem; ///< Semaphore for ready signal @@ -52,7 +51,6 @@ typedef struct eeprom_context_t eeprom_context_t; static const char TAG[] = "eeprom"; - // Workaround: The driver depends on some data in the flash and cannot be placed to DRAM easily for // now. Using the version in LL instead. #define gpio_set_level gpio_set_level_patch @@ -63,7 +61,6 @@ static inline esp_err_t gpio_set_level_patch(gpio_num_t gpio_num, uint32_t level return ESP_OK; } - static esp_err_t eeprom_simple_cmd(eeprom_context_t *ctx, uint16_t cmd) { spi_transaction_t t = { @@ -89,7 +86,9 @@ static esp_err_t eeprom_wait_done(eeprom_context_t* ctx) gpio_intr_disable(ctx->cfg.miso_io); gpio_set_level(ctx->cfg.cs_io, 0); - if (ret != pdTRUE) return ESP_ERR_TIMEOUT; + if (ret != pdTRUE) { + return ESP_ERR_TIMEOUT; + } } else { bool timeout = true; gpio_set_level(ctx->cfg.cs_io, 1); @@ -101,7 +100,9 @@ static esp_err_t eeprom_wait_done(eeprom_context_t* ctx) usleep(1); } gpio_set_level(ctx->cfg.cs_io, 0); - if (timeout) return ESP_ERR_TIMEOUT; + if (timeout) { + return ESP_ERR_TIMEOUT; + } } return ESP_OK; } @@ -144,13 +145,15 @@ esp_err_t spi_eeprom_init(const eeprom_config_t *cfg, eeprom_context_t** out_ctx } eeprom_context_t* ctx = (eeprom_context_t*)malloc(sizeof(eeprom_context_t)); - if (!ctx) return ESP_ERR_NO_MEM; + if (!ctx) { + return ESP_ERR_NO_MEM; + } *ctx = (eeprom_context_t) { .cfg = *cfg, }; - spi_device_interface_config_t devcfg={ + spi_device_interface_config_t devcfg = { .command_bits = 10, .clock_speed_hz = EEPROM_CLK_FREQ, .mode = 0, //SPI mode 0 @@ -167,7 +170,7 @@ esp_err_t spi_eeprom_init(const eeprom_config_t *cfg, eeprom_context_t** out_ctx }; //Attach the EEPROM to the SPI bus err = spi_bus_add_device(ctx->cfg.host, &devcfg, &ctx->spi); - if (err != ESP_OK) { + if (err != ESP_OK) { goto cleanup; } @@ -217,7 +220,9 @@ esp_err_t spi_eeprom_read(eeprom_context_t* ctx, uint8_t addr, uint8_t* out_data .user = ctx, }; esp_err_t err = spi_device_polling_transmit(ctx->spi, &t); - if (err!= ESP_OK) return err; + if (err != ESP_OK) { + return err; + } *out_data = t.rx_data[0]; return ESP_OK; @@ -227,7 +232,9 @@ esp_err_t spi_eeprom_erase(eeprom_context_t* ctx, uint8_t addr) { esp_err_t err; err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY); - if (err != ESP_OK) return err; + if (err != ESP_OK) { + return err; + } err = eeprom_simple_cmd(ctx, CMD_ERASE | (addr & ADDR_MASK)); @@ -243,7 +250,9 @@ esp_err_t spi_eeprom_write(eeprom_context_t* ctx, uint8_t addr, uint8_t data) { esp_err_t err; err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY); - if (err != ESP_OK) return err; + if (err != ESP_OK) { + return err; + } spi_transaction_t t = { .cmd = CMD_WRITE | (addr & ADDR_MASK), @@ -282,7 +291,9 @@ esp_err_t spi_eeprom_erase_all(eeprom_context_t* ctx) esp_err_t err; err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY); - if (err != ESP_OK) return err; + if (err != ESP_OK) { + return err; + } err = eeprom_simple_cmd(ctx, CMD_ERAL | ADD_ERAL); @@ -304,7 +315,9 @@ esp_err_t spi_eeprom_write_all(eeprom_context_t* ctx, uint8_t data) esp_err_t err; err = spi_device_acquire_bus(ctx->spi, portMAX_DELAY); - if (err != ESP_OK) return err; + if (err != ESP_OK) { + return err; + } spi_transaction_t t = { .cmd = CMD_WRAL | ADD_WRAL, diff --git a/examples/peripherals/spi_master/hd_eeprom/main/spi_eeprom_main.c b/examples/peripherals/spi_master/hd_eeprom/main/spi_eeprom_main.c index 071d02a73f..e9cdb5cc9c 100644 --- a/examples/peripherals/spi_master/hd_eeprom/main/spi_eeprom_main.c +++ b/examples/peripherals/spi_master/hd_eeprom/main/spi_eeprom_main.c @@ -18,7 +18,6 @@ #include "esp_log.h" #include "spi_eeprom.h" - /* This code demonstrates how to use the SPI master half duplex mode to read/write a AT932C46D EEPROM (8-bit mode). */ @@ -70,15 +69,14 @@ # define PIN_NUM_CS 1 #endif - static const char TAG[] = "main"; void app_main(void) { esp_err_t ret; #ifndef CONFIG_EXAMPLE_USE_SPI1_PINS - ESP_LOGI(TAG, "Initializing bus SPI%d...", EEPROM_HOST+1); - spi_bus_config_t buscfg={ + ESP_LOGI(TAG, "Initializing bus SPI%d...", EEPROM_HOST + 1); + spi_bus_config_t buscfg = { .miso_io_num = PIN_NUM_MISO, .mosi_io_num = PIN_NUM_MOSI, .sclk_io_num = PIN_NUM_CLK, diff --git a/examples/peripherals/spi_master/lcd/main/pretty_effect.c b/examples/peripherals/spi_master/lcd/main/pretty_effect.c index 9c6887977e..9ccd6fd020 100644 --- a/examples/peripherals/spi_master/lcd/main/pretty_effect.c +++ b/examples/peripherals/spi_master/lcd/main/pretty_effect.c @@ -20,11 +20,11 @@ uint16_t *pixels; static inline uint16_t get_bgnd_pixel(int x, int y) { //Get color of the pixel on x,y coords - return (uint16_t) *(pixels + (y * IMAGE_W) + x); + return (uint16_t) * (pixels + (y * IMAGE_W) + x); } //This variable is used to detect the next frame. -static int prev_frame=-1; +static int prev_frame = -1; //Instead of calculating the offsets for each pixel we grab, we pre-calculate the valueswhenever a frame changes, then re-use //these as we go through all the pixels in the frame. This is much, much faster. @@ -36,23 +36,30 @@ static int8_t xcomp[320], ycomp[240]; //is displayed; this is used to go to the next frame of animation. void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect) { - if (frame!=prev_frame) { + if (frame != prev_frame) { //We need to calculate a new set of offset coefficients. Take some random sines as offsets to make everything //look pretty and fluid-y. - for (int x=0; x<320; x++) xofs[x]=sin(frame*0.15+x*0.06)*4; - for (int y=0; y<240; y++) yofs[y]=sin(frame*0.1+y*0.05)*4; - for (int x=0; x<320; x++) xcomp[x]=sin(frame*0.11+x*0.12)*4; - for (int y=0; y<240; y++) ycomp[y]=sin(frame*0.07+y*0.15)*4; - prev_frame=frame; + for (int x = 0; x < 320; x++) { + xofs[x] = sin(frame * 0.15 + x * 0.06) * 4; + } + for (int y = 0; y < 240; y++) { + yofs[y] = sin(frame * 0.1 + y * 0.05) * 4; + } + for (int x = 0; x < 320; x++) { + xcomp[x] = sin(frame * 0.11 + x * 0.12) * 4; + } + for (int y = 0; y < 240; y++) { + ycomp[y] = sin(frame * 0.07 + y * 0.15) * 4; + } + prev_frame = frame; } - for (int y=line; yuser; + int dc = (int)t->user; gpio_set_level(PIN_NUM_DC, dc); } @@ -250,12 +252,12 @@ uint32_t lcd_get_id(spi_device_handle_t spi) spi_transaction_t t; memset(&t, 0, sizeof(t)); - t.length=8*3; + t.length = 8 * 3; t.flags = SPI_TRANS_USE_RXDATA; t.user = (void*)1; esp_err_t ret = spi_device_polling_transmit(spi, &t); - assert( ret == ESP_OK ); + assert(ret == ESP_OK); // Release bus spi_device_release_bus(spi); @@ -266,12 +268,12 @@ uint32_t lcd_get_id(spi_device_handle_t spi) //Initialize the display void lcd_init(spi_device_handle_t spi) { - int cmd=0; + int cmd = 0; const lcd_init_cmd_t* lcd_init_cmds; //Initialize non-SPI GPIOs gpio_config_t io_conf = {}; - io_conf.pin_bit_mask = ((1ULL<>8; //End Col High - trans[1].tx_data[3]=(320)&0xff; //End Col Low - trans[2].tx_data[0]=0x2B; //Page address set - trans[3].tx_data[0]=ypos>>8; //Start page high - trans[3].tx_data[1]=ypos&0xff; //start page low - trans[3].tx_data[2]=(ypos+PARALLEL_LINES)>>8; //end page high - trans[3].tx_data[3]=(ypos+PARALLEL_LINES)&0xff; //end page low - trans[4].tx_data[0]=0x2C; //memory write - trans[5].tx_buffer=linedata; //finally send the line data - trans[5].length=320*2*8*PARALLEL_LINES; //Data length, in bits - trans[5].flags=0; //undo SPI_TRANS_USE_TXDATA flag + trans[0].tx_data[0] = 0x2A; //Column Address Set + trans[1].tx_data[0] = 0; //Start Col High + trans[1].tx_data[1] = 0; //Start Col Low + trans[1].tx_data[2] = (320) >> 8; //End Col High + trans[1].tx_data[3] = (320) & 0xff; //End Col Low + trans[2].tx_data[0] = 0x2B; //Page address set + trans[3].tx_data[0] = ypos >> 8; //Start page high + trans[3].tx_data[1] = ypos & 0xff; //start page low + trans[3].tx_data[2] = (ypos + PARALLEL_LINES) >> 8; //end page high + trans[3].tx_data[3] = (ypos + PARALLEL_LINES) & 0xff; //end page low + trans[4].tx_data[0] = 0x2C; //memory write + trans[5].tx_buffer = linedata; //finally send the line data + trans[5].length = 320 * 2 * 8 * PARALLEL_LINES; //Data length, in bits + trans[5].flags = 0; //undo SPI_TRANS_USE_TXDATA flag //Queue all transactions. - for (x=0; x<6; x++) { - ret=spi_device_queue_trans(spi, &trans[x], portMAX_DELAY); - assert(ret==ESP_OK); + for (x = 0; x < 6; x++) { + ret = spi_device_queue_trans(spi, &trans[x], portMAX_DELAY); + assert(ret == ESP_OK); } //When we are here, the SPI driver is busy (in the background) getting the transactions sent. That happens @@ -387,20 +388,18 @@ static void send_lines(spi_device_handle_t spi, int ypos, uint16_t *linedata) //send_line_finish, which will wait for the transfers to be done and check their status. } - static void send_line_finish(spi_device_handle_t spi) { spi_transaction_t *rtrans; esp_err_t ret; //Wait for all 6 transactions to be done and get back the results. - for (int x=0; x<6; x++) { - ret=spi_device_get_trans_result(spi, &rtrans, portMAX_DELAY); - assert(ret==ESP_OK); + for (int x = 0; x < 6; x++) { + ret = spi_device_get_trans_result(spi, &rtrans, portMAX_DELAY); + assert(ret == ESP_OK); //We could inspect rtrans now if we received any info back. The LCD is treated as write-only, though. } } - //Simple routine to generate some patterns and send them to the LCD. Don't expect anything too //impressive. Because the SPI driver handles transactions in the background, we can calculate the next line //while the previous one is being sent. @@ -408,25 +407,27 @@ static void display_pretty_colors(spi_device_handle_t spi) { uint16_t *lines[2]; //Allocate memory for the pixel buffers - for (int i=0; i<2; i++) { - lines[i]=heap_caps_malloc(320*PARALLEL_LINES*sizeof(uint16_t), MALLOC_CAP_DMA); - assert(lines[i]!=NULL); + for (int i = 0; i < 2; i++) { + lines[i] = heap_caps_malloc(320 * PARALLEL_LINES * sizeof(uint16_t), MALLOC_CAP_DMA); + assert(lines[i] != NULL); } - int frame=0; + int frame = 0; //Indexes of the line currently being sent to the LCD and the line we're calculating. - int sending_line=-1; - int calc_line=0; + int sending_line = -1; + int calc_line = 0; - while(1) { + while (1) { frame++; - for (int y=0; y<240; y+=PARALLEL_LINES) { + for (int y = 0; y < 240; y += PARALLEL_LINES) { //Calculate a line. pretty_effect_calc_lines(lines[calc_line], y, frame, PARALLEL_LINES); //Finish up the sending process of the previous line, if any - if (sending_line!=-1) send_line_finish(spi); + if (sending_line != -1) { + send_line_finish(spi); + } //Swap sending_line and calc_line - sending_line=calc_line; - calc_line=(calc_line==1)?0:1; + sending_line = calc_line; + calc_line = (calc_line == 1) ? 0 : 1; //Send the line we currently calculated. send_lines(spi, y, lines[sending_line]); //The line set is queued up for sending now; the actual sending happens in the @@ -440,35 +441,35 @@ void app_main(void) { esp_err_t ret; spi_device_handle_t spi; - spi_bus_config_t buscfg={ - .miso_io_num=PIN_NUM_MISO, - .mosi_io_num=PIN_NUM_MOSI, - .sclk_io_num=PIN_NUM_CLK, - .quadwp_io_num=-1, - .quadhd_io_num=-1, - .max_transfer_sz=PARALLEL_LINES*320*2+8 + spi_bus_config_t buscfg = { + .miso_io_num = PIN_NUM_MISO, + .mosi_io_num = PIN_NUM_MOSI, + .sclk_io_num = PIN_NUM_CLK, + .quadwp_io_num = -1, + .quadhd_io_num = -1, + .max_transfer_sz = PARALLEL_LINES * 320 * 2 + 8 }; - spi_device_interface_config_t devcfg={ + spi_device_interface_config_t devcfg = { #ifdef CONFIG_LCD_OVERCLOCK - .clock_speed_hz=26*1000*1000, //Clock out at 26 MHz + .clock_speed_hz = 26 * 1000 * 1000, //Clock out at 26 MHz #else - .clock_speed_hz=10*1000*1000, //Clock out at 10 MHz + .clock_speed_hz = 10 * 1000 * 1000, //Clock out at 10 MHz #endif - .mode=0, //SPI mode 0 - .spics_io_num=PIN_NUM_CS, //CS pin - .queue_size=7, //We want to be able to queue 7 transactions at a time - .pre_cb=lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line + .mode = 0, //SPI mode 0 + .spics_io_num = PIN_NUM_CS, //CS pin + .queue_size = 7, //We want to be able to queue 7 transactions at a time + .pre_cb = lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line }; //Initialize the SPI bus - ret=spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO); + ret = spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO); ESP_ERROR_CHECK(ret); //Attach the LCD to the SPI bus - ret=spi_bus_add_device(LCD_HOST, &devcfg, &spi); + ret = spi_bus_add_device(LCD_HOST, &devcfg, &spi); ESP_ERROR_CHECK(ret); //Initialize the LCD lcd_init(spi); //Initialize the effect displayed - ret=pretty_effect_init(); + ret = pretty_effect_init(); ESP_ERROR_CHECK(ret); //Go do nice stuff. diff --git a/examples/peripherals/spi_slave/receiver/main/app_main.c b/examples/peripherals/spi_slave/receiver/main/app_main.c index b6c7c30802..1dde149447 100644 --- a/examples/peripherals/spi_slave/receiver/main/app_main.c +++ b/examples/peripherals/spi_slave/receiver/main/app_main.c @@ -18,7 +18,6 @@ #include "driver/spi_slave.h" #include "driver/gpio.h" - /* SPI receiver (slave) example. @@ -71,7 +70,6 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i #endif //CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - #ifdef CONFIG_IDF_TARGET_ESP32 #define RCV_HOST HSPI_HOST @@ -80,48 +78,48 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i #endif - - //Called after a transaction is queued and ready for pickup by master. We use this to set the handshake line high. -void my_post_setup_cb(spi_slave_transaction_t *trans) { +void my_post_setup_cb(spi_slave_transaction_t *trans) +{ gpio_set_level(GPIO_HANDSHAKE, 1); } //Called after transaction is sent/received. We use this to set the handshake line low. -void my_post_trans_cb(spi_slave_transaction_t *trans) { +void my_post_trans_cb(spi_slave_transaction_t *trans) +{ gpio_set_level(GPIO_HANDSHAKE, 0); } //Main application void app_main(void) { - int n=0; + int n = 0; esp_err_t ret; //Configuration for the SPI bus - spi_bus_config_t buscfg={ - .mosi_io_num=GPIO_MOSI, - .miso_io_num=GPIO_MISO, - .sclk_io_num=GPIO_SCLK, + spi_bus_config_t buscfg = { + .mosi_io_num = GPIO_MOSI, + .miso_io_num = GPIO_MISO, + .sclk_io_num = GPIO_SCLK, .quadwp_io_num = -1, .quadhd_io_num = -1, }; //Configuration for the SPI slave interface - spi_slave_interface_config_t slvcfg={ - .mode=0, - .spics_io_num=GPIO_CS, - .queue_size=3, - .flags=0, - .post_setup_cb=my_post_setup_cb, - .post_trans_cb=my_post_trans_cb + spi_slave_interface_config_t slvcfg = { + .mode = 0, + .spics_io_num = GPIO_CS, + .queue_size = 3, + .flags = 0, + .post_setup_cb = my_post_setup_cb, + .post_trans_cb = my_post_trans_cb }; //Configuration for the handshake line - gpio_config_t io_conf={ - .intr_type=GPIO_INTR_DISABLE, - .mode=GPIO_MODE_OUTPUT, - .pin_bit_mask=(1<= sizeof(sendbuf)) { printf("Data truncated\n"); } - t.length=sizeof(sendbuf)*8; - t.tx_buffer=sendbuf; - t.rx_buffer=recvbuf; + t.length = sizeof(sendbuf) * 8; + t.tx_buffer = sendbuf; + t.rx_buffer = recvbuf; //Wait for slave to be ready for next byte before sending xSemaphoreTake(rdySem, portMAX_DELAY); //Wait until slave is ready - ret=spi_device_transmit(handle, &t); + ret = spi_device_transmit(handle, &t); printf("Received: %s\n", recvbuf); n++; } //Never reached. - ret=spi_bus_remove_device(handle); - assert(ret==ESP_OK); + ret = spi_bus_remove_device(handle); + assert(ret == ESP_OK); } diff --git a/examples/peripherals/spi_slave_hd/append_mode/master/main/app_main.c b/examples/peripherals/spi_slave_hd/append_mode/master/main/app_main.c index 177344bdde..d34696ca4b 100644 --- a/examples/peripherals/spi_slave_hd/append_mode/master/main/app_main.c +++ b/examples/peripherals/spi_slave_hd/append_mode/master/main/app_main.c @@ -53,14 +53,14 @@ static void init_driver(spi_device_handle_t *out_spi, essl_handle_t *out_essl) ESP_ERROR_CHECK(spi_bus_initialize(HOST_ID, &bus_cfg, SPI_DMA_CH_AUTO)); spi_device_interface_config_t dev_cfg = { - .clock_speed_hz = 1 * 1 * 1000, - .flags = SPI_DEVICE_HALFDUPLEX, - .spics_io_num = GPIO_CS, - .queue_size = 16, - .command_bits = 8, - .address_bits = 8, - .dummy_bits = 8, - .mode = 0 + .clock_speed_hz = 1 * 1 * 1000, + .flags = SPI_DEVICE_HALFDUPLEX, + .spics_io_num = GPIO_CS, + .queue_size = 16, + .command_bits = 8, + .address_bits = 8, + .dummy_bits = 8, + .mode = 0 }; ESP_ERROR_CHECK(spi_bus_add_device(HOST_ID, &dev_cfg, &spi)); *out_spi = spi; @@ -88,7 +88,7 @@ static esp_err_t receiver(essl_handle_t essl) while (n--) { size_t actual_rx_length = 0; - ret = essl_get_packet(essl, recv_buf, TRANSACTION_LEN/2, &actual_rx_length, portMAX_DELAY); + ret = essl_get_packet(essl, recv_buf, TRANSACTION_LEN / 2, &actual_rx_length, portMAX_DELAY); if (ret == ESP_OK || ret == ESP_ERR_NOT_FINISHED) { ESP_LOGI("Receiver", "%d bytes are actually received:", actual_rx_length); ESP_LOG_BUFFER_HEX("Receiver", recv_buf, actual_rx_length); @@ -124,7 +124,7 @@ static esp_err_t sender(essl_handle_t essl) int n = EXAMPLE_CYCLES; while (n--) { for (int i = 0; i < TRANSACTION_LEN; i++) { - send_buf[i] = data+i; + send_buf[i] = data + i; } ret = essl_send_packet(essl, send_buf, TRANSACTION_LEN, portMAX_DELAY); diff --git a/examples/peripherals/spi_slave_hd/append_mode/slave/main/app_main.c b/examples/peripherals/spi_slave_hd/append_mode/slave/main/app_main.c index 9e6d1ef578..8b7160abe1 100644 --- a/examples/peripherals/spi_slave_hd/append_mode/slave/main/app_main.c +++ b/examples/peripherals/spi_slave_hd/append_mode/slave/main/app_main.c @@ -29,7 +29,6 @@ #define SLAVE_READY_FLAG 0x88 #define READY_FLAG_REG 0 - struct trans_link_s { spi_slave_hd_data_t trans; struct trans_link_s *next; @@ -41,7 +40,6 @@ typedef struct trans_link_s trans_link_t; trans_link_t *tx_curr_trans; trans_link_t *rx_curr_trans; - static void init_slave_hd(void) { spi_bus_config_t bus_cfg = {}; @@ -81,7 +79,7 @@ static esp_err_t create_transaction_pool(uint8_t **data_buf, trans_link_t *trans //link the recycling transaction descriptors if (i != QUEUE_SIZE - 1) { - trans_link[i].next = &trans_link[i+1]; + trans_link[i].next = &trans_link[i + 1]; } else { trans_link[i].next = &trans_link[0]; } @@ -100,7 +98,7 @@ static void prepare_tx_data(trans_link_t *tx_trans) */ uint8_t data = rand() % 50; tx_trans->trans.len = TRANSACTION_LEN; - for(int i = 0; i < tx_trans->trans.len; i++) { + for (int i = 0; i < tx_trans->trans.len; i++) { tx_trans->trans.data[i] = data + i; } tx_trans->recycled = 0; diff --git a/examples/peripherals/spi_slave_hd/segment_mode/seg_master/main/app_main.c b/examples/peripherals/spi_slave_hd/segment_mode/seg_master/main/app_main.c index eb20b9818a..f5571b09e2 100644 --- a/examples/peripherals/spi_slave_hd/segment_mode/seg_master/main/app_main.c +++ b/examples/peripherals/spi_slave_hd/segment_mode/seg_master/main/app_main.c @@ -68,7 +68,6 @@ static const char TAG[] = "SEG_MASTER"; - static void get_spi_bus_default_config(spi_bus_config_t *bus_cfg) { memset(bus_cfg, 0x0, sizeof(spi_bus_config_t)); @@ -85,7 +84,7 @@ static void get_spi_bus_default_config(spi_bus_config_t *bus_cfg) static void get_spi_device_default_config(spi_device_interface_config_t *dev_cfg) { memset(dev_cfg, 0x0, sizeof(spi_device_interface_config_t)); - dev_cfg->clock_speed_hz = 10*1000*1000; + dev_cfg->clock_speed_hz = 10 * 1000 * 1000; dev_cfg->mode = 0; dev_cfg->spics_io_num = GPIO_CS; dev_cfg->cs_ena_pretrans = 0; @@ -114,7 +113,6 @@ static void init_master_hd(spi_device_handle_t* out_spi) ESP_ERROR_CHECK(spi_bus_add_device(MASTER_HOST, &dev_cfg, out_spi)); } - //-------------------------------Function used for Master-Slave Synchronization---------------------------// //Wait for Slave to init the shared registers for its configurations, see the Helper Macros above static esp_err_t wait_for_slave_ready(spi_device_handle_t spi) diff --git a/examples/peripherals/spi_slave_hd/segment_mode/seg_slave/main/app_main.c b/examples/peripherals/spi_slave_hd/segment_mode/seg_slave/main/app_main.c index b4345efdef..18f61b6c0d 100644 --- a/examples/peripherals/spi_slave_hd/segment_mode/seg_slave/main/app_main.c +++ b/examples/peripherals/spi_slave_hd/segment_mode/seg_slave/main/app_main.c @@ -66,7 +66,6 @@ //Value in these 4 registers indicates number of the RX buffer that Slave has loaded to the DMA #define SLAVE_RX_READY_BUF_NUM_REG 16 - static const char TAG[] = "SEG_SLAVE"; /* Used for Master-Slave synchronization */ @@ -75,7 +74,6 @@ static uint32_t s_rx_ready_buf_num; //See ``cb_set_rx_ready_buf_num()`` static uint32_t s_tx_data_id; - //-------------------------------Function used for Master-Slave Synchronization---------------------------// /** * NOTE: Only if all the counters are in same size (here uint32_t), the calculation is safe (when the shared register overflows). diff --git a/examples/peripherals/temperature_sensor/temp_sensor_monitor/main/temp_sensor_monitor_main.c b/examples/peripherals/temperature_sensor/temp_sensor_monitor/main/temp_sensor_monitor_main.c index 34e5dfbf2e..96e4e981c2 100644 --- a/examples/peripherals/temperature_sensor/temp_sensor_monitor/main/temp_sensor_monitor_main.c +++ b/examples/peripherals/temperature_sensor/temp_sensor_monitor/main/temp_sensor_monitor_main.c @@ -25,7 +25,6 @@ void app_main(void) temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50); ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor)); - temperature_sensor_event_callbacks_t cbs = { .on_threshold = temp_sensor_monitor_cbs, }; diff --git a/examples/peripherals/timer_group/legacy_driver/main/timer_group_example_main.c b/examples/peripherals/timer_group/legacy_driver/main/timer_group_example_main.c index 697cf501de..90090deb71 100644 --- a/examples/peripherals/timer_group/legacy_driver/main/timer_group_example_main.c +++ b/examples/peripherals/timer_group/legacy_driver/main/timer_group_example_main.c @@ -102,7 +102,6 @@ void app_main(void) user_data->timer_idx = 0; user_data->alarm_value = TIMER_ALARM_PERIOD_S * TIMER_RESOLUTION_HZ; - ESP_LOGI(TAG, "Init timer with auto-reload"); user_data->auto_reload = true; example_tg_timer_init(user_data); diff --git a/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c index 1456c08571..a957a73d1e 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c @@ -108,8 +108,8 @@ void app_main(void) ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i])); /* Subscribe touch button events (On Press, On Release, On LongPress) */ ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i], - TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, - (void *)channel_array[i])); + TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, + (void *)channel_array[i])); #ifdef CONFIG_TOUCH_ELEM_EVENT /* Set EVENT as the dispatch method */ ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT)); diff --git a/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c index 631670de8d..86b3ec21fc 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c @@ -75,8 +75,8 @@ void app_main(void) ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i])); /* Subscribe touch button event(Press, Release, LongPress) */ ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i], - TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, - (void *)channel_array[i])); + TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, + (void *)channel_array[i])); /* Button set dispatch method */ ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT)); #ifdef CONFIG_TOUCH_WATERPROOF_GUARD_ENABLE diff --git a/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c index 7b8396527b..4d7a013b57 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -109,8 +109,8 @@ void button_example_init(void) ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i])); /* Subscribe touch button events (On Press, On Release, On LongPress) */ ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i], - TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, - (void *)button_channel_array[i])); + TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, + (void *)button_channel_array[i])); /* Set EVENT as the dispatch method */ ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT)); /* Set LongPress event trigger threshold time */ @@ -134,7 +134,7 @@ void slider_example_init(void) ESP_ERROR_CHECK(touch_slider_create(&slider_config, &slider_handle)); /* Subscribe touch slider events (On Press, On Release, On Calculation) */ ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle, - TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL)); + TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL)); /* Set EVENT as the dispatch method */ ESP_ERROR_CHECK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT)); ESP_LOGI(TAG, "Touch slider created"); diff --git a/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c index de6c092160..a8d248a092 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -60,13 +60,13 @@ static void matrix_handler_task(void *arg) const touch_matrix_message_t *matrix_message = touch_matrix_get_message(&element_message); if (matrix_message->event == TOUCH_MATRIX_EVT_ON_PRESS) { ESP_LOGI(TAG, "Matrix Press, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis, - matrix_message->position.y_axis, matrix_message->position.index); + matrix_message->position.y_axis, matrix_message->position.index); } else if (matrix_message->event == TOUCH_MATRIX_EVT_ON_RELEASE) { ESP_LOGI(TAG, "Matrix Release, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis, - matrix_message->position.y_axis, matrix_message->position.index); + matrix_message->position.y_axis, matrix_message->position.index); } else if (matrix_message->event == TOUCH_MATRIX_EVT_ON_LONGPRESS) { ESP_LOGI(TAG, "Matrix LongPress, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis, - matrix_message->position.y_axis, matrix_message->position.index); + matrix_message->position.y_axis, matrix_message->position.index); } } } @@ -80,13 +80,13 @@ void matrix_handler(touch_matrix_handle_t out_handle, touch_matrix_message_t *ou } if (out_message->event == TOUCH_MATRIX_EVT_ON_PRESS) { ESP_LOGI(TAG, "Matrix Press, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis, - out_message->position.y_axis, out_message->position.index); + out_message->position.y_axis, out_message->position.index); } else if (out_message->event == TOUCH_MATRIX_EVT_ON_RELEASE) { ESP_LOGI(TAG, "Matrix Release, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis, - out_message->position.y_axis, out_message->position.index); + out_message->position.y_axis, out_message->position.index); } else if (out_message->event == TOUCH_MATRIX_EVT_ON_LONGPRESS) { ESP_LOGI(TAG, "Matrix LongPress, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis, - out_message->position.y_axis, out_message->position.index); + out_message->position.y_axis, out_message->position.index); } } #endif @@ -113,7 +113,7 @@ void app_main(void) ESP_ERROR_CHECK(touch_matrix_create(&matrix_config, &matrix_handle)); /* Subscribe touch matrix events (On Press, On Release, On LongPress) */ ESP_ERROR_CHECK(touch_matrix_subscribe_event(matrix_handle, - TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, NULL)); + TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, NULL)); #ifdef CONFIG_TOUCH_ELEM_EVENT /* Set EVENT as the dispatch method */ ESP_ERROR_CHECK(touch_matrix_set_dispatch_method(matrix_handle, TOUCH_ELEM_DISP_EVENT)); diff --git a/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c index 4df27f2882..4257adcc83 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c @@ -99,7 +99,7 @@ void app_main(void) ESP_ERROR_CHECK(touch_slider_create(&slider_config, &slider_handle)); /* Subscribe touch slider events (On Press, On Release, On Calculation) */ ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle, - TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL)); + TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL)); #ifdef CONFIG_TOUCH_ELEM_EVENT /* Set EVENT as the dispatch method */ ESP_ERROR_CHECK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT)); diff --git a/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_read/main/tp_read_main.c b/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_read/main/tp_read_main.c index 59ba5955e3..0df84f9673 100644 --- a/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_read/main/tp_read_main.c +++ b/examples/peripherals/touch_sensor/touch_sensor_v1/touch_pad_read/main/tp_read_main.c @@ -47,7 +47,7 @@ static void tp_example_read_task(void *pvParameter) static void tp_example_touch_pad_init(void) { - for (int i = 0;i< TOUCH_PAD_MAX;i++) { + for (int i = 0; i < TOUCH_PAD_MAX; i++) { touch_pad_config(i, TOUCH_THRESH_NO_USE); } } diff --git a/examples/peripherals/twai/twai_network/twai_network_listen_only/main/twai_network_example_listen_only_main.c b/examples/peripherals/twai/twai_network/twai_network_listen_only/main/twai_network_example_listen_only_main.c index 3e2e02994b..dcfd828740 100644 --- a/examples/peripherals/twai/twai_network/twai_network_listen_only/main/twai_network_example_listen_only_main.c +++ b/examples/peripherals/twai/twai_network/twai_network_listen_only/main/twai_network_example_listen_only_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -43,11 +43,12 @@ static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS(); //Set TX queue length to 0 due to listen only mode static const twai_general_config_t g_config = {.mode = TWAI_MODE_LISTEN_ONLY, - .tx_io = TX_GPIO_NUM, .rx_io = RX_GPIO_NUM, - .clkout_io = TWAI_IO_UNUSED, .bus_off_io = TWAI_IO_UNUSED, - .tx_queue_len = 0, .rx_queue_len = 5, - .alerts_enabled = TWAI_ALERT_NONE, - .clkout_divider = 0}; + .tx_io = TX_GPIO_NUM, .rx_io = RX_GPIO_NUM, + .clkout_io = TWAI_IO_UNUSED, .bus_off_io = TWAI_IO_UNUSED, + .tx_queue_len = 0, .rx_queue_len = 5, + .alerts_enabled = TWAI_ALERT_NONE, + .clkout_divider = 0 + }; static SemaphoreHandle_t rx_sem; diff --git a/examples/peripherals/twai/twai_network/twai_network_master/main/twai_network_example_master_main.c b/examples/peripherals/twai/twai_network/twai_network_master/main/twai_network_example_master_main.c index 5d1b4b0c45..820bcfb770 100644 --- a/examples/peripherals/twai/twai_network/twai_network_master/main/twai_network_example_master_main.c +++ b/examples/peripherals/twai/twai_network/twai_network_master/main/twai_network_example_master_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -64,11 +64,14 @@ static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); static const twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL); static const twai_message_t ping_message = {.identifier = ID_MASTER_PING, .data_length_code = 0, - .ss = 1, .data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}}; + .ss = 1, .data = {0, 0, 0, 0, 0, 0, 0, 0} + }; static const twai_message_t start_message = {.identifier = ID_MASTER_START_CMD, .data_length_code = 0, - .data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}}; + .data = {0, 0, 0, 0, 0, 0, 0, 0} + }; static const twai_message_t stop_message = {.identifier = ID_MASTER_STOP_CMD, .data_length_code = 0, - .data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}}; + .data = {0, 0, 0, 0, 0, 0, 0, 0} + }; static QueueHandle_t tx_task_queue; static QueueHandle_t rx_task_queue; diff --git a/examples/peripherals/twai/twai_network/twai_network_slave/main/twai_network_example_slave_main.c b/examples/peripherals/twai/twai_network/twai_network_slave/main/twai_network_example_slave_main.c index 30a022cd05..73b79e3407 100644 --- a/examples/peripherals/twai/twai_network/twai_network_slave/main/twai_network_example_slave_main.c +++ b/examples/peripherals/twai/twai_network/twai_network_slave/main/twai_network_example_slave_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -64,12 +64,15 @@ static const twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPI static const twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS(); static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); static const twai_message_t ping_resp = {.identifier = ID_SLAVE_PING_RESP, .data_length_code = 0, - .data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}}; + .data = {0, 0, 0, 0, 0, 0, 0, 0} + }; static const twai_message_t stop_resp = {.identifier = ID_SLAVE_STOP_RESP, .data_length_code = 0, - .data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}}; + .data = {0, 0, 0, 0, 0, 0, 0, 0} + }; //Data bytes of data message will be initialized in the transmit task static twai_message_t data_message = {.identifier = ID_SLAVE_DATA, .data_length_code = 4, - .data = {0, 0 , 0 , 0 ,0 ,0 ,0 ,0}}; + .data = {0, 0, 0, 0, 0, 0, 0, 0} + }; static QueueHandle_t tx_task_queue; static QueueHandle_t rx_task_queue; @@ -230,7 +233,6 @@ void app_main(void) vTaskDelay(pdMS_TO_TICKS(1000)); } - //Create semaphores and tasks tx_task_queue = xQueueCreate(1, sizeof(tx_task_action_t)); rx_task_queue = xQueueCreate(1, sizeof(rx_task_action_t)); diff --git a/examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c b/examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c index 3a5402f237..94c18378ab 100644 --- a/examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c +++ b/examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c @@ -19,7 +19,8 @@ static const int RX_BUF_SIZE = 1024; #define TXD_PIN (GPIO_NUM_4) #define RXD_PIN (GPIO_NUM_5) -void init(void) { +void init(void) +{ const uart_config_t uart_config = { .baud_rate = 115200, .data_bits = UART_DATA_8_BITS, @@ -56,7 +57,7 @@ static void rx_task(void *arg) { static const char *RX_TASK_TAG = "RX_TASK"; esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO); - uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1); + uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE + 1); while (1) { const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 1000 / portTICK_PERIOD_MS); if (rxBytes > 0) { @@ -71,6 +72,6 @@ static void rx_task(void *arg) void app_main(void) { init(); - xTaskCreate(rx_task, "uart_rx_task", 1024*2, NULL, configMAX_PRIORITIES, NULL); - xTaskCreate(tx_task, "uart_tx_task", 1024*2, NULL, configMAX_PRIORITIES-1, NULL); + xTaskCreate(rx_task, "uart_rx_task", 1024 * 2, NULL, configMAX_PRIORITIES, NULL); + xTaskCreate(tx_task, "uart_tx_task", 1024 * 2, NULL, configMAX_PRIORITIES - 1, NULL); } diff --git a/examples/peripherals/uart/uart_echo_rs485/main/rs485_example.c b/examples/peripherals/uart/uart_echo_rs485/main/rs485_example.c index 8a64c7841d..63ff45e30c 100644 --- a/examples/peripherals/uart/uart_echo_rs485/main/rs485_example.c +++ b/examples/peripherals/uart/uart_echo_rs485/main/rs485_example.c @@ -98,7 +98,7 @@ static void echo_task(void *arg) ESP_LOGI(TAG, "UART start recieve loop.\r"); echo_send(uart_num, "Start RS485 UART test.\r\n", 24); - while(1) { + while (1) { //Read data from UART int len = uart_read_bytes(uart_num, data, BUF_SIZE, PACKET_READ_TICS); diff --git a/examples/peripherals/uart/uart_events/main/uart_events_example_main.c b/examples/peripherals/uart/uart_events/main/uart_events_example_main.c index dcf2614b14..d5200164bd 100644 --- a/examples/peripherals/uart/uart_events/main/uart_events_example_main.c +++ b/examples/peripherals/uart/uart_events/main/uart_events_example_main.c @@ -41,74 +41,74 @@ static void uart_event_task(void *pvParameters) uart_event_t event; size_t buffered_size; uint8_t* dtmp = (uint8_t*) malloc(RD_BUF_SIZE); - for(;;) { + for (;;) { //Waiting for UART event. - if(xQueueReceive(uart0_queue, (void * )&event, (TickType_t)portMAX_DELAY)) { + if (xQueueReceive(uart0_queue, (void *)&event, (TickType_t)portMAX_DELAY)) { bzero(dtmp, RD_BUF_SIZE); ESP_LOGI(TAG, "uart[%d] event:", EX_UART_NUM); - switch(event.type) { - //Event of UART receving data - /*We'd better handler data event fast, there would be much more data events than - other types of events. If we take too much time on data event, the queue might - be full.*/ - case UART_DATA: - ESP_LOGI(TAG, "[UART DATA]: %d", event.size); - uart_read_bytes(EX_UART_NUM, dtmp, event.size, portMAX_DELAY); - ESP_LOGI(TAG, "[DATA EVT]:"); - uart_write_bytes(EX_UART_NUM, (const char*) dtmp, event.size); - break; - //Event of HW FIFO overflow detected - case UART_FIFO_OVF: - ESP_LOGI(TAG, "hw fifo overflow"); - // If fifo overflow happened, you should consider adding flow control for your application. - // The ISR has already reset the rx FIFO, - // As an example, we directly flush the rx buffer here in order to read more data. + switch (event.type) { + //Event of UART receving data + /*We'd better handler data event fast, there would be much more data events than + other types of events. If we take too much time on data event, the queue might + be full.*/ + case UART_DATA: + ESP_LOGI(TAG, "[UART DATA]: %d", event.size); + uart_read_bytes(EX_UART_NUM, dtmp, event.size, portMAX_DELAY); + ESP_LOGI(TAG, "[DATA EVT]:"); + uart_write_bytes(EX_UART_NUM, (const char*) dtmp, event.size); + break; + //Event of HW FIFO overflow detected + case UART_FIFO_OVF: + ESP_LOGI(TAG, "hw fifo overflow"); + // If fifo overflow happened, you should consider adding flow control for your application. + // The ISR has already reset the rx FIFO, + // As an example, we directly flush the rx buffer here in order to read more data. + uart_flush_input(EX_UART_NUM); + xQueueReset(uart0_queue); + break; + //Event of UART ring buffer full + case UART_BUFFER_FULL: + ESP_LOGI(TAG, "ring buffer full"); + // If buffer full happened, you should consider increasing your buffer size + // As an example, we directly flush the rx buffer here in order to read more data. + uart_flush_input(EX_UART_NUM); + xQueueReset(uart0_queue); + break; + //Event of UART RX break detected + case UART_BREAK: + ESP_LOGI(TAG, "uart rx break"); + break; + //Event of UART parity check error + case UART_PARITY_ERR: + ESP_LOGI(TAG, "uart parity error"); + break; + //Event of UART frame error + case UART_FRAME_ERR: + ESP_LOGI(TAG, "uart frame error"); + break; + //UART_PATTERN_DET + case UART_PATTERN_DET: + uart_get_buffered_data_len(EX_UART_NUM, &buffered_size); + int pos = uart_pattern_pop_pos(EX_UART_NUM); + ESP_LOGI(TAG, "[UART PATTERN DETECTED] pos: %d, buffered size: %d", pos, buffered_size); + if (pos == -1) { + // There used to be a UART_PATTERN_DET event, but the pattern position queue is full so that it can not + // record the position. We should set a larger queue size. + // As an example, we directly flush the rx buffer here. uart_flush_input(EX_UART_NUM); - xQueueReset(uart0_queue); - break; - //Event of UART ring buffer full - case UART_BUFFER_FULL: - ESP_LOGI(TAG, "ring buffer full"); - // If buffer full happened, you should consider increasing your buffer size - // As an example, we directly flush the rx buffer here in order to read more data. - uart_flush_input(EX_UART_NUM); - xQueueReset(uart0_queue); - break; - //Event of UART RX break detected - case UART_BREAK: - ESP_LOGI(TAG, "uart rx break"); - break; - //Event of UART parity check error - case UART_PARITY_ERR: - ESP_LOGI(TAG, "uart parity error"); - break; - //Event of UART frame error - case UART_FRAME_ERR: - ESP_LOGI(TAG, "uart frame error"); - break; - //UART_PATTERN_DET - case UART_PATTERN_DET: - uart_get_buffered_data_len(EX_UART_NUM, &buffered_size); - int pos = uart_pattern_pop_pos(EX_UART_NUM); - ESP_LOGI(TAG, "[UART PATTERN DETECTED] pos: %d, buffered size: %d", pos, buffered_size); - if (pos == -1) { - // There used to be a UART_PATTERN_DET event, but the pattern position queue is full so that it can not - // record the position. We should set a larger queue size. - // As an example, we directly flush the rx buffer here. - uart_flush_input(EX_UART_NUM); - } else { - uart_read_bytes(EX_UART_NUM, dtmp, pos, 100 / portTICK_PERIOD_MS); - uint8_t pat[PATTERN_CHR_NUM + 1]; - memset(pat, 0, sizeof(pat)); - uart_read_bytes(EX_UART_NUM, pat, PATTERN_CHR_NUM, 100 / portTICK_PERIOD_MS); - ESP_LOGI(TAG, "read data: %s", dtmp); - ESP_LOGI(TAG, "read pat : %s", pat); - } - break; - //Others - default: - ESP_LOGI(TAG, "uart event type: %d", event.type); - break; + } else { + uart_read_bytes(EX_UART_NUM, dtmp, pos, 100 / portTICK_PERIOD_MS); + uint8_t pat[PATTERN_CHR_NUM + 1]; + memset(pat, 0, sizeof(pat)); + uart_read_bytes(EX_UART_NUM, pat, PATTERN_CHR_NUM, 100 / portTICK_PERIOD_MS); + ESP_LOGI(TAG, "read data: %s", dtmp); + ESP_LOGI(TAG, "read pat : %s", pat); + } + break; + //Others + default: + ESP_LOGI(TAG, "uart event type: %d", event.type); + break; } } } diff --git a/examples/peripherals/uart/uart_repl/main/uart_repl_example_main.c b/examples/peripherals/uart/uart_repl/main/uart_repl_example_main.c index 9e70780aac..efe0447528 100644 --- a/examples/peripherals/uart/uart_repl/main/uart_repl_example_main.c +++ b/examples/peripherals/uart/uart_repl/main/uart_repl_example_main.c @@ -84,7 +84,6 @@ static void configure_uarts(void) ESP_ERROR_CHECK(uart_set_pin(DEFAULT_UART_CHANNEL, DEFAULT_UART_TX_PIN, DEFAULT_UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); - connect_uarts(); } @@ -92,7 +91,8 @@ static void configure_uarts(void) * @brief Function called when command `consoletest` will be invoked. * It will simply print `test_message` defined above. */ -static int console_test(int argc, char **argv) { +static int console_test(int argc, char **argv) +{ printf("%s\n", test_message); return 0; } @@ -104,7 +104,8 @@ static int console_test(int argc, char **argv) { * the response on RX. * The response shall contain the test_message string. */ -static void send_commands(void* arg) { +static void send_commands(void* arg) +{ static char data[READ_BUF_SIZE]; char command[] = "consoletest\n"; int len = 0; @@ -115,12 +116,12 @@ static void send_commands(void* arg) { len = uart_read_bytes(DEFAULT_UART_CHANNEL, data, READ_BUF_SIZE, 100 / portTICK_PERIOD_MS); } while (len == 0); - if ( len == -1 ) { + if (len == -1) { goto end; } /* Send the command `consoletest` to the console UART. */ len = uart_write_bytes(DEFAULT_UART_CHANNEL, command, sizeof(command)); - if ( len == -1 ) { + if (len == -1) { goto end; } @@ -129,7 +130,7 @@ static void send_commands(void* arg) { len = uart_read_bytes(DEFAULT_UART_CHANNEL, data, READ_BUF_SIZE - 1, 250 / portTICK_PERIOD_MS); } while (len == 0); - if ( len == -1 ) { + if (len == -1) { goto end; } @@ -158,11 +159,11 @@ void app_main(void) .func = &console_test, }; esp_console_dev_uart_config_t uart_config = { - .channel = CONSOLE_UART_CHANNEL, - .baud_rate = UARTS_BAUD_RATE, - .tx_gpio_num = CONSOLE_UART_TX_PIN, - .rx_gpio_num = CONSOLE_UART_RX_PIN, - }; + .channel = CONSOLE_UART_CHANNEL, + .baud_rate = UARTS_BAUD_RATE, + .tx_gpio_num = CONSOLE_UART_TX_PIN, + .rx_gpio_num = CONSOLE_UART_RX_PIN, + }; /** * As we don't have a real serial terminal, (we just use default UART to * send and receive commands, ) we won't handle any escape sequence, so the @@ -172,7 +173,7 @@ void app_main(void) ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl)); configure_uarts(); - ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) ); + ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); /* Create a task for sending and receiving commands to and from the second UART. */ xTaskCreate(send_commands, "send_commands_task", TASK_STACK_SIZE, NULL, 10, NULL); diff --git a/examples/peripherals/uart/uart_select/main/uart_select_example_main.c b/examples/peripherals/uart/uart_select/main/uart_select_example_main.c index e9d5e28dce..065837e444 100644 --- a/examples/peripherals/uart/uart_select/main/uart_select_example_main.c +++ b/examples/peripherals/uart/uart_select/main/uart_select_example_main.c @@ -22,7 +22,7 @@ static const char* TAG = "uart_select_example"; static void uart_select_task(void *arg) { - if (uart_driver_install(UART_NUM_0, 2*1024, 0, 0, NULL, 0) != ESP_OK) { + if (uart_driver_install(UART_NUM_0, 2 * 1024, 0, 0, NULL, 0) != ESP_OK) { ESP_LOGE(TAG, "Driver installation failed"); vTaskDelete(NULL); } @@ -95,5 +95,5 @@ static void uart_select_task(void *arg) void app_main(void) { - xTaskCreate(uart_select_task, "uart_select_task", 4*1024, NULL, 5, NULL); + xTaskCreate(uart_select_task, "uart_select_task", 4 * 1024, NULL, 5, NULL); } diff --git a/examples/peripherals/usb/device/tusb_hid/main/tusb_hid_example_main.c b/examples/peripherals/usb/device/tusb_hid/main/tusb_hid_example_main.c index 022a46dfbe..8f3420d5c4 100644 --- a/examples/peripherals/usb/device/tusb_hid/main/tusb_hid_example_main.c +++ b/examples/peripherals/usb/device/tusb_hid/main/tusb_hid_example_main.c @@ -26,8 +26,8 @@ static const char *TAG = "example"; * so we must define both report descriptors */ const uint8_t hid_report_descriptor[] = { - TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD) ), - TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE) ) + TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD)), + TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE)) }; /** @@ -70,13 +70,13 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance) // Return zero will cause the stack to STALL request uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { - (void) instance; - (void) report_id; - (void) report_type; - (void) buffer; - (void) reqlen; + (void) instance; + (void) report_id; + (void) report_type; + (void) buffer; + (void) reqlen; - return 0; + return 0; } // Invoked when received SET_REPORT control request or diff --git a/examples/peripherals/usb/device/tusb_msc/main/tusb_msc_main.c b/examples/peripherals/usb/device/tusb_msc/main/tusb_msc_main.c index c1d4684690..9d44945ce8 100644 --- a/examples/peripherals/usb/device/tusb_msc/main/tusb_msc_main.c +++ b/examples/peripherals/usb/device/tusb_msc/main/tusb_msc_main.c @@ -131,7 +131,6 @@ static void _mount(void) ESP_LOGI(TAG, "Mount storage..."); ESP_ERROR_CHECK(tinyusb_msc_storage_mount(BASE_PATH)); - // List all the files in this directory ESP_LOGI(TAG, "\nls command output:"); struct dirent *d; @@ -388,7 +387,7 @@ void app_main(void) esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl)); for (int count = 0; count < sizeof(cmds) / sizeof(esp_console_cmd_t); count++) { - ESP_ERROR_CHECK( esp_console_cmd_register(&cmds[count]) ); + ESP_ERROR_CHECK(esp_console_cmd_register(&cmds[count])); } ESP_ERROR_CHECK(esp_console_start_repl(repl)); } diff --git a/examples/peripherals/usb/device/tusb_ncm/main/tusb_ncm_main.c b/examples/peripherals/usb/device/tusb_ncm/main/tusb_ncm_main.c index be38d1b9e9..79efe53a9b 100644 --- a/examples/peripherals/usb/device/tusb_ncm/main/tusb_ncm_main.c +++ b/examples/peripherals/usb/device/tusb_ncm/main/tusb_ncm_main.c @@ -24,7 +24,6 @@ #include "tinyusb.h" #include "tinyusb_net.h" - static const char *TAG = "USB_NCM"; static esp_err_t usb_recv_callback(void *buffer, uint16_t len, void *ctx) diff --git a/examples/peripherals/usb/host/cdc/cdc_acm_host/main/usb_cdc_example_main.c b/examples/peripherals/usb/host/cdc/cdc_acm_host/main/usb_cdc_example_main.c index 01a5862202..f8c548e01a 100644 --- a/examples/peripherals/usb/host/cdc/cdc_acm_host/main/usb_cdc_example_main.c +++ b/examples/peripherals/usb/host/cdc/cdc_acm_host/main/usb_cdc_example_main.c @@ -56,21 +56,21 @@ static bool handle_rx(const uint8_t *data, size_t data_len, void *arg) static void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx) { switch (event->type) { - case CDC_ACM_HOST_ERROR: - ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %i", event->data.error); - break; - case CDC_ACM_HOST_DEVICE_DISCONNECTED: - ESP_LOGI(TAG, "Device suddenly disconnected"); - ESP_ERROR_CHECK(cdc_acm_host_close(event->data.cdc_hdl)); - xSemaphoreGive(device_disconnected_sem); - break; - case CDC_ACM_HOST_SERIAL_STATE: - ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val); - break; - case CDC_ACM_HOST_NETWORK_CONNECTION: - default: - ESP_LOGW(TAG, "Unsupported CDC event: %i", event->type); - break; + case CDC_ACM_HOST_ERROR: + ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %i", event->data.error); + break; + case CDC_ACM_HOST_DEVICE_DISCONNECTED: + ESP_LOGI(TAG, "Device suddenly disconnected"); + ESP_ERROR_CHECK(cdc_acm_host_close(event->data.cdc_hdl)); + xSemaphoreGive(device_disconnected_sem); + break; + case CDC_ACM_HOST_SERIAL_STATE: + ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val); + break; + case CDC_ACM_HOST_NETWORK_CONNECTION: + default: + ESP_LOGW(TAG, "Unsupported CDC event: %i", event->type); + break; } } diff --git a/examples/peripherals/usb/host/cdc/cdc_acm_vcp/main/cdc_acm_vcp_example_main.cpp b/examples/peripherals/usb/host/cdc/cdc_acm_vcp/main/cdc_acm_vcp_example_main.cpp index f90620ec87..1ffd33c222 100644 --- a/examples/peripherals/usb/host/cdc/cdc_acm_vcp/main/cdc_acm_vcp_example_main.cpp +++ b/examples/peripherals/usb/host/cdc/cdc_acm_vcp/main/cdc_acm_vcp_example_main.cpp @@ -60,18 +60,18 @@ static bool handle_rx(const uint8_t *data, size_t data_len, void *arg) static void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx) { switch (event->type) { - case CDC_ACM_HOST_ERROR: - ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %d", event->data.error); - break; - case CDC_ACM_HOST_DEVICE_DISCONNECTED: - ESP_LOGI(TAG, "Device suddenly disconnected"); - xSemaphoreGive(device_disconnected_sem); - break; - case CDC_ACM_HOST_SERIAL_STATE: - ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val); - break; - case CDC_ACM_HOST_NETWORK_CONNECTION: - default: break; + case CDC_ACM_HOST_ERROR: + ESP_LOGE(TAG, "CDC-ACM error has occurred, err_no = %d", event->data.error); + break; + case CDC_ACM_HOST_DEVICE_DISCONNECTED: + ESP_LOGI(TAG, "Device suddenly disconnected"); + xSemaphoreGive(device_disconnected_sem); + break; + case CDC_ACM_HOST_SERIAL_STATE: + ESP_LOGI(TAG, "Serial state notif 0x%04X", event->data.serial_state.val); + break; + case CDC_ACM_HOST_NETWORK_CONNECTION: + default: break; } } diff --git a/examples/peripherals/usb/host/hid/main/hid_host_example.c b/examples/peripherals/usb/host/hid/main/hid_host_example.c index 7a37d95e90..2ed9383919 100644 --- a/examples/peripherals/usb/host/hid/main/hid_host_example.c +++ b/examples/peripherals/usb/host/hid/main/hid_host_example.c @@ -180,8 +180,8 @@ static inline bool hid_keyboard_is_modifier_shift(uint8_t modifier) * @return false Key scancode unknown */ static inline bool hid_keyboard_get_char(uint8_t modifier, - uint8_t key_code, - unsigned char *key_char) + uint8_t key_code, + unsigned char *key_char) { uint8_t mod = (hid_keyboard_is_modifier_shift(modifier)) ? 1 : 0; @@ -342,7 +342,6 @@ static void hid_host_generic_report_callback(const uint8_t *const data, const in putchar('\r'); } - /** * @brief USB HID Host interface callback * @@ -357,14 +356,14 @@ void hid_host_interface_callback(hid_host_device_handle_t hid_device_handle, uint8_t data[64] = { 0 }; size_t data_length = 0; hid_host_dev_params_t dev_params; - ESP_ERROR_CHECK( hid_host_device_get_params(hid_device_handle, &dev_params)); + ESP_ERROR_CHECK(hid_host_device_get_params(hid_device_handle, &dev_params)); switch (event) { case HID_HOST_INTERFACE_EVENT_INPUT_REPORT: - ESP_ERROR_CHECK( hid_host_device_get_raw_input_report_data(hid_device_handle, - data, - 64, - &data_length)); + ESP_ERROR_CHECK(hid_host_device_get_raw_input_report_data(hid_device_handle, + data, + 64, + &data_length)); if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) { if (HID_PROTOCOL_KEYBOARD == dev_params.proto) { @@ -380,7 +379,7 @@ void hid_host_interface_callback(hid_host_device_handle_t hid_device_handle, case HID_HOST_INTERFACE_EVENT_DISCONNECTED: ESP_LOGI(TAG, "HID Device, protocol '%s' DISCONNECTED", hid_proto_name_str[dev_params.proto]); - ESP_ERROR_CHECK( hid_host_device_close(hid_device_handle) ); + ESP_ERROR_CHECK(hid_host_device_close(hid_device_handle)); break; case HID_HOST_INTERFACE_EVENT_TRANSFER_ERROR: ESP_LOGI(TAG, "HID Device, protocol '%s' TRANSFER_ERROR", @@ -405,7 +404,7 @@ void hid_host_device_event(hid_host_device_handle_t hid_device_handle, void *arg) { hid_host_dev_params_t dev_params; - ESP_ERROR_CHECK( hid_host_device_get_params(hid_device_handle, &dev_params)); + ESP_ERROR_CHECK(hid_host_device_get_params(hid_device_handle, &dev_params)); switch (event) { case HID_HOST_DRIVER_EVENT_CONNECTED: @@ -417,14 +416,14 @@ void hid_host_device_event(hid_host_device_handle_t hid_device_handle, .callback_arg = NULL }; - ESP_ERROR_CHECK( hid_host_device_open(hid_device_handle, &dev_config) ); + ESP_ERROR_CHECK(hid_host_device_open(hid_device_handle, &dev_config)); if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) { - ESP_ERROR_CHECK( hid_class_request_set_protocol(hid_device_handle, HID_REPORT_PROTOCOL_BOOT)); + ESP_ERROR_CHECK(hid_class_request_set_protocol(hid_device_handle, HID_REPORT_PROTOCOL_BOOT)); if (HID_PROTOCOL_KEYBOARD == dev_params.proto) { - ESP_ERROR_CHECK( hid_class_request_set_idle(hid_device_handle, 0, 0)); + ESP_ERROR_CHECK(hid_class_request_set_idle(hid_device_handle, 0, 0)); } } - ESP_ERROR_CHECK( hid_host_device_start(hid_device_handle) ); + ESP_ERROR_CHECK(hid_host_device_start(hid_device_handle)); break; default: break; @@ -443,14 +442,14 @@ static void usb_lib_task(void *arg) .mode = GPIO_MODE_INPUT, .pull_up_en = GPIO_PULLUP_ENABLE, }; - ESP_ERROR_CHECK( gpio_config(&input_pin) ); + ESP_ERROR_CHECK(gpio_config(&input_pin)); const usb_host_config_t host_config = { .skip_phy_setup = false, .intr_flags = ESP_INTR_FLAG_LEVEL1, }; - ESP_ERROR_CHECK( usb_host_install(&host_config) ); + ESP_ERROR_CHECK(usb_host_install(&host_config)); xTaskNotifyGive(arg); while (gpio_get_level(APP_QUIT_PIN) != 0) { @@ -472,7 +471,7 @@ static void usb_lib_task(void *arg) ESP_LOGI(TAG, "USB shutdown"); // Clean up USB Host vTaskDelay(10); // Short delay to allow clients clean-up - ESP_ERROR_CHECK( usb_host_uninstall()); + ESP_ERROR_CHECK(usb_host_uninstall()); vTaskDelete(NULL); } @@ -558,7 +557,7 @@ void app_main(void) .callback_arg = NULL }; - ESP_ERROR_CHECK( hid_host_install(&hid_host_driver_config) ); + ESP_ERROR_CHECK(hid_host_install(&hid_host_driver_config)); // Task is working until the devices are gone (while 'user_shutdown' if false) user_shutdown = false; diff --git a/examples/peripherals/usb/host/msc/main/msc_example_main.c b/examples/peripherals/usb/host/msc/main/msc_example_main.c index 1e690e1e73..53c28bc26e 100644 --- a/examples/peripherals/usb/host/msc/main/msc_example_main.c +++ b/examples/peripherals/usb/host/msc/main/msc_example_main.c @@ -164,13 +164,13 @@ void app_main(void) .mode = GPIO_MODE_INPUT, .pull_up_en = GPIO_PULLUP_ENABLE, }; - ESP_ERROR_CHECK( gpio_config(&input_pin) ); + ESP_ERROR_CHECK(gpio_config(&input_pin)); usb_flags = xEventGroupCreate(); assert(usb_flags); const usb_host_config_t host_config = { .intr_flags = ESP_INTR_FLAG_LEVEL1 }; - ESP_ERROR_CHECK( usb_host_install(&host_config) ); + ESP_ERROR_CHECK(usb_host_install(&host_config)); task_created = xTaskCreate(handle_usb_events, "usb_events", 2048, NULL, 2, NULL); assert(task_created); @@ -180,7 +180,7 @@ void app_main(void) .stack_size = 4096, .callback = msc_event_cb, }; - ESP_ERROR_CHECK( msc_host_install(&msc_config) ); + ESP_ERROR_CHECK(msc_host_install(&msc_config)); const esp_vfs_fat_mount_config_t mount_config = { .format_if_mount_failed = false, @@ -191,28 +191,28 @@ void app_main(void) do { uint8_t device_address = wait_for_msc_device(); - ESP_ERROR_CHECK( msc_host_install_device(device_address, &msc_device) ); + ESP_ERROR_CHECK(msc_host_install_device(device_address, &msc_device)); msc_host_print_descriptors(msc_device); - ESP_ERROR_CHECK( msc_host_get_device_info(msc_device, &info) ); + ESP_ERROR_CHECK(msc_host_get_device_info(msc_device, &info)); print_device_info(&info); - ESP_ERROR_CHECK( msc_host_vfs_register(msc_device, "/usb", &mount_config, &vfs_handle) ); + ESP_ERROR_CHECK(msc_host_vfs_register(msc_device, "/usb", &mount_config, &vfs_handle)); while (!wait_for_event(DEVICE_DISCONNECTED, 200)) { file_operations(); } xEventGroupClearBits(usb_flags, READY_TO_UNINSTALL); - ESP_ERROR_CHECK( msc_host_vfs_unregister(vfs_handle) ); - ESP_ERROR_CHECK( msc_host_uninstall_device(msc_device) ); + ESP_ERROR_CHECK(msc_host_vfs_unregister(vfs_handle)); + ESP_ERROR_CHECK(msc_host_uninstall_device(msc_device)); } while (gpio_get_level(USB_DISCONNECT_PIN) != 0); ESP_LOGI(TAG, "Uninitializing USB ..."); - ESP_ERROR_CHECK( msc_host_uninstall() ); + ESP_ERROR_CHECK(msc_host_uninstall()); wait_for_event(READY_TO_UNINSTALL, portMAX_DELAY); - ESP_ERROR_CHECK( usb_host_uninstall() ); + ESP_ERROR_CHECK(usb_host_uninstall()); ESP_LOGI(TAG, "Done"); } diff --git a/examples/peripherals/usb/host/usb_host_lib/main/class_driver.c b/examples/peripherals/usb/host/usb_host_lib/main/class_driver.c index 15ae3201f8..ce7ee44487 100644 --- a/examples/peripherals/usb/host/usb_host_lib/main/class_driver.c +++ b/examples/peripherals/usb/host/usb_host_lib/main/class_driver.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -33,22 +33,22 @@ static void client_event_cb(const usb_host_client_event_msg_t *event_msg, void * { class_driver_t *driver_obj = (class_driver_t *)arg; switch (event_msg->event) { - case USB_HOST_CLIENT_EVENT_NEW_DEV: - if (driver_obj->dev_addr == 0) { - driver_obj->dev_addr = event_msg->new_dev.address; - //Open the device next - driver_obj->actions |= ACTION_OPEN_DEV; - } - break; - case USB_HOST_CLIENT_EVENT_DEV_GONE: - if (driver_obj->dev_hdl != NULL) { - //Cancel any other actions and close the device next - driver_obj->actions = ACTION_CLOSE_DEV; - } - break; - default: - //Should never occur - abort(); + case USB_HOST_CLIENT_EVENT_NEW_DEV: + if (driver_obj->dev_addr == 0) { + driver_obj->dev_addr = event_msg->new_dev.address; + //Open the device next + driver_obj->actions |= ACTION_OPEN_DEV; + } + break; + case USB_HOST_CLIENT_EVENT_DEV_GONE: + if (driver_obj->dev_hdl != NULL) { + //Cancel any other actions and close the device next + driver_obj->actions = ACTION_CLOSE_DEV; + } + break; + default: + //Should never occur + abort(); } } @@ -146,7 +146,7 @@ void class_driver_task(void *arg) .max_num_event_msg = CLIENT_NUM_EVENT_MSG, .async = { .client_event_callback = client_event_cb, - .callback_arg = (void *)&driver_obj, + .callback_arg = (void *) &driver_obj, }, }; ESP_ERROR_CHECK(usb_host_client_register(&client_config, &driver_obj.client_hdl)); diff --git a/examples/peripherals/usb/host/usb_host_lib/main/usb_host_lib_main.c b/examples/peripherals/usb/host/usb_host_lib/main/usb_host_lib_main.c index 9ee388a284..f73880cabc 100644 --- a/examples/peripherals/usb/host/usb_host_lib/main/usb_host_lib_main.c +++ b/examples/peripherals/usb/host/usb_host_lib/main/usb_host_lib_main.c @@ -35,7 +35,7 @@ static void host_lib_daemon_task(void *arg) bool has_clients = true; bool has_devices = true; - while (has_clients || has_devices ) { + while (has_clients || has_devices) { uint32_t event_flags; ESP_ERROR_CHECK(usb_host_lib_handle_events(portMAX_DELAY, &event_flags)); if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) { diff --git a/examples/peripherals/usb/host/uvc/main/main.c b/examples/peripherals/usb/host/uvc/main/main.c index 7cf4f476b6..9f87bdf412 100644 --- a/examples/peripherals/usb/host/uvc/main/main.c +++ b/examples/peripherals/usb/host/uvc/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -99,7 +99,7 @@ static void uninitialize_usb_host_lib(void) xSemaphoreTake(ready_to_uninstall_usb, portMAX_DELAY); vSemaphoreDelete(ready_to_uninstall_usb); - if ( usb_host_uninstall() != ESP_OK) { + if (usb_host_uninstall() != ESP_OK) { ESP_LOGE(TAG, "Failed to uninstall usb_host"); } } @@ -163,9 +163,9 @@ int app_main(int argc, char **argv) .mode = GPIO_MODE_INPUT, .pull_up_en = GPIO_PULLUP_ENABLE, }; - ESP_ERROR_CHECK( gpio_config(&input_pin) ); + ESP_ERROR_CHECK(gpio_config(&input_pin)); - ESP_ERROR_CHECK( initialize_usb_host_lib() ); + ESP_ERROR_CHECK(initialize_usb_host_lib()); libuvc_adapter_config_t config = { .create_background_task = true, @@ -176,20 +176,20 @@ int app_main(int argc, char **argv) libuvc_adapter_set_config(&config); - UVC_CHECK( uvc_init(&ctx, NULL) ); + UVC_CHECK(uvc_init(&ctx, NULL)); // Streaming takes place only when enabled in menuconfig - ESP_ERROR_CHECK( tcp_server_wait_for_connection() ); + ESP_ERROR_CHECK(tcp_server_wait_for_connection()); do { printf("Waiting for device\n"); wait_for_event(UVC_DEVICE_CONNECTED); - UVC_CHECK( uvc_find_device(ctx, &dev, PID, VID, SERIAL_NUMBER) ); + UVC_CHECK(uvc_find_device(ctx, &dev, PID, VID, SERIAL_NUMBER)); puts("Device found"); - UVC_CHECK( uvc_open(dev, &devh) ); + UVC_CHECK(uvc_open(dev, &devh)); // Uncomment to print configuration descriptor // libuvc_adapter_print_descriptors(devh); @@ -200,10 +200,10 @@ int app_main(int argc, char **argv) uvc_print_diag(devh, stderr); // Negotiate stream profile - res = uvc_get_stream_ctrl_format_size(devh, &ctrl, FORMAT, WIDTH, HEIGHT, FPS ); + res = uvc_get_stream_ctrl_format_size(devh, &ctrl, FORMAT, WIDTH, HEIGHT, FPS); while (res != UVC_SUCCESS) { printf("Negotiating streaming format failed, trying again...\n"); - res = uvc_get_stream_ctrl_format_size(devh, &ctrl, FORMAT, WIDTH, HEIGHT, FPS ); + res = uvc_get_stream_ctrl_format_size(devh, &ctrl, FORMAT, WIDTH, HEIGHT, FPS); sleep(1); } @@ -213,7 +213,7 @@ int app_main(int argc, char **argv) uvc_print_stream_ctrl(&ctrl, stderr); - UVC_CHECK( uvc_start_streaming(devh, &ctrl, frame_callback, NULL, 0) ); + UVC_CHECK(uvc_start_streaming(devh, &ctrl, frame_callback, NULL, 0)); puts("Streaming..."); wait_for_event(UVC_DEVICE_DISCONNECTED); diff --git a/examples/peripherals/usb/host/uvc/main/tcp_server.c b/examples/peripherals/usb/host/uvc/main/tcp_server.c index d11c8b3a4e..0d2a3ee544 100644 --- a/examples/peripherals/usb/host/uvc/main/tcp_server.c +++ b/examples/peripherals/usb/host/uvc/main/tcp_server.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -53,7 +53,7 @@ static void sender_task(void *arg) while (1) { size_t bytes_received = 0; char *payload = (char *)xRingbufferReceiveUpTo( - server->buffer, &bytes_received, pdMS_TO_TICKS(2500), 20000); + server->buffer, &bytes_received, pdMS_TO_TICKS(2500), 20000); if (payload != NULL && server->is_active) { int sent = send(server->sock, payload, bytes_received, 0); @@ -82,7 +82,7 @@ esp_err_t tcp_server_send(uint8_t *payload, size_t size) return ESP_OK; } - if ( xRingbufferSend(s_server->buffer, payload, size, pdMS_TO_TICKS(1)) != pdTRUE ) { + if (xRingbufferSend(s_server->buffer, payload, size, pdMS_TO_TICKS(1)) != pdTRUE) { ESP_LOGW(TAG, "Failed to send frame to ring buffer."); return ESP_FAIL; } @@ -179,18 +179,17 @@ esp_err_t tcp_server_wait_for_connection(void) } server->buffer = xRingbufferCreate(100000, RINGBUF_TYPE_BYTEBUF); - if ( server->buffer == NULL) { + if (server->buffer == NULL) { free(server); return ESP_ERR_NO_MEM;; } - if ( create_server(server) != ESP_OK) { + if (create_server(server) != ESP_OK) { vRingbufferDelete(server->buffer); free(server); return ESP_FAIL; } - BaseType_t task_created = xTaskCreate(sender_task, "sender_task", 4096, server, 10, &task_handle); if (!task_created) { socket_close(server); diff --git a/tools/ci/astyle-rules.yml b/tools/ci/astyle-rules.yml index 7fa747ff22..b09def62d5 100644 --- a/tools/ci/astyle-rules.yml +++ b/tools/ci/astyle-rules.yml @@ -66,7 +66,6 @@ components_not_formatted_temporary: - "/components/esp_https_ota/" - "/components/esp_https_server/" - "/components/esp_hw_support/" - - "/components/esp_lcd/" - "/components/esp_local_ctrl/" - "/components/esp_mm/" - "/components/esp_netif/" @@ -128,7 +127,6 @@ components_not_formatted_temporary: - "/examples/mesh/" - "/examples/network/" - "/examples/openthread/" - - "/examples/peripherals/" - "/examples/phy/" - "/examples/protocols/" - "/examples/provisioning/" @@ -175,6 +173,9 @@ components_not_formatted_permanent: - "/components/app_trace/sys_view/SEGGER/" # SoC header files (generated) - "/components/soc/*/include/soc/" + # Example resource files (generated) + - "/examples/peripherals/lcd/i80_controller/main/images/" + - "/examples/peripherals/dac/dac_continuous/dac_audio/main/audio_example_file.h" docs: # Docs directory contains some .inc files, which are not C include files