pub struct GpioHandler {}Expand description
Contains the configuration and the implementation for the GPIO handler.
Implementations§
Source§impl GpioHandler
impl GpioHandler
Sourcepub fn check_valid_gpio_pin_config(
config: &GpioHandlerConfig,
) -> Result<(), GpioHandlerError>
pub fn check_valid_gpio_pin_config( config: &GpioHandlerConfig, ) -> Result<(), GpioHandlerError>
Checks if the GPIO pin configuration is valid and free from conflicts.
This function performs two essential validation checks on the configured GPIO pins:
- Range Check: Ensures all pins fall within the permissible operating
range defined by
GPIO_MINandGPIO_MAX. - Uniqueness Check: Verifies that all assigned pins are distinct, preventing multiple devices from being configured to the same physical pin.
§Arguments
config- TheGpioHandlerConfigstruct containing the GPIO pin assignments.
§Returns
An empty Result (Ok(())) if all GPIO pins are valid.
§Errors
Returns a GpioHandlerError if any validation check fails:
GpioHandlerError::PinOutsideRange: If any configured GPIO pin is outside the valid range (e.g., less than or equal to 3, or greater than or equal to 28).GpioHandlerError::PinDuplicateValue: If the same GPIO pin is assigned to more than one device.
Sourcepub fn new(
config: GpioHandlerConfig,
) -> Result<Option<GpioHandler>, GpioHandlerError>
pub fn new( config: GpioHandlerConfig, ) -> Result<Option<GpioHandler>, GpioHandlerError>
Creates a new GpioHandler instance for development or non-target platforms.
This constructor is activated when compiling for a non-Linux OS or when the
target_hw feature is disabled. It allows the application to run in a
simulated mode without requiring real GPIO hardware.
§Arguments
config- Configuration data for the GPIO handler.
§Returns
A Result containing Ok(None) if the configuration is valid and use_simulator
is true, indicating that no hardware handle is needed.
§Errors
Returns a GpioHandlerError if initialization fails:
GpioHandlerError::PlatformNotSupported: Ifuse_simulatorisfalse, as hardware access is not possible on the current platform.GpioHandlerError::PinOutsideRangeorPinDuplicateValue: If the pin configuration is invalid (propagated fromcheck_valid_gpio_pin_config)