Driver improvements (#535)
- New drivers: - SD SPI - spi_peripheral - touch_placeholder - display_placeholder - Devicetree compiler: - Implement phandle-arrays - Implement device addresses - Add placeholder drivers to all devices with a SPI display - SPI driver: add `cs-pins` and set them to high on driver start - FileSystem: add `file_system_set_owner()` and `file_system_get_owner()` - File locking is now checking if the related `FileSystem` is part of a shared SPI bus - Add `device_get_child_count()` - SDMMC driver: Remove default of `slot` value - Fix for Crowpanel Basic 3.5" display (add delay to booting) - Fix for LilyGO T-HMI SD card mounting (delayed mounting by disabling it initially in the dts)
This commit is contained in:
committed by
GitHub
parent
e50659a3fb
commit
599fa46766
@@ -6,9 +6,11 @@
|
||||
|
||||
#include "tactility/drivers/gpio_descriptor.h"
|
||||
#include <tactility/drivers/esp32_gpio_helpers.h>
|
||||
#include <tactility/drivers/gpio_controller.h>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
#include <soc/gpio_num.h>
|
||||
#include <vector>
|
||||
|
||||
#define TAG "esp32_spi"
|
||||
|
||||
@@ -21,13 +23,16 @@ struct Esp32SpiInternal {
|
||||
RecursiveMutex mutex = {};
|
||||
bool initialized = false;
|
||||
|
||||
// Pin descriptors
|
||||
// Bus pin descriptors
|
||||
GpioDescriptor* sclk_descriptor = nullptr;
|
||||
GpioDescriptor* mosi_descriptor = nullptr;
|
||||
GpioDescriptor* miso_descriptor = nullptr;
|
||||
GpioDescriptor* wp_descriptor = nullptr;
|
||||
GpioDescriptor* hd_descriptor = nullptr;
|
||||
|
||||
// CS pin descriptors
|
||||
std::vector<GpioDescriptor*> cs_descriptors;
|
||||
|
||||
explicit Esp32SpiInternal() {
|
||||
recursive_mutex_construct(&mutex);
|
||||
}
|
||||
@@ -43,6 +48,10 @@ struct Esp32SpiInternal {
|
||||
release_pin(&miso_descriptor);
|
||||
release_pin(&wp_descriptor);
|
||||
release_pin(&hd_descriptor);
|
||||
for (auto*& desc : cs_descriptors) {
|
||||
release_pin(&desc);
|
||||
}
|
||||
cs_descriptors.clear();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -117,10 +126,30 @@ static error_t start(Device* device) {
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
// Acquire and deselect all CS pins (drive high)
|
||||
for (uint8_t i = 0; i < dts_config->cs_gpios_count; i++) {
|
||||
const GpioPinSpec* cs = &dts_config->cs_gpios[i];
|
||||
if (cs->gpio_controller == nullptr) continue;
|
||||
GpioDescriptor* desc = gpio_descriptor_acquire(cs->gpio_controller, cs->pin, GPIO_OWNER_SPI);
|
||||
if (desc != nullptr) {
|
||||
gpio_descriptor_set_flags(desc, GPIO_FLAG_DIRECTION_OUTPUT);
|
||||
gpio_descriptor_set_level(desc, true);
|
||||
data->cs_descriptors.push_back(desc);
|
||||
}
|
||||
}
|
||||
|
||||
data->initialized = true;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
void esp32_spi_deselect_all_cs(Device* device) {
|
||||
auto* data = GET_DATA(device);
|
||||
if (data == nullptr) return;
|
||||
for (auto* desc : data->cs_descriptors) {
|
||||
gpio_descriptor_set_level(desc, true);
|
||||
}
|
||||
}
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
LOG_I(TAG, "stop %s", device->name);
|
||||
auto* driver_data = GET_DATA(device);
|
||||
@@ -136,6 +165,16 @@ static error_t stop(Device* device) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t esp32_spi_get_cs_pin(Device* child_device, GpioPinSpec* out_pin) {
|
||||
auto* parent = device_get_parent(child_device);
|
||||
if (parent == nullptr || device_get_type(parent) != &SPI_CONTROLLER_TYPE) return ERROR_INVALID_STATE;
|
||||
auto* config = GET_CONFIG(parent);
|
||||
int32_t index = child_device->address;
|
||||
if (index < 0 || index >= config->cs_gpios_count) return ERROR_OUT_OF_RANGE;
|
||||
*out_pin = config->cs_gpios[index];
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
const static struct SpiControllerApi esp32_spi_api = {
|
||||
.lock = lock,
|
||||
.try_lock = try_lock,
|
||||
|
||||
Reference in New Issue
Block a user