1 Star 0 Fork 4.9K

fish / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sensor-driver-overview.md 24.33 KB
一键复制 编辑 原始数据 按行查看 历史
NEEN 提交于 2021-03-12 17:59 . !197 Docs Update version 1.0.1

Sensor Driver Overview

Introduction

The sensor driver module provides APIs for upper-layer sensor services to implement basic sensor capabilities, including querying the sensor list, enabling or disabling a sensor, subscribing to or unsubscribing from sensor data, and setting sensor options. The sensor driver model is developed based on the Hardware Driver Foundation (HDF) and supports functions such as cross-OS migration and differentiated device configuration. The following figure shows the architecture of the sensor driver model.

Figure 1 Architecture of the sensor driver model

The sensor driver model offers the following APIs:

  • Hardware Driver Interfaces (HDIs) for sensors: Facilitate service development.
  • APIs for implementing sensor driver model capabilities: Implement the capabilities of registering, loading, and unregistering sensor drivers as well as detecting sensor devices depending on the HDF, normalize APIs for sensor devices of the same type, and offer APIs for parsing register configurations, abstract APIs for bus access, and abstract platform APIs.
  • APIs to be implemented by developers: Based on the HDF Configuration Source (HCS), implement differentiated configuration for sensors of the same type and serialized configuration of sensor device parameters, and offer APIs for some sensor device operations to simplify sensor driver development.

Available APIs

The following table lists the APIs provided by the sensor driver model.

Table 1 External APIs provided by the sensor driver model

Category

API

Description

Query

int32_t GetAllSensors(struct SensorInformation **sensorInfo, int32_t *count)

Obtains information about all sensors in the system. The information about a sensor generally includes the sensor name, sensor vendor, firmware version, hardware version, sensor type ID, sensor ID, maximum measurement range, accuracy, and power.

Setting

int32_t Enable(int32_t sensorId)

Enables the sensor that has been subscribed to. The subscriber can obtain the sensor data only after the sensor is enabled.

int32_t Disable(int32_t sensorId)

Disables a sensor.

int32_t SetBatch(iint32_t sensorId, int64_t samplingInterval, int64_t reportInterval)

Sets the data sampling interval and data reporting interval for the specified sensor.

int32_t SetMode(int32_t sensorTypeId, SensorUser *user, int32_t mode)

Sets the data reporting mode for the specified sensor.

int32_t SetOption(int32_t sensorId, uint32_t option)

Sets options for the specified sensor, including its measurement range and accuracy.

Data subscription and unsubscription

int32_t Register(RecordDataCallback cb)

Registers the callback for reporting sensor data to the subscriber.

int32_t Unregister(void)

Unregisters the callback for reporting sensor data.

Instance creation

const struct SensorInterface *NewSensorInterfaceInstance(void)

Creates a SensorInterface instance.

int32_t FreeSensorInterfaceInstance(void)

Releases the SensorInterface instance.

The following table lists the APIs provided by the sensor driver model for driver developers. You can directly call these APIs without any implementations.

Table 2 APIs provided by the sensor driver model for driver developers

Category

API

Description

Device management

int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo)

Adds a sensor of the current type to the sensor management module.

int32_t DeleteSensorDevice(int32_t sensorId)

Deletes a specified sensor from the sensor management module.

int32_t ReportSensorEvent(const struct SensorReportEvent *events)

Reports data of a specified sensor type.

Abstract bus and platform operations

int32_t ReadSensor(struct SensorBusCfg *busCfg, uint16_t regAddr, uint8_t *data, uint16_t dataLen)

Reads sensor configuration data from the sensor register based on the bus configuration.

int32_t WriteSensor(struct SensorBusCfg *busCfg, uint8_t *writeData, uint16_t len)

Writes sensor configuration data to the sensor register based on the bus configuration.

int32_t CreateSensorThread(struct OsalThread *thread, OsalThreadEntry threadEntry, char *name, void *entryPara)

Creates a scheduled thread for a specified sensor to process sensor data reporting.

void DestroySensorThread(struct OsalThread *thread, uint8_t *status);

Destroys the scheduled thread created for the sensor.

Common configuration

int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group);

Sets the sensor register group configuration based on the sensor bus type.

Configuration parsing

int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct SensorCfgData *config)

Obtains basic configuration information such as sensor, bus, and attribute configurations based on the HCS resource configuration of the sensor device, and initializes the basic configuration data structure.

int32_t ParseSensorRegConfig(struct SensorCfgData *config)

Parses the register group information based on the HCS resource configuration of the sensor device and initializes the configuration data structure.

void ReleaseSensorAllRegConfig(struct SensorCfgData *config)

Releases the resources allocated to the sensor configuration data structure.

int32_t GetSensorBusHandle(struct SensorBusCfg *busCfg)

Obtains the sensor bus handle information.

int32_t ReleaseSensorBusHandle(struct SensorBusCfg *busCfg)

Releases the sensor bus handle information.

The following table lists the APIs that need to be implemented by driver developers.

Table 3 APIs that need to be implemented by driver developers

Category

API

Description

Basic functions

int32_t init(void)

Initializes the configuration of a sensor device after it is detected successfully.

int32_t GetInfo(struct SensorBasicInfo *info)

Obtains the basic information about the current sensor device from the HCS of sensor devices.

int32_t Enable(void)

Enables the current sensor device by delivering the register configuration in the operation group based on the HCS of the current sensor device.

int32_t Disable(void)

Disables the current sensor device by delivering the register configuration in the operation group based on the HCS of the current sensor device.

int32_t SetBatch(int64_t samplingInterval, int64_t reportInterval)

Sets the processing time of the data reporting thread for the current sensor device based on the data sampling interval and data reporting interval.

int32_t SetMode(int32_t mode)

Sets the data reporting mode of the current sensor device.

int32_t SetOption(uint32_t option)

Sets the register configuration such as the measurement range and accuracy based on sensor options.

void ReadSensorData(void)

Reads sensor data.

For details about the API implementation, see 4.

1
https://gitee.com/fish_neil/docs.git
git@gitee.com:fish_neil/docs.git
fish_neil
docs
docs
master

搜索帮助