DISPLAY - Allow FC to boot normally if OLED display is not connected at

boot.  FC can detect when the display is unplugged and recovers after
display I2C timeouts.
This commit is contained in:
Dominic Clifton 2015-04-18 20:13:16 +01:00
parent a5c2c70541
commit ebd5475a55
3 changed files with 32 additions and 14 deletions

View File

@ -169,14 +169,15 @@ static const uint8_t const multiWiiFont[][5] = { // Refer to "Times New Roman" F
};
#define OLED_address 0x3C // OLED at address 0x3C in 7bit
void i2c_OLED_send_cmd(uint8_t command)
static bool i2c_OLED_send_cmd(uint8_t command)
{
i2cWrite(OLED_address, 0x80, command);
return i2cWrite(OLED_address, 0x80, command);
}
static void i2c_OLED_send_byte(uint8_t val)
static bool i2c_OLED_send_byte(uint8_t val)
{
i2cWrite(OLED_address, 0x40, val);
return i2cWrite(OLED_address, 0x40, val);
}
void i2c_OLED_clear_display(void)
@ -247,9 +248,14 @@ void i2c_OLED_send_string(const char *string)
* according to http://www.adafruit.com/datasheets/UG-2864HSWEG01.pdf Chapter 4.4 Page 15
*/
#if 1
void ug2864hsweg01InitI2C(void)
bool ug2864hsweg01InitI2C(void)
{
i2c_OLED_send_cmd(0xAE); // Set display OFF
// Set display OFF
if (!i2c_OLED_send_cmd(0xAE)) {
return false;
}
i2c_OLED_send_cmd(0xD4); // Set Display Clock Divide Ratio / OSC Frequency
i2c_OLED_send_cmd(0x80); // Display Clock Divide Ratio / OSC Frequency
i2c_OLED_send_cmd(0xA8); // Set Multiplex Ratio
@ -272,7 +278,10 @@ void ug2864hsweg01InitI2C(void)
i2c_OLED_send_cmd(0xA4); // Set all pixels OFF
i2c_OLED_send_cmd(0xA6); // Set display not inverted
i2c_OLED_send_cmd(0xAF); // Set display On
i2c_OLED_clear_display();
return true;
}
#else
void ug2864hsweg01InitI2C(void)

View File

@ -34,7 +34,7 @@
#define VERTICAL_BARGRAPH_ZERO_CHARACTER (128 + 32)
#define VERTICAL_BARGRAPH_CHARACTER_COUNT 7
void ug2864hsweg01InitI2C(void);
bool ug2864hsweg01InitI2C(void);
void i2c_OLED_set_xy(uint8_t col, uint8_t row);
void i2c_OLED_set_line(uint8_t row);

View File

@ -73,6 +73,7 @@ controlRateConfig_t *getControlRateConfig(uint8_t profileIndex);
#define PAGE_CYCLE_FREQUENCY (MILLISECONDS_IN_A_SECOND * 5)
static uint32_t nextDisplayUpdateAt = 0;
static bool displayPresent = false;
static rxConfig_t *rxConfig;
@ -136,7 +137,7 @@ typedef struct pageState_s {
static pageState_t pageState;
void resetDisplay(void) {
ug2864hsweg01InitI2C();
displayPresent = ug2864hsweg01InitI2C();
}
void LCDprint(uint8_t i) {
@ -211,11 +212,6 @@ void showTitle()
void handlePageChange(void)
{
// Some OLED displays do not respond on the first initialisation so refresh the display
// when the page changes in the hopes the hardware responds. This also allows the
// user to power off/on the display or connect it while powered.
resetDisplay();
i2c_OLED_clear_display_quick();
showTitle();
}
@ -533,9 +529,22 @@ void updateDisplay(void)
}
if (pageState.pageChanging) {
handlePageChange();
pageState.pageFlags &= ~PAGE_STATE_FLAG_FORCE_PAGE_CHANGE;
pageState.nextPageAt = now + PAGE_CYCLE_FREQUENCY;
// Some OLED displays do not respond on the first initialisation so refresh the display
// when the page changes in the hopes the hardware responds. This also allows the
// user to power off/on the display or connect it while powered.
resetDisplay();
if (!displayPresent) {
return;
}
handlePageChange();
}
if (!displayPresent) {
return;
}
switch(pageState.pageId) {