Program Listing for File spi.hpp
↰ Return to documentation for file (libspookyaction/include/pn532/esp32/spi.hpp
)
//
// Created by spak on 3/25/21.
//
#ifndef PN532_ESP32_SPI_HPP
#define PN532_ESP32_SPI_HPP
#include <driver/gpio.h>
#include <driver/spi_master.h>
#include <optional>
#include <pn532/channel.hpp>
#include <pn532/esp32/capable_mem.hpp>
#include <pn532/esp32/irq_assert.hpp>
namespace pn532::esp32 {
using capable_buffer = std::vector<std::uint8_t, capable_allocator<std::uint8_t>>;
enum struct spi_command : std::uint8_t {
data_write = 0b01,
status_read = 0b10,
data_read = 0b11,
none
};
class spi_channel final : public channel {
capable_buffer _dma_buffer;
std::optional<spi_host_device_t> _host;
spi_device_handle_t _device;
irq_assert _irq_assert;
enum struct recv_op_status {
init,
did_poll,
data_read
};
recv_op_status _recv_op_status;
result<> perform_transaction(capable_buffer &buffer, spi_command cmd, comm_dir mode, ms timeout);
protected:
result<> raw_send(mlab::range<bin_data::const_iterator> buffer, ms timeout) override;
result<> raw_receive(mlab::range<bin_data::iterator> buffer, ms timeout) override;
result<> raw_poll_status(ms timeout);
bool on_receive_prepare(ms timeout) override;
void on_receive_complete(result<> const &) override;
[[nodiscard]] comm_rx_mode raw_receive_mode() const override;
public:
bool wake() override;
spi_channel(spi_host_device_t host, spi_bus_config_t const &bus_config, spi_device_interface_config_t device_cfg, spi_dma_chan_t dma_chan);
spi_channel(spi_host_device_t host, spi_bus_config_t const &bus_config, spi_device_interface_config_t device_cfg, int dma_chan,
gpio_num_t response_irq_line, bool manage_isr_service);
~spi_channel() override;
};
}// namespace pn532::esp32
#endif//PN532_ESP32_SPI_HPP