ardnew / STUSB4500

Arduino library for USB PD sink controller (STUSB4500)
MIT License
29 stars 3 forks source link

STUSB4500

Arduino library (and Go module) for real-time capabilities of the STUSB4500 USB PD sink controller

This repository and README contains the original Arduino source code and docs. For the TinyGo port, please see the project referenced in the Go module section.


Arduino

Features include:

An example sketch is included that demonstrates callback functionality, analyzing available source power profiles, and setting a custom power profile.

Supported Devices

I can confirm the library functions on the following devices (similar devices should also be supported).

Key Meaning
:heavy_check_mark: Tested, working
:x: Tested, not working
:heavy_minus_sign: Not tested
Manufacturer Board MCU Status
Adafruit Trinket M0 ATSAMD21E18 (Cortex-M0) :heavy_check_mark:
Adafruit ItsyBitsy M0 ATSAMD21G18 (Cortex-M0) :heavy_check_mark:
Adafruit ItsyBitsy M4 ATSAMD51G19A (Cortex-M4) :heavy_check_mark:
Adafruit Feather M4 ATSAMD51J19A (Cortex-M4) :heavy_check_mark:
Adafruit Grand Central M4 ATSAMD51P20A (Cortex-M4) :heavy_check_mark:
Adafruit STM32F405 Feather STM32F405RG (Cortex-M4) :heavy_check_mark:
PJRC Teensy 3.2 MK20DX256VLH7 (Cortex-M4) :heavy_check_mark:
PJRC Teensy 3.6 MK66FX1M0 (Cortex-M4) :heavy_check_mark:
PJRC Teensy 4.0 MIMXRT1062DVL6A (Cortex-M7) :heavy_check_mark:
PJRC Teensy 4.1 MIMXRT1062DVJ6A (Cortex-M7) :heavy_check_mark:
STMicroelectronics STM32G0 Nucleo-64 STM32G071RB (Cortex-M0) :heavy_check_mark:
STMicroelectronics STM32G0 Nucleo-32 STM32G031K8 (Cortex-M0) :heavy_check_mark:
STMicroelectronics STM32G4 Nucleo-32 STM32G431KB (Cortex-M4) :heavy_check_mark:
Nordic Semiconductor nRF51x (Cortex-M0) :heavy_minus_sign:
Nordic Semiconductor nRF52x (Cortex-M4) :heavy_minus_sign:
Nordic Semiconductor nRF53x (Cortex-M33) :heavy_minus_sign:
Nordic Semiconductor nRF91x (Cortex-M33) :heavy_minus_sign:
Espressif ESP8266 :heavy_minus_sign:
Espressif ESP32 :heavy_minus_sign:

Troubleshooting

The PD protocol has very rigid timing requirements. These can be difficult to accommodate even in normal circumstances, but is even more difficult since there is another device (our STUSB4500) mediating communication over an I²C bus, which is rather slow. This is partly why the interrupts are vital to successful operation.

Point being, it may be difficult to achieve reliable results on some systems (such as AVR-based devices like Arduino Uno), and you may need to experiment with different microcontrollers.

If you have issues receiving cable attach/detach or PD capability discovery events, ensure the following:


TinyGo Upgrade

This library has been rewritten and ported to Go for use with the TinyGo Project, with improved performance, stability, and device compatibility.

If feasible, I highly recommend you use that software for future projects (tinygo-stusb4500), because it is subjected to more comprehensive testing, supports many more chips and boards, and won't suffer from the fate of Arduino's Wire (I²C) library (i.e., it will run better).