start work on EPR support

This commit is contained in:
Alessandro Mauri 2026-05-05 22:32:51 +02:00
parent 5e12e9a4a0
commit f7f5a16d64
3 changed files with 35 additions and 5 deletions

View File

@ -39,6 +39,7 @@
#define MAX_TIP_TEMP 500 #define MAX_TIP_TEMP 500
#define TURN_OFF_DELAY 2 #define TURN_OFF_DELAY 2
#define CYCLES_PER_MEASURE 2 #define CYCLES_PER_MEASURE 2
#define BOARD_MAX_VOLTAGE 28000
#endif // _FUNCONFIG_H #endif // _FUNCONFIG_H

View File

@ -422,7 +422,7 @@ __attribute__((noreturn)) int main(void)
u8g2_SetBitmapMode(u8g2, 1); u8g2_SetBitmapMode(u8g2, 1);
u8g2_SetFontMode(u8g2, 1); u8g2_SetFontMode(u8g2, 1);
u8g2_SetFont(u8g2, u8g2_font_5x8_tr); u8g2_SetFont(u8g2, u8g2_font_5x8_tr);
u8g2_DrawStr(u8g2, 0, 18, "negotiating..."); u8g2_DrawStr(u8g2, x_off+0, y_off+7, "Negotiating...");
u8g2_SendBuffer(u8g2); u8g2_SendBuffer(u8g2);
// Init USBPD // Init USBPD
@ -437,7 +437,7 @@ __attribute__((noreturn)) int main(void)
u8g2_SendBuffer(u8g2); u8g2_SendBuffer(u8g2);
Delay_Ms(5000); Delay_Ms(5000);
} else { } else {
pd_get_profile(&pd_profile, 100); pd_get_profile(&pd_profile, 60);
// TODO: let the user decide the power profile // TODO: let the user decide the power profile
pd_profile.set_temp = 200; pd_profile.set_temp = 200;

35
fw/pd.c
View File

@ -3,9 +3,14 @@
#define USBPD_IMPLEMENTATION #define USBPD_IMPLEMENTATION
#include "usbpd.h" #include "usbpd.h"
#include "funconfig.h"
#include "display.h"
#include "pd.h" #include "pd.h"
extern u8g2_t *u8g2;
static size_t cap_count = 0; static size_t cap_count = 0;
static USBPD_SPR_CapabilitiesMessage_t *capabilities = NULL; static USBPD_SPR_CapabilitiesMessage_t *capabilities = NULL;
static USBPD_Result_e result; static USBPD_Result_e result;
@ -35,7 +40,15 @@ bool pd_negotiate(USBPD_VCC_e vcc)
if (now - start > Ticks_from_Ms(5000)) { if (now - start > Ticks_from_Ms(5000)) {
break; break;
} }
Delay_Ms(100);
u8g2_ClearBuffer(u8g2);
u8g2_SetBitmapMode(u8g2, 1);
u8g2_SetFontMode(u8g2, 1);
u8g2_SetFont(u8g2, u8g2_font_5x8_tr);
u8g2_DrawStr(u8g2, 0, 8+7, USBPD_StateToStr(USBPD_GetState()));
u8g2_SendBuffer(u8g2);
Delay_Ms(1);
} }
if (result != eUSBPD_OK) { if (result != eUSBPD_OK) {
return false; return false;
@ -78,12 +91,28 @@ bool pd_get_profile(struct pd_profile_t *profile, uint16_t min_power)
// } // }
break; break;
case eUSBPD_PDO_AUGMENTED: case eUSBPD_PDO_AUGMENTED:
// TODO: EPR switch (pdo->Header.AugmentedType) {
case eUSBPD_APDO_SPR_PPS:
// TODO: SPR_PPS
break;
case eUSBPD_APDO_SPR_AVS:
// TODO: SPR AVS
break;
case eUSBPD_APDO_EPR_AVS:
/* TODO: EPR AVS
voltage = pdo->EPR_AVS.MaxVoltageIn100mV * 100;
current = pdo->EPR_AVS.PeakCurrent * 1000;
power = pdo->EPR_AVS.PDPIn1W;
*/
break;
default:
break;
}
break; break;
} }
// Selects the first PDO that meets the minimum power requirement // Selects the first PDO that meets the minimum power requirement
if (power >= min_power) { if (power >= min_power && voltage <= BOARD_MAX_VOLTAGE) {
if (USBPD_SelectPDO(i, 0) != eUSBPD_OK) { if (USBPD_SelectPDO(i, 0) != eUSBPD_OK) {
return false; return false;
} }