mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
Fixes
This commit is contained in:
parent
d9a39726d1
commit
fc941ff495
@ -17,7 +17,7 @@
|
|||||||
spi0 {
|
spi0 {
|
||||||
compatible = "espressif,esp32-spi";
|
compatible = "espressif,esp32-spi";
|
||||||
host = <SPI2_HOST>;
|
host = <SPI2_HOST>;
|
||||||
pin-mosi = <&gpio0 7 GPIO_FLAG_NONE>;
|
pin-mosi = <7>;
|
||||||
pin-sclk = <&gpio0 6 GPIO_FLAG_NONE>;
|
pin-sclk = <6>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -52,8 +52,6 @@ add_custom_command(
|
|||||||
OUTPUT "${GENERATED_DIR}/devicetree.c"
|
OUTPUT "${GENERATED_DIR}/devicetree.c"
|
||||||
"${GENERATED_DIR}/devicetree.h"
|
"${GENERATED_DIR}/devicetree.h"
|
||||||
COMMAND pip install lark==1.3.1 pyyaml==6.0.3
|
COMMAND pip install lark==1.3.1 pyyaml==6.0.3
|
||||||
COMMAND echo python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py"
|
|
||||||
"${DEVICETREE_LOCATION}" "${GENERATED_DIR}"
|
|
||||||
COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py"
|
COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py"
|
||||||
"${DEVICETREE_LOCATION}" "${GENERATED_DIR}"
|
"${DEVICETREE_LOCATION}" "${GENERATED_DIR}"
|
||||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
#define ACK_CHECK_EN 1
|
#define ACK_CHECK_EN 1
|
||||||
|
|
||||||
struct Esp32SpiInternal {
|
struct Esp32SpiInternal {
|
||||||
Mutex mutex { 0 };
|
Mutex mutex {};
|
||||||
GpioDescriptor* sda_descriptor = nullptr;
|
GpioDescriptor* sda_descriptor = nullptr;
|
||||||
GpioDescriptor* scl_descriptor = nullptr;
|
GpioDescriptor* scl_descriptor = nullptr;
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ static error_t start(Device* device) {
|
|||||||
|
|
||||||
auto* scl_descriptor = gpio_descriptor_acquire(scl_spec.gpio_controller, scl_spec.pin, GPIO_OWNER_GPIO);
|
auto* scl_descriptor = gpio_descriptor_acquire(scl_spec.gpio_controller, scl_spec.pin, GPIO_OWNER_GPIO);
|
||||||
if (!scl_descriptor) {
|
if (!scl_descriptor) {
|
||||||
LOG_E(TAG, "Failed to acquire pin %u", sda_spec.pin);
|
LOG_E(TAG, "Failed to acquire pin %u", scl_spec.pin);
|
||||||
gpio_descriptor_release(sda_descriptor);
|
gpio_descriptor_release(sda_descriptor);
|
||||||
return ERROR_RESOURCE;
|
return ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ static error_t start(Device* device) {
|
|||||||
check(gpio_descriptor_get_native_pin_number(sda_descriptor, &sda_pin) == ERROR_NONE);
|
check(gpio_descriptor_get_native_pin_number(sda_descriptor, &sda_pin) == ERROR_NONE);
|
||||||
check(gpio_descriptor_get_native_pin_number(scl_descriptor, &scl_pin) == ERROR_NONE);
|
check(gpio_descriptor_get_native_pin_number(scl_descriptor, &scl_pin) == ERROR_NONE);
|
||||||
|
|
||||||
gpio_flags_t sda_flags, scl_flags;;
|
gpio_flags_t sda_flags, scl_flags;
|
||||||
check(gpio_descriptor_get_flags(sda_descriptor, &sda_flags) == ERROR_NONE);
|
check(gpio_descriptor_get_flags(sda_descriptor, &sda_flags) == ERROR_NONE);
|
||||||
check(gpio_descriptor_get_flags(scl_descriptor, &scl_flags) == ERROR_NONE);
|
check(gpio_descriptor_get_flags(scl_descriptor, &scl_flags) == ERROR_NONE);
|
||||||
|
|
||||||
@ -192,11 +192,15 @@ static error_t start(Device* device) {
|
|||||||
esp_err_t error = i2c_param_config(dts_config->port, &esp_config);
|
esp_err_t error = i2c_param_config(dts_config->port, &esp_config);
|
||||||
if (error != ESP_OK) {
|
if (error != ESP_OK) {
|
||||||
LOG_E(TAG, "Failed to configure port %d: %s", static_cast<int>(dts_config->port), esp_err_to_name(error));
|
LOG_E(TAG, "Failed to configure port %d: %s", static_cast<int>(dts_config->port), esp_err_to_name(error));
|
||||||
|
check(gpio_descriptor_release(sda_descriptor) == ERROR_NONE);
|
||||||
|
check(gpio_descriptor_release(scl_descriptor) == ERROR_NONE);
|
||||||
return ERROR_RESOURCE;
|
return ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = i2c_driver_install(dts_config->port, esp_config.mode, 0, 0, 0);
|
error = i2c_driver_install(dts_config->port, esp_config.mode, 0, 0, 0);
|
||||||
if (error != ESP_OK) {
|
if (error != ESP_OK) {
|
||||||
|
check(gpio_descriptor_release(sda_descriptor) == ERROR_NONE);
|
||||||
|
check(gpio_descriptor_release(scl_descriptor) == ERROR_NONE);
|
||||||
LOG_E(TAG, "Failed to install driver at port %d: %s", static_cast<int>(dts_config->port), esp_err_to_name(error));
|
LOG_E(TAG, "Failed to install driver at port %d: %s", static_cast<int>(dts_config->port), esp_err_to_name(error));
|
||||||
return ERROR_RESOURCE;
|
return ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ struct Esp32SpiInternal {
|
|||||||
RecursiveMutex mutex = {};
|
RecursiveMutex mutex = {};
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
|
|
||||||
Esp32SpiInternal(GpioDescriptor* pDescriptor, GpioDescriptor* pGpioDescriptor) {
|
explicit Esp32SpiInternal() {
|
||||||
recursive_mutex_construct(&mutex);
|
recursive_mutex_construct(&mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ static error_t unlock(Device* device) {
|
|||||||
|
|
||||||
static error_t start(Device* device) {
|
static error_t start(Device* device) {
|
||||||
ESP_LOGI(TAG, "start %s", device->name);
|
ESP_LOGI(TAG, "start %s", device->name);
|
||||||
auto* data = new (std::nothrow) Esp32SpiInternal(nullptr, nullptr);
|
auto* data = new (std::nothrow) Esp32SpiInternal();
|
||||||
if (!data) return ERROR_OUT_OF_MEMORY;
|
if (!data) return ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
device_set_driver_data(device, data);
|
device_set_driver_data(device, data);
|
||||||
|
|||||||
@ -32,7 +32,7 @@ struct GpioControllerApi {
|
|||||||
/**
|
/**
|
||||||
* @brief Configures the options for a GPIO pin.
|
* @brief Configures the options for a GPIO pin.
|
||||||
* @param[in,out] descriptor the pin descriptor
|
* @param[in,out] descriptor the pin descriptor
|
||||||
* @param[in] options configuration flags (direction, pull-up/down, etc.)
|
* @param[in] flags configuration flags (direction, pull-up/down, etc.)
|
||||||
* @return ERROR_NONE if successful
|
* @return ERROR_NONE if successful
|
||||||
*/
|
*/
|
||||||
error_t (*set_flags)(struct GpioDescriptor* descriptor, gpio_flags_t flags);
|
error_t (*set_flags)(struct GpioDescriptor* descriptor, gpio_flags_t flags);
|
||||||
@ -40,7 +40,7 @@ struct GpioControllerApi {
|
|||||||
/**
|
/**
|
||||||
* @brief Gets the configuration options for a GPIO pin.
|
* @brief Gets the configuration options for a GPIO pin.
|
||||||
* @param[in] descriptor the pin descriptor
|
* @param[in] descriptor the pin descriptor
|
||||||
* @param[out] options pointer to store the configuration flags
|
* @param[out] flags pointer to store the configuration flags
|
||||||
* @return ERROR_NONE if successful
|
* @return ERROR_NONE if successful
|
||||||
*/
|
*/
|
||||||
error_t (*get_flags)(struct GpioDescriptor* descriptor, gpio_flags_t* flags);
|
error_t (*get_flags)(struct GpioDescriptor* descriptor, gpio_flags_t* flags);
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
|
||||||
|
struct Device;
|
||||||
|
|
||||||
struct GpioDescriptor {
|
struct GpioDescriptor {
|
||||||
/** @brief The controller that owns this pin */
|
/** @brief The controller that owns this pin */
|
||||||
struct Device* controller;
|
struct Device* controller;
|
||||||
|
|||||||
@ -16,23 +16,28 @@ extern "C" {
|
|||||||
struct GpioControllerData {
|
struct GpioControllerData {
|
||||||
struct Mutex mutex {};
|
struct Mutex mutex {};
|
||||||
uint32_t pin_count;
|
uint32_t pin_count;
|
||||||
struct GpioDescriptor* descriptors;
|
struct GpioDescriptor* descriptors = nullptr;
|
||||||
|
|
||||||
explicit GpioControllerData(Device* device, uint32_t pin_count, void* controller_context) : pin_count(pin_count) {
|
explicit GpioControllerData(uint32_t pin_count) : pin_count(pin_count) {
|
||||||
mutex_construct(&mutex);
|
mutex_construct(&mutex);
|
||||||
descriptors = (struct GpioDescriptor*)calloc(pin_count, sizeof(struct GpioDescriptor));
|
}
|
||||||
check(descriptors);
|
|
||||||
|
|
||||||
|
error_t init_descriptors(Device* device, void* controller_context) {
|
||||||
|
descriptors = (struct GpioDescriptor*)calloc(pin_count, sizeof(struct GpioDescriptor));
|
||||||
|
if (!descriptors) return ERROR_OUT_OF_MEMORY;
|
||||||
for (uint32_t i = 0; i < pin_count; ++i) {
|
for (uint32_t i = 0; i < pin_count; ++i) {
|
||||||
descriptors[i].controller = device;
|
descriptors[i].controller = device;
|
||||||
descriptors[i].pin = (gpio_pin_t)i;
|
descriptors[i].pin = (gpio_pin_t)i;
|
||||||
descriptors[i].owner_type = GPIO_OWNER_NONE;
|
descriptors[i].owner_type = GPIO_OWNER_NONE;
|
||||||
descriptors[i].controller_context = controller_context;
|
descriptors[i].controller_context = controller_context;
|
||||||
}
|
}
|
||||||
|
return ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
~GpioControllerData() {
|
~GpioControllerData() {
|
||||||
free(descriptors);
|
if (descriptors != nullptr) {
|
||||||
|
free(descriptors);
|
||||||
|
}
|
||||||
mutex_destruct(&mutex);
|
mutex_destruct(&mutex);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -42,6 +47,8 @@ struct GpioDescriptor* gpio_descriptor_acquire(
|
|||||||
gpio_pin_t pin_number,
|
gpio_pin_t pin_number,
|
||||||
enum GpioOwnerType owner
|
enum GpioOwnerType owner
|
||||||
) {
|
) {
|
||||||
|
check(owner != GPIO_OWNER_NONE);
|
||||||
|
|
||||||
auto* data = (struct GpioControllerData*)device_get_driver_data(controller);
|
auto* data = (struct GpioControllerData*)device_get_driver_data(controller);
|
||||||
|
|
||||||
mutex_lock(&data->mutex);
|
mutex_lock(&data->mutex);
|
||||||
@ -74,8 +81,14 @@ error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context) {
|
error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context) {
|
||||||
auto* data = new(std::nothrow) GpioControllerData(device, pin_count, controller_context);
|
auto* data = new(std::nothrow) GpioControllerData(pin_count);
|
||||||
if (!data) return ERROR_OUT_OF_MEMORY;
|
if (!data) return ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
if (data->init_descriptors(device, controller_context) != ERROR_NONE) {
|
||||||
|
delete data;
|
||||||
|
return ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
device_set_driver_data(device, data);
|
device_set_driver_data(device, data);
|
||||||
return ERROR_NONE;
|
return ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user