summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-01-26 12:37:10 (GMT)
committerJF <jf@codingfield.com>2020-01-26 12:37:10 (GMT)
commit5fa4f5abe0b752bb2d990378e02d6424a1d1b661 (patch)
treebc2e731c488573d678aec1d388a00f754b24fb02 /src/main.cpp
parenteb7a1b3ac9cbacb74afb7fcd1d40c51a18c90060 (diff)
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.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp47
1 files changed, 39 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 284113c..13dddca 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 <drivers/St7789.h>
+#include <drivers/SpiMaster.h>
+#include <Components/Gfx/Gfx.h>
#if NRF_LOG_ENABLED
#include "Logging/NrfLogger.h"
@@ -24,6 +28,18 @@ Pinetime::Logging::NrfLogger logger;
Pinetime::Logging::DummyLogger logger;
#endif
+std::unique_ptr<Pinetime::Drivers::SpiMaster> spi;
+std::unique_ptr<Pinetime::Drivers::St7789> lcd;
+std::unique_ptr<Pinetime::Components::Gfx> gfx;
+std::unique_ptr<Pinetime::Drivers::Cst816S> 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<Pinetime::Applications::DisplayApp> 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();