020aa471e2
Remove FileMutex and wire locking into driver subsystems.
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
// SPDX-License-Identifier: Apache-2.0
|
|
#include <tactility/drivers/spi_controller.h>
|
|
#include <tactility/error.h>
|
|
#include <tactility/device.h>
|
|
|
|
#define SPI_DRIVER_API(driver) ((struct SpiControllerApi*)driver->api)
|
|
|
|
extern "C" {
|
|
|
|
error_t spi_controller_lock(Device* device) {
|
|
const auto* driver = device_get_driver(device);
|
|
return SPI_DRIVER_API(driver)->lock(device);
|
|
}
|
|
|
|
error_t spi_controller_try_lock(Device* device, TickType_t timeout) {
|
|
const auto* driver = device_get_driver(device);
|
|
return SPI_DRIVER_API(driver)->try_lock(device, timeout);
|
|
}
|
|
|
|
error_t spi_controller_unlock(Device* device) {
|
|
const auto* driver = device_get_driver(device);
|
|
return SPI_DRIVER_API(driver)->unlock(device);
|
|
}
|
|
|
|
error_t spi_controller_lock_bus_of(Device* device) {
|
|
Device* parent = device_get_parent(device);
|
|
if (parent == nullptr || device_get_type(parent) != &SPI_CONTROLLER_TYPE) {
|
|
return ERROR_NONE;
|
|
}
|
|
return spi_controller_lock(parent);
|
|
}
|
|
|
|
void spi_controller_unlock_bus_of(Device* device) {
|
|
Device* parent = device_get_parent(device);
|
|
if (parent == nullptr || device_get_type(parent) != &SPI_CONTROLLER_TYPE) {
|
|
return;
|
|
}
|
|
spi_controller_unlock(parent);
|
|
}
|
|
|
|
const DeviceType SPI_CONTROLLER_TYPE {
|
|
.name = "spi-controller"
|
|
};
|
|
|
|
}
|