mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Implement U8x8 based display support in bootloader.
This commit is contained in:
parent
a36abc705c
commit
44e3792ffb
13 changed files with 193 additions and 117 deletions
|
@ -1,13 +1,25 @@
|
|||
#include <stm32f37x_conf.h>
|
||||
|
||||
#include "stmlib/system/bootloader_utils.h"
|
||||
#include "midi2cv/drivers/eco_display.h"
|
||||
#include <U8x8lib.h>
|
||||
|
||||
using namespace stmlib;
|
||||
|
||||
const uint32_t kStartAddress = 0x08008000;
|
||||
|
||||
int main(void) {
|
||||
EcoDisplay display;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
SystemInit();
|
||||
|
||||
display.Init();
|
||||
|
||||
display.u8x8()->setFont(u8x8_font_amstrad_cpc_extended_r);
|
||||
display.u8x8()->drawString(0, 0, "Moin");
|
||||
for (int i = 0; i < 100000000; i++)
|
||||
;
|
||||
Uninitialize();
|
||||
JumpTo(kStartAddress);
|
||||
}
|
||||
|
|
91
midi2cv/drivers/base_display.cc
Normal file
91
midi2cv/drivers/base_display.cc
Normal file
|
@ -0,0 +1,91 @@
|
|||
#include "base_display.h"
|
||||
#include "spi_mode.h"
|
||||
#include <U8x8lib.h>
|
||||
#include <stm32f37x_conf.h>
|
||||
|
||||
static const uint16_t kPinEnable = GPIO_Pin_2;
|
||||
static const uint16_t kPinReset = GPIO_Pin_0;
|
||||
static const uint16_t kPinDataCommand = GPIO_Pin_9;
|
||||
|
||||
uint8_t u8x8_stm32_gpio_and_delay(U8X8_UNUSED u8x8_t* u8x8,
|
||||
U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int,
|
||||
U8X8_UNUSED void* arg_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_4wire_stm32_spi(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int,
|
||||
void* arg_ptr)
|
||||
{
|
||||
uint8_t* data;
|
||||
switch (msg) {
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t*)arg_ptr;
|
||||
while (arg_int > 0) {
|
||||
while (!(SPI2->SR & SPI_SR_TXE)) {
|
||||
}
|
||||
SPI_SendData8(SPI2, (uint8_t)*data);
|
||||
arg_int--;
|
||||
data++;
|
||||
}
|
||||
break;
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
if (arg_int)
|
||||
GPIO_WriteBit(GPIOB, kPinDataCommand, Bit_SET);
|
||||
else
|
||||
GPIO_WriteBit(GPIOB, kPinDataCommand, Bit_RESET);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
InitSPI(SPI_MODE_DISPLAY);
|
||||
GPIO_WriteBit(GPIOB, kPinEnable, Bit_RESET);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
GPIO_WriteBit(GPIOB, kPinEnable, Bit_SET);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BaseDisplay::Init()
|
||||
{
|
||||
// init SS/CS/RST GPIO
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio_init;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_OUT;
|
||||
gpio_init.GPIO_OType = GPIO_OType_PP;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
gpio_init.GPIO_Pin = kPinEnable | kPinReset | kPinDataCommand;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
|
||||
GPIO_WriteBit(GPIOB, kPinEnable, Bit_SET);
|
||||
|
||||
// init AF GPIO
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
||||
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF;
|
||||
gpio_init.GPIO_OType = GPIO_OType_PP;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_5);
|
||||
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_5);
|
||||
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_5);
|
||||
|
||||
// init SPI
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
|
||||
SPI_I2S_DeInit(SPI2);
|
||||
// Initialize SPI
|
||||
InitSPI(SPI_MODE_DISPLAY);
|
||||
GPIO_WriteBit(GPIOB, kPinReset, Bit_RESET);
|
||||
asm("nop");
|
||||
|
||||
GPIO_WriteBit(GPIOB, kPinReset, Bit_SET);
|
||||
InitGLib();
|
||||
}
|
19
midi2cv/drivers/base_display.h
Normal file
19
midi2cv/drivers/base_display.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <stmlib/stmlib.h>
|
||||
#include <U8x8lib.h>
|
||||
|
||||
extern uint8_t u8x8_stm32_gpio_and_delay(U8X8_UNUSED u8x8_t* u8x8,
|
||||
U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int,
|
||||
U8X8_UNUSED void* arg_ptr);
|
||||
|
||||
extern uint8_t u8x8_byte_4wire_stm32_spi(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int,
|
||||
void* arg_ptr);
|
||||
|
||||
class BaseDisplay {
|
||||
public:
|
||||
void Init();
|
||||
|
||||
protected:
|
||||
virtual void InitGLib();
|
||||
};
|
|
@ -8,63 +8,17 @@
|
|||
|
||||
using namespace stmlib;
|
||||
|
||||
static const uint16_t kPinEnable = GPIO_Pin_2;
|
||||
static const uint16_t kPinReset = GPIO_Pin_0;
|
||||
static const uint16_t kPinDataCommand = GPIO_Pin_9;
|
||||
|
||||
static uint8_t* default_buf;
|
||||
static uint8_t second_buf[1024];
|
||||
static uint8_t* output_buf;
|
||||
|
||||
uint8_t u8x8_stm32_gpio_and_delay(U8X8_UNUSED u8x8_t* u8x8,
|
||||
U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int,
|
||||
U8X8_UNUSED void* arg_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_4wire_hw_spi(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int,
|
||||
void* arg_ptr)
|
||||
{
|
||||
uint8_t* data;
|
||||
switch (msg) {
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t*)arg_ptr;
|
||||
while (arg_int > 0) {
|
||||
while (!(SPI2->SR & SPI_SR_TXE)) {
|
||||
}
|
||||
SPI_SendData8(SPI2, (uint8_t)*data);
|
||||
arg_int--;
|
||||
data++;
|
||||
}
|
||||
break;
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
if (arg_int)
|
||||
GPIO_WriteBit(GPIOB, kPinDataCommand, Bit_SET);
|
||||
else
|
||||
GPIO_WriteBit(GPIOB, kPinDataCommand, Bit_RESET);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
InitSPI(SPI_MODE_DISPLAY);
|
||||
GPIO_WriteBit(GPIOB, kPinEnable, Bit_RESET);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
GPIO_WriteBit(GPIOB, kPinEnable, Bit_SET);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
class U8G2_SH1106_128x64_NONAME_F_SPI : public U8G2 {
|
||||
public:
|
||||
U8G2_SH1106_128x64_NONAME_F_SPI()
|
||||
: U8G2()
|
||||
{
|
||||
u8g2_Setup_sh1106_128x64_noname_f(&this->u8g2, U8G2_R0, u8x8_byte_4wire_hw_spi, u8x8_stm32_gpio_and_delay);
|
||||
u8g2_Setup_sh1106_128x64_noname_f(&this->u8g2, U8G2_R0, u8x8_byte_4wire_stm32_spi, u8x8_stm32_gpio_and_delay);
|
||||
output_buf = default_buf = this->u8g2.tile_buf_ptr;
|
||||
/*u8g2_InitDisplay(&u8g2_);
|
||||
u8g2_SetContrast(&u8g2_, 255);
|
||||
|
@ -79,46 +33,6 @@ U8G2* Display::u8g2()
|
|||
return &u8g2_;
|
||||
}
|
||||
|
||||
void Display::Init()
|
||||
{
|
||||
// init SS/CS/RST GPIO
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpio_init;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_OUT;
|
||||
gpio_init.GPIO_OType = GPIO_OType_PP;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
gpio_init.GPIO_Pin = kPinEnable | kPinReset | kPinDataCommand;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
|
||||
GPIO_WriteBit(GPIOB, kPinEnable, Bit_SET);
|
||||
|
||||
// init AF GPIO
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
||||
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF;
|
||||
gpio_init.GPIO_OType = GPIO_OType_PP;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_5);
|
||||
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_5);
|
||||
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_5);
|
||||
|
||||
// init SPI
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
|
||||
SPI_I2S_DeInit(SPI2);
|
||||
// Initialize SPI
|
||||
InitSPI(SPI_MODE_DISPLAY);
|
||||
GPIO_WriteBit(GPIOB, kPinReset, Bit_RESET);
|
||||
asm("nop");
|
||||
|
||||
GPIO_WriteBit(GPIOB, kPinReset, Bit_SET);
|
||||
InitGLib();
|
||||
}
|
||||
|
||||
void Display::InitGLib()
|
||||
{
|
||||
u8g2_.begin();
|
||||
|
|
|
@ -2,18 +2,25 @@
|
|||
#define MIDI2CV_DRIVERS_DISPLAY_H
|
||||
|
||||
#include "stmlib/stmlib.h"
|
||||
#include <stm32f37x_conf.h>
|
||||
#include "base_display.h"
|
||||
#include <U8g2lib.h>
|
||||
#include <stm32f37x_conf.h>
|
||||
|
||||
#define DISPLAY_WIDTH 128
|
||||
#define DISPLAY_HEIGHT 64
|
||||
|
||||
class Display {
|
||||
extern uint8_t u8x8_stm32_gpio_and_delay(U8X8_UNUSED u8x8_t* u8x8,
|
||||
U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int,
|
||||
U8X8_UNUSED void* arg_ptr);
|
||||
|
||||
extern uint8_t u8x8_byte_4wire_stm32_spi(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int,
|
||||
void* arg_ptr);
|
||||
|
||||
class Display : public BaseDisplay {
|
||||
public:
|
||||
Display() {}
|
||||
~Display() {}
|
||||
|
||||
void Init();
|
||||
U8G2* u8g2();
|
||||
void Flush();
|
||||
void Swap();
|
||||
|
@ -22,5 +29,5 @@ private:
|
|||
DISALLOW_COPY_AND_ASSIGN(Display);
|
||||
void InitGLib();
|
||||
};
|
||||
extern Display display;
|
||||
|
||||
#endif
|
||||
|
|
28
midi2cv/drivers/eco_display.h
Normal file
28
midi2cv/drivers/eco_display.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include "base_display.h"
|
||||
#include <U8x8lib.h>
|
||||
|
||||
class U8X8_SH1106_128X64_NONAME_4W_SW_SPI : public U8X8 {
|
||||
public:
|
||||
U8X8_SH1106_128X64_NONAME_4W_SW_SPI()
|
||||
: U8X8()
|
||||
{
|
||||
u8x8_Setup(getU8x8(), u8x8_d_sh1106_128x64_noname, u8x8_cad_001, u8x8_byte_4wire_stm32_spi, u8x8_stm32_gpio_and_delay);
|
||||
}
|
||||
};
|
||||
|
||||
class EcoDisplay : public BaseDisplay {
|
||||
protected:
|
||||
void InitGLib() {
|
||||
this->u8x8()->begin();
|
||||
}
|
||||
|
||||
public:
|
||||
U8X8* u8x8() {
|
||||
return &this->instance;
|
||||
}
|
||||
|
||||
U8X8_SH1106_128X64_NONAME_4W_SW_SPI instance;
|
||||
|
||||
};
|
|
@ -30,6 +30,7 @@ SYSCLOCK = SYSCLK_FREQ_72MHz
|
|||
FAMILY = f37x
|
||||
# USB = enabled
|
||||
U8G2 = enabled
|
||||
PRINTF_FLOATS = enabled
|
||||
APPLICATION_LARGE = TRUE
|
||||
BOOTLOADER = midi2cv_bootloader
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ Settings settings;
|
|||
|
||||
Part parts[PART_COUNT];
|
||||
Part* part_pointers[PART_COUNT] = { &parts[0], &parts[1], &parts[2], &parts[3] };
|
||||
UI ui(part_pointers, &settings);
|
||||
UI ui(part_pointers, &display, &settings);
|
||||
|
||||
// Default interrupt handlers.
|
||||
extern "C" {
|
||||
|
|
|
@ -65,7 +65,7 @@ class Settings {
|
|||
State state_;
|
||||
|
||||
stmlib::ChunkStorage<
|
||||
0x08004000,
|
||||
0x08006000,
|
||||
0x08008000,
|
||||
PersistentData,
|
||||
State>
|
||||
|
|
|
@ -14,12 +14,13 @@ using namespace stmlib;
|
|||
|
||||
const uint32_t kEncoderLongPressTime = 600;
|
||||
|
||||
UI::UI(Part** part_pointers, Settings* settings)
|
||||
: main_menu(part_pointers)
|
||||
UI::UI(Part** part_pointers, Display* display, Settings* settings)
|
||||
: settings(settings)
|
||||
, display(display)
|
||||
, main_menu(part_pointers)
|
||||
, parts(part_pointers)
|
||||
{
|
||||
this->input_queue.Init();
|
||||
this->settings = settings;
|
||||
|
||||
LoadState();
|
||||
}
|
||||
|
@ -53,11 +54,11 @@ void UI::Poll()
|
|||
|
||||
void UI::Draw()
|
||||
{
|
||||
display.u8g2()->clearBuffer();
|
||||
this->display->u8g2()->clearBuffer();
|
||||
|
||||
main_menu.render(display.u8g2(), 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
main_menu.render(this->display->u8g2(), 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
|
||||
display.Swap();
|
||||
this->display->Swap();
|
||||
}
|
||||
|
||||
void UI::LoadState()
|
||||
|
@ -77,7 +78,7 @@ void UI::SaveState()
|
|||
|
||||
void UI::Flush()
|
||||
{
|
||||
display.Flush();
|
||||
this->display->Flush();
|
||||
}
|
||||
|
||||
void UI::DoEvents()
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
#include "config.h"
|
||||
#include "settings.h"
|
||||
#include "ui/main_menu.h"
|
||||
#include <array>
|
||||
|
||||
#include "drivers/display.h"
|
||||
|
||||
class UI {
|
||||
public:
|
||||
UI(Part** part_pointers, Settings* settings);
|
||||
UI(Part** part_pointers, Display* display, Settings* settings);
|
||||
~UI() {}
|
||||
|
||||
void Poll();
|
||||
|
@ -23,6 +24,8 @@ class UI {
|
|||
|
||||
Settings* settings;
|
||||
|
||||
Display* display;
|
||||
|
||||
bool long_press_event_sent_;
|
||||
uint32_t start_stop_press_time_;
|
||||
bool encoder_long_press_event_sent_;
|
||||
|
|
2
stmlib
2
stmlib
|
@ -1 +1 @@
|
|||
Subproject commit 99e1ad5fb7b241e13ec780c00ef1c3fd0200fdac
|
||||
Subproject commit b5f84c61b8a10dbba36f0ba12877ffde4b42d199
|
Loading…
Reference in a new issue