AP33772S Driver
A platform-agnostic Rust driver for the AP33772S USB Power Delivery (USB-PD) Sink Controller.
Features
- Platform-agnostic: Built on
embedded-haltraits for maximum compatibility - USB-PD Support: Full support for USB Power Delivery negotiation
- SPR and EPR: Supports both Standard Power Range (SPR) and Extended Power Range (EPR) modes
- Programmable Power: Support for Programmable Power Supply (PPS) and Adjustable Voltage Supply (AVS)
- Protection Features: Built-in over-voltage, over-current, over-temperature, and under-voltage protection
- no_std Compatible: Works in embedded environments without heap allocation (with
allocfeature)
Supported Voltages
The AP33772S supports negotiation for the following standard voltages:
- 5V (USB-PD default)
- 9V
- 12V
- 15V
- 20V
- 28V (EPR)
- 36V (EPR)
- 40V (EPR)
- 48V (EPR)
The driver supports both Standard Power Range (SPR) and Extended Power Range (EPR) modes. Custom voltages and currents are also supported through programmable PDOs.
Quick Start
Add this to your Cargo.toml:
[]
= "0.1"
For std environments, enable the std feature:
[]
= { = "0.1", = ["std"] }
Example Usage
use ;
// Create driver instance
let mut pd_controller = AP33772Snew;
// Initialize the controller (requires I2C implementation)
pd_controller.init?;
// Request 12V from the USB-PD source
pd_controller.request_voltage?;
// Read current status
let status = pd_controller.get_status?;
println!;
// Request custom voltage/current (if supported by source)
pd_controller.request_custom_voltage?; // 15V, 2A
// Get available power capabilities
for pdo in pd_controller.get_pdo_list
Platform Integration
This driver uses the embedded-hal I2C traits, making it compatible with any platform that provides an I2C implementation. Here are examples for popular platforms:
ESP32 (esp-idf-hal)
use *;
use AP33772S;
// Set up I2C
let i2c_config = new.baudrate;
let mut i2c = new?;
// Use the driver
let mut pd_controller = AP33772Snew;
pd_controller.init?;
STM32 (stm32f4xx-hal)
use I2c;
use AP33772S;
let mut i2c = new;
let mut pd_controller = AP33772Snew;
pd_controller.init?;
Raspberry Pi (rppal)
use I2c;
use AP33772S;
let mut i2c = new?;
let mut pd_controller = AP33772Snew;
pd_controller.init?;
Error Handling
The driver uses a comprehensive error type that wraps the underlying I2C errors:
match pd_controller.request_voltage
Register Map
The driver provides access to all AP33772S registers through constants:
- Status and Control:
REG_STATUS,REG_CONFIG,REG_SYSTEM - Measurements:
REG_VOLTAGE,REG_CURRENT,REG_TEMP - Power Delivery:
REG_VREQ,REG_IREQ,REG_PD_REQMSG - Source Capabilities:
REG_SRCPDO,REG_SRC_SPR_PDO1..REG_SRC_EPR_PDO13
Protection Features
Configure the built-in protection features:
// Enable all protections
pd_controller.configure_protections?;
Power Data Objects (PDOs)
The driver automatically enumerates all available PDOs from the connected source:
for pdo in pd_controller.get_pdo_list
Advanced Features
VOUT Control
Control the output voltage manually:
// Auto control (default)
pd_controller.set_vout_auto_control?;
// Force output off
pd_controller.force_vout_off?;
// Force output on
pd_controller.force_vout_on?;
Hard Reset
Perform a USB-PD hard reset:
pd_controller.hard_reset?;
Specifications
- I2C Address: 0x52 (7-bit)
- I2C Speed: Up to 400kHz
- Supply Voltage: 3.3V or 5V
- Temperature Range: -40°C to +85°C
- USB-PD Compliance: USB-PD 3.1 compatible
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.