diff options
Diffstat (limited to 'src/Platform')
-rw-r--r-- | src/Platform/Platform.cpp | 58 | ||||
-rw-r--r-- | src/Platform/Platform.h | 15 | ||||
-rw-r--r-- | src/Platform/Tasks.cpp | 13 |
3 files changed, 73 insertions, 13 deletions
diff --git a/src/Platform/Platform.cpp b/src/Platform/Platform.cpp index 08489c13..e82780c4 100644 --- a/src/Platform/Platform.cpp +++ b/src/Platform/Platform.cpp @@ -3761,6 +3761,29 @@ void Platform::ResetChannel(size_t chan) noexcept #endif } +#if defined(DUET3_MB6HC) + +// this is safe to call before Platform has been created +/*static*/ BoardType Platform::GetMB6HCBoardType() noexcept +{ + // Driver 0 direction has a pulldown resistor on v0.6 and v1.0 boards, but not on v1.01 or v1.02 boards + // Driver 1 has a pulldown resistor on v0.1 and v1.0 boards, however we don't support v0.1 and we don't care about the difference between v0.6 and v1.0, so we don't need to read it + // Driver 2 has a pulldown resistor on v1.02 only + pinMode(DIRECTION_PINS[2], INPUT_PULLUP); + pinMode(DIRECTION_PINS[0], INPUT_PULLUP); + delayMicroseconds(20); // give the pullup resistor time to work + if (digitalRead(DIRECTION_PINS[2])) + { + return (digitalRead(DIRECTION_PINS[0])) ? BoardType::Duet3_6HC_v101 : BoardType::Duet3_6HC_v06_100; + } + else + { + return BoardType::Duet3_6HC_v102; + } +} + +#endif + // Set the board type. This must be called quite early, because for some builds it relies on pins not having been programmed for their intended use yet. void Platform::SetBoardType(BoardType bt) noexcept { @@ -3774,21 +3797,20 @@ void Platform::SetBoardType(BoardType bt) noexcept ? BoardType::Duet3Mini_WiFi : BoardType::Duet3Mini_Ethernet; #elif defined(DUET3_MB6HC) - // Driver 0 direction has a pulldown resistor on v0.6 and v1.0 boards, but not on v1.01 or v1.02 boards - // Driver 1 has a pulldown resistor on v0.1 and v1.0 boards, however we don't support v0.1 and we don't care about the difference between v0.6 and v1.0, so we don't need to read it - // Driver 2 has a pulldown resistor on v1.02 only - pinMode(DIRECTION_PINS[2], INPUT_PULLUP); - pinMode(DIRECTION_PINS[0], INPUT_PULLUP); - delayMicroseconds(20); // give the pullup resistor time to work - if (digitalRead(DIRECTION_PINS[2])) + board = GetMB6HCBoardType(); + if (board == BoardType::Duet3_6HC_v102) { - board = (digitalRead(DIRECTION_PINS[0])) ? BoardType::Duet3_6HC_v101 : BoardType::Duet3_6HC_v06_100; - powerMonitorVoltageRange = PowerMonitorVoltageRange_v101; + powerMonitorVoltageRange = PowerMonitorVoltageRange_v102; + DiagPin = DiagPin102; + ActLedPin = ActLedPin102; + DiagOnPolarity = DiagOnPolarity102; } else { - board = BoardType::Duet3_6HC_v102; - powerMonitorVoltageRange = PowerMonitorVoltageRange_v102; + powerMonitorVoltageRange = PowerMonitorVoltageRange_v101; + DiagPin = DiagPinPre102; + ActLedPin = ActLedPinPre102; + DiagOnPolarity = DiagOnPolarityPre102; } driverPowerOnAdcReading = PowerVoltageToAdcReading(10.0); driverPowerOffAdcReading = PowerVoltageToAdcReading(9.5); @@ -4646,6 +4668,20 @@ uint32_t Platform::Random() noexcept #endif +void Platform::SetDiagLed(bool on) const noexcept +{ + digitalWrite(DiagPin, XNor(DiagOnPolarity, on)); +} + +#if SUPPORT_MULTICAST_DISCOVERY + +void Platform::InvertDiagLed() const noexcept +{ + digitalWrite(DiagPin, !digitalRead(DiagPin)); +} + +#endif + #if HAS_CPU_TEMP_SENSOR && SAME5x void Platform::TemperatureCalibrationInit() noexcept diff --git a/src/Platform/Platform.h b/src/Platform/Platform.h index 1ed5186b..22735a98 100644 --- a/src/Platform/Platform.h +++ b/src/Platform/Platform.h @@ -672,7 +672,17 @@ public: #endif #if SUPPORT_CAN_EXPANSION - void OnProcessingCanMessage() noexcept; // called when we start processing any CAN message except for regular messages e.g. time sync + void OnProcessingCanMessage() noexcept; // called when we start processing any CAN message except for regular messages e.g. time sync +#endif + +#if defined(DUET3_MB6HC) + static BoardType GetMB6HCBoardType() noexcept; // this is safe to call before Platform has been created +#endif + + void SetDiagLed(bool on) const noexcept; + +#if SUPPORT_MULTICAST_DISCOVERY + void InvertDiagLed() const noexcept; #endif protected: @@ -894,6 +904,9 @@ private: float powerMonitorVoltageRange; uint16_t driverPowerOnAdcReading; uint16_t driverPowerOffAdcReading; + Pin DiagPin; + Pin ActLedPin; + bool DiagOnPolarity; #endif bool autoSaveEnabled; diff --git a/src/Platform/Tasks.cpp b/src/Platform/Tasks.cpp index 7d7c39e8..4d42d332 100644 --- a/src/Platform/Tasks.cpp +++ b/src/Platform/Tasks.cpp @@ -128,8 +128,19 @@ void *Tasks::GetNVMBuffer(const uint32_t *_ecv_array null stk) noexcept // Application entry point [[noreturn]] void AppMain() noexcept { +#if defined(DUET3_MB6HC) // for MB6HC the Status and Activity pins and polarity depend on the board version + const BoardType bt = Platform::GetMB6HCBoardType(); + const Pin DiagPin = (bt == BoardType::Duet3_6HC_v102) ? DiagPin102 : DiagPinPre102; + const Pin ActLedPin = (bt == BoardType::Duet3_6HC_v102) ? ActLedPin102 : ActLedPinPre102; + const bool DiagOnPolarity = (bt == BoardType::Duet3_6HC_v102) ? DiagOnPolarity102 : DiagOnPolarityPre102; + if (bt == BoardType::Duet3_6HC_v102) + { + pinMode(UsbPowerSwitchPin, OUTPUT_LOW); // turn USB power off + pinMode(UsbModePin, OUTPUT_LOW); // USB mode = device/UFP + } +#endif pinMode(DiagPin, (DiagOnPolarity) ? OUTPUT_LOW : OUTPUT_HIGH); // set up status LED for debugging and turn it off -#if defined(DUET3MINI) || defined(DUET3_MB6XD) +#if defined(DUET3MINI) || defined(DUET3_MB6HC) || defined(DUET3_MB6XD) pinMode(ActLedPin, (ActOnPolarity) ? OUTPUT_LOW : OUTPUT_HIGH); // set up activity LED and turn it off #endif |