Drivers can use component framework's [structured configuration](https://fuchsia.dev/docs/reference/components/structured_config)
to read values provided at product assembly time (see [providing configuration](https://fuchsia.dev/docs/development/drivers/driver_guides/configuration/providing_configuration)).
See the example [C++](https://cs.opensource.google/fuchsia/fuchsia/+/main:/examples/drivers/config/cpp/) and [Rust](https://cs.opensource.google/fuchsia/fuchsia/+/main:/examples/drivers/config/rust/) drivers.

## Include the configuration use in CML

In your driver CML, `use` the `config` capability with the name of your configuration:

    use: [
        {
            config: "fuchsia.power.SuspendEnabled",
            key: "suspend_enabled",
            type: "bool",
        },
    ],

## Set up the build

In the build file, you need to declare the manifest target manually, so that you can use the
build target to generate the library to access the configuration:

### C++

    fuchsia_component_manifest("component-manifest") {
      component_name = "example_config_driver"
      manifest = "meta/config_driver.cml"
    }

    fuchsia_structured_config_cpp_elf_lib("example-config-driver-config") {
      cm_label = ":component-manifest"
    }

    fuchsia_driver_component("component") {
      cm_label = ":component-manifest"
      deps = [
        ":bind",
        ":driver",
      ]
      info = "meta/component-info.json"
    }

    fuchsia_cc_driver("driver") {
      output_name = "example_config_driver"
      sources = [ "config_driver.cc" ]
      deps = [
        ":example-config-driver-config",
        "//sdk/lib/driver/component/cpp",
        "//src/devices/lib/driver:driver_runtime",
      ]
    }

### Rust

    fuchsia_component_manifest("manifest") {
      component_name = "example_config_driver_rust"
      manifest = "meta/config_driver.cml"
    }

    fuchsia_structured_config_rust_lib("example-config-driver-config") {
      cm_label = ":manifest"
    }

    fuchsia_driver_component("component") {
      cm_label = ":manifest"
      deps = [
        ":bind",
        ":driver",
      ]
      info = "meta/component-info.json"
    }

    fuchsia_rust_driver("driver") {
      edition = "2024"

      output_name = "example_config_driver_rust"
      sources = [ "src/lib.rs" ]
      deps = [
        ":example-config-driver-config",
        "//sdk/fidl/fuchsia.driver.framework:fuchsia.driver.framework_rust",
        "//sdk/lib/driver/component/rust",
        "//sdk/lib/driver/runtime/rust",
        "//sdk/rust/zx",
        "//third_party/rust_crates:anyhow",
        "//third_party/rust_crates:log",
      ]
    }

## Access the configuration in code

You can now access the configuration values in the code by using the generated library.

1. Include the library dependency:

   ### C++

       #include "examples/drivers/config/cpp/example_config_driver_config.h"

   ### Rust

       use example_config_driver_config::Config;

2. Use the library to access the configuration from the start arguments of the driver:

   ### C++

       auto config = context.take_config<example_config_driver_config::Config>();
       fdf::info("My config value is: {}", config.suspend_enabled());

   ### Rust

       let config = context.take_config::<Config>()?;
       info!("My config value is: {}", config.suspend_enabled);

[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/development/drivers/driver_guides/configuration/reading_configuration.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/development/drivers/driver_guides/configuration/reading_configuration.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/development/drivers/driver_guides/configuration/reading_configuration.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/development/drivers/driver_guides/configuration/reading_configuration.md "Edit the source code of this page")