From 5fa4f5abe0b752bb2d990378e02d6424a1d1b661 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 26 Jan 2020 13:37:10 +0100 Subject: Better integration of SPI with DMA and IRQ. Using only 'End' IRQ. Perf could be improved by using 'Started' IRQ to prepare the next buffer while the current one is beeing sent. --- src/main.cpp | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 284113c1..13dddca6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,10 @@ #include "BLE/BleManager.h" #include "Components/Battery/BatteryController.h" #include "Components/Ble/BleController.h" +#include "../drivers/Cst816s.h" +#include +#include +#include #if NRF_LOG_ENABLED #include "Logging/NrfLogger.h" @@ -24,6 +28,18 @@ Pinetime::Logging::NrfLogger logger; Pinetime::Logging::DummyLogger logger; #endif +std::unique_ptr spi; +std::unique_ptr lcd; +std::unique_ptr gfx; +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; + + std::unique_ptr displayApp; TaskHandle_t systemThread; bool isSleeping = false; @@ -85,9 +101,29 @@ void SystemTask(void *) { APP_GPIOTE_INIT(2); bool erase_bonds=false; nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds); - displayApp->Start(); + 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)); + gfx.reset(new Pinetime::Components::Gfx(*lcd)); + touchPanel.reset(new Pinetime::Drivers::Cst816S()); + + spi->Init(); + lcd->Init(); + touchPanel->Init(); batteryController.Init(); + + displayApp.reset(new Pinetime::Applications::DisplayApp(*lcd, *gfx, *touchPanel, batteryController, bleController, dateTimeController)); + displayApp->Start(); + batteryController.Update(); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel); @@ -158,27 +194,22 @@ void OnNewTime(current_time_char_t* currentTime) { dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG)); } -extern Pinetime::Drivers::SpiMaster* spiInstance; 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; - spiInstance->irqEnd(); + spi->OnEndEvent(*gfx); } if(((NRF_SPIM0->INTENSET & (1<<19)) != 0) && NRF_SPIM0->EVENTS_STARTED == 1) { NRF_SPIM0->EVENTS_STARTED = 0; - spiInstance->irqStarted(); + spi->OnStartedEvent(*gfx); } - if(((NRF_SPIM0->INTENSET & (1<<1)) != 0) && NRF_SPIM0->EVENTS_STOPPED == 1) { NRF_SPIM0->EVENTS_STOPPED = 0; } - - return; } int main(void) { - displayApp.reset(new Pinetime::Applications::DisplayApp(batteryController, bleController, dateTimeController)); logger.Init(); nrf_drv_clock_init(); -- cgit v1.2.3-70-g09d2