Ken Van Hoeylandt 55bfb9fe3b
Lockable renamed to Lock (#219)
Also changed usage from unique_ptr to class value.
2025-02-12 22:28:22 +01:00

51 lines
1.4 KiB
C++

#pragma once
#include "SpiCompat.h"
#include <Tactility/Lock.h>
#include <Tactility/RtosCompat.h>
namespace tt::hal::spi {
constexpr TickType_t defaultTimeout = 10 / portTICK_PERIOD_MS;
enum class InitMode {
ByTactility, // Tactility will initialize it in the correct bootup phase
ByExternal, // The device is already initialized and Tactility should assume it works
Disabled // Not initialized by default
};
struct Configuration {
spi_host_device_t device;
spi_common_dma_t dma;
spi_bus_config_t config;
/** Whether this bus should be initialized when device starts up */
InitMode initMode;
/** Whether this bus can stopped and re-started. */
bool canReinit;
/** Whether configuration can be changed. */
bool hasMutableConfiguration;
/** Optional custom lock */
std::shared_ptr<Lock> _Nullable lock;
};
enum class Status {
Started,
Stopped,
Unknown
};
/** Start communications */
bool start(spi_host_device_t device);
/** Stop communications */
bool stop(spi_host_device_t device);
/** @return true if communications were started successfully */
bool isStarted(spi_host_device_t device);
/** @return the lock that represents the specified device. Can be used with third party SPI implementations or native API calls (e.g. ESP-IDF). */
Lock& getLock(spi_host_device_t device);
} // namespace tt::hal::spi