InfiniTime/src/drivers/Spi.cpp
Reinhold Gschweicher ac7b2da611 Update includes to to be relative to src directory
Don't use relative imports like `../foo.h` as those depend on the
relative position of both files. Rather than that use imports relative
to the `src` directory, which explicitly is part of the include
directories.
2021-11-15 22:02:49 +01:00

39 lines
1001 B
C++

#include "drivers/Spi.h"
#include <hal/nrf_gpio.h>
#include <nrfx_log.h>
using namespace Pinetime::Drivers;
Spi::Spi(SpiMaster& spiMaster, uint8_t pinCsn) : spiMaster {spiMaster}, pinCsn {pinCsn} {
nrf_gpio_cfg_output(pinCsn);
nrf_gpio_pin_set(pinCsn);
}
bool Spi::Write(const uint8_t* data, size_t size) {
return spiMaster.Write(pinCsn, data, size);
}
bool Spi::Read(uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) {
return spiMaster.Read(pinCsn, cmd, cmdSize, data, dataSize);
}
void Spi::Sleep() {
nrf_gpio_cfg_default(pinCsn);
NRF_LOG_INFO("[SPI] Sleep")
}
bool Spi::WriteCmdAndBuffer(const uint8_t* cmd, size_t cmdSize, const uint8_t* data, size_t dataSize) {
return spiMaster.WriteCmdAndBuffer(pinCsn, cmd, cmdSize, data, dataSize);
}
bool Spi::Init() {
nrf_gpio_pin_set(pinCsn); /* disable Set slave select (inactive high) */
return true;
}
void Spi::Wakeup() {
nrf_gpio_cfg_output(pinCsn);
nrf_gpio_pin_set(pinCsn);
NRF_LOG_INFO("[SPI] Wakeup")
}