Reviewed on: 2024-02-20
Simple Driver is an example that showcase how to write a DFv1 driver with common driver patterns:
This example also demonstrate the driver lifecycle such as Init(), Suspend(), and Release().
To include the driver to your build, append --with //examples/drivers:drivers
to your fx set
command. For example:
$ fx set core.x64 --with //examples/drivers:drivers $ fx build
Register the driver by running this command
$ ffx driver register fuchsia-pkg://fuchsia.com/simple_dfv1#meta/simple_dfv1.cm
Verify that fuchsia-pkg://fuchsia.com/simple_dfv1#meta/simple_dfv1.cm
shows up in this command
ffx driver list
Add a test node that binds to the driver:
$ ffx driver test-node add simple_node_v1 gizmo.example.TEST_NODE_ID=simple_driver_v1
Run the following command to verify that the driver is bound to the node:
$ ffx driver list-devices -v simple_node_v1
You should see something like this:
Name : simple_node_v1 Moniker : dev.simple_node Driver : fuchsia-pkg://fuchsia.com/simple_dfv1#meta/simple_dfv1.cm 2 Properties [ 1/ 2] : Key "gizmo.example.TEST_NODE_ID" Value "simple_driver_v1" [ 2/ 2] : Key "fuchsia.platform.DRIVER_FRAMEWORK_VERSION" Value 0x000002 0 Offers Name : simple_child Moniker : dev.simple_node_v1.simple_child Driver : unbound 2 Properties [ 1/ 2] : Key "fuchsia.test.TEST_CHILD" Value "simple" [ 2/ 2] : Key "fuchsia.platform.DRIVER_FRAMEWORK_VERSION" Value 0x000002 [ 3/ 3] : Key "fuchsia.driver.compat.Service" Value "fuchsia.driver.compat.Service.ZirconTransport" 1 Offers Service: fuchsia.driver.compat.Service Source: dev.simple_node_v1 Instances: default
If you want to explore the driver lifecycle and test the driver's stop functions, stop the driver by removing the node:
$ ffx driver test-node remove simple_node_v1
View the driver logs with ffx log --filter simple
to see the execution order of the driver functions.
The core implementation is in simple_driver.cc
.