Use atomic block for accessing lcd_encoder_diff
There was still the possibility of lcd_encoder_diff being updated from the ISR while the new enc_diff was being computed. Flash: +8B SRAM: 0B
This commit is contained in:
parent
1f181a949a
commit
c037e6dfba
|
|
@ -4,6 +4,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
#include <util/atomic.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
|
||||||
|
|
@ -684,15 +685,15 @@ void lcd_knob_update() {
|
||||||
if (lcd_backlight_wake_trigger) {
|
if (lcd_backlight_wake_trigger) {
|
||||||
lcd_backlight_wake_trigger = false;
|
lcd_backlight_wake_trigger = false;
|
||||||
backlight_wake();
|
backlight_wake();
|
||||||
int8_t enc_diff = lcd_encoder_diff;
|
bool did_rotate = false;
|
||||||
if (abs(enc_diff) >= ENCODER_PULSES_PER_STEP) {
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||||
lcd_encoder += enc_diff / ENCODER_PULSES_PER_STEP;
|
if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
|
||||||
enc_diff %= ENCODER_PULSES_PER_STEP;
|
lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
|
||||||
lcd_encoder_diff = enc_diff;
|
lcd_encoder_diff %= ENCODER_PULSES_PER_STEP;
|
||||||
Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
|
did_rotate = true;
|
||||||
} else {
|
}
|
||||||
Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
|
|
||||||
}
|
}
|
||||||
|
Sound_MakeSound(did_rotate ? e_SOUND_TYPE_EncoderMove : e_SOUND_TYPE_ButtonEcho);
|
||||||
|
|
||||||
if (lcd_draw_update == 0) {
|
if (lcd_draw_update == 0) {
|
||||||
// Update LCD rendering at minimum
|
// Update LCD rendering at minimum
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue