The light driver model provides APIs for the upper-layer light hardware service layer to control lights, including obtaining the light type, setting the lighting mode and blinking effect, and turning on or off a light. This model implements functionalities such as cross-OS migration and differentiated configurations based on the Hardware Driver Foundation (HDF) to achieve the goal of "one-time development for cross-system deployment" of the light driver. The figure below shows the light driver model.
The light driver model provides APIs for the upper-layer light hardware service layer to control lights, including obtaining the light type, setting the lighting mode and blinking effect, and turning on or off a light. This model implements functionalities such as cross-OS migration and differentiated configurations based on the Hardware Driver Foundation (HDF) to achieve the goal of "one-time development for cross-system deployment" of the light driver.
The figure below shows the light driver model.
**Figure 1** Light driver model
**Figure 1** Light driver model
...
@@ -23,7 +25,7 @@ The following uses the Hi3516D V300 development board powered by the standard sy
...
@@ -23,7 +25,7 @@ The following uses the Hi3516D V300 development board powered by the standard sy
1. The light driver reads the light device management configuration from **Light Host** in the **device_info.hcs** file.
1. The light driver reads the light device management configuration from **Light Host** in the **device_info.hcs** file.
2. The light driver reads the light data configuration from the **light_config.hcs** file.
2. The light driver reads the light data configuration from the **light_config.hcs** file.
3. The light driver parses information about the light device management configuration and associates with the corresponding device driver.
3. The light driver parses the light device management configuration and associates with the corresponding device driver.
4. The light proxy delivers an instruction to the light stub.
4. The light proxy delivers an instruction to the light stub.
5. The light stub delivers an instruction to the light controller.
5. The light stub delivers an instruction to the light controller.
6. The light abstract driver interface is started.
6. The light abstract driver interface is started.
...
@@ -40,17 +42,17 @@ The light driver model provides APIs to obtain information about all the lights
...
@@ -40,17 +42,17 @@ The light driver model provides APIs to obtain information about all the lights
| int32_t (*GetLightInfo)(struct LightInfo **lightInfo, uint32_t *count) | Obtains information about all lights in the system. **lightInfo** indicates the double pointer to the basic light information. **count** indicates the pointer to the number of lights.|
| int32_t (*GetLightInfo)(struct LightInfo **lightInfo, uint32_t *count) | Obtains information about all lights in the system. <br/>- **lightInfo** indicates the double pointer to the basic light information. <br/>- **count** indicates the pointer to the number of lights. |
| int32_t (*TurnOnLight)(uint32_t type, struct LightEffect *effect) | Turns on available lights in the list based on the specified light type. **type** indicates the light type, and **effect** indicates the pointer to the blinking effect.|
| int32_t (*TurnOnLight)(uint32_t lightId, struct LightEffect *effect) | Turns on available lights in the list based on the specified light type. <br/>**lightId** indicates the light type, and **effect** indicates the pointer to the blinking effect. |
| int32_t (*TurnOffLight)(uint32_t type) | Turns off available lights in the light list based on the specified light type. **type** indicates the light type. |
| int32_t (*TurnOffLight)(uint32_t lightId) | Turns off available lights in the light list based on the specified light type. <br/>**lightId** indicates the light type. |
### How to Develop
### How to Develop
1. Based on the HDF and the driver entry, complete the light abstract driver development (using the **Bind**, **Init**, **Release**, and **Dispatch** functions), resource configuration, and HCS parsing. Configure the light driver device information.
1. Based on the HDF and the driver entry, complete the light abstract driver development (using the **Bind**, **Init**, **Release**, and **Dispatch** functions), resource configuration, and HCS parsing. Configure the light driver device information.
- Call **HDF_INIT** to register the driver entry with the HDF. Generally, the HDF calls the **Bind** function and then the **Init** function to load the driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
- Call **HDF_INIT** to register the driver entry with the HDF. Generally, the HDF calls the **Bind** function and then the **Init** function to load the driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
The light driver model uses HDF configuration source (HCS). For details about HCS fields, see [Configuration Management](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-hdf-manage.md).
The light driver model uses HDF configuration source (HCS). For details about HCS fields, see [Configuration Management](../driver/driver-hdf-manage.md).
The light driver entry is defined as follows:
The light driver entry is defined as follows:
```c
```c
...
@@ -62,7 +64,7 @@ The light driver model provides APIs to obtain information about all the lights
...
@@ -62,7 +64,7 @@ The light driver model provides APIs to obtain information about all the lights
.Init = InitLightDriver, // Initialize the light driver.
.Init = InitLightDriver, // Initialize the light driver.
.Release = ReleaseLightDriver, // Release the light resources.
.Release = ReleaseLightDriver, // Release the light resources.
};
};
/* Call HDF_INIT to register the driver entry with the HDF. The HDF calls the Bind function and then the Init function to load a driver. If Init fails to be called, the HDF calls Release to release driver resources and exit. */
/* Call HDF_INIT to register the driver entry with the HDF. When loading the driver, the HDF calls Bind() and then Init() to load the driver. If Init() fails to be called, the HDF will call Release() to release resources and exit. */
HDF_INIT(g_lightDriverEntry);
HDF_INIT(g_lightDriverEntry);
```
```
...
@@ -81,13 +83,13 @@ The light driver model provides APIs to obtain information about all the lights
...
@@ -81,13 +83,13 @@ The light driver model provides APIs to obtain information about all the lights
@@ -128,6 +130,11 @@ The light driver model provides APIs to obtain information about all the lights
...
@@ -128,6 +130,11 @@ The light driver model provides APIs to obtain information about all the lights
HDF_LOGE("%s: get light config fail!", __func__);
HDF_LOGE("%s: get light config fail!", __func__);
return HDF_FAILURE;
return HDF_FAILURE;
}
}
/* Set the GPIO pin direction. */
if (SetLightGpioDir(drvData) != HDF_SUCCESS) {
HDF_LOGE("%s: set light gpio dir fail!", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
return HDF_SUCCESS;
}
}
...
@@ -153,18 +160,18 @@ The light driver model provides APIs to obtain information about all the lights
...
@@ -153,18 +160,18 @@ The light driver model provides APIs to obtain information about all the lights
}
}
```
```
- The light device management module dispatches light device APIs in the system. During the system startup process, the HDF loads the device management driver from the HCS of the light host.
- The light device management module publishes light device APIs in the system. During the system startup process, the HDF loads the device management driver based on **Light Host** in the HCS.
```
```
/* Light device HCS */
/* Light device HCS */
device_light :: device {
device_light :: device {
device0 :: deviceNode {
device0 :: deviceNode {
policy = 2; // Driver service dispatch policy (0: no service is dispatched; 1: services are dispatched to the kernel mode; 2: services are dispatched to both the kernel mode and user mode)
policy = 2; // Policy for the driver to publish services. (0: The driver does not provide services. 1: The driver publishes services for the kernel space. 2: The driver publishes services for both the kernel space and user space.)
priority = 100; // Light driver startup priority. The value ranges from 0 to 200. A larger value indicates a lower priority. The value 100 is recommended. If the priorities are the same, the device loading sequence cannot be ensured.
priority = 100; // Light driver startup priority. The value ranges from 0 to 200. A larger value indicates a lower priority. The value 100 is recommended. If the priorities are the same, the device loading sequence cannot be ensured.
preload = 0; // Field for specifying whether to load the driver. The value 0 means to load the driver, and 2 means the opposite.
preload = 0; // Whether to load the driver on demand. The value 0 means to load the driver on demand; the value 2 means the opposite.
permission = 0664; // Permission for the driver to create a device node.
permission = 0664; // Permission for the driver to create a device node.
moduleName = "HDF_LIGHT"; // Light driver name. The value of this field must be the same as that of moduleName in the HdfDriverEntry structure.
moduleName = "HDF_LIGHT"; // Light driver name. The value of this field must be the same as that of moduleName in the HdfDriverEntry structure.
serviceName = "hdf_light"; // Service name of the driver, which must be unique.
serviceName = "hdf_light"; // Unique name of the service published by the driver.
deviceMatchAttr = "hdf_light_driver"; // Keyword for matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver.
deviceMatchAttr = "hdf_light_driver"; // Keyword for matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver.
}
}
```
```
...
@@ -173,16 +180,16 @@ The light driver model provides APIs to obtain information about all the lights
...
@@ -173,16 +180,16 @@ The light driver model provides APIs to obtain information about all the lights
/* Receive the lightBrightness value passed in. Bits 24 to 31 are extension bits, bits 16 to 23 indicate red, bits 8 to 15 indicate green, and bits 0 to 7 indicate blue. If lightBrightness is not 0, enable the light in the specified color.
Set the light brightness to a value ranging from 0 to 255 if supported. */
/* If the specified blinking duration is less than the minimum time period supported by the system, the time configured by the system (in HCS) is used. */
/* If the specified blinking duration is less than the minimum time period supported by the system, the time configured by the system (in HCS) is used. */
@@ -298,16 +340,16 @@ The light driver model provides APIs to obtain information about all the lights
...
@@ -298,16 +340,16 @@ The light driver model provides APIs to obtain information about all the lights
After the driver is developed, develop auto-test cases in the light unit test to verify the basic functionalities of the driver. Use the developer self-test platform as the test environment.
After the driver is developed, develop auto-test cases in the light unit test to verify the basic functionalities of the driver. Use the developer self-test platform as the test environment.
```c++
```c++
/* Initialize the light interface instance before executing the test case. */
/* Initialize the LightInterfaceInstance before executing the test case. */
voidHdfLightTest::SetUpTestCase()
voidHdfLightTest::SetUpTestCase()
{
{
g_lightDev=NewLightInterfaceInstance();
g_lightDev=NewLightInterfaceInstance();
if(g_lightDev==nullptr){
if(g_lightDev==nullptr){
printf("test light get Module instance failed\n\r");
printf("test light get Module instance fail\n\r");