Skip to content

Commit 49e709b

Browse files
committed
Fix SOP sequence decoding for devices with UCPD
1 parent 171c215 commit 49e709b

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=USBPowerDelivery
2-
version=1.0.2
2+
version=1.0.3
33
author=Manuel Bl. <manuel.bleichenbacher@gmail.com>
44
maintainer=Manuel Bl. <manuel.bleichenbacher@gmail.com>
55
sentence=USB Power Delivery for Arduino.

src/PDPhySTM32UCPD.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ void PDPhySTM32UCPD::handleInterrupt() {
219219
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);
220220
if ((status & UCPD_SR_RXERR) == 0) {
221221
uint32_t orderedSet = LL_UCPD_ReadRxOrderSet(UCPD1);
222-
rxMessage->sopSequence = orderedSet <= LL_UCPD_ORDERED_SET_SOP2_DEBUG
223-
? static_cast<PDSOPSequence>(orderedSet) : PDSOPSequence::cableReset;
222+
rxMessage->sopSequence = mapSOPSequence(orderedSet);
224223
rxMessage->cc = ccActive;
225224
PowerController.onMessageReceived(rxMessage);
226225

@@ -251,4 +250,23 @@ void PDPhySTM32UCPD::handleInterrupt() {
251250
}
252251
}
253252

253+
PDSOPSequence PDPhySTM32UCPD::mapSOPSequence(uint32_t orderedSet) {
254+
switch (orderedSet) {
255+
case LL_UCPD_RXORDSET_SOP:
256+
return PDSOPSequence::sop;
257+
case LL_UCPD_RXORDSET_SOP1:
258+
return PDSOPSequence::sop1;
259+
case LL_UCPD_RXORDSET_SOP2:
260+
return PDSOPSequence::sop2;
261+
case LL_UCPD_RXORDSET_SOP1_DEBUG:
262+
return PDSOPSequence::sop1Debug;
263+
case LL_UCPD_RXORDSET_SOP2_DEBUG:
264+
return PDSOPSequence::sop2Debug;
265+
case LL_UCPD_RXORDSET_CABLE_RESET:
266+
return PDSOPSequence::cableReset;
267+
default:
268+
return PDSOPSequence::invalid;
269+
}
270+
}
271+
254272
#endif

src/PDPhySTM32UCPD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct PDPhySTM32UCPD : PDPhy {
2424
static void enableCommunication(int cc);
2525
static void disableCommunication();
2626
static void enableRead();
27+
static PDSOPSequence mapSOPSequence(uint32_t orderedSet);
2728

2829
static void handleInterrupt();
2930

test/VoltageChange/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void setup() {
3030

3131
void loop() {
3232
PowerSink.poll();
33-
PDProtocolAnalyzer::poll();
33+
PDProtocolAnalyzer.poll();
3434

3535
if (isUSBPDSource && hasExpired(nextVoltageChangeTime))
3636
switchVoltage();

0 commit comments

Comments
 (0)