Services

[中文]

A service is a software implementation of specific product functions, such as input keys, network configuration management, and battery check. Each service is also an abstraction of hardware. For example, the input key service supports ADC keys and GPIO keys. Services can be reused on different products, and high-level APIs and events allow easy and convenient product development.

For details please refer to descriptions listed below.

Header File

Functions

periph_service_handle_t periph_service_create(periph_service_config_t *config)

brief Create peripheral service instance

Parameters

config[in] Configuration of the peripheral service instance

Returns

  • NULL, Fail

  • Others, Success

esp_err_t periph_service_destroy(periph_service_handle_t handle)

brief Destroy peripheral service instance

Parameters

handle[in] The peripheral service instance

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t periph_service_start(periph_service_handle_t handle)

brief Start the specific peripheral service

Parameters

handle[in] The peripheral service instance

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t periph_service_stop(periph_service_handle_t handle)

brief Stop the specific peripheral service

Parameters

handle[in] The peripheral service instance

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t periph_service_set_callback(periph_service_handle_t handle, periph_service_cb cb, void *ctx)

brief Set the specific peripheral service callback function

Parameters
  • handle[in] The peripheral service instance

  • cb[in] A pointer to service_callback

  • ctx[in] A pointer to user context

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t periph_service_callback(periph_service_handle_t handle, periph_service_event_t *evt)

brief Called peripheral service by configurations

Parameters
Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t periph_service_set_data(periph_service_handle_t handle, void *data)

brief Set user data to specific peripheral service instance

Parameters
  • handle[in] The peripheral service instance

  • data[in] A pointer to user data

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

void *periph_service_get_data(periph_service_handle_t handle)

brief Get user data by specific peripheral service instance

Parameters

handle[in] The peripheral service instance

Returns

A pointer to user data

esp_err_t periph_service_ioctl(periph_service_handle_t handle, void *ioctl_handle, int cmd, int value)

brief In/out control by peripheral service instance

Parameters
  • handle[in] The peripheral service instance

  • ioctl_handle[in] Sub-instance handle

  • cmd[in] Command of value

  • value[in] Data of the command

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

Structures

struct periph_service_event_t

Peripheral service event informations.

Public Members

int type

Type of event

void *source

Event source

void *data

Event data

int len

Length of data

struct periph_service_config_t

Peripheral service configurations.

Public Members

int task_stack

>0 Service task stack; =0 with out task created

int task_prio

Service task priority (based on freeRTOS priority)

int task_core

Service task running in core (0 or 1)

TaskFunction_t task_func

Service task function

bool extern_stack

Task stack allocate on the extern ram

periph_service_ctrl service_start

Start function

periph_service_ctrl service_stop

Stop function

periph_service_ctrl service_destroy

Destroy function

periph_service_io service_ioctl

In out control function

char *service_name

Name of peripheral service

void *user_data

User data

Type Definitions

typedef struct periph_service_impl *periph_service_handle_t
typedef esp_err_t (*periph_service_ctrl)(periph_service_handle_t handle)
typedef esp_err_t (*periph_service_io)(void *ioctl_handle, int cmd, int value)
typedef esp_err_t (*periph_service_cb)(periph_service_handle_t handle, periph_service_event_t *evt, void *ctx)

Enumerations

enum periph_service_state_t

Peripheral service state.

Values:

enumerator PERIPH_SERVICE_STATE_UNKNOWN
enumerator PERIPH_SERVICE_STATE_IDLE
enumerator PERIPH_SERVICE_STATE_RUNNING
enumerator PERIPH_SERVICE_STATE_STOPPED

Header File

Functions

audio_service_handle_t audio_service_create(audio_service_config_t *config)

brief Create audio service instance

Parameters

config[in] Configuration of the audio service instance

Returns

  • NULL, Fail

  • Others, Success

esp_err_t audio_service_destroy(audio_service_handle_t handle)

brief Destroy audio service instance

Parameters

handle[in] The audio service instance

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t audio_service_start(audio_service_handle_t handle)

brief Start the specific audio service

Parameters

handle[in] The audio service instance

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t audio_service_stop(audio_service_handle_t handle)

brief Stop the specific audio service

Parameters

handle[in] The audio service instance

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t audio_service_set_callback(audio_service_handle_t handle, service_callback cb, void *ctx)

brief Set the specific audio service callback function.

Parameters
  • handle[in] The audio service instance

  • cb[in] A pointer to service_callback

  • ctx[in] A pointer to user context

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t audio_service_callback(audio_service_handle_t handle, service_event_t *evt)

brief Called audio service by configurations

Parameters
  • handle[in] The audio service instance

  • evt[in] A pointer to service_event_t

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t audio_service_connect(audio_service_handle_t handle)

brief Connect the specific audio service

Parameters

handle[in] The audio service instance

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t audio_service_disconnect(audio_service_handle_t handle)

brief Disconnect the specific audio service

Parameters

handle[in] The audio service instance

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

esp_err_t audio_service_set_data(audio_service_handle_t handle, void *data)

brief Set user data to specific audio service instance

Parameters
  • handle[in] The audio service instance

  • data[in] A pointer to user data

Returns

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

void *audio_service_get_data(audio_service_handle_t handle)

brief Get user data by specific audio service instance

Parameters

handle[in] The audio service instance

Returns

A pointer to user data

Structures

struct service_event_t

Audio service event informations.

Public Members

int type

Type of event

void *source

Event source

void *data

Event data

int len

Length of data

struct audio_service_config_t

Audio service configurations.

Public Members

int task_stack

>0 Service task stack; =0 with out task created

int task_prio

Service task priority (based on freeRTOS priority)

int task_core

Service task running in core (0 or 1)

TaskFunction_t task_func

A pointer to TaskFunction_t for service task function

service_ctrl service_start

Start function

service_ctrl service_stop

Stop function

service_ctrl service_connect

Connect function

service_ctrl service_disconnect

Disconnect function

service_ctrl service_destroy

Destroy function

const char *service_name

Name of audio service

void *user_data

User context

Type Definitions

typedef struct audio_service_impl *audio_service_handle_t
typedef esp_err_t (*service_ctrl)(audio_service_handle_t handle)
typedef esp_err_t (*service_callback)(audio_service_handle_t handle, service_event_t *evt, void *ctx)

Enumerations

enum service_state_t

Audio service state.

Values:

enumerator SERVICE_STATE_UNKNOWN
enumerator SERVICE_STATE_IDLE
enumerator SERVICE_STATE_CONNECTING
enumerator SERVICE_STATE_CONNECTED
enumerator SERVICE_STATE_RUNNING
enumerator SERVICE_STATE_STOPPED