1+ #ifndef MEX_HAL_DEVICE_TREE_H
2+ #define MEX_HAL_DEVICE_TREE_H
3+
4+ #include < cstdint>
5+ #include < string>
6+ #include < vector>
7+ #include < optional>
8+
9+ // / @brief mex_hal Hardware Abstraction Layer - Device Tree Representation \namespace mex_hal
10+ namespace mex_hal
11+ {
12+ // / @brief Device Tree Property \struct DTProperty
13+ struct DTProperty
14+ {
15+ std::string name;
16+ std::vector<uint8_t > value;
17+ };
18+
19+ // / @brief Device Tree Node \struct DTNode
20+ struct DTNode
21+ {
22+ std::string name;
23+ std::string path;
24+ std::vector<DTProperty> properties;
25+ std::vector<DTNode> children;
26+ };
27+
28+ // / @brief Device Tree Interface \class DeviceTreeInterface
29+ class DeviceTreeInterface
30+ {
31+ public:
32+ /* *
33+ * @brief Virtual descturto
34+ */
35+ virtual ~DeviceTreeInterface () = default ;
36+
37+ /* *
38+ * @brief Load the device tree from a specified path
39+ * @param overlayPath The file path to the device tree overlay (e.g., .dtbo file)
40+ * @return A boolean indicating success or failure of loading the device tree
41+ */
42+ virtual bool loadOverlay (const std::string& overlayPath) = 0;
43+
44+ /* *
45+ * @brief Remove a previously loaded device tree overlay by name
46+ * @param overlayName The name of the device tree overlay to remove (e.g., "my_overlay")
47+ * @return A boolean indicating success or failure of removing the device tree overlay
48+ */
49+ virtual bool removeOverlay (const std::string& overlayName) = 0;
50+
51+ /* *
52+ * @brief List the currently loaded device tree overlays
53+ * @return A vector of strings containing the names of the currently loaded device tree overlays
54+ */
55+ [[nodiscard]] virtual std::vector<std::string> listOverlays () const = 0;
56+
57+ /* *
58+ * @brief Read a property from a device tree node
59+ * @param nodePath The path to the device tree node (e.g., "/soc/i2c@40000000")
60+ * @param propertyName The name of the property to read (e.g., "compatible")
61+ * @return An optional containing the DTProperty if found, or std::nullopt if not found
62+ */
63+ [[nodiscard]] virtual std::optional<DTProperty> readProperty (
64+ const std::string& nodePath,
65+ const std::string& propertyName) const = 0;
66+
67+ /* *
68+ * @brief Check if a device tree node exists at the specified path
69+ * @param nodePath A string representing the path to the device tree node (e.g., "/soc/i2c@40000000")
70+ * @return The boolean value indicating whether the node exists (true) or not (false)
71+ */
72+ [[nodiscard]] virtual bool nodeExists (const std::string& nodePath) const = 0;
73+
74+ /* *
75+ * @brief Get the compatible string of a device tree node
76+ * @param nodePath The path to the device tree node (e.g., "/soc/i2c@40000000")
77+ * @return A string containing the compatible value if found, or an empty string if not found
78+ */
79+ [[nodiscard]] virtual std::string getCompatible (const std::string& nodePath) const = 0;
80+
81+ /* *
82+ * @brief Get the status of a device tree node
83+ * @param nodePath The path to the device tree node (e.g., "/soc/i2c@40000000")
84+ * @return A string containing the status value if found, or an empty string if not found
85+ */
86+ [[nodiscard]] virtual std::string getNodeStatus (const std::string& nodePath) const = 0;
87+
88+ protected:
89+ inline static const std::string DT_BASE_PATH = " /proc/device-tree" ;
90+ inline static const std::string DT_OVERLAY_PATH = " /sys/kernel/config/device-tree/overlays" ;
91+ };
92+ }
93+
94+ #endif // MEX_HAL_DEVICE_TREE_H
0 commit comments