class BothSerials : public Print {
public:
size_t write(uint8_t c) override {
return 1;
}
};
static BothSerials out;
static void askForVolts(long volts) {
if (volts != 5 && volts != 9 && volts != 12 && volts != 15 && volts != 20) {
out.println("Send 5, 9, 12, 15 or 20.");
return;
}
out.print("Asking for up to ");
out.print(volts);
}
static void printStatus() {
out.print("profiles:");
for (uint8_t i = 0; i < count; i++) {
out.print(' ');
out.print(profiles[i].millivolts / 1000.0, 1);
out.print("V/");
out.print(profiles[i].milliamps / 1000.0, 2);
out.print('A');
}
out.print(" contract: offer ");
out.print(", ");
out.print(" mA VBUS: ");
out.println(" V");
}
const unsigned long start =
millis();
out.println("USB-PD controller not answering");
while (true) {}
}
out.println("Send 5, 9, 12, 15 or 20 to set the highest voltage.");
}
const long volts =
Serial.parseInt();
if (volts != 0) askForVolts(volts);
}
const long volts =
Serial1.parseInt();
if (volts != 0) askForVolts(volts);
}
printStatus();
}
SerialUARTClass Serial1
UART0 on D1 (TX) and D0 (RX).
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
unsigned long millis(void)
Milliseconds since the board started.
void delay(unsigned long)
Waits a number of milliseconds.
bool begin()
Sets up I2C1 and the control pins.
uint8_t getProfiles(Profile *out)
Reads the active profiles.
uint8_t contractPosition()
Which charger offer is in use.
uint16_t contractMilliamps()
Operating current agreed in the current contract.
constexpr uint8_t kMaxProfiles
Number of profiles the chip holds.
Definition stusb4500.h:44
uint8_t boardProfiles(uint16_t max_millivolts, Profile *out)
The board's profiles for Tools > USB-PD Power.
bool setProfiles(const Profile *profiles, uint8_t count)
Loads 1-3 profiles and renegotiates if they differ from the current ones.
uint32_t vbusMillivolts()
VBUS measured by the on-board ADC (MAX11635 channel 3).
One sink profile (PDO): a voltage the board accepts and the current it draws.
Definition stusb4500.h:38
Driver for the on-board STUSB4500 USB Power Delivery sink controller (U6).