服务

[English]

服务 (service) 框架是具体产品功能在软件层面上的实现,如输入按键、网络配置管理、电池检测等功能。每个服务也是对硬件的抽象,如输入按键服务支持 ADC 类型和 GPIO 类型的的按键。服务可以复用在不同产品上,高级 API 和事件可以让用户简单便捷的开发产品。

更多信息请参考以下文档。

Header File

Functions

periph_service_handle_t periph_service_create(periph_service_config_t *config)

brief Create peripheral service instance

参数

config[in] Configuration of the peripheral service instance

返回

  • NULL, Fail

  • Others, Success

esp_err_t periph_service_destroy(periph_service_handle_t handle)

brief Destroy peripheral service instance

参数

handle[in] The peripheral service instance

返回

  • 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

参数

handle[in] The peripheral service instance

返回

  • 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

参数

handle[in] The peripheral service instance

返回

  • 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

参数
  • handle[in] The peripheral service instance

  • cb[in] A pointer to service_callback

  • ctx[in] A pointer to user context

返回

  • 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

参数
返回

  • 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

参数
  • handle[in] The peripheral service instance

  • data[in] A pointer to user data

返回

  • 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

参数

handle[in] The peripheral service instance

返回

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

参数
  • handle[in] The peripheral service instance

  • ioctl_handle[in] Sub-instance handle

  • cmd[in] Command of value

  • value[in] Data of the command

返回

  • 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

参数

config[in] Configuration of the audio service instance

返回

  • NULL, Fail

  • Others, Success

esp_err_t audio_service_destroy(audio_service_handle_t handle)

brief Destroy audio service instance

参数

handle[in] The audio service instance

返回

  • 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

参数

handle[in] The audio service instance

返回

  • 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

参数

handle[in] The audio service instance

返回

  • 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.

参数
  • handle[in] The audio service instance

  • cb[in] A pointer to service_callback

  • ctx[in] A pointer to user context

返回

  • 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

参数
  • handle[in] The audio service instance

  • evt[in] A pointer to service_event_t

返回

  • 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

参数

handle[in] The audio service instance

返回

  • 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

参数

handle[in] The audio service instance

返回

  • 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

参数
  • handle[in] The audio service instance

  • data[in] A pointer to user data

返回

  • 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

参数

handle[in] The audio service instance

返回

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