2021-10-13 20:08:35 +00:00
|
|
|
#include "drivers/Spi.h"
|
2020-05-07 17:53:51 +00:00
|
|
|
#include <hal/nrf_gpio.h>
|
2020-08-22 15:59:59 +00:00
|
|
|
#include <nrfx_log.h>
|
2020-05-07 17:53:51 +00:00
|
|
|
|
|
|
|
using namespace Pinetime::Drivers;
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
Spi::Spi(SpiMaster& spiMaster, uint8_t pinCsn) : spiMaster {spiMaster}, pinCsn {pinCsn} {
|
2020-05-11 16:50:37 +00:00
|
|
|
nrf_gpio_cfg_output(pinCsn);
|
|
|
|
nrf_gpio_pin_set(pinCsn);
|
2020-05-07 17:53:51 +00:00
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
bool Spi::Write(const uint8_t* data, size_t size) {
|
2020-05-07 17:53:51 +00:00
|
|
|
return spiMaster.Write(pinCsn, data, size);
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
bool Spi::Read(uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) {
|
2020-05-11 16:50:37 +00:00
|
|
|
return spiMaster.Read(pinCsn, cmd, cmdSize, data, dataSize);
|
2020-05-07 17:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Spi::Sleep() {
|
|
|
|
nrf_gpio_cfg_default(pinCsn);
|
2020-08-22 15:59:59 +00:00
|
|
|
NRF_LOG_INFO("[SPI] Sleep")
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
bool Spi::WriteCmdAndBuffer(const uint8_t* cmd, size_t cmdSize, const uint8_t* data, size_t dataSize) {
|
2020-08-22 15:59:59 +00:00
|
|
|
return spiMaster.WriteCmdAndBuffer(pinCsn, cmd, cmdSize, data, dataSize);
|
2020-05-07 17:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Spi::Init() {
|
|
|
|
nrf_gpio_pin_set(pinCsn); /* disable Set slave select (inactive high) */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-22 15:59:59 +00:00
|
|
|
void Spi::Wakeup() {
|
|
|
|
nrf_gpio_cfg_output(pinCsn);
|
|
|
|
nrf_gpio_pin_set(pinCsn);
|
|
|
|
NRF_LOG_INFO("[SPI] Wakeup")
|
2020-05-11 16:50:37 +00:00
|
|
|
}
|