diff --git a/make/source.mk b/make/source.mk
index 21454264d..5bc8d2ee0 100644
--- a/make/source.mk
+++ b/make/source.mk
@@ -63,6 +63,7 @@ COMMON_SRC = \
pg/adc.c \
pg/bus_i2c.c \
pg/flash.c \
+ pg/max7456.c \
pg/pg.c \
scheduler/scheduler.c \
sensors/battery.c \
diff --git a/src/main/drivers/max7456.c b/src/main/drivers/max7456.c
index b7fa267e2..23d961be2 100644
--- a/src/main/drivers/max7456.c
+++ b/src/main/drivers/max7456.c
@@ -25,6 +25,7 @@
#include "build/debug.h"
+#include "pg/max7456.h"
#include "pg/pg.h"
#include "pg/pg_ids.h"
@@ -220,13 +221,6 @@ static IO_t max7456CsPin = IO_NONE;
static uint8_t max7456DeviceType;
-PG_REGISTER_WITH_RESET_TEMPLATE(max7456Config_t, max7456Config, PG_MAX7456_CONFIG, 0);
-
-PG_RESET_TEMPLATE(max7456Config_t, max7456Config,
- .clockConfig = MAX7456_CLOCK_CONFIG_OC, // SPI clock based on device type and overclock state
-);
-
-
static uint8_t max7456Send(uint8_t add, uint8_t data)
{
spiTransferByte(MAX7456_SPI_INSTANCE, add);
@@ -415,7 +409,7 @@ void max7456ReInit(void)
// Here we init only CS and try to init MAX for first time.
// Also detect device type (MAX v.s. AT)
-void max7456Init(const vcdProfile_t *pVcdProfile, bool cpuOverclock)
+void max7456Init(const max7456Config_t *max7456Config, const vcdProfile_t *pVcdProfile, bool cpuOverclock)
{
max7456HardwareReset();
@@ -441,7 +435,7 @@ void max7456Init(const vcdProfile_t *pVcdProfile, bool cpuOverclock)
#if defined(STM32F4) && !defined(DISABLE_OVERCLOCK)
// Determine SPI clock divisor based on config and the device type.
- switch (max7456Config()->clockConfig) {
+ switch (max7456Config->clockConfig) {
case MAX7456_CLOCK_CONFIG_HALF:
max7456SpiClock = MAX7456_SPI_CLK * 2;
break;
@@ -459,6 +453,7 @@ void max7456Init(const vcdProfile_t *pVcdProfile, bool cpuOverclock)
DEBUG_SET(DEBUG_MAX7456_SPICLOCK, DEBUG_MAX7456_SPICLOCK_DEVTYPE, max7456DeviceType);
DEBUG_SET(DEBUG_MAX7456_SPICLOCK, DEBUG_MAX7456_SPICLOCK_DIVISOR, max7456SpiClock);
#else
+ UNUSED(max7456Config);
UNUSED(cpuOverclock);
#endif
diff --git a/src/main/drivers/max7456.h b/src/main/drivers/max7456.h
index ad4b3af01..b713119d6 100644
--- a/src/main/drivers/max7456.h
+++ b/src/main/drivers/max7456.h
@@ -27,7 +27,8 @@ extern uint16_t maxScreenSize;
struct vcdProfile_s;
void max7456HardwareReset(void);
-void max7456Init(const struct vcdProfile_s *vcdProfile, bool cpuOverclock);
+struct max7456Config_s;
+void max7456Init(const struct max7456Config_s *max7456Config, const struct vcdProfile_s *vcdProfile, bool cpuOverclock);
void max7456Invert(bool invert);
void max7456Brightness(uint8_t black, uint8_t white);
void max7456DrawScreen(void);
@@ -39,13 +40,3 @@ void max7456ClearScreen(void);
void max7456RefreshAll(void);
uint8_t* max7456GetScreenBuffer(void);
bool max7456DmaInProgress(void);
-
-typedef struct max7456Config_s {
- uint8_t clockConfig; // 0 = force half clock, 1 = half if OC, 2 = force full
-} max7456Config_t;
-
-#define MAX7456_CLOCK_CONFIG_HALF 0
-#define MAX7456_CLOCK_CONFIG_OC 1
-#define MAX7456_CLOCK_CONFIG_FULL 2
-
-PG_DECLARE(max7456Config_t, max7456Config);
diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c
index 34f91328d..cfc5ab651 100644
--- a/src/main/interface/settings.c
+++ b/src/main/interface/settings.c
@@ -28,15 +28,11 @@
#include "common/utils.h"
-#include "pg/pg.h"
-#include "pg/pg_ids.h"
-
#include "drivers/adc.h"
#include "drivers/bus_i2c.h"
#include "drivers/bus_spi.h"
#include "drivers/light_led.h"
#include "drivers/camera_control.h"
-#include "drivers/max7456.h"
#include "drivers/vtx_common.h"
#include "fc/config.h"
@@ -66,6 +62,9 @@
#include "io/vtx_rtc6705.h"
#include "pg/adc.h"
+#include "pg/max7456.h"
+#include "pg/pg.h"
+#include "pg/pg_ids.h"
#include "rx/rx.h"
#include "rx/cc2500_frsky_common.h"
diff --git a/src/main/io/displayport_max7456.c b/src/main/io/displayport_max7456.c
index 2c443fef5..440da4acc 100644
--- a/src/main/io/displayport_max7456.c
+++ b/src/main/io/displayport_max7456.c
@@ -24,9 +24,6 @@
#include "common/utils.h"
-#include "pg/pg.h"
-#include "pg/pg_ids.h"
-
#include "drivers/display.h"
#include "drivers/max7456.h"
#include "drivers/vcd.h"
@@ -37,6 +34,10 @@
#include "io/osd.h"
#include "io/osd_slave.h"
+#include "pg/max7456.h"
+#include "pg/pg.h"
+#include "pg/pg_ids.h"
+
displayPort_t max7456DisplayPort;
PG_REGISTER_WITH_RESET_FN(displayPortProfile_t, displayPortProfileMax7456, PG_DISPLAY_PORT_MAX7456_CONFIG, 0);
@@ -157,9 +158,9 @@ displayPort_t *max7456DisplayPortInit(const vcdProfile_t *vcdProfile)
{
displayInit(&max7456DisplayPort, &max7456VTable);
#ifdef USE_OSD_SLAVE
- max7456Init(vcdProfile, false);
+ max7456Init(max7456Config(), vcdProfile, false);
#else
- max7456Init(vcdProfile, systemConfig()->cpu_overclock);
+ max7456Init(max7456Config(), vcdProfile, systemConfig()->cpu_overclock);
#endif
resync(&max7456DisplayPort);
return &max7456DisplayPort;
diff --git a/src/main/pg/max7456.c b/src/main/pg/max7456.c
new file mode 100644
index 000000000..f28517a89
--- /dev/null
+++ b/src/main/pg/max7456.c
@@ -0,0 +1,33 @@
+/*
+ * This file is part of Cleanflight.
+ *
+ * Cleanflight is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cleanflight is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cleanflight. If not, see .
+ */
+
+#include "platform.h"
+
+#ifdef USE_MAX7456
+
+#include "pg/pg.h"
+#include "pg/pg_ids.h"
+
+#include "max7456.h"
+
+PG_REGISTER_WITH_RESET_TEMPLATE(max7456Config_t, max7456Config, PG_MAX7456_CONFIG, 0);
+
+PG_RESET_TEMPLATE(max7456Config_t, max7456Config,
+ .clockConfig = MAX7456_CLOCK_CONFIG_OC, // SPI clock based on device type and overclock state
+);
+
+#endif // USE_MAX7456
diff --git a/src/main/pg/max7456.h b/src/main/pg/max7456.h
new file mode 100644
index 000000000..a40318117
--- /dev/null
+++ b/src/main/pg/max7456.h
@@ -0,0 +1,30 @@
+/*
+ * This file is part of Cleanflight.
+ *
+ * Cleanflight is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cleanflight is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cleanflight. If not, see .
+ */
+
+#pragma once
+
+#include "pg/pg.h"
+
+#define MAX7456_CLOCK_CONFIG_HALF 0
+#define MAX7456_CLOCK_CONFIG_OC 1
+#define MAX7456_CLOCK_CONFIG_FULL 2
+
+typedef struct max7456Config_s {
+ uint8_t clockConfig; // 0 = force half clock, 1 = half if OC, 2 = force full
+} max7456Config_t;
+
+PG_DECLARE(max7456Config_t, max7456Config);
diff --git a/src/main/target/OMNIBUSF4/config.c b/src/main/target/OMNIBUSF4/config.c
index 63b7cebad..6880695b1 100644
--- a/src/main/target/OMNIBUSF4/config.c
+++ b/src/main/target/OMNIBUSF4/config.c
@@ -22,10 +22,11 @@
#ifdef USE_TARGET_CONFIG
-#include "pg/pg.h"
-#include "drivers/max7456.h"
#include "io/serial.h"
+#include "pg/max7456.h"
+#include "pg/pg.h"
+
void targetConfiguration(void)
{
#ifdef OMNIBUSF4BASE