InfiniTime/src/drivers/SpiMaster.h

53 lines
1.3 KiB
C
Raw Normal View History

2019-12-07 16:11:50 +00:00
#pragma once
#include <cstdint>
#include <cstddef>
#include <array>
#include <atomic>
2019-12-07 16:11:50 +00:00
namespace Pinetime {
namespace Drivers {
class SpiMaster {
public:;
enum class SpiModule : uint8_t {SPI0, SPI1};
enum class BitOrder : uint8_t {Msb_Lsb, Lsb_Msb};
enum class Modes : uint8_t {Mode0, Mode1, Mode2, Mode3};
enum class Frequencies : uint8_t {Freq8Mhz};
struct Parameters {
BitOrder bitOrder;
Modes mode;
Frequencies Frequency;
uint8_t pinSCK;
uint8_t pinMOSI;
uint8_t pinMISO;
uint8_t pinCSN;
};
SpiMaster(const SpiModule spi, const Parameters& params);
bool Init();
2019-12-07 16:11:50 +00:00
bool Write(const uint8_t* data, size_t size);
bool WriteRepeat(const uint8_t *data, size_t size, int repeat);
2020-01-19 18:47:49 +00:00
void setup_workaround_for_ftpan_58(NRF_SPIM_Type *spim, uint32_t ppi_channel, uint32_t gpiote_channel);
2019-12-07 16:11:50 +00:00
void Sleep();
void Wakeup();
2020-01-19 18:47:49 +00:00
bool GetStatusEnd();
bool GetStatusStarted();
void irq();
2019-12-07 16:11:50 +00:00
private:
2020-01-19 18:47:49 +00:00
NRF_SPIM_Type * spiBaseAddress;
2019-12-07 16:11:50 +00:00
uint8_t pinCsn;
SpiMaster::SpiModule spi;
SpiMaster::Parameters params;
std::atomic<bool> busy {false};
uint32_t bufferAddr = 0;
size_t bufferSize = 0;
2019-12-07 16:11:50 +00:00
};
}
}