USB-PD driver stack for the FUSB302.
This is a modified fork of the PD Buddy firmware stack. All inspiration and groking of the PD spec belongs to Clara Hobb's.
This was originally part of the IronOS project but has been extracted to allow for re-use and testing in isolation. The code has been moved to C++ static classes and had minor changes to improve its features for its intended application. As part of this, some logic that was originally in the PD Buddy firmware has been removed.
To add this library to your project, either download the source code as a zip file up there ^ or add this library as a git submodule.
An example implementation of this library is available for the black pill STM32F401.
Steps for implementation:
The minimum required function calls are the fusb302 objects irq handler and the thread call in the policy engine.
The IRQ call will query over the I2C bus the status of the fusb object, and if a message is pending, read it in.
The thread call on the policy engine will perform at most one step of the state machine. It will return true if there are more iterations to perform.
This allows for the implementer to decide how to handle iterations, and makes each call a calculatable maximum execution time.
If this is a not a concern, a tight while loop (while (pe.thread){}
) can be used.
Once an interrupt is recieved from the fusb302, it is reccomended to iterate the thread until it stops (to avoid backlog in processing).
The key function to implement is the pdbs_dpm_evaluate_capability
.
This is provided the chargers advertised power options, and should assemble a response to be sent back.
You can implement any logic that you desire to select the option.