Event Interface

The ADF provides the Event Interface API to establish communication between Audio Elements in a pipeline. The API is built around FreeRTOS queue. It implements ‘listeners’ to watch for incoming messages and inform about them with a callback function.

Application Examples

Implementation of this API is demonstrated in couple of examples including get-started/play_mp3_control.

API Reference

Header File

Functions

audio_event_iface_handle_t audio_event_iface_init(audio_event_iface_cfg_t *config)

Initialize audio event.

Parameters

config – The configurations

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_destroy(audio_event_iface_handle_t evt)

Cleanup event, it doesn’t free evt pointer.

Parameters

evt – The event

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_set_listener(audio_event_iface_handle_t evt, audio_event_iface_handle_t listener)

Add audio event evt to the listener, then we can listen evt event from listen

Parameters
  • listener – The event can listen another event

  • evt – The event to be added to

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_remove_listener(audio_event_iface_handle_t listener, audio_event_iface_handle_t evt)

Remove audio event evt from the listener.

Parameters
  • listener – The event listener

  • evt – The event to be removed from

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_set_cmd_waiting_timeout(audio_event_iface_handle_t evt, TickType_t wait_time)

Set current queue wait time for the event.

Parameters
  • evt – The event

  • wait_time[in] The wait time

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_waiting_cmd_msg(audio_event_iface_handle_t evt)

Waiting internal queue message.

Parameters

evt – The event

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_cmd(audio_event_iface_handle_t evt, audio_event_iface_msg_t *msg)

Trigger an event for internal queue with a message.

Parameters
  • evt – The event

  • msg – The message

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_cmd_from_isr(audio_event_iface_handle_t evt, audio_event_iface_msg_t *msg)

It’s same with audio_event_iface_cmd, but can send a message from ISR.

Parameters
  • evt[in] The event

  • msg – The message

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_sendout(audio_event_iface_handle_t evt, audio_event_iface_msg_t *msg)

Trigger and event out with a message.

Parameters
  • evt – The event

  • msg – The message

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_discard(audio_event_iface_handle_t evt)

Discard all ongoing event message.

Parameters

evt – The event

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t audio_event_iface_listen(audio_event_iface_handle_t evt, audio_event_iface_msg_t *msg, TickType_t wait_time)

Listening and invoke callback function if there are any event are comming.

Parameters
  • evt – The event

  • msg – The message

  • wait_time – The wait time

Returns

  • ESP_OK

  • ESP_FAIL

QueueHandle_t audio_event_iface_get_queue_handle(audio_event_iface_handle_t evt)

Get External queue handle of Emmitter.

Parameters

evt[in] The external queue

Returns

External QueueHandle_t

esp_err_t audio_event_iface_read(audio_event_iface_handle_t evt, audio_event_iface_msg_t *msg, TickType_t wait_time)

Read the event from all the registered event emitters in the queue set of the interface.

Parameters
  • evt[in] The event interface

  • msg[out] The pointer to structure in which event is to be received

  • wait_time[in] Timeout for receiving event

Returns

  • ESP_OK On successful receiving of event

  • ESP_FAIL In case of a timeout or invalid parameter passed

QueueHandle_t audio_event_iface_get_msg_queue_handle(audio_event_iface_handle_t evt)

Get Internal queue handle of Emmitter.

Parameters

evt[in] The Internal queue

Returns

Internal QueueHandle_t

esp_err_t audio_event_iface_set_msg_listener(audio_event_iface_handle_t evt, audio_event_iface_handle_t listener)

Add audio internal event evt to the listener, then we can listen evt event from listen

Parameters
  • listener – The event can listen another event

  • evt – The event to be added to

Returns

  • ESP_OK

  • ESP_FAIL

Structures

struct audio_event_iface_msg_t

Event message

Public Members

int cmd

Command id

void *data

Data pointer

int data_len

Data length

void *source

Source event

int source_type

Source type (To know where it came from)

bool need_free_data

Need to free data pointer after the event has been processed

struct audio_event_iface_cfg_t

Event interface configurations

Public Members

int internal_queue_size

It’s optional, Queue size for event internal_queue

int external_queue_size

It’s optional, Queue size for event external_queue

int queue_set_size

It’s optional, QueueSet size for event queue_set

on_event_iface_func on_cmd

Function callback for listener when any event arrived

void *context

Context will pass to callback function

TickType_t wait_time

Timeout to check for event queue

int type

it will pass to audio_event_iface_msg_t source_type (To know where it came from)

Macros

DEFAULT_AUDIO_EVENT_IFACE_SIZE
AUDIO_EVENT_IFACE_DEFAULT_CFG()

Type Definitions

typedef esp_err_t (*on_event_iface_func)(audio_event_iface_msg_t*, void*)
typedef struct audio_event_iface *audio_event_iface_handle_t