Refactor ctor() and Ini() of SpiMaster.
This commit is contained in:
parent
86d9f6e6c8
commit
2b3e6b1cde
|
@ -17,8 +17,16 @@ using namespace Pinetime::Applications;
|
|||
DisplayApp::DisplayApp(Controllers::Battery &batteryController,
|
||||
Controllers::Ble &bleController,
|
||||
Controllers::DateTime &dateTimeController) :
|
||||
spi{},
|
||||
lcd{new Drivers::St7789(spi, 18)},
|
||||
spi{Drivers::SpiMaster::SpiModule::SPI0, {
|
||||
Drivers::SpiMaster::BitOrder::Msb_Lsb,
|
||||
Drivers::SpiMaster::Modes::Mode3,
|
||||
Drivers::SpiMaster::Frequencies::Freq8Mhz,
|
||||
pinSpiSck,
|
||||
pinSpiMosi,
|
||||
pinSpiMiso,
|
||||
pinSpiCsn
|
||||
}},
|
||||
lcd{new Drivers::St7789(spi, pinLcdDataCommand)},
|
||||
gfx{new Components::Gfx(*lcd.get()) },
|
||||
batteryController{batteryController},
|
||||
bleController{bleController},
|
||||
|
@ -44,26 +52,16 @@ void DisplayApp::Process(void *instance) {
|
|||
}
|
||||
|
||||
void DisplayApp::InitHw() {
|
||||
nrf_gpio_cfg_output(14);
|
||||
nrf_gpio_cfg_output(22);
|
||||
nrf_gpio_cfg_output(23);
|
||||
nrf_gpio_pin_clear(14);
|
||||
nrf_gpio_pin_clear(22);
|
||||
nrf_gpio_pin_clear(23);
|
||||
nrf_gpio_cfg_output(pinLcdBacklight1);
|
||||
nrf_gpio_cfg_output(pinLcdBacklight2);
|
||||
nrf_gpio_cfg_output(pinLcdBacklight3);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight1);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight2);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight3);
|
||||
|
||||
Drivers::SpiMaster::Parameters params;
|
||||
params.bitOrder = Drivers::SpiMaster::BitOrder::Msb_Lsb;
|
||||
params.mode = Drivers::SpiMaster::Modes::Mode3;
|
||||
params.Frequency = Drivers::SpiMaster::Frequencies::Freq8Mhz;
|
||||
params.pinCSN = 25;
|
||||
params.pinMISO = 4;
|
||||
params.pinMOSI = 3;
|
||||
params.pinSCK = 2;
|
||||
spi.Init(Drivers::SpiMaster::SpiModule::SPI0, params);
|
||||
spi.Init();
|
||||
gfx->Init();
|
||||
|
||||
currentScreen->Refresh(true);
|
||||
|
||||
touchPanel.Init();
|
||||
}
|
||||
|
||||
|
@ -84,11 +82,11 @@ void DisplayApp::Refresh() {
|
|||
if (xQueueReceive(msgQueue, &msg, queueTimeout)) {
|
||||
switch (msg) {
|
||||
case Messages::GoToSleep:
|
||||
nrf_gpio_pin_set(23);
|
||||
nrf_gpio_pin_set(pinLcdBacklight3);
|
||||
vTaskDelay(100);
|
||||
nrf_gpio_pin_set(22);
|
||||
nrf_gpio_pin_set(pinLcdBacklight2);
|
||||
vTaskDelay(100);
|
||||
nrf_gpio_pin_set(14);
|
||||
nrf_gpio_pin_set(pinLcdBacklight1);
|
||||
lcd->DisplayOff();
|
||||
lcd->Sleep();
|
||||
touchPanel.Sleep();
|
||||
|
@ -99,9 +97,9 @@ void DisplayApp::Refresh() {
|
|||
touchPanel.Wakeup();
|
||||
|
||||
lcd->DisplayOn();
|
||||
nrf_gpio_pin_clear(23);
|
||||
nrf_gpio_pin_clear(22);
|
||||
nrf_gpio_pin_clear(14);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight3);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight2);
|
||||
nrf_gpio_pin_clear(pinLcdBacklight1);
|
||||
state = States::Running;
|
||||
break;
|
||||
case Messages::UpdateDateTime:
|
||||
|
|
|
@ -59,6 +59,14 @@ namespace Pinetime {
|
|||
Screens::Screen* currentScreen = nullptr;
|
||||
// Screens::Message messageScreen;
|
||||
// bool screenState = false;
|
||||
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;
|
||||
static constexpr uint8_t pinLcdBacklight1 = 14;
|
||||
static constexpr uint8_t pinLcdBacklight2 = 22;
|
||||
static constexpr uint8_t pinLcdBacklight3 = 23;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
|
||||
using namespace Pinetime::Drivers;
|
||||
|
||||
bool SpiMaster::Init(const SpiMaster::SpiModule spi, const SpiMaster::Parameters ¶ms) {
|
||||
configSpiModule = spi;
|
||||
configParams = params;
|
||||
SpiMaster::SpiMaster(const SpiMaster::SpiModule spi, const SpiMaster::Parameters ¶ms) :
|
||||
spi{spi}, params{params} {
|
||||
}
|
||||
|
||||
bool SpiMaster::Init() {
|
||||
/* Configure GPIO pins used for pselsck, pselmosi, pselmiso and pselss for SPI0 */
|
||||
nrf_gpio_cfg_output(params.pinSCK);
|
||||
nrf_gpio_cfg_output(params.pinMOSI);
|
||||
|
@ -94,12 +95,12 @@ void SpiMaster::Sleep() {
|
|||
while(NRF_SPI0->ENABLE != 0) {
|
||||
NRF_SPI0->ENABLE = (SPIM_ENABLE_ENABLE_Disabled << SPIM_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
nrf_gpio_cfg_default(configParams.pinSCK);
|
||||
nrf_gpio_cfg_default(configParams.pinMOSI);
|
||||
nrf_gpio_cfg_default(configParams.pinMISO);
|
||||
nrf_gpio_cfg_default(configParams.pinCSN);
|
||||
nrf_gpio_cfg_default(params.pinSCK);
|
||||
nrf_gpio_cfg_default(params.pinMOSI);
|
||||
nrf_gpio_cfg_default(params.pinMISO);
|
||||
nrf_gpio_cfg_default(params.pinCSN);
|
||||
}
|
||||
|
||||
void SpiMaster::Wakeup() {
|
||||
Init(configSpiModule, configParams);
|
||||
Init();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ namespace Pinetime {
|
|||
uint8_t pinMISO;
|
||||
uint8_t pinCSN;
|
||||
};
|
||||
bool Init(const SpiModule spi, const Parameters& params);
|
||||
|
||||
SpiMaster(const SpiModule spi, const Parameters& params);
|
||||
bool Init();
|
||||
bool Write(const uint8_t* data, size_t size);
|
||||
|
||||
void Sleep();
|
||||
|
@ -30,8 +32,8 @@ namespace Pinetime {
|
|||
NRF_SPI_Type * spiBaseAddress;
|
||||
uint8_t pinCsn;
|
||||
|
||||
SpiMaster::SpiModule configSpiModule;
|
||||
SpiMaster::Parameters configParams;
|
||||
SpiMaster::SpiModule spi;
|
||||
SpiMaster::Parameters params;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue