Chapter 2. API Reference
Note This function is called from startup code. Applications do not need to call this function before using
other esp_timer APIs.
Return
• ESP_OK on success
esp_err_t esp_timer_init(void)
Initialize esp_timer library.
Note This function is called from startup code. Applications do not need to call this function before using
other esp_timer APIs. Before calling this function, esp_timer_early_init must be called by the startup
code.
Return
• ESP_OK on success
• ESP_ERR_NO_MEM if allocation has failed
• ESP_ERR_INVALID_STATE if already initialized
• other errors from interrupt allocator
esp_err_t esp_timer_deinit(void)
De-initialize esp_timer library.
Note Normally this function should not be called from applications
Return
• ESP_OK on success
• ESP_ERR_INVALID_STATE if not yet initialized
esp_err_t esp_timer_create(const esp_timer_create_args_t *create_args, esp_timer_handle_t
*out_handle)
Create an esp_timer instance.
Note When done using the timer, delete it with esp_timer_delete function.
Return
• ESP_OK on success
• ESP_ERR_INVALID_ARG if some of the create_args are not valid
• ESP_ERR_INVALID_STATE if esp_timer library is not initialized yet
• ESP_ERR_NO_MEM if memory allocation fails
Parameters
• create_args: Pointer to a structure with timer creation arguments. Not saved by the library,
can be allocated on the stack.
• [out] out_handle: Output, pointer to esp_timer_handle_t variable which will hold the created
timer handle.
esp_err_t esp_timer_start_once(esp_timer_handle_t timer, uint64_t timeout_us)
Start one-shot timer.
Timer should not be running when this function is called.
Return
• ESP_OK on success
• ESP_ERR_INVALID_ARG if the handle is invalid
• ESP_ERR_INVALID_STATE if the timer is already running
Parameters
• timer: timer handle created using esp_timer_create
• timeout_us: timer timeout, in microseconds relative to the current moment
esp_err_t esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t period)
Start a periodic timer.
Timer should not be running when this function is called. This function will start the timer which will trigger
every ‘period’microseconds.
Return
• ESP_OK on success
• ESP_ERR_INVALID_ARG if the handle is invalid
• ESP_ERR_INVALID_STATE if the timer is already running
Espressif Systems 996
Submit Document Feedback
Release v4.4