[input_sample] Sample Input Driver Using input_reports_reader

Sample Input Driver implementing fuchsia.input.report which uses
input_reports_reader to send fake mouse reports every 1 second.

Test: tested on QEMU that we can use `ffx driver print-input-report
read` to read the fake reports from sample driver.
      bazel run --config=fuchsia_x64 src/input_sample:pkg.component
      tools/ffx driver print-input-report descriptor
      tools/ffx driver print-input-report read

Bug: 103070
Change-Id: I3eeb571f044e4570aa93c16607e5def0a30134ef
Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-samples/drivers/+/692855
Reviewed-by: Suraj Malhotra <surajmalhotra@google.com>
Commit-Queue: Ruby Zhuang <rdzhuang@google.com>
Reviewed-by: David Gilhooley <dgilhooley@google.com>
6 files changed
tree: f5f429ef26b70f12500694ab446f2ecb41fab428
  1. scripts/
  2. src/
  3. third_party/
  4. tools/
  5. .bazelrc
  6. .clang-format
  7. .gitignore
  8. .gitmodules
  9. AUTHORS
  10. CONTRIBUTING.md
  11. LICENSE
  12. OWNERS
  13. PATENTS
  14. README.md
  15. update_dependencies.md
  16. WORKSPACE.bazel
README.md

Fuchsia samples using the Fuchsia SDK

This repository contains instructions and source code to build, package and run Fuchsia samples using only the Fuchsia SDK. To update the dependencies of this repository, follow the instructions in update_dependencies.md.

Requirements

  1. Install Bazel version 5.1 or later by following the instructions at https://bazel.build/install. In some Linux distributions, sudo apt-get install bazel should be enough.

  2. Make sure this repository has the required submodules:

    git submodule update --recursive --init
    
  3. Ensure that there are Fuchsia SSH keys in your host machine. You will need them for running the Fuchsia emulator.

     [[ -f "${HOME}/.ssh/fuchsia_ed25519" ]] || ssh-keygen -P "" -t ed25519 -f "${HOME}/.ssh/fuchsia_ed25519" -C "${USER}@$(hostname -f) Shared SSH Key for Fuchsia"
    
     [[ -f "${HOME}/.ssh/fuchsia_authorized_keys" ]] || ssh-keygen -y -f "${HOME}/.ssh/fuchsia_ed25519" > "${HOME}/.ssh/fuchsia_authorized_keys"
    

Build, run and test the samples

Now the repository is ready to build the samples.

  1. Build the samples:

    Note: in order to use an SDK produced by a local Fuchsia platform tree, you can set an environment variable named LOCAL_FUCHSIA_PLATFORM_BUILD as described in https://fuchsia.googlesource.com/sdk-integration/+/0503b02c059a6de76242280b467898358ba30ae3

    bazel build --config=fuchsia_x64 src:samples_repository
    

    This command will build and package all the samples.

  2. If using an emmulator:

    1. Fetch the system images

      tools/ffx product-bundle get workstation.qemu-x64
      
    2. Start the emulator

      tools/ffx emu start workstation.qemu-x64 --headless \
         --kernel-args "driver_manager.use_driver_framework_v2=true" \
         --kernel-args "driver_manager.root-driver=fuchsia-boot:///#meta/platform-bus.cm" \
         --kernel-args "devmgr.enable-ephemeral=true"
      
    3. The product bundle comes with on-demand packages in a separate repository. Use the following command to register it with the emulator:

      tools/ffx target repository register -r workstation.qemu-x64 --alias fuchsia.com
      
  3. If using a physical device like a Pixelbook Go:

    1. Fetch the system images

      tools/ffx product-bundle get workstation.qemu-x64-dfv2
      
    2. Prepare and connect the Pixelbook Go, by flashing and/or paving it (not covered here), and connect using Ethernet.

    3. The product bundle comes with on-demand packages in a separate repository. Use the following command to register it with the device:

      tools/ffx target repository register -r workstation.qemu-x64-dfv2 --alias fuchsia.com
      
    4. Update (OTA) the device to the version of the SDK:

      tools/ffx target update check-now --monitor
      
  4. (optional) watch the device log in a separate window

    tools/ffx log
    
  5. Load the sample drivers

    Now you are ready to register a driver. Starting with the example driver:

    First, let's confirm that the driver is not loaded:

    tools/ffx driver list | grep example_driver
    

    The command above should not return any driver named “example_driver” because it has not been registered.

    Now register the driver:

    bazel run --config=fuchsia_x64 src/example_driver:pkg.component
    

    The driver now should show in the list of loaded drivers:

    tools/ffx driver list | grep example_driver
    fuchsia-pkg://bazel.pkg.component/example_driver#meta/example_driver.cm
    

    You can also watch in the log to see if the driver is loaded correctly. The ffx log window should show a message similar to:

    [88.961][bootstrap/driver_manager][driver_manager.cm][I] Loaded driver 'fuchsia-pkg://bazel.pkg.component/example_driver#meta/example_driver.cm'