2020-05-07 13:53:51 -04:00
|
|
|
#include <hal/nrf_gpio.h>
|
|
|
|
#include "Spi.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Drivers;
|
|
|
|
|
|
|
|
Spi::Spi(SpiMaster& spiMaster, uint8_t pinCsn) :
|
|
|
|
spiMaster{spiMaster}, pinCsn{pinCsn} {
|
2020-05-11 12:50:37 -04:00
|
|
|
nrf_gpio_cfg_output(pinCsn);
|
|
|
|
nrf_gpio_pin_set(pinCsn);
|
2020-05-07 13:53:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Spi::Write(const uint8_t *data, size_t size) {
|
|
|
|
return spiMaster.Write(pinCsn, data, size);
|
|
|
|
}
|
|
|
|
|
2020-05-11 12:50:37 -04:00
|
|
|
bool Spi::Read(uint8_t* cmd, size_t cmdSize, uint8_t *data, size_t dataSize) {
|
|
|
|
return spiMaster.Read(pinCsn, cmd, cmdSize, data, dataSize);
|
2020-05-07 13:53:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Spi::Sleep() {
|
|
|
|
// TODO sleep spi
|
|
|
|
nrf_gpio_cfg_default(pinCsn);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Spi::Init() {
|
|
|
|
nrf_gpio_pin_set(pinCsn); /* disable Set slave select (inactive high) */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-01 12:32:46 -04:00
|
|
|
bool Spi::WriteCmdAndBuffer(const uint8_t *cmd, size_t cmdSize, const uint8_t *data, size_t dataSize) {
|
2020-05-11 12:50:37 -04:00
|
|
|
return spiMaster.WriteCmdAndBuffer(pinCsn, cmd, cmdSize, data, dataSize);
|
|
|
|
}
|
|
|
|
|
2020-05-07 13:53:51 -04:00
|
|
|
|