bool Display_SSD1306_I2C::hw_init() { struct { uint8_t reg; uint8_t seq[31]; } init_seq = { 0x0, {0xAE, 0xD5, 0x80, 0xA8, 0x3F, 0xD3, 0x00, 0x40, 0x8D, 0x14, 0x20, 0x00, 0xA1, 0xC8, 0xDA, 0x12, 0x81, 0xCF, 0xD9, 0xF1, 0xDB, 0x40, 0xA4, 0xA6, 0xAF, 0x21, 0, 127, 0x22, 0, 7 } }; _dev = std::move(hal.i2c_mgr->get_device(SSD1306_I2C_BUS, SSD1306_I2C_ADDR)); // take i2c bus sempahore if (!_dev || !_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) { return false; } // init display _dev->transfer((uint8_t *)&init_seq, sizeof(init_seq), nullptr, 0); // give back i2c semaphore _dev->get_semaphore()->give(); // clear display hw_update(); return true; }
void Display::update() { static uint8_t timer = 0; // return immediately if not enabled if (!_healthy) { return; } // max update frequency 2Hz if (timer++ < 25) { return; } timer = 0; // check if status has changed if (_flags.armed != AP_Notify::flags.armed) { update_arm(); _flags.armed = AP_Notify::flags.armed; } if (_flags.pre_arm_check != AP_Notify::flags.pre_arm_check) { update_prearm(); _flags.pre_arm_check = AP_Notify::flags.pre_arm_check; } if (_flags.gps_status != AP_Notify::flags.gps_status) { update_gps(); _flags.gps_status = AP_Notify::flags.gps_status; } if (_flags.gps_num_sats != AP_Notify::flags.gps_num_sats) { update_gps_sats(); _flags.gps_num_sats = AP_Notify::flags.gps_num_sats; } if (_flags.ekf_bad != AP_Notify::flags.ekf_bad) { update_ekf(); _flags.ekf_bad = AP_Notify::flags.ekf_bad; } // if somethings has changed, update display if (_need_update) { hw_update(); _need_update = false; } }
bool Display::init(void) { memset(&_flags, 0, sizeof(_flags)); _healthy = hw_init(); if (!_healthy) { return false; } // update all on display update_all(); hw_update(); return true; }