Add HW EEPROM reset
Now the whole functionality takes +196B As noted by @leptun, we cannot reliably check for >1 buttons pressed at once. Since the left button is the least used, let's use it for invoking the HW EEPROM clear upon MMU start.pull/260/head
parent
14d12caf8a
commit
72fbffea72
|
|
@ -184,39 +184,39 @@ void Application::ReportWriteRegister(const mp::RequestMsg &rq) {
|
||||||
/// Intended only for visualization of EEPROM reset, not to be used in while the MMU is running normally
|
/// Intended only for visualization of EEPROM reset, not to be used in while the MMU is running normally
|
||||||
namespace EEPROMResetVis {
|
namespace EEPROMResetVis {
|
||||||
|
|
||||||
static void Delay(){
|
static void Delay() {
|
||||||
uint32_t start = mt::timebase.Millis();
|
uint32_t start = mt::timebase.Millis();
|
||||||
while( ! mt::timebase.Elapsed(start, 100) ){
|
while (!mt::timebase.Elapsed(start, 50)) {
|
||||||
ml::leds.Step();
|
ml::leds.Step();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__((noinline)) Green(uint8_t i){
|
static void __attribute__((noinline)) Green(uint8_t i) {
|
||||||
ml::leds.SetPairButOffOthers(i, ml::on, ml::off);
|
ml::leds.SetPairButOffOthers(i, ml::on, ml::off);
|
||||||
Delay();
|
Delay();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__((noinline)) Red(uint8_t i){
|
static void __attribute__((noinline)) Red(uint8_t i) {
|
||||||
ml::leds.SetPairButOffOthers(i, ml::on, ml::off);
|
ml::leds.SetPairButOffOthers(i, ml::off, ml::on);
|
||||||
Delay();
|
Delay();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Run(){
|
static void Run() {
|
||||||
for(uint8_t i = 0; i < ml::leds.LedPairsCount(); ++i){
|
for (uint8_t i = 0; i < ml::leds.LedPairsCount(); ++i) {
|
||||||
Green(i);
|
|
||||||
Red(i);
|
Red(i);
|
||||||
|
Green(i);
|
||||||
}
|
}
|
||||||
for(uint8_t i = ml::leds.LedPairsCount(); i != 0; --i){
|
for (uint8_t i = ml::leds.LedPairsCount(); i != 0; --i) {
|
||||||
Red(i);
|
|
||||||
Green(i);
|
Green(i);
|
||||||
|
Red(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace EEPROMResetVis
|
} // namespace EEPROMResetVis
|
||||||
|
|
||||||
void Application::ProcessReset(uint8_t resetType){
|
void Application::ProcessReset(ResetTypes resetType) {
|
||||||
switch(resetType){
|
switch (resetType) {
|
||||||
case 42: // perform an EEPROM reset if the resetType == The Answer to the Ultimate Question of Life, the Universe, and Everything :)
|
case ResetTypes::EEPROMAndSoftware: // perform an EEPROM reset if the resetType == The Answer to the Ultimate Question of Life, the Universe, and Everything :)
|
||||||
mps::EraseAll();
|
mps::EraseAll();
|
||||||
EEPROMResetVis::Run();
|
EEPROMResetVis::Run();
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
|
@ -242,7 +242,7 @@ void Application::ProcessRequestMsg(const mp::RequestMsg &rq) {
|
||||||
break;
|
break;
|
||||||
case mp::RequestMsgCodes::Reset:
|
case mp::RequestMsgCodes::Reset:
|
||||||
// immediately reset the board - there is no response in this case
|
// immediately reset the board - there is no response in this case
|
||||||
ProcessReset(rq.value);
|
ProcessReset((ResetTypes)rq.value);
|
||||||
break;
|
break;
|
||||||
case mp::RequestMsgCodes::Version:
|
case mp::RequestMsgCodes::Version:
|
||||||
case mp::RequestMsgCodes::Read:
|
case mp::RequestMsgCodes::Read:
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,16 @@ public:
|
||||||
uint8_t CurrentProgressCode();
|
uint8_t CurrentProgressCode();
|
||||||
uint16_t CurrentErrorCode();
|
uint16_t CurrentErrorCode();
|
||||||
|
|
||||||
|
/// Types of Reset parameters
|
||||||
|
enum class ResetTypes : uint8_t {
|
||||||
|
Software = 0,
|
||||||
|
EEPROMAndSoftware = 42,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Performs a reset of the MMU board.
|
||||||
|
/// @param resetType == EEPROMAndSoftware, the EEPROM is cleared before resetting the board. Otherwise the MMU board "just" resets.
|
||||||
|
void ProcessReset(ResetTypes resetType);
|
||||||
|
|
||||||
#ifndef UNITTEST
|
#ifndef UNITTEST
|
||||||
private:
|
private:
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -46,7 +56,6 @@ private:
|
||||||
void ReportReadRegister(const mp::RequestMsg &rq);
|
void ReportReadRegister(const mp::RequestMsg &rq);
|
||||||
void ReportWriteRegister(const mp::RequestMsg &rq);
|
void ReportWriteRegister(const mp::RequestMsg &rq);
|
||||||
void ProcessRequestMsg(const mp::RequestMsg &rq);
|
void ProcessRequestMsg(const mp::RequestMsg &rq);
|
||||||
void ProcessReset(uint8_t resetType);
|
|
||||||
|
|
||||||
uint16_t lastCommandProcessedMs;
|
uint16_t lastCommandProcessedMs;
|
||||||
|
|
||||||
|
|
|
||||||
12
src/main.cpp
12
src/main.cpp
|
|
@ -82,13 +82,16 @@ static void setup() {
|
||||||
ml::leds.Step();
|
ml::leds.Step();
|
||||||
|
|
||||||
mu::cdc.Init();
|
mu::cdc.Init();
|
||||||
|
|
||||||
|
mb::buttons.Step();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Second part of setup - executed with interrupts enabled
|
/// Second part of setup - executed with interrupts enabled
|
||||||
static void setup2() {
|
static void setup2() {
|
||||||
// waits at least finda debounce period
|
// waits at least finda debounce period
|
||||||
// which is abused to let the LEDs shine for ~100ms
|
// which is abused to let the LEDs shine for ~100ms and let the buttons "debounce" during that period
|
||||||
mf::finda.BlockingInit();
|
mf::finda.BlockingInit();
|
||||||
|
mb::buttons.Step();
|
||||||
|
|
||||||
// Turn off all leds
|
// Turn off all leds
|
||||||
for (uint8_t i = 0; i < config::toolCount; i++) {
|
for (uint8_t i = 0; i < config::toolCount; i++) {
|
||||||
|
|
@ -96,6 +99,13 @@ static void setup2() {
|
||||||
ml::leds.SetMode(i, ml::red, ml::off);
|
ml::leds.SetMode(i, ml::red, ml::off);
|
||||||
}
|
}
|
||||||
ml::leds.Step();
|
ml::leds.Step();
|
||||||
|
mb::buttons.Step();
|
||||||
|
|
||||||
|
// Check left button pressed -> EEPROM reset - we cannot reliably check for multiple buttons due to electrical design
|
||||||
|
if (mb::buttons.ButtonPressed(mb::Left)) {
|
||||||
|
application.ProcessReset(Application::ResetTypes::EEPROMAndSoftware);
|
||||||
|
// note: there is no need to perform anything else, ProcessReset will just reboot the board
|
||||||
|
}
|
||||||
|
|
||||||
// Prep hardware sanity:
|
// Prep hardware sanity:
|
||||||
logic::hwSanity.Reset(0);
|
logic::hwSanity.Reset(0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue