mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Implement double buffering for screen, only do transmission in interrupt handler
This commit is contained in:
parent
f594aa9f43
commit
8c0ad0007a
5 changed files with 40 additions and 10 deletions
|
@ -12,6 +12,9 @@ const uint16_t kPinReset = GPIO_Pin_0;
|
|||
const uint16_t kPinDataCommand = GPIO_Pin_9;
|
||||
|
||||
u8g2_t u8g2_;
|
||||
uint8_t* default_buf;
|
||||
uint8_t second_buf[1024];
|
||||
uint8_t* output_buf;
|
||||
|
||||
u8g2_t* Display::u8g2()
|
||||
{
|
||||
|
@ -115,8 +118,27 @@ uint8_t u8x8_byte_4wire_hw_spi(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int,
|
|||
void Display::InitGLib()
|
||||
{
|
||||
u8g2_Setup_sh1106_128x64_noname_f(&u8g2_, U8G2_R0, u8x8_byte_4wire_hw_spi, u8x8_stm32_gpio_and_delay);
|
||||
output_buf = default_buf = u8g2_.tile_buf_ptr;
|
||||
u8g2_InitDisplay(&u8g2_);
|
||||
u8g2_SetContrast(&u8g2_, 127);
|
||||
u8g2_SetPowerSave(&u8g2_, 0);
|
||||
|
||||
Random::Seed(42);
|
||||
}
|
||||
|
||||
void Display::Flush()
|
||||
{
|
||||
uint8_t* cache = u8g2_.tile_buf_ptr;
|
||||
u8g2_.tile_buf_ptr = output_buf;
|
||||
u8g2_SendBuffer(&u8g2_);
|
||||
u8g2_.tile_buf_ptr = cache;
|
||||
}
|
||||
|
||||
void Display::Swap()
|
||||
{
|
||||
output_buf = u8g2_.tile_buf_ptr;
|
||||
if (output_buf == default_buf)
|
||||
u8g2_.tile_buf_ptr = second_buf;
|
||||
else
|
||||
u8g2_.tile_buf_ptr = default_buf;
|
||||
}
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
#ifndef MIDI2CV_DRIVERS_DISPLAY_H
|
||||
#define MIDI2CV_DRIVERS_DISPLAY_H
|
||||
|
||||
#include <stm32f37x_conf.h>
|
||||
#include "stmlib/stmlib.h"
|
||||
#include <stm32f37x_conf.h>
|
||||
#include <u8g2.h>
|
||||
|
||||
|
||||
class Display {
|
||||
public:
|
||||
Display() { }
|
||||
public:
|
||||
Display() {}
|
||||
~Display() {}
|
||||
|
||||
void Init();
|
||||
u8g2_t* u8g2();
|
||||
private:
|
||||
void Flush();
|
||||
void Swap();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Display);
|
||||
void InitGLib();
|
||||
};
|
||||
|
|
|
@ -60,7 +60,7 @@ void TIM2_IRQHandler(void)
|
|||
static uint8_t count = 0;
|
||||
count++;
|
||||
if (count % 192 == 0) {
|
||||
ui.Update();
|
||||
ui.Flush();
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
@ -112,6 +112,6 @@ int main(void)
|
|||
{
|
||||
Init();
|
||||
while (1) {
|
||||
//ui.Update();
|
||||
ui.Update();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,5 +27,10 @@ void UI::Update()
|
|||
dy = -1;
|
||||
if (y <= 7)
|
||||
dy = 1;
|
||||
u8g2_SendBuffer(u8g2_);
|
||||
display.Swap();
|
||||
}
|
||||
|
||||
void UI::Flush()
|
||||
{
|
||||
display.Flush();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ public:
|
|||
~UI() {}
|
||||
|
||||
void Update();
|
||||
void Flush();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(UI);
|
||||
|
|
Loading…
Reference in a new issue