#ifndef __PLATFORM_NRF52_SPI_H__
#define __PLATFORM_NRF52_SPI_H__

#include "gpio_interface.h"
#include "spi_interface.h"

#include "platform/nrf52/InterruptHandler.h"

namespace pinetime::platform::nrf52 {

class Spi
    : public pinetime::platform::nrf52::InterruptHandler
    , public pinetime::interfaces::SpiInterface
{
public:
    Spi(uint32_t instance, uint32_t sck, uint32_t mosi, uint32_t miso, pinetime::interfaces::GpioInterface & cs);
    ~Spi();
    void send(const uint8_t * buffer, uint32_t len) override;
    void recv(uint8_t * buffer, uint32_t len) override;

private:
    uint32_t transfer(uint32_t);

    void handle() override;

    pinetime::interfaces::GpioInterface & chip_select;
    volatile bool xfer_active;
};

}

#endif
