Lockable renamed to Lock (#219)
Also changed usage from unique_ptr to class value.
This commit is contained in:
committed by
GitHub
parent
2e86d4774b
commit
55bfb9fe3b
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "./I2cCompat.h"
|
||||
#include "Tactility/Lockable.h"
|
||||
#include "Tactility/Lock.h"
|
||||
|
||||
#include <Tactility/RtosCompat.h>
|
||||
|
||||
@@ -89,6 +89,6 @@ bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeo
|
||||
* The lock for the specified bus.
|
||||
* This can be used when calling native I2C functionality outside of Tactility.
|
||||
*/
|
||||
Lockable& getLock(i2c_port_t port);
|
||||
Lock& getLock(i2c_port_t port);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
public:
|
||||
|
||||
explicit SdCardDevice(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {}
|
||||
virtual ~SdCardDevice() override = default;
|
||||
~SdCardDevice() override = default;
|
||||
|
||||
Type getType() const final { return Type::SdCard; };
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
/** Return empty string when not mounted or the mount path if mounted */
|
||||
virtual std::string getMountPath() const = 0;
|
||||
|
||||
virtual std::shared_ptr<Lockable> getLockable() const = 0;
|
||||
virtual Lock& getLock() const = 0;
|
||||
|
||||
virtual MountBehaviour getMountBehaviour() const { return mountBehaviour; }
|
||||
bool isMounted() const { return getState() == State::Mounted; }
|
||||
@@ -55,10 +55,9 @@ std::shared_ptr<SdCardDevice> _Nullable find(const std::string& path);
|
||||
template<typename ReturnType>
|
||||
inline ReturnType withSdCardLock(const std::string& path, std::function<ReturnType()> fn) {
|
||||
auto sdcard = find(path);
|
||||
std::unique_ptr<ScopedLockableUsage> scoped_lockable;
|
||||
if (sdcard != nullptr) {
|
||||
scoped_lockable = sdcard->getLockable()->scoped();
|
||||
scoped_lockable->lock(portMAX_DELAY);
|
||||
auto scoped_lockable = sdcard->getLock().asScopedLock();
|
||||
scoped_lockable.lock(portMAX_DELAY);
|
||||
}
|
||||
|
||||
return fn();
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
gpio_num_t spiPinWp,
|
||||
gpio_num_t spiPinInt,
|
||||
MountBehaviour mountBehaviourAtBoot,
|
||||
std::shared_ptr<Lockable> lockable = std::make_shared<Mutex>(),
|
||||
std::shared_ptr<Lock> lockable = std::make_shared<Mutex>(),
|
||||
std::vector<gpio_num_t> csPinWorkAround = std::vector<gpio_num_t>(),
|
||||
spi_host_device_t spiHost = SPI2_HOST,
|
||||
int spiFrequencyKhz = SDMMC_FREQ_DEFAULT
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
gpio_num_t spiPinWp; // Write-protect
|
||||
gpio_num_t spiPinInt; // Interrupt
|
||||
SdCardDevice::MountBehaviour mountBehaviourAtBoot;
|
||||
std::shared_ptr<Lockable> _Nullable lockable;
|
||||
std::shared_ptr<Lock> _Nullable lockable;
|
||||
std::vector<gpio_num_t> csPinWorkAround;
|
||||
spi_host_device_t spiHost;
|
||||
bool formatOnMountFailed = false;
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
bool unmount() final;
|
||||
std::string getMountPath() const final { return mountPath; }
|
||||
|
||||
std::shared_ptr<Lockable> getLockable() const final { return config->lockable; }
|
||||
Lock& getLock() const final { return *config->lockable; }
|
||||
|
||||
State getState() const override;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "SpiCompat.h"
|
||||
|
||||
#include <Tactility/Lockable.h>
|
||||
#include <Tactility/Lock.h>
|
||||
#include <Tactility/RtosCompat.h>
|
||||
|
||||
namespace tt::hal::spi {
|
||||
@@ -26,7 +26,7 @@ struct Configuration {
|
||||
/** Whether configuration can be changed. */
|
||||
bool hasMutableConfiguration;
|
||||
/** Optional custom lock */
|
||||
std::shared_ptr<Lockable> _Nullable lock;
|
||||
std::shared_ptr<Lock> _Nullable lock;
|
||||
};
|
||||
|
||||
enum class Status {
|
||||
@@ -45,6 +45,6 @@ bool stop(spi_host_device_t device);
|
||||
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). */
|
||||
Lockable& getLock(spi_host_device_t device);
|
||||
Lock& getLock(spi_host_device_t device);
|
||||
|
||||
} // namespace tt::hal::spi
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Tactility/RtosCompat.h>
|
||||
|
||||
#include "../Gpio.h"
|
||||
#include "Tactility/Lockable.h"
|
||||
#include "Tactility/Lock.h"
|
||||
#include "UartCompat.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -59,7 +59,7 @@ bool stop(uart_port_t port);
|
||||
bool isStarted(uart_port_t port);
|
||||
|
||||
/** @return a lock that is usable for using ESP-IDF directly, or for use with third party APIs */
|
||||
Lockable& getLock(uart_port_t port);
|
||||
Lock& getLock(uart_port_t port);
|
||||
|
||||
/**
|
||||
* Read up to a specified amount of bytes
|
||||
|
||||
Reference in New Issue
Block a user