Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device Tree Support #15

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Device Tree Support #15

wants to merge 20 commits into from

Commits on Nov 25, 2024

  1. rust: zephyr-build: Conversion of Device Tree

    This code parses the DTS file generated by the Zephyr build, along with a
    few entries from the generated header file, to build a representation of
    the device tree.  There is a notion of "augments" that add various
    methods.  This is currently just hard-coded.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    551752e View commit details
    Browse the repository at this point in the history
  2. Create blinky application

    Blinky is a rust port of the samples/blinky application from the main
    zephyr repo.  It performs the same function, but using the DT and GPIO
    abstractions provided in the zephyr::sys module.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    518799a View commit details
    Browse the repository at this point in the history
  3. zephyr: sys: Create wrappers for gpio and flash

    Create two modules with wrappers for Zephyr gpio and flash devices.
    These have no methods, but allow the DT generated code to compile, with
    `get_instance` methods that return these values.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    fd6a98d View commit details
    Browse the repository at this point in the history
  4. zephyr: sys: gpio: Add is_ready method

    The is_ready method on both `Gpio` and `GpioPin` will ultimately call
    the underlying `device_is_ready` entry.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    75d0953 View commit details
    Browse the repository at this point in the history
  5. zephyr: sys: gpio: Add configure and pin toggle

    Create wrappers for config and pin toggle on the gpios.  This is enough
    to allow the blink app to work.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    c7a813c View commit details
    Browse the repository at this point in the history
  6. Eliminate warnings in the auto-generated device tree

    Move the module declaration for the device tree up into `lib.rs` to
    allow insertion of allow directives to eliminate documentation warnings
    on the generated devicetree.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    d0cabf5 View commit details
    Browse the repository at this point in the history
  7. zephyr-build: YAML-based augment code

    Instead of hardcoding all of the augments in the code, put these
    augments into a data structure.  Load the actual rules from a yaml file
    (with a future ability to extend this with per-app or per-module defined
    augments.
    
    Convert all of the existing hardcoded augment rules into the initial
    augment file.
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    bee6e96 View commit details
    Browse the repository at this point in the history
  8. zephyr: Add unsafe constructor to device types

    Add constructors to the individual device types.  These are unsafe, and
    are all referenced from the generated devicetree code.
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    d8f0967 View commit details
    Browse the repository at this point in the history
  9. zephyr: Enforce uniqueness on device tree wrappers

    Move all of the device implementations into a `zephyr::device` module.
    
    In this module, add a `Unique` type that supports the constructors on
    the device requiring a unique instance.
    
    The device tree augmentation code adds a declaration for these
    uniqueness markers for each instance, passing it into the constructor.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    bebfcbc View commit details
    Browse the repository at this point in the history
  10. zephyr: Make gpio interface much more "unsafe"

    Gpios in Zephyr are inherently unsafe.  There is a shared controller
    that is not just used by the pins defined here, but extensively across
    various drivers.
    
    As such, make all of the gpio pin operations themselves unsafe.
    
    We can help, a little bit, to at least enforce uniqueness with the
    Rust drivers that use gpios by requiring them to take a mutable instance
    of `GpioToken`, which has a singleton getter.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    f62cc26 View commit details
    Browse the repository at this point in the history
  11. zephyr-build: devicetree: Move augments into module

    The hard-coded augments in augment.rs are no long used, so remove them
    all, and move the config version into this file to avoid needing a
    separate module, just for the trait.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    5df90b1 View commit details
    Browse the repository at this point in the history
  12. zephyr-build: Include DT node presence configs

    Generate a full list of nodes that are present in the given device tree,
    and provide a tool that build.rs in the app can use to make these
    active.  This will allow conditionals like:
    
        #[cfg(dt = "aliases::led")]
    
    to be used, which will make it possible to handle nodes being present or
    not in the DTS.
    
    See a subsequent patch to the blinky sample for an example of usage.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    b529da5 View commit details
    Browse the repository at this point in the history
  13. samples: blinky: Domonstrate conditional DT compilation

    Show how an application can be conditional based on the presence of a
    node in the devicetree.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    ec6d92e View commit details
    Browse the repository at this point in the history
  14. zephyr: device: Split gpio and flash to own files

    Move this code out of the device.rs file, and into separate files for
    each module.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    3fc5708 View commit details
    Browse the repository at this point in the history
  15. platforms: Remove mps2

    The gpio device tree entries for the mps2 are defined with a
    `#gpio-cells` value of 1, despite these values not being interpreted by
    the driver, but by the devicetree code.  I'm not sure if these actually
    work with any of the demos, as it is unclear what the macros would do
    with this.  It doesn't give us a value to use for dt_flags.
    
    If someone wants to put in some effort to fix this, feel free.  But I
    don't think the problem is on the Rust side.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    21fbfc9 View commit details
    Browse the repository at this point in the history
  16. zephyr: gpio/flash: Allow constructor to be unused

    Prevents a warning on boards where there are no gpios or flash
    controllers are defined.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    b1f9a43 View commit details
    Browse the repository at this point in the history
  17. dt-rust: Add the nrf51 flash controller

    This allows a build on the nrf51, preventing an error when the
    partitions are detected, but the controller wasn't.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    6b599d2 View commit details
    Browse the repository at this point in the history
  18. zephyr-sys: Bump to newer bindgen

    This fixes a weird issue with bindgen missing the `__device_dts_ord_nn`
    declarations in some circumstances.  It is unclear when this was
    occuring, and hopefully it doesn't return at some point.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    dd1ccdd View commit details
    Browse the repository at this point in the history
  19. zephyr-build: Use parsed DT for both uses

    Instead of trying to hand off data through a file between the build of
    different crates, which was causing build failures in applications that
    need to use cfgs based on the presence of DT nodes, instead, just parse
    the DT again, and recalculate the node tree from it.
    
    This should fix build issues with the all nodes txt file missing.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    04ecb3f View commit details
    Browse the repository at this point in the history
  20. samples: blink: Fix for upstream API changes

    Several things have become unsafe, so use those in unsafe blocks.
    The GPIO driver now has a token that must be passed to each action, to
    enforce single threadded use.
    
    Signed-off-by: David Brown <[email protected]>
    d3zd3z committed Nov 25, 2024
    Configuration menu
    Copy the full SHA
    a74021a View commit details
    Browse the repository at this point in the history