From 821c70f5d7df7ffcfaaa013dba60cc9c38b43512 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 22 Mar 2017 12:36:11 +0800 Subject: [PATCH] examples: Standardise naming of files, symbols, etc. in examples * Use "example" in all example function & variable names, ie use i2c_example_xxx instead of i2c_xxx for example functions. Closes #198 https://github.com/espressif/esp-idf/issues/198 * Mark example functions, etc. static * Replace uses of "test" & "demo" with "example" * Split the UART example into two * Rename "main" example files to end with "_main.c" for disambiguation --- examples/README.md | 3 + .../main/{blufi_demo.h => blufi_example.h} | 12 +- .../{blufi_main.c => blufi_example_main.c} | 36 +- .../bluetooth/blufi/main/blufi_security.c | 2 +- ...thernet_main.c => ethernet_example_main.c} | 2 +- .../main/{gpio_test.c => gpio_example_main.c} | 6 +- .../main/{i2c_test.c => i2c_example_main.c} | 74 ++-- .../main/{app_main.c => i2s_example_main.c} | 0 .../main/{ledc_fade.c => ledc_example_main.c} | 0 .../main/{pcnt_test.c => pcnt_example_main.c} | 8 +- examples/peripherals/rmt_nec_tx_rx/README.md | 4 +- .../rmt_nec_tx_rx/main/infrared_nec.c | 358 ------------------ .../rmt_nec_tx_rx/main/infrared_nec_main.c | 353 ++++++++++++++++- ...delta_test.c => sigmadelta_example_main.c} | 4 +- ...spi_master.c => spi_master_example_main.c} | 6 +- ...mer_group.c => timer_group_example_main.c} | 12 +- .../main/tp_interrupt_main.c | 20 +- .../touch_pad_read/main/tp_read_main.c | 4 +- .../peripherals/{uart => uart_echo}/Makefile | 2 +- .../{uart => uart_echo}/main/component.mk | 0 .../uart_echo/main/uart_echo_example_main.c | 73 ++++ examples/peripherals/uart_events/Makefile | 9 + .../peripherals/uart_events/main/component.mk | 3 + .../main/uart_events_example_main.c} | 99 ++--- ...ap_client.c => coap_client_example_main.c} | 4 +- ...ap_server.c => coap_server_example_main.c} | 4 +- ...est_main.c => http_request_example_main.c} | 0 ...st_main.c => https_request_example_main.c} | 0 .../protocols/mdns/main/mdns_example_main.c | 4 +- ...nssl_client.h => openssl_client_example.h} | 24 +- ...client.c => openssl_client_example_main.c} | 42 +- ...nssl_server.h => openssl_server_example.h} | 10 +- ...server.c => openssl_server_example_main.c} | 32 +- .../main/{sntp_main.c => sntp_example_main.c} | 0 ...{nvs_rw_blob.c => nvs_blob_example_main.c} | 0 ...vs_rw_value.c => nvs_value_example_main.c} | 0 .../{sd_card.c => sd_card_example_main.c} | 0 ...eep_wakeup.c => deep_sleep_example_main.c} | 0 .../{ota_example.c => ota_example_main.c} | 8 +- .../main/wpa2_enterprise_main.c | 4 +- 40 files changed, 624 insertions(+), 598 deletions(-) rename examples/bluetooth/blufi/main/{blufi_demo.h => blufi_example.h} (59%) rename examples/bluetooth/blufi/main/{blufi_main.c => blufi_example_main.c} (91%) rename examples/ethernet/ethernet/main/{ethernet_main.c => ethernet_example_main.c} (99%) rename examples/peripherals/gpio/main/{gpio_test.c => gpio_example_main.c} (96%) rename examples/peripherals/i2c/main/{i2c_test.c => i2c_example_main.c} (77%) rename examples/peripherals/i2s/main/{app_main.c => i2s_example_main.c} (100%) rename examples/peripherals/ledc/main/{ledc_fade.c => ledc_example_main.c} (100%) rename examples/peripherals/pcnt/main/{pcnt_test.c => pcnt_example_main.c} (97%) delete mode 100644 examples/peripherals/rmt_nec_tx_rx/main/infrared_nec.c rename examples/peripherals/sigmadelta/main/{sigmadelta_test.c => sigmadelta_example_main.c} (95%) rename examples/peripherals/spi_master/main/{spi_master.c => spi_master_example_main.c} (98%) rename examples/peripherals/timer_group/main/{timer_group.c => timer_group_example_main.c} (96%) rename examples/peripherals/{uart => uart_echo}/Makefile (85%) rename examples/peripherals/{uart => uart_echo}/main/component.mk (100%) create mode 100644 examples/peripherals/uart_echo/main/uart_echo_example_main.c create mode 100644 examples/peripherals/uart_events/Makefile create mode 100644 examples/peripherals/uart_events/main/component.mk rename examples/peripherals/{uart/main/uart_test.c => uart_events/main/uart_events_example_main.c} (57%) rename examples/protocols/coap_client/main/{coap_client.c => coap_client_example_main.c} (98%) rename examples/protocols/coap_server/main/{coap_server.c => coap_server_example_main.c} (98%) rename examples/protocols/http_request/main/{http_request_main.c => http_request_example_main.c} (100%) rename examples/protocols/https_request/main/{https_request_main.c => https_request_example_main.c} (100%) rename examples/protocols/openssl_client/main/{openssl_client.h => openssl_client_example.h} (56%) rename examples/protocols/openssl_client/main/{openssl_client.c => openssl_client_example_main.c} (82%) rename examples/protocols/openssl_server/main/{openssl_server.h => openssl_server_example.h} (75%) rename examples/protocols/openssl_server/main/{openssl_server.c => openssl_server_example_main.c} (88%) rename examples/protocols/sntp/main/{sntp_main.c => sntp_example_main.c} (100%) rename examples/storage/nvs_rw_blob/main/{nvs_rw_blob.c => nvs_blob_example_main.c} (100%) rename examples/storage/nvs_rw_value/main/{nvs_rw_value.c => nvs_value_example_main.c} (100%) rename examples/storage/sd_card/main/{sd_card.c => sd_card_example_main.c} (100%) rename examples/system/deep_sleep/main/{deep_sleep_wakeup.c => deep_sleep_example_main.c} (100%) rename examples/system/ota/main/{ota_example.c => ota_example_main.c} (97%) diff --git a/examples/README.md b/examples/README.md index e4422e91b..ead17f0b7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -32,4 +32,7 @@ In addition, here are some tips for creating good examples: * A good example is documented and the basic options can be configured. * A good example does not contain a lot of code. If there is a lot of generic code in the example, consider refactoring that code into a standalone component and then use the component's API in your example. +* Names (of files, functions, variables, etc.) inside examples should be distinguishable from names of other parts of IDF (ideally, use `example` in names.) +* Functions and variables used inside examples should be declared static where possible. +* Examples should demonstrate one distinct thing each. Avoid multi-purposed "demo" examples, split these into multiple examples instead. * Examples must be licensed under the Apache License 2.0 or (preferably for examples) if possible you can declare the example to be Public Domain / Creative Commons Zero. diff --git a/examples/bluetooth/blufi/main/blufi_demo.h b/examples/bluetooth/blufi/main/blufi_example.h similarity index 59% rename from examples/bluetooth/blufi/main/blufi_demo.h rename to examples/bluetooth/blufi/main/blufi_example.h index c5bf55c7d..955e238c7 100644 --- a/examples/bluetooth/blufi/main/blufi_demo.h +++ b/examples/bluetooth/blufi/main/blufi_example.h @@ -1,10 +1,8 @@ -#ifndef __BLUFI_DEMO_H__ -#define __BLUFI_DEMO_H__ +#pragma once - -#define BLUFI_DEMO_TAG "BLUFI_DEMO" -#define BLUFI_INFO(fmt, ...) ESP_LOGI(BLUFI_DEMO_TAG, fmt, ##__VA_ARGS__) -#define BLUFI_ERROR(fmt, ...) ESP_LOGE(BLUFI_DEMO_TAG, fmt, ##__VA_ARGS__) +#define BLUFI_EXAMPLE_TAG "BLUFI_EXAMPLE" +#define BLUFI_INFO(fmt, ...) ESP_LOGI(BLUFI_EXAMPLE_TAG, fmt, ##__VA_ARGS__) +#define BLUFI_ERROR(fmt, ...) ESP_LOGE(BLUFI_EXAMPLE_TAG, fmt, ##__VA_ARGS__) void blufi_dh_negotiate_data_handler(uint8_t *data, int len, uint8_t **output_data, int *output_len, bool *need_free); int blufi_aes_encrypt(uint8_t iv8, uint8_t *crypt_data, int crypt_len); @@ -13,5 +11,3 @@ uint16_t blufi_crc_checksum(uint8_t iv8, uint8_t *data, int len); int blufi_security_init(void); void blufi_security_deinit(void); - -#endif /* __BLUFI_DEMO_H__ */ diff --git a/examples/bluetooth/blufi/main/blufi_main.c b/examples/bluetooth/blufi/main/blufi_example_main.c similarity index 91% rename from examples/bluetooth/blufi/main/blufi_main.c rename to examples/bluetooth/blufi/main/blufi_example_main.c index d35ab7121..05f39c485 100644 --- a/examples/bluetooth/blufi/main/blufi_main.c +++ b/examples/bluetooth/blufi/main/blufi_example_main.c @@ -30,19 +30,19 @@ #include "esp_gap_ble_api.h" #include "esp_bt_main.h" #include "esp_bt_device.h" -#include "blufi_demo.h" +#include "blufi_example.h" -static void blufi_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param); +static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param); #define BLUFI_DEVICE_NAME "BLUFI_DEVICE" -static uint8_t blufi_service_uuid128[32] = { +static uint8_t example_service_uuid128[32] = { /* LSB <--------------------------------------------------------------------------------> MSB */ //first uuid, 16bit, [12],[13] is the value 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, }; //static uint8_t test_manufacturer[TEST_MANUFACTURER_DATA_LEN] = {0x12, 0x23, 0x45, 0x56}; -static esp_ble_adv_data_t blufi_adv_data = { +static esp_ble_adv_data_t example_adv_data = { .set_scan_rsp = false, .include_name = true, .include_txpower = true, @@ -54,11 +54,11 @@ static esp_ble_adv_data_t blufi_adv_data = { .service_data_len = 0, .p_service_data = NULL, .service_uuid_len = 16, - .p_service_uuid = blufi_service_uuid128, + .p_service_uuid = example_service_uuid128, .flag = 0x6, }; -static esp_ble_adv_params_t blufi_adv_params = { +static esp_ble_adv_params_t example_adv_params = { .adv_int_min = 0x100, .adv_int_max = 0x100, .adv_type = ADV_TYPE_IND, @@ -88,7 +88,7 @@ static uint8_t gl_sta_bssid[6]; static uint8_t gl_sta_ssid[32]; static int gl_sta_ssid_len; -static esp_err_t event_handler(void *ctx, system_event_t *event) +static esp_err_t example_net_event_handler(void *ctx, system_event_t *event) { wifi_mode_t mode; @@ -146,7 +146,7 @@ static void initialise_wifi(void) { tcpip_adapter_init(); wifi_event_group = xEventGroupCreate(); - ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); + ESP_ERROR_CHECK( esp_event_loop_init(example_net_event_handler, NULL) ); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); @@ -154,24 +154,24 @@ static void initialise_wifi(void) ESP_ERROR_CHECK( esp_wifi_start() ); } -static esp_blufi_callbacks_t blufi_callbacks = { - .event_cb = blufi_event_callback, +static esp_blufi_callbacks_t example_callbacks = { + .event_cb = example_event_callback, .negotiate_data_handler = blufi_dh_negotiate_data_handler, .encrypt_func = blufi_aes_encrypt, .decrypt_func = blufi_aes_decrypt, .checksum_func = blufi_crc_checksum, }; -static void blufi_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param) +static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param) { /* actually, should post to blufi_task handle the procedure, - * now, as a demo, we do simplely */ + * now, as a example, we do it more simply */ switch (event) { case ESP_BLUFI_EVENT_INIT_FINISH: BLUFI_INFO("BLUFI init finish\n"); esp_ble_gap_set_device_name(BLUFI_DEVICE_NAME); - esp_ble_gap_config_adv_data(&blufi_adv_data); + esp_ble_gap_config_adv_data(&example_adv_data); break; case ESP_BLUFI_EVENT_DEINIT_FINISH: BLUFI_INFO("BLUFI init finish\n"); @@ -184,7 +184,7 @@ static void blufi_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_ break; case ESP_BLUFI_EVENT_BLE_DISCONNECT: BLUFI_INFO("BLUFI ble disconnect\n"); - esp_ble_gap_start_advertising(&blufi_adv_params); + esp_ble_gap_start_advertising(&example_adv_params); break; case ESP_BLUFI_EVENT_SET_WIFI_OPMODE: BLUFI_INFO("BLUFI Set WIFI opmode %d\n", param->wifi_mode.op_mode); @@ -297,11 +297,11 @@ static void blufi_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_ } } -static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) +static void example_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { switch (event) { case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: - esp_ble_gap_start_advertising(&blufi_adv_params); + esp_ble_gap_start_advertising(&example_adv_params); break; default: break; @@ -340,8 +340,8 @@ void app_main() BLUFI_INFO("BLUFI VERSION %04x\n", esp_blufi_get_version()); blufi_security_init(); - esp_ble_gap_register_callback(gap_event_handler); + esp_ble_gap_register_callback(example_gap_event_handler); - esp_blufi_register_callbacks(&blufi_callbacks); + esp_blufi_register_callbacks(&example_callbacks); esp_blufi_profile_init(); } diff --git a/examples/bluetooth/blufi/main/blufi_security.c b/examples/bluetooth/blufi/main/blufi_security.c index 59d889a52..1005c94c1 100644 --- a/examples/bluetooth/blufi/main/blufi_security.c +++ b/examples/bluetooth/blufi/main/blufi_security.c @@ -29,7 +29,7 @@ #include "esp_bt_defs.h" #include "esp_gap_ble_api.h" #include "esp_bt_main.h" -#include "blufi_demo.h" +#include "blufi_example.h" #include "mbedtls/aes.h" #include "mbedtls/dhm.h" diff --git a/examples/ethernet/ethernet/main/ethernet_main.c b/examples/ethernet/ethernet/main/ethernet_example_main.c similarity index 99% rename from examples/ethernet/ethernet/main/ethernet_main.c rename to examples/ethernet/ethernet/main/ethernet_example_main.c index f76bd1d76..d46e2e6d9 100644 --- a/examples/ethernet/ethernet/main/ethernet_main.c +++ b/examples/ethernet/ethernet/main/ethernet_example_main.c @@ -34,7 +34,7 @@ #include "driver/gpio.h" #include "tlk110_phy.h" -static const char *TAG = "eth_demo"; +static const char *TAG = "eth_example"; #define DEFAULT_PHY_CONFIG (AUTO_MDIX_ENABLE|AUTO_NEGOTIATION_ENABLE|AN_1|AN_0|LED_CFG) #define PIN_PHY_POWER 17 diff --git a/examples/peripherals/gpio/main/gpio_test.c b/examples/peripherals/gpio/main/gpio_example_main.c similarity index 96% rename from examples/peripherals/gpio/main/gpio_test.c rename to examples/peripherals/gpio/main/gpio_example_main.c index a5e9571bc..3b306ac14 100644 --- a/examples/peripherals/gpio/main/gpio_test.c +++ b/examples/peripherals/gpio/main/gpio_example_main.c @@ -41,13 +41,13 @@ static xQueueHandle gpio_evt_queue = NULL; -void IRAM_ATTR gpio_isr_handler(void* arg) +static void IRAM_ATTR gpio_isr_handler(void* arg) { uint32_t gpio_num = (uint32_t) arg; xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL); } -void gpio_task_example(void* arg) +static void gpio_task_example(void* arg) { uint32_t io_num; for(;;) { @@ -62,7 +62,7 @@ void app_main() gpio_config_t io_conf; //disable interrupt io_conf.intr_type = GPIO_PIN_INTR_DISABLE; - //set as output mode + //set as output mode io_conf.mode = GPIO_MODE_OUTPUT; //bit mask of the pins that you want to set,e.g.GPIO18/19 io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL; diff --git a/examples/peripherals/i2c/main/i2c_test.c b/examples/peripherals/i2c/main/i2c_example_main.c similarity index 77% rename from examples/peripherals/i2c/main/i2c_test.c rename to examples/peripherals/i2c/main/i2c_example_main.c index 2ef6d75b2..51f8dc47e 100644 --- a/examples/peripherals/i2c/main/i2c_test.c +++ b/examples/peripherals/i2c/main/i2c_example_main.c @@ -47,18 +47,18 @@ #define RW_TEST_LENGTH 129 /*! -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "freertos/semphr.h" -#include "esp_err.h" -#include "esp_log.h" -#include "driver/rmt.h" -#include "driver/periph_ctrl.h" -#include "soc/rmt_reg.h" - -static const char* NEC_TAG = "NEC"; - -//CHOOSE SELF TEST OR NORMAL TEST -#define RMT_RX_SELF_TEST 1 - -/******************************************************/ -/***** SELF TEST: *****/ -/*Connect RMT_TX_GPIO_NUM with RMT_RX_GPIO_NUM */ -/*TX task will send NEC data with carrier disabled */ -/*RX task will print NEC data it receives. */ -/******************************************************/ -#if RMT_RX_SELF_TEST -#define RMT_RX_ACTIVE_LEVEL 1 /*!< Data bit is active high for self test mode */ -#define RMT_TX_CARRIER_EN 0 /*!< Disable carrier for self test mode */ -#else -//Test with infrared LED, we have to enable carrier for transmitter -//When testing via IR led, the receiver waveform is usually active-low. -#define RMT_RX_ACTIVE_LEVEL 0 /*!< If we connect with a IR receiver, the data is active low */ -#define RMT_TX_CARRIER_EN 1 /*!< Enable carrier for IR transmitter test with IR led */ -#endif - -#define RMT_TX_CHANNEL 1 /*!< RMT channel for transmitter */ -#define RMT_TX_GPIO_NUM 16 /*!< GPIO number for transmitter signal */ -#define RMT_RX_CHANNEL 0 /*!< RMT channel for receiver */ -#define RMT_RX_GPIO_NUM 19 /*!< GPIO number for receiver */ -#define RMT_CLK_DIV 100 /*!< RMT counter clock divider */ -#define RMT_TICK_10_US (80000000/RMT_CLK_DIV/100000) /*!< RMT counter value for 10 us.(Source clock is APB clock) */ - -#define NEC_HEADER_HIGH_US 9000 /*!< NEC protocol header: positive 9ms */ -#define NEC_HEADER_LOW_US 4500 /*!< NEC protocol header: negative 4.5ms*/ -#define NEC_BIT_ONE_HIGH_US 560 /*!< NEC protocol data bit 1: positive 0.56ms */ -#define NEC_BIT_ONE_LOW_US (2250-NEC_BIT_ONE_HIGH_US) /*!< NEC protocol data bit 1: negative 1.69ms */ -#define NEC_BIT_ZERO_HIGH_US 560 /*!< NEC protocol data bit 0: positive 0.56ms */ -#define NEC_BIT_ZERO_LOW_US (1120-NEC_BIT_ZERO_HIGH_US) /*!< NEC protocol data bit 0: negative 0.56ms */ -#define NEC_BIT_END 560 /*!< NEC protocol end: positive 0.56ms */ -#define NEC_BIT_MARGIN 20 /*!< NEC parse margin time */ - -#define NEC_ITEM_DURATION(d) ((d & 0x7fff)*10/RMT_TICK_10_US) /*!< Parse duration time from memory register value */ -#define NEC_DATA_ITEM_NUM 34 /*!< NEC code item number: header + 32bit data + end */ -#define RMT_TX_DATA_NUM 100 /*!< NEC tx test data number */ -#define rmt_item32_tIMEOUT_US 9500 /*!< RMT receiver timeout value(us) */ - -/* - * @brief Build register value of waveform for NEC one data bit - */ -inline void nec_fill_item_level(rmt_item32_t* item, int high_us, int low_us) -{ - item->level0 = 1; - item->duration0 = (high_us) / 10 * RMT_TICK_10_US; - item->level1 = 0; - item->duration1 = (low_us) / 10 * RMT_TICK_10_US; -} - -/* - * @brief Generate NEC header value: active 9ms + negative 4.5ms - */ -static void nec_fill_item_header(rmt_item32_t* item) -{ - nec_fill_item_level(item, NEC_HEADER_HIGH_US, NEC_HEADER_LOW_US); -} - -/* - * @brief Generate NEC data bit 1: positive 0.56ms + negative 1.69ms - */ -static void nec_fill_item_bit_one(rmt_item32_t* item) -{ - nec_fill_item_level(item, NEC_BIT_ONE_HIGH_US, NEC_BIT_ONE_LOW_US); -} - -/* - * @brief Generate NEC data bit 0: positive 0.56ms + negative 0.56ms - */ -static void nec_fill_item_bit_zero(rmt_item32_t* item) -{ - nec_fill_item_level(item, NEC_BIT_ZERO_HIGH_US, NEC_BIT_ZERO_LOW_US); -} - -/* - * @brief Generate NEC end signal: positive 0.56ms - */ -static void nec_fill_item_end(rmt_item32_t* item) -{ - nec_fill_item_level(item, NEC_BIT_END, 0x7fff); -} - -/* - * @brief Check whether duration is around target_us - */ -inline bool nec_check_in_range(int duration_ticks, int target_us, int margin_us) -{ - if(( NEC_ITEM_DURATION(duration_ticks) < (target_us + margin_us)) - && ( NEC_ITEM_DURATION(duration_ticks) > (target_us - margin_us))) { - return true; - } else { - return false; - } -} - -/* - * @brief Check whether this value represents an NEC header - */ -static bool nec_header_if(rmt_item32_t* item) -{ - if((item->level0 == RMT_RX_ACTIVE_LEVEL && item->level1 != RMT_RX_ACTIVE_LEVEL) - && nec_check_in_range(item->duration0, NEC_HEADER_HIGH_US, NEC_BIT_MARGIN) - && nec_check_in_range(item->duration1, NEC_HEADER_LOW_US, NEC_BIT_MARGIN)) { - return true; - } - return false; -} - -/* - * @brief Check whether this value represents an NEC data bit 1 - */ -static bool nec_bit_one_if(rmt_item32_t* item) -{ - if((item->level0 == RMT_RX_ACTIVE_LEVEL && item->level1 != RMT_RX_ACTIVE_LEVEL) - && nec_check_in_range(item->duration0, NEC_BIT_ONE_HIGH_US, NEC_BIT_MARGIN) - && nec_check_in_range(item->duration1, NEC_BIT_ONE_LOW_US, NEC_BIT_MARGIN)) { - return true; - } - return false; -} - -/* - * @brief Check whether this value represents an NEC data bit 0 - */ -static bool nec_bit_zero_if(rmt_item32_t* item) -{ - if((item->level0 == RMT_RX_ACTIVE_LEVEL && item->level1 != RMT_RX_ACTIVE_LEVEL) - && nec_check_in_range(item->duration0, NEC_BIT_ZERO_HIGH_US, NEC_BIT_MARGIN) - && nec_check_in_range(item->duration1, NEC_BIT_ZERO_LOW_US, NEC_BIT_MARGIN)) { - return true; - } - return false; -} - - -/* - * @brief Parse NEC 32 bit waveform to address and command. - */ -static int nec_parse_items(rmt_item32_t* item, int item_num, uint16_t* addr, uint16_t* data) -{ - int w_len = item_num; - if(w_len < NEC_DATA_ITEM_NUM) { - return -1; - } - int i = 0, j = 0; - if(!nec_header_if(item++)) { - return -1; - } - uint16_t addr_t = 0; - for(j = 0; j < 16; j++) { - if(nec_bit_one_if(item)) { - addr_t |= (1 << j); - } else if(nec_bit_zero_if(item)) { - addr_t |= (0 << j); - } else { - return -1; - } - item++; - i++; - } - uint16_t data_t = 0; - for(j = 0; j < 16; j++) { - if(nec_bit_one_if(item)) { - data_t |= (1 << j); - } else if(nec_bit_zero_if(item)) { - data_t |= (0 << j); - } else { - return -1; - } - item++; - i++; - } - *addr = addr_t; - *data = data_t; - return i; -} - -/* - * @brief Build NEC 32bit waveform. - */ -static int nec_build_items(int channel, rmt_item32_t* item, int item_num, uint16_t addr, uint16_t cmd_data) -{ - int i = 0, j = 0; - if(item_num < NEC_DATA_ITEM_NUM) { - return -1; - } - nec_fill_item_header(item++); - i++; - for(j = 0; j < 16; j++) { - if(addr & 0x1) { - nec_fill_item_bit_one(item); - } else { - nec_fill_item_bit_zero(item); - } - item++; - i++; - addr >>= 1; - } - for(j = 0; j < 16; j++) { - if(cmd_data & 0x1) { - nec_fill_item_bit_one(item); - } else { - nec_fill_item_bit_zero(item); - } - item++; - i++; - cmd_data >>= 1; - } - nec_fill_item_end(item); - i++; - return i; -} - -/* - * @brief RMT transmitter initialization - */ -static void rmt_tx_init() -{ - rmt_config_t rmt_tx; - rmt_tx.channel = RMT_TX_CHANNEL; - rmt_tx.gpio_num = RMT_TX_GPIO_NUM; - rmt_tx.mem_block_num = 1; - rmt_tx.clk_div = RMT_CLK_DIV; - rmt_tx.tx_config.loop_en = false; - rmt_tx.tx_config.carrier_duty_percent = 50; - rmt_tx.tx_config.carrier_freq_hz = 38000; - rmt_tx.tx_config.carrier_level = 1; - rmt_tx.tx_config.carrier_en = RMT_TX_CARRIER_EN; - rmt_tx.tx_config.idle_level = 0; - rmt_tx.tx_config.idle_output_en = true; - rmt_tx.rmt_mode = 0; - rmt_config(&rmt_tx); - rmt_driver_install(rmt_tx.channel, 0, 0); -} - -/* - * @brief RMT receiver initialization - */ -void rmt_rx_init() -{ - rmt_config_t rmt_rx; - rmt_rx.channel = RMT_RX_CHANNEL; - rmt_rx.gpio_num = RMT_RX_GPIO_NUM; - rmt_rx.clk_div = RMT_CLK_DIV; - rmt_rx.mem_block_num = 1; - rmt_rx.rmt_mode = RMT_MODE_RX; - rmt_rx.rx_config.filter_en = true; - rmt_rx.rx_config.filter_ticks_thresh = 100; - rmt_rx.rx_config.idle_threshold = rmt_item32_tIMEOUT_US / 10 * (RMT_TICK_10_US); - rmt_config(&rmt_rx); - rmt_driver_install(rmt_rx.channel, 1000, 0); -} - -/** - * @brief RMT receiver demo, this task will print each received NEC data. - * - */ -void rmt_nec_rx_task() -{ - int channel = RMT_RX_CHANNEL; - rmt_rx_init(); - RingbufHandle_t rb = NULL; - //get RMT RX ringbuffer - rmt_get_ringbuf_handler(channel, &rb); - rmt_rx_start(channel, 1); - while(rb) { - size_t rx_size = 0; - //try to receive data from ringbuffer. - //RMT driver will push all the data it receives to its ringbuffer. - //We just need to parse the value and return the spaces of ringbuffer. - rmt_item32_t* item = (rmt_item32_t*) xRingbufferReceive(rb, &rx_size, 1000); - if(item) { - uint16_t rmt_addr; - uint16_t rmt_cmd; - int offset = 0; - while(1) { - //parse data value from ringbuffer. - int res = nec_parse_items(item + offset, rx_size / 4 - offset, &rmt_addr, &rmt_cmd); - if(res > 0) { - offset += res + 1; - ESP_LOGI(NEC_TAG, "RMT RCV --- addr: 0x%04x cmd: 0x%04x", rmt_addr, rmt_cmd); - } else { - break; - } - } - //after parsing the data, return spaces to ringbuffer. - vRingbufferReturnItem(rb, (void*) item); - } else { - break; - } - } - vTaskDelete(NULL); -} - -/** - * @brief RMT transmitter demo, this task will periodically send NEC data. (100 * 32 bits each time.) - * - */ -void rmt_nec_tx_task() -{ - vTaskDelay(10); - rmt_tx_init(); - esp_log_level_set(NEC_TAG, ESP_LOG_INFO); - int channel = RMT_TX_CHANNEL; - uint16_t cmd = 0x0; - uint16_t addr = 0x11; - int nec_tx_num = RMT_TX_DATA_NUM; - for(;;) { - ESP_LOGI(NEC_TAG, "RMT TX DATA"); - size_t size = (sizeof(rmt_item32_t) * NEC_DATA_ITEM_NUM * nec_tx_num); - //each item represent a cycle of waveform. - rmt_item32_t* item = (rmt_item32_t*) malloc(size); - int item_num = NEC_DATA_ITEM_NUM * nec_tx_num; - memset((void*) item, 0, size); - int i, offset = 0; - while(1) { - //To build a series of waveforms. - i = nec_build_items(channel, item + offset, item_num - offset, ((~addr) << 8) | addr, cmd); - if(i < 0) { - break; - } - cmd++; - addr++; - offset += i; - } - //To send data according to the waveform items. - rmt_write_items(channel, item, item_num, true); - //Wait until sending is done. - rmt_wait_tx_done(channel); - //before we free the data, make sure sending is already done. - free(item); - vTaskDelay(2000 / portTICK_PERIOD_MS); - } - vTaskDelete(NULL); -} diff --git a/examples/peripherals/rmt_nec_tx_rx/main/infrared_nec_main.c b/examples/peripherals/rmt_nec_tx_rx/main/infrared_nec_main.c index c680f25a5..1bc01a386 100644 --- a/examples/peripherals/rmt_nec_tx_rx/main/infrared_nec_main.c +++ b/examples/peripherals/rmt_nec_tx_rx/main/infrared_nec_main.c @@ -7,17 +7,358 @@ CONDITIONS OF ANY KIND, either express or implied. */ #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "esp_system.h" -#include "nvs_flash.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "esp_err.h" +#include "esp_log.h" #include "driver/rmt.h" #include "driver/periph_ctrl.h" -extern void rmt_nec_tx_task(); -extern void rmt_nec_rx_task(); +#include "soc/rmt_reg.h" + +static const char* NEC_TAG = "NEC"; + +//CHOOSE SELF TEST OR NORMAL TEST +#define RMT_RX_SELF_TEST 1 + +/******************************************************/ +/***** SELF TEST: *****/ +/*Connect RMT_TX_GPIO_NUM with RMT_RX_GPIO_NUM */ +/*TX task will send NEC data with carrier disabled */ +/*RX task will print NEC data it receives. */ +/******************************************************/ +#if RMT_RX_SELF_TEST +#define RMT_RX_ACTIVE_LEVEL 1 /*!< Data bit is active high for self test mode */ +#define RMT_TX_CARRIER_EN 0 /*!< Disable carrier for self test mode */ +#else +//Test with infrared LED, we have to enable carrier for transmitter +//When testing via IR led, the receiver waveform is usually active-low. +#define RMT_RX_ACTIVE_LEVEL 0 /*!< If we connect with a IR receiver, the data is active low */ +#define RMT_TX_CARRIER_EN 1 /*!< Enable carrier for IR transmitter test with IR led */ +#endif + +#define RMT_TX_CHANNEL 1 /*!< RMT channel for transmitter */ +#define RMT_TX_GPIO_NUM 16 /*!< GPIO number for transmitter signal */ +#define RMT_RX_CHANNEL 0 /*!< RMT channel for receiver */ +#define RMT_RX_GPIO_NUM 19 /*!< GPIO number for receiver */ +#define RMT_CLK_DIV 100 /*!< RMT counter clock divider */ +#define RMT_TICK_10_US (80000000/RMT_CLK_DIV/100000) /*!< RMT counter value for 10 us.(Source clock is APB clock) */ + +#define NEC_HEADER_HIGH_US 9000 /*!< NEC protocol header: positive 9ms */ +#define NEC_HEADER_LOW_US 4500 /*!< NEC protocol header: negative 4.5ms*/ +#define NEC_BIT_ONE_HIGH_US 560 /*!< NEC protocol data bit 1: positive 0.56ms */ +#define NEC_BIT_ONE_LOW_US (2250-NEC_BIT_ONE_HIGH_US) /*!< NEC protocol data bit 1: negative 1.69ms */ +#define NEC_BIT_ZERO_HIGH_US 560 /*!< NEC protocol data bit 0: positive 0.56ms */ +#define NEC_BIT_ZERO_LOW_US (1120-NEC_BIT_ZERO_HIGH_US) /*!< NEC protocol data bit 0: negative 0.56ms */ +#define NEC_BIT_END 560 /*!< NEC protocol end: positive 0.56ms */ +#define NEC_BIT_MARGIN 20 /*!< NEC parse margin time */ + +#define NEC_ITEM_DURATION(d) ((d & 0x7fff)*10/RMT_TICK_10_US) /*!< Parse duration time from memory register value */ +#define NEC_DATA_ITEM_NUM 34 /*!< NEC code item number: header + 32bit data + end */ +#define RMT_TX_DATA_NUM 100 /*!< NEC tx test data number */ +#define rmt_item32_tIMEOUT_US 9500 /*!< RMT receiver timeout value(us) */ + +/* + * @brief Build register value of waveform for NEC one data bit + */ +static inline void nec_fill_item_level(rmt_item32_t* item, int high_us, int low_us) +{ + item->level0 = 1; + item->duration0 = (high_us) / 10 * RMT_TICK_10_US; + item->level1 = 0; + item->duration1 = (low_us) / 10 * RMT_TICK_10_US; +} + +/* + * @brief Generate NEC header value: active 9ms + negative 4.5ms + */ +static void nec_fill_item_header(rmt_item32_t* item) +{ + nec_fill_item_level(item, NEC_HEADER_HIGH_US, NEC_HEADER_LOW_US); +} + +/* + * @brief Generate NEC data bit 1: positive 0.56ms + negative 1.69ms + */ +static void nec_fill_item_bit_one(rmt_item32_t* item) +{ + nec_fill_item_level(item, NEC_BIT_ONE_HIGH_US, NEC_BIT_ONE_LOW_US); +} + +/* + * @brief Generate NEC data bit 0: positive 0.56ms + negative 0.56ms + */ +static void nec_fill_item_bit_zero(rmt_item32_t* item) +{ + nec_fill_item_level(item, NEC_BIT_ZERO_HIGH_US, NEC_BIT_ZERO_LOW_US); +} + +/* + * @brief Generate NEC end signal: positive 0.56ms + */ +static void nec_fill_item_end(rmt_item32_t* item) +{ + nec_fill_item_level(item, NEC_BIT_END, 0x7fff); +} + +/* + * @brief Check whether duration is around target_us + */ +inline bool nec_check_in_range(int duration_ticks, int target_us, int margin_us) +{ + if(( NEC_ITEM_DURATION(duration_ticks) < (target_us + margin_us)) + && ( NEC_ITEM_DURATION(duration_ticks) > (target_us - margin_us))) { + return true; + } else { + return false; + } +} + +/* + * @brief Check whether this value represents an NEC header + */ +static bool nec_header_if(rmt_item32_t* item) +{ + if((item->level0 == RMT_RX_ACTIVE_LEVEL && item->level1 != RMT_RX_ACTIVE_LEVEL) + && nec_check_in_range(item->duration0, NEC_HEADER_HIGH_US, NEC_BIT_MARGIN) + && nec_check_in_range(item->duration1, NEC_HEADER_LOW_US, NEC_BIT_MARGIN)) { + return true; + } + return false; +} + +/* + * @brief Check whether this value represents an NEC data bit 1 + */ +static bool nec_bit_one_if(rmt_item32_t* item) +{ + if((item->level0 == RMT_RX_ACTIVE_LEVEL && item->level1 != RMT_RX_ACTIVE_LEVEL) + && nec_check_in_range(item->duration0, NEC_BIT_ONE_HIGH_US, NEC_BIT_MARGIN) + && nec_check_in_range(item->duration1, NEC_BIT_ONE_LOW_US, NEC_BIT_MARGIN)) { + return true; + } + return false; +} + +/* + * @brief Check whether this value represents an NEC data bit 0 + */ +static bool nec_bit_zero_if(rmt_item32_t* item) +{ + if((item->level0 == RMT_RX_ACTIVE_LEVEL && item->level1 != RMT_RX_ACTIVE_LEVEL) + && nec_check_in_range(item->duration0, NEC_BIT_ZERO_HIGH_US, NEC_BIT_MARGIN) + && nec_check_in_range(item->duration1, NEC_BIT_ZERO_LOW_US, NEC_BIT_MARGIN)) { + return true; + } + return false; +} + + +/* + * @brief Parse NEC 32 bit waveform to address and command. + */ +static int nec_parse_items(rmt_item32_t* item, int item_num, uint16_t* addr, uint16_t* data) +{ + int w_len = item_num; + if(w_len < NEC_DATA_ITEM_NUM) { + return -1; + } + int i = 0, j = 0; + if(!nec_header_if(item++)) { + return -1; + } + uint16_t addr_t = 0; + for(j = 0; j < 16; j++) { + if(nec_bit_one_if(item)) { + addr_t |= (1 << j); + } else if(nec_bit_zero_if(item)) { + addr_t |= (0 << j); + } else { + return -1; + } + item++; + i++; + } + uint16_t data_t = 0; + for(j = 0; j < 16; j++) { + if(nec_bit_one_if(item)) { + data_t |= (1 << j); + } else if(nec_bit_zero_if(item)) { + data_t |= (0 << j); + } else { + return -1; + } + item++; + i++; + } + *addr = addr_t; + *data = data_t; + return i; +} + +/* + * @brief Build NEC 32bit waveform. + */ +static int nec_build_items(int channel, rmt_item32_t* item, int item_num, uint16_t addr, uint16_t cmd_data) +{ + int i = 0, j = 0; + if(item_num < NEC_DATA_ITEM_NUM) { + return -1; + } + nec_fill_item_header(item++); + i++; + for(j = 0; j < 16; j++) { + if(addr & 0x1) { + nec_fill_item_bit_one(item); + } else { + nec_fill_item_bit_zero(item); + } + item++; + i++; + addr >>= 1; + } + for(j = 0; j < 16; j++) { + if(cmd_data & 0x1) { + nec_fill_item_bit_one(item); + } else { + nec_fill_item_bit_zero(item); + } + item++; + i++; + cmd_data >>= 1; + } + nec_fill_item_end(item); + i++; + return i; +} + +/* + * @brief RMT transmitter initialization + */ +static void nec_tx_init() +{ + rmt_config_t rmt_tx; + rmt_tx.channel = RMT_TX_CHANNEL; + rmt_tx.gpio_num = RMT_TX_GPIO_NUM; + rmt_tx.mem_block_num = 1; + rmt_tx.clk_div = RMT_CLK_DIV; + rmt_tx.tx_config.loop_en = false; + rmt_tx.tx_config.carrier_duty_percent = 50; + rmt_tx.tx_config.carrier_freq_hz = 38000; + rmt_tx.tx_config.carrier_level = 1; + rmt_tx.tx_config.carrier_en = RMT_TX_CARRIER_EN; + rmt_tx.tx_config.idle_level = 0; + rmt_tx.tx_config.idle_output_en = true; + rmt_tx.rmt_mode = 0; + rmt_config(&rmt_tx); + rmt_driver_install(rmt_tx.channel, 0, 0); +} + +/* + * @brief RMT receiver initialization + */ +static void nec_rx_init() +{ + rmt_config_t rmt_rx; + rmt_rx.channel = RMT_RX_CHANNEL; + rmt_rx.gpio_num = RMT_RX_GPIO_NUM; + rmt_rx.clk_div = RMT_CLK_DIV; + rmt_rx.mem_block_num = 1; + rmt_rx.rmt_mode = RMT_MODE_RX; + rmt_rx.rx_config.filter_en = true; + rmt_rx.rx_config.filter_ticks_thresh = 100; + rmt_rx.rx_config.idle_threshold = rmt_item32_tIMEOUT_US / 10 * (RMT_TICK_10_US); + rmt_config(&rmt_rx); + rmt_driver_install(rmt_rx.channel, 1000, 0); +} + +/** + * @brief RMT receiver demo, this task will print each received NEC data. + * + */ +static void rmt_example_nec_rx_task() +{ + int channel = RMT_RX_CHANNEL; + nec_rx_init(); + RingbufHandle_t rb = NULL; + //get RMT RX ringbuffer + rmt_get_ringbuf_handler(channel, &rb); + rmt_rx_start(channel, 1); + while(rb) { + size_t rx_size = 0; + //try to receive data from ringbuffer. + //RMT driver will push all the data it receives to its ringbuffer. + //We just need to parse the value and return the spaces of ringbuffer. + rmt_item32_t* item = (rmt_item32_t*) xRingbufferReceive(rb, &rx_size, 1000); + if(item) { + uint16_t rmt_addr; + uint16_t rmt_cmd; + int offset = 0; + while(1) { + //parse data value from ringbuffer. + int res = nec_parse_items(item + offset, rx_size / 4 - offset, &rmt_addr, &rmt_cmd); + if(res > 0) { + offset += res + 1; + ESP_LOGI(NEC_TAG, "RMT RCV --- addr: 0x%04x cmd: 0x%04x", rmt_addr, rmt_cmd); + } else { + break; + } + } + //after parsing the data, return spaces to ringbuffer. + vRingbufferReturnItem(rb, (void*) item); + } else { + break; + } + } + vTaskDelete(NULL); +} + +/** + * @brief RMT transmitter demo, this task will periodically send NEC data. (100 * 32 bits each time.) + * + */ +static void rmt_example_nec_tx_task() +{ + vTaskDelay(10); + nec_tx_init(); + esp_log_level_set(NEC_TAG, ESP_LOG_INFO); + int channel = RMT_TX_CHANNEL; + uint16_t cmd = 0x0; + uint16_t addr = 0x11; + int nec_tx_num = RMT_TX_DATA_NUM; + for(;;) { + ESP_LOGI(NEC_TAG, "RMT TX DATA"); + size_t size = (sizeof(rmt_item32_t) * NEC_DATA_ITEM_NUM * nec_tx_num); + //each item represent a cycle of waveform. + rmt_item32_t* item = (rmt_item32_t*) malloc(size); + int item_num = NEC_DATA_ITEM_NUM * nec_tx_num; + memset((void*) item, 0, size); + int i, offset = 0; + while(1) { + //To build a series of waveforms. + i = nec_build_items(channel, item + offset, item_num - offset, ((~addr) << 8) | addr, cmd); + if(i < 0) { + break; + } + cmd++; + addr++; + offset += i; + } + //To send data according to the waveform items. + rmt_write_items(channel, item, item_num, true); + //Wait until sending is done. + rmt_wait_tx_done(channel); + //before we free the data, make sure sending is already done. + free(item); + vTaskDelay(2000 / portTICK_PERIOD_MS); + } + vTaskDelete(NULL); +} void app_main() { - xTaskCreate(rmt_nec_rx_task, "rmt_nec_rx_task", 2048, NULL, 10, NULL); - xTaskCreate(rmt_nec_tx_task, "rmt_nec_tx_task", 2048, NULL, 10, NULL); + xTaskCreate(rmt_example_nec_rx_task, "rmt_nec_rx_task", 2048, NULL, 10, NULL); + xTaskCreate(rmt_example_nec_tx_task, "rmt_nec_tx_task", 2048, NULL, 10, NULL); } diff --git a/examples/peripherals/sigmadelta/main/sigmadelta_test.c b/examples/peripherals/sigmadelta/main/sigmadelta_example_main.c similarity index 95% rename from examples/peripherals/sigmadelta/main/sigmadelta_test.c rename to examples/peripherals/sigmadelta/main/sigmadelta_example_main.c index 60880311d..5249d2dea 100644 --- a/examples/peripherals/sigmadelta/main/sigmadelta_test.c +++ b/examples/peripherals/sigmadelta/main/sigmadelta_example_main.c @@ -20,7 +20,7 @@ /** * @brief Sigma-delta initialization. */ -static void sigmadelta_init(void) +static void sigmadelta_example_init(void) { sigmadelta_config_t sigmadelta_cfg = { /* Sigma-delta channel0*/ @@ -40,7 +40,7 @@ static void sigmadelta_init(void) */ void app_main() { - sigmadelta_init(); + sigmadelta_example_init(); int8_t duty = 0; int inc = 1; while(1) { diff --git a/examples/peripherals/spi_master/main/spi_master.c b/examples/peripherals/spi_master/main/spi_master_example_main.c similarity index 98% rename from examples/peripherals/spi_master/main/spi_master.c rename to examples/peripherals/spi_master/main/spi_master_example_main.c index 577cada4c..b9cdd2009 100644 --- a/examples/peripherals/spi_master/main/spi_master.c +++ b/examples/peripherals/spi_master/main/spi_master_example_main.c @@ -147,7 +147,7 @@ void ili_init(spi_device_handle_t spi) //before sending the line data itself; a total of 6 transactions. (We can't put all of this in just one transaction //because the D/C line needs to be toggled in the middle.) //This routine queues these commands up so they get sent as quickly as possible. -void send_line(spi_device_handle_t spi, int ypos, uint16_t *line) +static void send_line(spi_device_handle_t spi, int ypos, uint16_t *line) { esp_err_t ret; int x; @@ -198,7 +198,7 @@ void send_line(spi_device_handle_t spi, int ypos, uint16_t *line) } -void send_line_finish(spi_device_handle_t spi) +static void send_line_finish(spi_device_handle_t spi) { spi_transaction_t *rtrans; esp_err_t ret; @@ -214,7 +214,7 @@ void send_line_finish(spi_device_handle_t spi) //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. -void display_pretty_colors(spi_device_handle_t spi) +static void display_pretty_colors(spi_device_handle_t spi) { uint16_t line[2][320]; int x, y, frame=0; diff --git a/examples/peripherals/timer_group/main/timer_group.c b/examples/peripherals/timer_group/main/timer_group_example_main.c similarity index 96% rename from examples/peripherals/timer_group/main/timer_group.c rename to examples/peripherals/timer_group/main/timer_group_example_main.c index 37e22faaf..fcc25dcf0 100644 --- a/examples/peripherals/timer_group/main/timer_group.c +++ b/examples/peripherals/timer_group/main/timer_group_example_main.c @@ -44,7 +44,7 @@ static void inline print_u64(uint64_t val) printf("0x%08x%08x\n", (uint32_t) (val >> 32), (uint32_t) (val)); } -void timer_evt_task(void *arg) +static void timer_example_evt_task(void *arg) { while(1) { timer_event_t evt; @@ -135,7 +135,7 @@ void IRAM_ATTR timer_group0_isr(void *para) /* * @brief timer group0 hardware timer0 init */ -void tg0_timer0_init() +static void example_tg0_timer0_init() { int timer_group = TIMER_GROUP_0; int timer_idx = TIMER_0; @@ -165,7 +165,7 @@ void tg0_timer0_init() /* * @brief timer group0 hardware timer1 init */ -void tg0_timer1_init() +static void example_tg0_timer1_init() { int timer_group = TIMER_GROUP_0; int timer_idx = TIMER_1; @@ -198,8 +198,8 @@ void tg0_timer1_init() void app_main() { timer_queue = xQueueCreate(10, sizeof(timer_event_t)); - tg0_timer0_init(); - tg0_timer1_init(); - xTaskCreate(timer_evt_task, "timer_evt_task", 2048, NULL, 5, NULL); + example_tg0_timer0_init(); + example_tg0_timer1_init(); + xTaskCreate(timer_example_evt_task, "timer_evt_task", 2048, NULL, 5, NULL); } diff --git a/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c b/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c index 90f94f65f..490d8683e 100644 --- a/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c +++ b/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c @@ -17,7 +17,7 @@ static const char* TAG = "Touch pad"; -static bool touch_pad_activated[TOUCH_PAD_MAX]; +static bool s_pad_activated[TOUCH_PAD_MAX]; /* @@ -29,7 +29,7 @@ static bool touch_pad_activated[TOUCH_PAD_MAX]; Do not touch any pads when this routine is running (on application start). */ -static void touch_pad_set_thresholds(void) +static void tp_example_set_thresholds(void) { uint16_t touch_value; for (int i=0; i> i) & 0x01) { - touch_pad_activated[i] = true; + s_pad_activated[i] = true; } } } @@ -96,9 +96,9 @@ void app_main() // Initialize touch pad peripheral ESP_LOGI(TAG, "Initializing touch pad"); touch_pad_init(); - touch_pad_set_thresholds(); - touch_pad_isr_handler_register(touch_pad_rtc_intr, NULL, 0, NULL); + tp_example_set_thresholds(); + touch_pad_isr_handler_register(tp_example_rtc_intr, NULL, 0, NULL); // Start a task to show what pads have been touched - xTaskCreate(&touch_pad_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); + xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); } diff --git a/examples/peripherals/touch_pad_read/main/tp_read_main.c b/examples/peripherals/touch_pad_read/main/tp_read_main.c index 69bb87d17..da7baa6ba 100644 --- a/examples/peripherals/touch_pad_read/main/tp_read_main.c +++ b/examples/peripherals/touch_pad_read/main/tp_read_main.c @@ -17,7 +17,7 @@ Read values sensed at all available touch pads. Print out values in a loop on a serial monitor. */ -void touch_pad_read_task(void *pvParameter) +static void tp_example_read_task(void *pvParameter) { while (1) { uint16_t touch_value; @@ -36,6 +36,6 @@ void app_main() touch_pad_init(); // Start task to read values sensed by pads - xTaskCreate(&touch_pad_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); + xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); } diff --git a/examples/peripherals/uart/Makefile b/examples/peripherals/uart_echo/Makefile similarity index 85% rename from examples/peripherals/uart/Makefile rename to examples/peripherals/uart_echo/Makefile index 4c523bd68..e4714e57f 100644 --- a/examples/peripherals/uart/Makefile +++ b/examples/peripherals/uart_echo/Makefile @@ -3,7 +3,7 @@ # project subdirectory. # -PROJECT_NAME := uart +PROJECT_NAME := uart_echo include $(IDF_PATH)/make/project.mk diff --git a/examples/peripherals/uart/main/component.mk b/examples/peripherals/uart_echo/main/component.mk similarity index 100% rename from examples/peripherals/uart/main/component.mk rename to examples/peripherals/uart_echo/main/component.mk diff --git a/examples/peripherals/uart_echo/main/uart_echo_example_main.c b/examples/peripherals/uart_echo/main/uart_echo_example_main.c new file mode 100644 index 000000000..5b8baf7fb --- /dev/null +++ b/examples/peripherals/uart_echo/main/uart_echo_example_main.c @@ -0,0 +1,73 @@ +/* Uart Events Example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "nvs_flash.h" +#include "driver/uart.h" +#include "freertos/queue.h" +#include "esp_log.h" +#include "soc/uart_struct.h" + +/** + * This is a example exaple which echos any data it receives on UART1 back to the sender, with hardware flow control + * turned on. It does not use UART driver event queue. + * + * - port: UART1 + * - rx buffer: on + * - tx buffer: off + * - flow control: on + * - event queue: off + * - pin assignment: txd(io4), rxd(io5), rts(18), cts(19) + */ + +#define ECHO_TEST_TXD (4) +#define ECHO_TEST_RXD (5) +#define ECHO_TEST_RTS (18) +#define ECHO_TEST_CTS (19) + +#define BUF_SIZE (1024) + +//an example of echo test with hardware flow control on UART1 +static void echo_task() +{ + const int uart_num = UART_NUM_1; + uart_config_t uart_config = { + .baud_rate = 115200, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS, + .rx_flow_ctrl_thresh = 122, + }; + //Configure UART1 parameters + uart_param_config(uart_num, &uart_config); + //Set UART1 pins(TX: IO4, RX: I05, RTS: IO18, CTS: IO19) + uart_set_pin(uart_num, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS); + //Install UART driver (we don't need an event queue here) + //In this example we don't even use a buffer for sending data. + uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0); + + uint8_t* data = (uint8_t*) malloc(BUF_SIZE); + while(1) { + //Read data from UART + int len = uart_read_bytes(uart_num, data, BUF_SIZE, 20 / portTICK_RATE_MS); + //Write data back to UART + uart_write_bytes(uart_num, (const char*) data, len); + } +} + +void app_main() +{ + //A uart read/write example without event queue; + xTaskCreate(echo_task, "uart_echo_task", 1024, NULL, 10, NULL); +} diff --git a/examples/peripherals/uart_events/Makefile b/examples/peripherals/uart_events/Makefile new file mode 100644 index 000000000..496941720 --- /dev/null +++ b/examples/peripherals/uart_events/Makefile @@ -0,0 +1,9 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := uart_events + +include $(IDF_PATH)/make/project.mk + diff --git a/examples/peripherals/uart_events/main/component.mk b/examples/peripherals/uart_events/main/component.mk new file mode 100644 index 000000000..44bd2b527 --- /dev/null +++ b/examples/peripherals/uart_events/main/component.mk @@ -0,0 +1,3 @@ +# +# Main Makefile. This is basically the same as a component makefile. +# diff --git a/examples/peripherals/uart/main/uart_test.c b/examples/peripherals/uart_events/main/uart_events_example_main.c similarity index 57% rename from examples/peripherals/uart/main/uart_test.c rename to examples/peripherals/uart_events/main/uart_events_example_main.c index 9a0d0003c..50cbad7e5 100644 --- a/examples/peripherals/uart/main/uart_test.c +++ b/examples/peripherals/uart_events/main/uart_events_example_main.c @@ -17,46 +17,36 @@ #include "freertos/queue.h" #include "esp_log.h" #include "soc/uart_struct.h" -static const char *TAG = "uart_example"; + +static const char *TAG = "uart_events"; /** - * Test code brief - * This example shows how to configure uart settings and install uart driver. + * This example shows how to use the UART driver to handle special UART events. + * + * It also reads data from UART0 directly, and echoes it to console. * - * uart_evt_test() is an example that read and write data on UART0, and handler some of the special events. * - port: UART0 * - rx buffer: on * - tx buffer: on * - flow control: off * - event queue: on * - pin assignment: txd(default), rxd(default) - * - * uart_echo_test() is an example that read and write data on UART1, with hardware flow control turning on. - * - port: UART1 - * - rx buffer: on - * - tx buffer: off - * - flow control: on - * - event queue: off - * - pin assignment: txd(io4), rxd(io5), rts(18), cts(19) */ -#define BUF_SIZE (1024) -#define ECHO_TEST_TXD (4) -#define ECHO_TEST_RXD (5) -#define ECHO_TEST_RTS (18) -#define ECHO_TEST_CTS (19) +#define EX_UART_NUM UART_NUM_0 -QueueHandle_t uart0_queue; -void uart_task(void *pvParameters) +#define BUF_SIZE (1024) +static QueueHandle_t uart0_queue; + +static void uart_event_task(void *pvParameters) { - int uart_num = (int) pvParameters; uart_event_t event; size_t buffered_size; uint8_t* dtmp = (uint8_t*) malloc(BUF_SIZE); for(;;) { //Waiting for UART event. if(xQueueReceive(uart0_queue, (void * )&event, (portTickType)portMAX_DELAY)) { - ESP_LOGI(TAG, "uart[%d] event:", uart_num); + 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 @@ -64,7 +54,7 @@ void uart_task(void *pvParameters) be full. in this example, we don't process data in event, but read data outside.*/ case UART_DATA: - uart_get_buffered_data_len(uart_num, &buffered_size); + uart_get_buffered_data_len(EX_UART_NUM, &buffered_size); ESP_LOGI(TAG, "data, len: %d; buffered len: %d", event.size, buffered_size); break; //Event of HW FIFO overflow detected @@ -72,14 +62,14 @@ void uart_task(void *pvParameters) ESP_LOGI(TAG, "hw fifo overflow\n"); //If fifo overflow happened, you should consider adding flow control for your application. //We can read data out out the buffer, or directly flush the rx buffer. - uart_flush(uart_num); + uart_flush(EX_UART_NUM); break; //Event of UART ring buffer full case UART_BUFFER_FULL: ESP_LOGI(TAG, "ring buffer full\n"); //If buffer full happened, you should consider encreasing your buffer size //We can read data out out the buffer, or directly flush the rx buffer. - uart_flush(uart_num); + uart_flush(EX_UART_NUM); break; //Event of UART RX break detected case UART_BREAK: @@ -109,9 +99,9 @@ void uart_task(void *pvParameters) vTaskDelete(NULL); } -void uart_evt_test() +/* Configure the UART events example */ +void app_main() { - int uart_num = UART_NUM_0; uart_config_t uart_config = { .baud_rate = 115200, .data_bits = UART_DATA_8_BITS, @@ -121,63 +111,26 @@ void uart_evt_test() .rx_flow_ctrl_thresh = 122, }; //Set UART parameters - uart_param_config(uart_num, &uart_config); + uart_param_config(EX_UART_NUM, &uart_config); //Set UART log level esp_log_level_set(TAG, ESP_LOG_INFO); //Install UART driver, and get the queue. - uart_driver_install(uart_num, BUF_SIZE * 2, BUF_SIZE * 2, 10, &uart0_queue, 0); - //Set UART pins,(-1: default pin, no change.) - //For UART0, we can just use the default pins. - //uart_set_pin(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 10, &uart0_queue, 0); + + //Set UART pins (using UART0 default pins ie no changes.) + uart_set_pin(EX_UART_NUM, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + //Set uart pattern detect function. - uart_enable_pattern_det_intr(uart_num, '+', 3, 10000, 10, 10); + uart_enable_pattern_det_intr(EX_UART_NUM, '+', 3, 10000, 10, 10); //Create a task to handler UART event from ISR - xTaskCreate(uart_task, "uart_task", 2048, (void*)uart_num, 12, NULL); + xTaskCreate(uart_event_task, "uart_event_task", 2048, NULL, 12, NULL); //process data uint8_t* data = (uint8_t*) malloc(BUF_SIZE); do { - int len = uart_read_bytes(uart_num, data, BUF_SIZE, 100 / portTICK_RATE_MS); + int len = uart_read_bytes(EX_UART_NUM, data, BUF_SIZE, 100 / portTICK_RATE_MS); if(len > 0) { ESP_LOGI(TAG, "uart read : %d", len); - uart_write_bytes(uart_num, (const char*)data, len); + uart_write_bytes(EX_UART_NUM, (const char*)data, len); } } while(1); } - -//an example of echo test with hardware flow control on UART1 -void uart_echo_test() -{ - int uart_num = UART_NUM_1; - uart_config_t uart_config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS, - .rx_flow_ctrl_thresh = 122, - }; - //Configure UART1 parameters - uart_param_config(uart_num, &uart_config); - //Set UART1 pins(TX: IO4, RX: I05, RTS: IO18, CTS: IO19) - uart_set_pin(uart_num, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS); - //Install UART driver( We don't need an event queue here) - //In this example we don't even use a buffer for sending data. - uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0); - - uint8_t* data = (uint8_t*) malloc(BUF_SIZE); - while(1) { - //Read data from UART - int len = uart_read_bytes(uart_num, data, BUF_SIZE, 20 / portTICK_RATE_MS); - //Write data back to UART - uart_write_bytes(uart_num, (const char*) data, len); - } -} - -void app_main() -{ - //A uart read/write example without event queue; - xTaskCreate(uart_echo_test, "uart_echo_test", 1024, NULL, 10, NULL); - - //A uart example with event queue. - uart_evt_test(); -} diff --git a/examples/protocols/coap_client/main/coap_client.c b/examples/protocols/coap_client/main/coap_client_example_main.c similarity index 98% rename from examples/protocols/coap_client/main/coap_client.c rename to examples/protocols/coap_client/main/coap_client_example_main.c index a45f748d4..c9d8b22fc 100644 --- a/examples/protocols/coap_client/main/coap_client.c +++ b/examples/protocols/coap_client/main/coap_client_example_main.c @@ -65,7 +65,7 @@ static void message_handler(struct coap_context_t *ctx, const coap_endpoint_t *l } } -static void coap_demo_thread(void *p) +static void coap_example_task(void *p) { struct hostent *hp; struct ip4_addr *ip4_addr; @@ -201,5 +201,5 @@ void app_main(void) { ESP_ERROR_CHECK( nvs_flash_init() ); wifi_conn_init(); - xTaskCreate(coap_demo_thread, "coap", 2048, NULL, 5, NULL); + xTaskCreate(coap_example_task, "coap", 2048, NULL, 5, NULL); } diff --git a/examples/protocols/coap_server/main/coap_server.c b/examples/protocols/coap_server/main/coap_server_example_main.c similarity index 98% rename from examples/protocols/coap_server/main/coap_server.c rename to examples/protocols/coap_server/main/coap_server_example_main.c index f23285388..47f47dfc5 100644 --- a/examples/protocols/coap_server/main/coap_server.c +++ b/examples/protocols/coap_server/main/coap_server_example_main.c @@ -80,7 +80,7 @@ async_handler(coap_context_t *ctx, struct coap_resource_t *resource, async = coap_register_async(ctx, peer, request, COAP_ASYNC_SEPARATE | COAP_ASYNC_CONFIRM, (void*)"no data"); } -static void coap_demo_thread(void *p) +static void coap_example_thread(void *p) { coap_context_t* ctx = NULL; coap_address_t serv_addr; @@ -188,5 +188,5 @@ void app_main(void) ESP_ERROR_CHECK( nvs_flash_init() ); wifi_conn_init(); - xTaskCreate(coap_demo_thread, "coap", 2048, NULL, 5, NULL); + xTaskCreate(coap_example_thread, "coap", 2048, NULL, 5, NULL); } diff --git a/examples/protocols/http_request/main/http_request_main.c b/examples/protocols/http_request/main/http_request_example_main.c similarity index 100% rename from examples/protocols/http_request/main/http_request_main.c rename to examples/protocols/http_request/main/http_request_example_main.c diff --git a/examples/protocols/https_request/main/https_request_main.c b/examples/protocols/https_request/main/https_request_example_main.c similarity index 100% rename from examples/protocols/https_request/main/https_request_main.c rename to examples/protocols/https_request/main/https_request_example_main.c diff --git a/examples/protocols/mdns/main/mdns_example_main.c b/examples/protocols/mdns/main/mdns_example_main.c index 50b74e08c..29e4e9b47 100644 --- a/examples/protocols/mdns/main/mdns_example_main.c +++ b/examples/protocols/mdns/main/mdns_example_main.c @@ -125,7 +125,7 @@ static void query_mdns_service(mdns_server_t * mdns, const char * service, const } } -static void mdns_task(void *pvParameters) +static void mdns_example_task(void *pvParameters) { mdns_server_t * mdns = NULL; while(1) { @@ -180,5 +180,5 @@ void app_main() { ESP_ERROR_CHECK( nvs_flash_init() ); initialise_wifi(); - xTaskCreate(&mdns_task, "mdns_task", 2048, NULL, 5, NULL); + xTaskCreate(&mdns_example_task, "mdns_example_task", 2048, NULL, 5, NULL); } diff --git a/examples/protocols/openssl_client/main/openssl_client.h b/examples/protocols/openssl_client/main/openssl_client_example.h similarity index 56% rename from examples/protocols/openssl_client/main/openssl_client.h rename to examples/protocols/openssl_client/main/openssl_client_example.h index f5ab887ad..7b6ef8d40 100644 --- a/examples/protocols/openssl_client/main/openssl_client.h +++ b/examples/protocols/openssl_client/main/openssl_client_example.h @@ -7,8 +7,8 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#ifndef _OPENSSL_DEMO_H_ -#define _OPENSSL_DEMO_H_ +#ifndef _OPENSSL_EXAMPLE_H_ +#define _OPENSSL_EXAMPLE_H_ /* The examples use simple WiFi configuration that you can set via 'make menuconfig'. @@ -23,21 +23,21 @@ you can set via 'make menuconfig'. If you'd rather not, just change the below entries to strings with - the config you want - ie #define OPENSSL_DEMO_TARGET_NAME "www.baidu.com" - and ie #define OPENSSL_DEMO_TARGET_TCP_PORT 433 + the config you want - ie #define OPENSSL_EXAMPLE_TARGET_NAME "www.baidu.com" + and ie #define OPENSSL_EXAMPLE_TARGET_TCP_PORT 433 */ -#define OPENSSL_DEMO_TARGET_NAME CONFIG_TARGET_DOMAIN -#define OPENSSL_DEMO_TARGET_TCP_PORT CONFIG_TARGET_PORT_NUMBER +#define OPENSSL_EXAMPLE_TARGET_NAME CONFIG_TARGET_DOMAIN +#define OPENSSL_EXAMPLE_TARGET_TCP_PORT CONFIG_TARGET_PORT_NUMBER -#define OPENSSL_DEMO_REQUEST "{\"path\": \"/v1/ping/\", \"method\": \"GET\"}\r\n" +#define OPENSSL_EXAMPLE_REQUEST "{\"path\": \"/v1/ping/\", \"method\": \"GET\"}\r\n" -#define OPENSSL_DEMO_THREAD_NAME "OpenSSL_demo" -#define OPENSSL_DEMO_THREAD_STACK_WORDS 10240 -#define OPENSSL_DEMO_THREAD_PRORIOTY 8 +#define OPENSSL_EXAMPLE_TASK_NAME "openssl_example" +#define OPENSSL_EXAMPLE_TASK_STACK_WORDS 10240 +#define OPENSSL_EXAMPLE_TASK_PRORIOTY 8 -#define OPENSSL_DEMO_RECV_BUF_LEN 1024 +#define OPENSSL_EXAMPLE_RECV_BUF_LEN 1024 -#define OPENSSL_DEMO_LOCAL_TCP_PORT 443 +#define OPENSSL_EXAMPLE_LOCAL_TCP_PORT 443 #endif diff --git a/examples/protocols/openssl_client/main/openssl_client.c b/examples/protocols/openssl_client/main/openssl_client_example_main.c similarity index 82% rename from examples/protocols/openssl_client/main/openssl_client.c rename to examples/protocols/openssl_client/main/openssl_client_example_main.c index 16c9a0efa..cb114ddf8 100644 --- a/examples/protocols/openssl_client/main/openssl_client.c +++ b/examples/protocols/openssl_client/main/openssl_client_example_main.c @@ -7,7 +7,7 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "openssl_client.h" +#include "openssl_client_example.h" #include @@ -33,9 +33,9 @@ static EventGroupHandle_t wifi_event_group; to the AP with an IP? */ const static int CONNECTED_BIT = BIT0; -const static char *TAG = "Openssl_demo"; +const static char *TAG = "openssl_example"; -void openssl_demo_thread(void *p) +static void openssl_example_task(void *p) { int ret; SSL_CTX *ctx; @@ -46,15 +46,15 @@ void openssl_demo_thread(void *p) struct ip4_addr *ip4_addr; int recv_bytes = 0; - char recv_buf[OPENSSL_DEMO_RECV_BUF_LEN]; + char recv_buf[OPENSSL_EXAMPLE_RECV_BUF_LEN]; - const char send_data[] = OPENSSL_DEMO_REQUEST; + const char send_data[] = OPENSSL_EXAMPLE_REQUEST; const int send_bytes = sizeof(send_data); ESP_LOGI(TAG, "OpenSSL demo thread start OK"); ESP_LOGI(TAG, "get target IP address"); - hp = gethostbyname(OPENSSL_DEMO_TARGET_NAME); + hp = gethostbyname(OPENSSL_EXAMPLE_TARGET_NAME); if (!hp) { ESP_LOGI(TAG, "failed"); goto failed1; @@ -84,7 +84,7 @@ void openssl_demo_thread(void *p) memset(&sock_addr, 0, sizeof(sock_addr)); sock_addr.sin_family = AF_INET; sock_addr.sin_addr.s_addr = 0; - sock_addr.sin_port = htons(OPENSSL_DEMO_LOCAL_TCP_PORT); + sock_addr.sin_port = htons(OPENSSL_EXAMPLE_LOCAL_TCP_PORT); ret = bind(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); if (ret) { ESP_LOGI(TAG, "failed"); @@ -92,11 +92,11 @@ void openssl_demo_thread(void *p) } ESP_LOGI(TAG, "OK"); - ESP_LOGI(TAG, "socket connect to remote %s ......", OPENSSL_DEMO_TARGET_NAME); + ESP_LOGI(TAG, "socket connect to remote %s ......", OPENSSL_EXAMPLE_TARGET_NAME); memset(&sock_addr, 0, sizeof(sock_addr)); sock_addr.sin_family = AF_INET; sock_addr.sin_addr.s_addr = ip4_addr->addr; - sock_addr.sin_port = htons(OPENSSL_DEMO_TARGET_TCP_PORT); + sock_addr.sin_port = htons(OPENSSL_EXAMPLE_TARGET_TCP_PORT); ret = connect(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); if (ret) { ESP_LOGI(TAG, "failed"); @@ -115,7 +115,7 @@ void openssl_demo_thread(void *p) SSL_set_fd(ssl, socket); ESP_LOGI(TAG, "SSL connected to %s port %d ......", - OPENSSL_DEMO_TARGET_NAME, OPENSSL_DEMO_TARGET_TCP_PORT); + OPENSSL_EXAMPLE_TARGET_NAME, OPENSSL_EXAMPLE_TARGET_TCP_PORT); ret = SSL_connect(ssl); if (!ret) { ESP_LOGI(TAG, "failed " ); @@ -124,7 +124,7 @@ void openssl_demo_thread(void *p) ESP_LOGI(TAG, "OK"); ESP_LOGI(TAG, "send https request to %s port %d ......", - OPENSSL_DEMO_TARGET_NAME, OPENSSL_DEMO_TARGET_TCP_PORT); + OPENSSL_EXAMPLE_TARGET_NAME, OPENSSL_EXAMPLE_TARGET_TCP_PORT); ret = SSL_write(ssl, send_data, send_bytes); if (ret <= 0) { ESP_LOGI(TAG, "failed"); @@ -133,7 +133,7 @@ void openssl_demo_thread(void *p) ESP_LOGI(TAG, "OK"); do { - ret = SSL_read(ssl, recv_buf, OPENSSL_DEMO_RECV_BUF_LEN - 1); + ret = SSL_read(ssl, recv_buf, OPENSSL_EXAMPLE_RECV_BUF_LEN - 1); if (ret <= 0) { break; } @@ -141,7 +141,7 @@ void openssl_demo_thread(void *p) ESP_LOGI(TAG, "%s", recv_buf); } while (1); - ESP_LOGI(TAG, "totaly read %d bytes data from %s ......", recv_bytes, OPENSSL_DEMO_TARGET_NAME); + ESP_LOGI(TAG, "totaly read %d bytes data from %s ......", recv_bytes, OPENSSL_EXAMPLE_TARGET_NAME); failed5: SSL_shutdown(ssl); @@ -159,20 +159,20 @@ failed1: return ; } -static void openssl_client_init(void) +static void openssl_example_client_init(void) { int ret; xTaskHandle openssl_handle; - ret = xTaskCreate(openssl_demo_thread, - OPENSSL_DEMO_THREAD_NAME, - OPENSSL_DEMO_THREAD_STACK_WORDS, + ret = xTaskCreate(openssl_example_task, + OPENSSL_EXAMPLE_TASK_NAME, + OPENSSL_EXAMPLE_TASK_STACK_WORDS, NULL, - OPENSSL_DEMO_THREAD_PRORIOTY, - &openssl_handle); + OPENSSL_EXAMPLE_TASK_PRORIOTY, + &openssl_handle); if (ret != pdPASS) { - ESP_LOGI(TAG, "create thread %s failed", OPENSSL_DEMO_THREAD_NAME); + ESP_LOGI(TAG, "create thread %s failed", OPENSSL_EXAMPLE_TASK_NAME); } } @@ -184,7 +184,7 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_GOT_IP: xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); - openssl_client_init(); + openssl_example_client_init(); break; case SYSTEM_EVENT_STA_DISCONNECTED: /* This is a workaround as ESP32 WiFi libs don't currently diff --git a/examples/protocols/openssl_server/main/openssl_server.h b/examples/protocols/openssl_server/main/openssl_server_example.h similarity index 75% rename from examples/protocols/openssl_server/main/openssl_server.h rename to examples/protocols/openssl_server/main/openssl_server_example.h index 51708535f..bdb84bae5 100755 --- a/examples/protocols/openssl_server/main/openssl_server.h +++ b/examples/protocols/openssl_server/main/openssl_server_example.h @@ -21,13 +21,13 @@ #define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID #define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD -#define OPENSSL_DEMO_THREAD_NAME "OpenSSL_demo" -#define OPENSSL_DEMO_THREAD_STACK_WORDS 10240 -#define OPENSSL_DEMO_THREAD_PRORIOTY 8 +#define OPENSSL_EXAMPLE_TASK_NAME "openssl_example" +#define OPENSSL_EXAMPLE_TASK_STACK_WORDS 10240 +#define OPENSSL_EXAMPLE_TASK_PRORIOTY 8 -#define OPENSSL_DEMO_RECV_BUF_LEN 1024 +#define OPENSSL_EXAMPLE_RECV_BUF_LEN 1024 -#define OPENSSL_DEMO_LOCAL_TCP_PORT 443 +#define OPENSSL_EXAMPLE_LOCAL_TCP_PORT 443 #endif diff --git a/examples/protocols/openssl_server/main/openssl_server.c b/examples/protocols/openssl_server/main/openssl_server_example_main.c similarity index 88% rename from examples/protocols/openssl_server/main/openssl_server.c rename to examples/protocols/openssl_server/main/openssl_server_example_main.c index e1d0619d2..bc0f7c355 100755 --- a/examples/protocols/openssl_server/main/openssl_server.c +++ b/examples/protocols/openssl_server/main/openssl_server_example_main.c @@ -7,7 +7,7 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "openssl_server.h" +#include "openssl_server_example.h" #include @@ -33,20 +33,20 @@ static EventGroupHandle_t wifi_event_group; to the AP with an IP? */ const static int CONNECTED_BIT = BIT0; -const static char *TAG = "Openssl_demo"; +const static char *TAG = "Openssl_example"; -#define OPENSSL_DEMO_SERVER_ACK "HTTP/1.1 200 OK\r\n" \ +#define OPENSSL_EXAMPLE_SERVER_ACK "HTTP/1.1 200 OK\r\n" \ "Content-Type: text/html\r\n" \ "Content-Length: 98\r\n\r\n" \ "\r\n" \ "\r\n" \ - "OpenSSL demo\r\n" \ - "OpenSSL server demo!\r\n" \ + "OpenSSL example\r\n" \ + "OpenSSL server example!\r\n" \ "\r\n" \ "\r\n" \ "\r\n" -static void openssl_demo_thread(void *p) +static void openssl_example_task(void *p) { int ret; @@ -57,9 +57,9 @@ static void openssl_demo_thread(void *p) socklen_t addr_len; struct sockaddr_in sock_addr; - char recv_buf[OPENSSL_DEMO_RECV_BUF_LEN]; + char recv_buf[OPENSSL_EXAMPLE_RECV_BUF_LEN]; - const char send_data[] = OPENSSL_DEMO_SERVER_ACK; + const char send_data[] = OPENSSL_EXAMPLE_SERVER_ACK; const int send_bytes = sizeof(send_data); extern const unsigned char cacert_pem_start[] asm("_binary_cacert_pem_start"); @@ -110,7 +110,7 @@ static void openssl_demo_thread(void *p) memset(&sock_addr, 0, sizeof(sock_addr)); sock_addr.sin_family = AF_INET; sock_addr.sin_addr.s_addr = 0; - sock_addr.sin_port = htons(OPENSSL_DEMO_LOCAL_TCP_PORT); + sock_addr.sin_port = htons(OPENSSL_EXAMPLE_LOCAL_TCP_PORT); ret = bind(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); if (ret) { ESP_LOGI(TAG, "failed"); @@ -155,8 +155,8 @@ reconnect: ESP_LOGI(TAG, "SSL server read message ......"); do { - memset(recv_buf, 0, OPENSSL_DEMO_RECV_BUF_LEN); - ret = SSL_read(ssl, recv_buf, OPENSSL_DEMO_RECV_BUF_LEN - 1); + memset(recv_buf, 0, OPENSSL_EXAMPLE_RECV_BUF_LEN); + ret = SSL_read(ssl, recv_buf, OPENSSL_EXAMPLE_RECV_BUF_LEN - 1); if (ret <= 0) { break; } @@ -199,15 +199,15 @@ static void openssl_client_init(void) int ret; xTaskHandle openssl_handle; - ret = xTaskCreate(openssl_demo_thread, - OPENSSL_DEMO_THREAD_NAME, - OPENSSL_DEMO_THREAD_STACK_WORDS, + ret = xTaskCreate(openssl_example_task, + OPENSSL_EXAMPLE_TASK_NAME, + OPENSSL_EXAMPLE_TASK_STACK_WORDS, NULL, - OPENSSL_DEMO_THREAD_PRORIOTY, + OPENSSL_EXAMPLE_TASK_PRORIOTY, &openssl_handle); if (ret != pdPASS) { - ESP_LOGI(TAG, "create thread %s failed", OPENSSL_DEMO_THREAD_NAME); + ESP_LOGI(TAG, "create task %s failed", OPENSSL_EXAMPLE_TASK_NAME); } } diff --git a/examples/protocols/sntp/main/sntp_main.c b/examples/protocols/sntp/main/sntp_example_main.c similarity index 100% rename from examples/protocols/sntp/main/sntp_main.c rename to examples/protocols/sntp/main/sntp_example_main.c diff --git a/examples/storage/nvs_rw_blob/main/nvs_rw_blob.c b/examples/storage/nvs_rw_blob/main/nvs_blob_example_main.c similarity index 100% rename from examples/storage/nvs_rw_blob/main/nvs_rw_blob.c rename to examples/storage/nvs_rw_blob/main/nvs_blob_example_main.c diff --git a/examples/storage/nvs_rw_value/main/nvs_rw_value.c b/examples/storage/nvs_rw_value/main/nvs_value_example_main.c similarity index 100% rename from examples/storage/nvs_rw_value/main/nvs_rw_value.c rename to examples/storage/nvs_rw_value/main/nvs_value_example_main.c diff --git a/examples/storage/sd_card/main/sd_card.c b/examples/storage/sd_card/main/sd_card_example_main.c similarity index 100% rename from examples/storage/sd_card/main/sd_card.c rename to examples/storage/sd_card/main/sd_card_example_main.c diff --git a/examples/system/deep_sleep/main/deep_sleep_wakeup.c b/examples/system/deep_sleep/main/deep_sleep_example_main.c similarity index 100% rename from examples/system/deep_sleep/main/deep_sleep_wakeup.c rename to examples/system/deep_sleep/main/deep_sleep_example_main.c diff --git a/examples/system/ota/main/ota_example.c b/examples/system/ota/main/ota_example_main.c similarity index 97% rename from examples/system/ota/main/ota_example.c rename to examples/system/ota/main/ota_example_main.c index bc910f70c..bb931ae0a 100644 --- a/examples/system/ota/main/ota_example.c +++ b/examples/system/ota/main/ota_example_main.c @@ -135,7 +135,7 @@ static bool read_past_http_header(char text[], int total_len, esp_ota_handle_t u return false; } -bool connect_to_http_server() +static bool connect_to_http_server() { ESP_LOGI(TAG, "Server IP: %s Server Port:%s", EXAMPLE_SERVER_IP, EXAMPLE_SERVER_PORT); sprintf(http_request, "GET %s HTTP/1.1\r\nHost: %s:%s \r\n\r\n", EXAMPLE_FILENAME, EXAMPLE_SERVER_IP, EXAMPLE_SERVER_PORT); @@ -168,7 +168,7 @@ bool connect_to_http_server() return false; } -void __attribute__((noreturn)) task_fatal_error() +static void __attribute__((noreturn)) task_fatal_error() { ESP_LOGE(TAG, "Exiting task due to fatal error..."); close(socket_id); @@ -179,7 +179,7 @@ void __attribute__((noreturn)) task_fatal_error() } } -void main_task(void *pvParameter) +static void ota_example_task(void *pvParameter) { esp_err_t err; /* update handle : set by esp_ota_begin(), must be freed via esp_ota_end() */ @@ -295,5 +295,5 @@ void app_main() ESP_ERROR_CHECK( err ); initialise_wifi(); - xTaskCreate(&main_task, "main_task", 8192, NULL, 5, NULL); + xTaskCreate(&ota_example_task, "ota_example_task", 8192, NULL, 5, NULL); } diff --git a/examples/wifi/wpa2_enterprise/main/wpa2_enterprise_main.c b/examples/wifi/wpa2_enterprise/main/wpa2_enterprise_main.c index 0932aec93..d2b6344ec 100644 --- a/examples/wifi/wpa2_enterprise/main/wpa2_enterprise_main.c +++ b/examples/wifi/wpa2_enterprise/main/wpa2_enterprise_main.c @@ -127,7 +127,7 @@ static void initialise_wifi(void) ESP_ERROR_CHECK( esp_wifi_start() ); } -static void wpa2_enterprise_task(void *pvParameters) +static void wpa2_enterprise_example_task(void *pvParameters) { tcpip_adapter_ip_info_t ip; memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t)); @@ -150,5 +150,5 @@ void app_main() { ESP_ERROR_CHECK( nvs_flash_init() ); initialise_wifi(); - xTaskCreate(&wpa2_enterprise_task, "wpa2_enterprise_task", 4096, NULL, 5, NULL); + xTaskCreate(&wpa2_enterprise_example_task, "wpa2_enterprise_example_task", 4096, NULL, 5, NULL); }