esp_event_loop.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_EVENT_LOOP_H__
  14. #define __ESP_EVENT_LOOP_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #include "esp_event.h"
  19. #include "freertos/FreeRTOS.h"
  20. #include "freertos/queue.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /**
  25. * @brief Application specified event callback function
  26. *
  27. * @param void *ctx : reserved for user
  28. * @param system_event_t *event : event type defined in this file
  29. *
  30. * @return ESP_OK : succeed
  31. * @return others : fail
  32. */
  33. typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
  34. /**
  35. * @brief Initialize event loop
  36. * Create the event handler and task
  37. *
  38. * @param system_event_cb_t cb : application specified event callback, it can be modified by call esp_event_set_cb
  39. * @param void *ctx : reserved for user
  40. *
  41. * @return ESP_OK : succeed
  42. * @return others : fail
  43. */
  44. esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
  45. /**
  46. * @brief Set application specified event callback function
  47. *
  48. * @attention 1. If cb is NULL, means application don't need to handle
  49. * If cb is not NULL, it will be call when an event is received, after the default event callback is completed
  50. *
  51. * @param system_event_cb_t cb : callback
  52. * @param void *ctx : reserved for user
  53. *
  54. * @return system_event_cb_t : old callback
  55. */
  56. system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx);
  57. /**
  58. * @brief Get the queue used by event loop
  59. *
  60. * @attention : currently this API is used to initialize "q" parameter
  61. * of wifi_init structure.
  62. *
  63. * @return QueueHandle_t : event queue handle
  64. */
  65. QueueHandle_t esp_event_loop_get_queue(void);
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* __ESP_EVENT_LOOP_H__ */