motor-driver-hal-0.1.0 has been yanked.
Motor Driver HAL
A hardware abstraction layer (HAL) for motor drivers built on top of embedded-hal traits. This crate provides a generic, platform-independent interface for controlling various types of motor drivers commonly used in embedded systems and robotics applications.
Supported Motor Driver Types
- H-Bridge Drivers: Bidirectional DC motor control with optional brake functionality
- ✅ BTS7960: High-current H-bridge motor driver module
- Single Direction Drivers: Simple unidirectional motor control
- Dual H-Bridge: Independent control of two motors
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
For no_std environments, disable the default features:
[]
= { = "0.1.0", = false }
Quick Start
use ;
use OutputPin;
use SetDutyCycle;
// Your platform-specific GPIO and PWM implementations
// (see examples for Raspberry Pi implementation)
// Create motor driver instance
let enable_pin = your_gpio_pin;
let pwm_channel = your_pwm_channel;
let mut motor = new_single_enable_single_pwm;
// Initialize and use the motor
motor.initialize?;
motor.enable?;
motor.set_speed?; // 50% forward speed
motor.set_speed?; // 30% reverse speed
motor.brake?;
motor.stop?;
Examples
The example/ directory contains practical implementations for different scenarios:
Available Examples
basic_motor- Simple motor control demonstrationspeed_control- Variable speed control with PWMdirection_control- Forward/reverse direction controlbrake_test- Braking functionality demonstrationencoder_monitor- Motor with encoder feedback
Running Examples
# Navigate to examples directory
# Run a specific example (requires Raspberry Pi hardware)
API Overview
Core Trait: MotorDriver
All motor drivers implement the MotorDriver trait:
Speed Values
Speed is controlled using signed 16-bit integers:
- Positive values: Forward direction (0 to max_duty)
- Negative values: Reverse direction (-max_duty to 0)
- Zero: Motor stopped
Motor States
- Uninitialized: Fresh driver instance, not ready for use
- Initialized: Driver configured and ready, but motor disabled
- Enabled: Motor powered and ready to move
- Disabled: Motor power cut, safe state
Hardware Integration
To use this crate with your specific hardware platform:
- Implement the
embedded-haltraits for your GPIO and PWM peripherals - Create wrapper types that adapt your platform's types to the HAL traits
- Use the motor driver with your wrapped types
Supported Platforms
- Raspberry Pi (via
rppalcrate - see examples) - ESP32 (via
esp-hal) - STM32 (via
stm32-halfamily) - Any platform with
embedded-halsupport