Refactor ctor() and Ini() of SpiMaster.
This commit is contained in:
parent
86d9f6e6c8
commit
2b3e6b1cde
4 changed files with 45 additions and 36 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue