From 40bdbe503c6dc838ce3fa8bae279a86b0a4f2c98 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 1 Mar 2020 16:00:43 +0100 Subject: Instantiate spi, lcd, lvg and touchpanel as global variables instead of unique_ptr (avoids dynamic alloc at run-time. --- src/main.cpp | 54 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 5a9df6cb..72db6ea8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,17 +25,26 @@ Pinetime::Logging::NrfLogger logger; Pinetime::Logging::DummyLogger logger; #endif -std::unique_ptr spi; -std::unique_ptr lcd; -std::unique_ptr lvgl; -std::unique_ptr touchPanel; - static constexpr uint8_t pinSpiSck = 2; static constexpr uint8_t pinSpiMosi = 3; static constexpr uint8_t pinSpiMiso = 4; static constexpr uint8_t pinSpiCsn = 25; static constexpr uint8_t pinLcdDataCommand = 18; +Pinetime::Drivers::SpiMaster spi{Pinetime::Drivers::SpiMaster::SpiModule::SPI0, { + Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb, + Pinetime::Drivers::SpiMaster::Modes::Mode3, + Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz, + pinSpiSck, + pinSpiMosi, + pinSpiMiso, + pinSpiCsn + } +}; +Pinetime::Drivers::St7789 lcd {spi, pinLcdDataCommand}; +Pinetime::Drivers::Cst816S touchPanel {}; +Pinetime::Components::LittleVgl lvgl {lcd, touchPanel}; + TimerHandle_t debounceTimer; Pinetime::Controllers::Battery batteryController; @@ -94,12 +103,12 @@ void OnNewTime(current_time_char_t* currentTime) { void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { if(((NRF_SPIM0->INTENSET & (1<<6)) != 0) && NRF_SPIM0->EVENTS_END == 1) { NRF_SPIM0->EVENTS_END = 0; - spi->OnEndEvent(); + spi.OnEndEvent(); } if(((NRF_SPIM0->INTENSET & (1<<19)) != 0) && NRF_SPIM0->EVENTS_STARTED == 1) { NRF_SPIM0->EVENTS_STARTED = 0; - spi->OnStartedEvent(); + spi.OnStartedEvent(); } if(((NRF_SPIM0->INTENSET & (1<<1)) != 0) && NRF_SPIM0->EVENTS_STOPPED == 1) { @@ -109,23 +118,28 @@ void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { int main(void) { logger.Init(); + + nrf_gpio_cfg_output(27); + nrf_gpio_pin_clear(27); + nrf_gpio_cfg_output(29); + nrf_gpio_pin_clear(29); + + nrf_gpio_cfg_output(20); + nrf_gpio_pin_clear(20); + + nrf_gpio_cfg_output(17); + nrf_gpio_pin_clear(17); + + nrf_gpio_cfg_output(11); + nrf_gpio_pin_clear(11); + + + nrf_drv_clock_init(); - spi.reset(new Pinetime::Drivers::SpiMaster {Pinetime::Drivers::SpiMaster::SpiModule::SPI0, { - Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb, - Pinetime::Drivers::SpiMaster::Modes::Mode3, - Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz, - pinSpiSck, - pinSpiMosi, - pinSpiMiso, - pinSpiCsn - }}); - lcd.reset(new Pinetime::Drivers::St7789(*spi, pinLcdDataCommand)); - touchPanel.reset(new Pinetime::Drivers::Cst816S()); - lvgl.reset(new Pinetime::Components::LittleVgl(*lcd, *touchPanel)); debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback); - systemTask.reset(new Pinetime::System::SystemTask(*spi, *lcd, *touchPanel, *lvgl, batteryController, bleController, dateTimeController)); + systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, touchPanel, lvgl, batteryController, bleController, dateTimeController)); systemTask->Start(); // ble_manager_init(); -- cgit v1.2.3