//! Device tree driver macros

/// Performs registration of a device tree driver.
///
/// The `compatible` list should contain strings, ordered from the most specific to the most
/// generic implementation supported.
///
/// The registration happens in runtime, after the kernel sets up memory management, through the
/// `.init_array`-based mechanism.
pub macro device_tree_driver(
    compatible: [$($compatible:literal),+ $(,)?],
    driver: $driver:tt
) {
    struct __DtDriver;

    impl $crate::driver::Driver for __DtDriver $driver

    static __DT_DRIVER: __DtDriver = __DtDriver;
    #[link_section = ".init_array"]
    #[used]
    static __REGISTER_FN: extern "C" fn() = __register_fn;

    extern "C" fn __register_fn() {
        $crate::driver::register_driver(
            &[$($compatible),+],
            &__DT_DRIVER
        )
    }
}
