diff --git a/fw/HackSpaceCon/src/main.cpp b/fw/HackSpaceCon/src/main.cpp index a85ff6a..e9dd2f8 100644 --- a/fw/HackSpaceCon/src/main.cpp +++ b/fw/HackSpaceCon/src/main.cpp @@ -1,3 +1,29 @@ +/* + + hackspacecon wand firmware + + initially written by true + rgb programs and further hacking by 000000widow + + operation workflow: + - at poweron, set up GPIO and used peripherals, then go into standby mode. + - when button interrupt happens, wake up and process. if button is pushed, + prepare to run RGB program. + - enable the TCB0 periodic timer, which will interrupt every ~61Hz. + - initialize the rgb program. idle the CPU. + - timer will interrupt every ~61Hz and the program function will be called + again, until prog function returns 0. + - run the RGB program. if program returns 0, disable periodic timer, and + wait for the next button event to wake us up and run a program again. + + todo: + - test the code + - actually process the RGB data in the sample rainbow puke program + - add more programs + - support incrementing or randomly selecting the next program on each button push + - run TCB0 in standby mode to save a little more power +*/ + #include #include #include @@ -43,11 +69,12 @@ void loop() { case 1: { // just started running a program digitalWrite(PIN_PA6, HIGH); // enable LED power supply, delay(10); // wait a moment for LEDs to stabilize, - enable_rgb_timer(); // then start the RGB program timebase. rgb_program[0](1); // initialize the program, run_rgb_program++; // and set to running mode. + enable_rgb_timer(); // then start the RGB program timebase. + // we can idle the CPU after running the program SLPCTRL.CTRLA = SLPCTRL_SMODE_IDLE_gc | SLPCTRL_SEN_bm; __asm("sleep");