The Samuel L. Jackson face was for the question "I tested the files, first I got 58fps, then 90, did you made something to the oled.
While 3 post earlier, where you downloaded the file: "(Lots of detail) Hey guys I made a lot of optimizations to the i2c code, now the screen runs at 90fps!"
This firmware is pretty complex. Although I did my best by adding comments and keeping the code tidy, there's still a lot of code.
It took me weeks to fully understand the code. I had never programmed arm/stm32, neither used eclipse, and my C skills were more than rusted.
So it was a long way until I got there. I had to figure all by myself!
I can make a quick summary, but I can't keep answering such simple and basic questions like "does checksumtime do anything?", when the answer is in a 3-second-away search.
What I said, either download CubeIde and properly review the code (You can search in all project files with control+H), or use github search.
Actually the code is huge, but the program workflow is pretty simple.
(main.c, Init)
After CubeMX setup, it initializes the rest of the system, like:
-Loading the system settings.
-Enabling the ADC.
-Runing ironInit (This is the most important part).
(iron.c, ironInit)
- Sets up some variables.
- Runs initTimers.
That's the most crucial part, everything works based on the timers.
The system watchdog is not being refreshed, so if the timers don't run, the system will reset.
Once the timers started, the interrupts will run the rest of the program, resfreshing the WD.
(main.c, main)
The main function only runs non critical stuff:
- oled_handle: reads the processed input, updates the widgets, draws them and updates the screen.
- checkSettings: Tracks changes in system options and updates the stored data.
(main.c, program_handler)
Called from SysTick_Handler at 1KHz rate.
- Reads the encoder pins.
- Reads the wake input.
- Handles buzzer state.
And here it comes the important part, the interrupts!
(main.c, HAL_TIM_PWM_PulseFinishedCallback)-
- Called when the PWM wave goes low.
- Checks that the adc status is correct, and enables the delay timer.
(main.c, HAL_TIM_PeriodElapsedCallback)
- Called when the delay timer expired. Now it's time to sample the adc!
- Runs ADC_Start_DMA.
(adc_global.c, ADC_Start_DMA)
- Starts the ADC in DMA mode
(adc_global.c, HAL_ADC_ConvCpltCallback)
- Called when the ADC conversion is done (All data, not single conversion).
- Refreshes the watchdog timer.
- Runs handle_ADC_Data (Processes and filters the adquired data).
- Runs handleIron (Checks for error conditions, timeouts, pwm setting updates, runs calculatePID to get the new PWM value).
- Runs runAwayCheck (If pwm is active, checks that the temperature is not going out of control).
If something wrong happens with the timers, or the program stalls somewhere, the watchdog won't be resfreshed anymore, and 500mS later the system will be resetted.
And that's pretty much it. The timing is adjusted so the PWM never starts again before the HAL_ADC_ConvCpltCallback ends.
On next PWM cycle everything happens again.
The time between the ADC conversion start and HAL_ADC_ConvCpltCallback finish is around 300uS.
The code is ajusted for 350uS to have a safety gap. Actually this timing is for 36MHz devices (KSGER v2/v3), for Quicko F103 and others running at 64MHz it's ~200uS, but I use the same timing for all because it hardly makes a difference while adds complexity.
For the rest, you'll have to look at it and learn, don't ever expect to understand in 2 nights a firmware that wasn't made by you!