mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 06:45:16 +03:00
Prevent font upload if max7456 is not detected (#9158)
Prevent font upload if max7456 is not detected
This commit is contained in:
commit
229bafee2d
3 changed files with 29 additions and 8 deletions
|
@ -193,6 +193,7 @@ static displayPortLayer_e activeLayer = DISPLAYPORT_LAYER_FOREGROUND;
|
||||||
busDevice_t max7456BusDevice;
|
busDevice_t max7456BusDevice;
|
||||||
busDevice_t *busdev = &max7456BusDevice;
|
busDevice_t *busdev = &max7456BusDevice;
|
||||||
|
|
||||||
|
static bool max7456DeviceDetected = false;
|
||||||
static uint16_t max7456SpiClock = MAX7456_SPI_CLK;
|
static uint16_t max7456SpiClock = MAX7456_SPI_CLK;
|
||||||
|
|
||||||
uint16_t maxScreenSize = VIDEO_BUFFER_CHARS_PAL;
|
uint16_t maxScreenSize = VIDEO_BUFFER_CHARS_PAL;
|
||||||
|
@ -450,6 +451,8 @@ void max7456PreInit(const max7456Config_t *max7456Config)
|
||||||
|
|
||||||
bool max7456Init(const max7456Config_t *max7456Config, const vcdProfile_t *pVcdProfile, bool cpuOverclock)
|
bool max7456Init(const max7456Config_t *max7456Config, const vcdProfile_t *pVcdProfile, bool cpuOverclock)
|
||||||
{
|
{
|
||||||
|
max7456DeviceDetected = false;
|
||||||
|
|
||||||
// initialize all layers
|
// initialize all layers
|
||||||
for (unsigned i = 0; i < MAX7456_SUPPORTED_LAYER_COUNT; i++) {
|
for (unsigned i = 0; i < MAX7456_SUPPORTED_LAYER_COUNT; i++) {
|
||||||
max7456ClearLayer(i);
|
max7456ClearLayer(i);
|
||||||
|
@ -484,15 +487,15 @@ bool max7456Init(const max7456Config_t *max7456Config, const vcdProfile_t *pVcdP
|
||||||
|
|
||||||
uint8_t osdm = max7456Send(MAX7456ADD_OSDM|MAX7456ADD_READ, 0xff);
|
uint8_t osdm = max7456Send(MAX7456ADD_OSDM|MAX7456ADD_READ, 0xff);
|
||||||
|
|
||||||
|
__spiBusTransactionEnd(busdev);
|
||||||
|
|
||||||
if (osdm != 0x1B) {
|
if (osdm != 0x1B) {
|
||||||
IOConfigGPIO(busdev->busdev_u.spi.csnPin, IOCFG_IPU);
|
IOConfigGPIO(busdev->busdev_u.spi.csnPin, IOCFG_IPU);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
__spiBusTransactionEnd(busdev);
|
|
||||||
|
|
||||||
// At this point, we can claim the ownership of the CS pin
|
// At this point, we can claim the ownership of the CS pin
|
||||||
|
max7456DeviceDetected = true;
|
||||||
IOInit(busdev->busdev_u.spi.csnPin, OWNER_OSD_CS, 0);
|
IOInit(busdev->busdev_u.spi.csnPin, OWNER_OSD_CS, 0);
|
||||||
|
|
||||||
// Detect device type by writing and reading CA[8] bit at CMAL[6].
|
// Detect device type by writing and reading CA[8] bit at CMAL[6].
|
||||||
|
@ -822,8 +825,11 @@ void max7456RefreshAll(void)
|
||||||
max7456DrawScreenSlow();
|
max7456DrawScreenSlow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void max7456WriteNvm(uint8_t char_address, const uint8_t *font_data)
|
bool max7456WriteNvm(uint8_t char_address, const uint8_t *font_data)
|
||||||
{
|
{
|
||||||
|
if (!max7456DeviceDetected) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#ifdef MAX7456_DMA_CHANNEL_TX
|
#ifdef MAX7456_DMA_CHANNEL_TX
|
||||||
while (dmaTransactionInProgress);
|
while (dmaTransactionInProgress);
|
||||||
#endif
|
#endif
|
||||||
|
@ -854,6 +860,7 @@ void max7456WriteNvm(uint8_t char_address, const uint8_t *font_data)
|
||||||
while ((max7456Send(MAX7456ADD_STAT, 0x00) & STAT_NVR_BUSY) != 0x00);
|
while ((max7456Send(MAX7456ADD_STAT, 0x00) & STAT_NVR_BUSY) != 0x00);
|
||||||
|
|
||||||
__spiBusTransactionEnd(busdev);
|
__spiBusTransactionEnd(busdev);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MAX7456_NRST_PIN
|
#ifdef MAX7456_NRST_PIN
|
||||||
|
@ -877,4 +884,8 @@ void max7456HardwareReset(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool max7456IsDeviceDetected(void)
|
||||||
|
{
|
||||||
|
return max7456DeviceDetected;
|
||||||
|
}
|
||||||
#endif // USE_MAX7456
|
#endif // USE_MAX7456
|
||||||
|
|
|
@ -37,7 +37,7 @@ bool max7456Init(const struct max7456Config_s *max7456Config, const struct vc
|
||||||
void max7456Invert(bool invert);
|
void max7456Invert(bool invert);
|
||||||
void max7456Brightness(uint8_t black, uint8_t white);
|
void max7456Brightness(uint8_t black, uint8_t white);
|
||||||
void max7456DrawScreen(void);
|
void max7456DrawScreen(void);
|
||||||
void max7456WriteNvm(uint8_t char_address, const uint8_t *font_data);
|
bool max7456WriteNvm(uint8_t char_address, const uint8_t *font_data);
|
||||||
uint8_t max7456GetRowsCount(void);
|
uint8_t max7456GetRowsCount(void);
|
||||||
void max7456Write(uint8_t x, uint8_t y, const char *buff);
|
void max7456Write(uint8_t x, uint8_t y, const char *buff);
|
||||||
void max7456WriteChar(uint8_t x, uint8_t y, uint8_t c);
|
void max7456WriteChar(uint8_t x, uint8_t y, uint8_t c);
|
||||||
|
@ -48,3 +48,4 @@ bool max7456BuffersSynced(void);
|
||||||
bool max7456LayerSupported(displayPortLayer_e layer);
|
bool max7456LayerSupported(displayPortLayer_e layer);
|
||||||
bool max7456LayerSelect(displayPortLayer_e layer);
|
bool max7456LayerSelect(displayPortLayer_e layer);
|
||||||
bool max7456LayerCopy(displayPortLayer_e destLayer, displayPortLayer_e sourceLayer);
|
bool max7456LayerCopy(displayPortLayer_e destLayer, displayPortLayer_e sourceLayer);
|
||||||
|
bool max7456IsDeviceDetected(void);
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "common/streambuf.h"
|
#include "common/streambuf.h"
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
|
|
||||||
|
#include "config/config.h"
|
||||||
#include "config/config_eeprom.h"
|
#include "config/config_eeprom.h"
|
||||||
#include "config/feature.h"
|
#include "config/feature.h"
|
||||||
|
|
||||||
|
@ -67,7 +68,6 @@
|
||||||
#include "drivers/vtx_table.h"
|
#include "drivers/vtx_table.h"
|
||||||
|
|
||||||
#include "fc/board_info.h"
|
#include "fc/board_info.h"
|
||||||
#include "config/config.h"
|
|
||||||
#include "fc/controlrate_profile.h"
|
#include "fc/controlrate_profile.h"
|
||||||
#include "fc/core.h"
|
#include "fc/core.h"
|
||||||
#include "fc/rc.h"
|
#include "fc/rc.h"
|
||||||
|
@ -110,6 +110,7 @@
|
||||||
#include "pg/beeper.h"
|
#include "pg/beeper.h"
|
||||||
#include "pg/board.h"
|
#include "pg/board.h"
|
||||||
#include "pg/gyrodev.h"
|
#include "pg/gyrodev.h"
|
||||||
|
#include "pg/max7456.h"
|
||||||
#include "pg/motor.h"
|
#include "pg/motor.h"
|
||||||
#include "pg/rx.h"
|
#include "pg/rx.h"
|
||||||
#include "pg/rx_spi.h"
|
#include "pg/rx_spi.h"
|
||||||
|
@ -796,13 +797,19 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
|
||||||
#define OSD_FLAGS_RESERVED_1 (1 << 2)
|
#define OSD_FLAGS_RESERVED_1 (1 << 2)
|
||||||
#define OSD_FLAGS_RESERVED_2 (1 << 3)
|
#define OSD_FLAGS_RESERVED_2 (1 << 3)
|
||||||
#define OSD_FLAGS_OSD_HARDWARE_MAX_7456 (1 << 4)
|
#define OSD_FLAGS_OSD_HARDWARE_MAX_7456 (1 << 4)
|
||||||
|
#define OSD_FLAGS_MAX7456_DETECTED (1 << 5)
|
||||||
|
|
||||||
uint8_t osdFlags = 0;
|
uint8_t osdFlags = 0;
|
||||||
#if defined(USE_OSD)
|
#if defined(USE_OSD)
|
||||||
osdFlags |= OSD_FLAGS_OSD_FEATURE;
|
osdFlags |= OSD_FLAGS_OSD_FEATURE;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_MAX7456
|
#ifdef USE_MAX7456
|
||||||
osdFlags |= OSD_FLAGS_OSD_HARDWARE_MAX_7456;
|
if (max7456Config()->csTag && max7456Config()->spiDevice) {
|
||||||
|
osdFlags |= OSD_FLAGS_OSD_HARDWARE_MAX_7456;
|
||||||
|
if (max7456IsDeviceDetected()) {
|
||||||
|
osdFlags |= OSD_FLAGS_MAX7456_DETECTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sbufWriteU8(dst, osdFlags);
|
sbufWriteU8(dst, osdFlags);
|
||||||
|
@ -3281,7 +3288,9 @@ static mspResult_e mspCommonProcessInCommand(mspDescriptor_t srcDesc, uint8_t cm
|
||||||
font_data[i] = sbufReadU8(src);
|
font_data[i] = sbufReadU8(src);
|
||||||
}
|
}
|
||||||
// !!TODO - replace this with a device independent implementation
|
// !!TODO - replace this with a device independent implementation
|
||||||
max7456WriteNvm(addr, font_data);
|
if (!max7456WriteNvm(addr, font_data)) {
|
||||||
|
return MSP_RESULT_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue