TactilityKernel improvements and more (#459)
This commit is contained in:
committed by
GitHub
parent
96eccbdc8d
commit
dfe2c865d1
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <esp_err.h>
|
||||
|
||||
#include <Tactility/Error.h>
|
||||
|
||||
error_t esp_err_to_error(esp_err_t error);
|
||||
@@ -8,7 +8,7 @@ extern "C" {
|
||||
#include <stdint.h>
|
||||
|
||||
struct Esp32GpioConfig {
|
||||
uint8_t gpio_count;
|
||||
uint8_t gpioCount;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -9,9 +9,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
struct Esp32I2cConfig {
|
||||
uint32_t clock_frequency;
|
||||
struct GpioPinConfig pin_sda;
|
||||
struct GpioPinConfig pin_scl;
|
||||
uint32_t clockFrequency;
|
||||
struct GpioPinConfig pinSda;
|
||||
struct GpioPinConfig pinScl;
|
||||
const i2c_port_t port;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <Tactility/ErrorEsp32.h>
|
||||
|
||||
error_t esp_err_to_error(esp_err_t error) {
|
||||
switch (error) {
|
||||
case ESP_OK:
|
||||
return ERROR_NONE;
|
||||
case ESP_ERR_INVALID_ARG:
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
case ESP_ERR_INVALID_STATE:
|
||||
return ERROR_INVALID_STATE;
|
||||
case ESP_ERR_TIMEOUT:
|
||||
return ERROR_TIMEOUT;
|
||||
default:
|
||||
return ERROR_UNDEFINED;
|
||||
}
|
||||
}
|
||||
+26
-23
@@ -3,9 +3,11 @@
|
||||
|
||||
#include <Tactility/Driver.h>
|
||||
#include <Tactility/drivers/Esp32Gpio.h>
|
||||
#include <Tactility/drivers/GpioController.h>
|
||||
#include <Tactility/drivers/Gpio.h>
|
||||
|
||||
#include <Tactility/ErrorEsp32.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/drivers/Gpio.h>
|
||||
#include <Tactility/drivers/GpioController.h>
|
||||
|
||||
#define TAG LOG_TAG(esp32_gpio)
|
||||
|
||||
@@ -13,20 +15,21 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
static bool set_level(Device* device, gpio_pin_t pin, bool high) {
|
||||
return gpio_set_level(static_cast<gpio_num_t>(pin), high) == ESP_OK;
|
||||
static error_t set_level(Device* device, gpio_pin_t pin, bool high) {
|
||||
auto esp_error = gpio_set_level(static_cast<gpio_num_t>(pin), high);
|
||||
return esp_err_to_error(esp_error);
|
||||
}
|
||||
|
||||
static bool get_level(Device* device, gpio_pin_t pin, bool* high) {
|
||||
static error_t get_level(Device* device, gpio_pin_t pin, bool* high) {
|
||||
*high = gpio_get_level(static_cast<gpio_num_t>(pin)) != 0;
|
||||
return true;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static bool set_options(Device* device, gpio_pin_t pin, gpio_flags_t options) {
|
||||
static error_t set_options(Device* device, gpio_pin_t pin, gpio_flags_t options) {
|
||||
const Esp32GpioConfig* config = GET_CONFIG(device);
|
||||
|
||||
if (pin >= config->gpio_count) {
|
||||
return false;
|
||||
if (pin >= config->gpioCount) {
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
gpio_mode_t mode;
|
||||
@@ -37,8 +40,7 @@ static bool set_options(Device* device, gpio_pin_t pin, gpio_flags_t options) {
|
||||
} else if (options & GPIO_DIRECTION_OUTPUT) {
|
||||
mode = GPIO_MODE_OUTPUT;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "set_options: no direction flag specified for pin %d", pin);
|
||||
return false;
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
const gpio_config_t esp_config = {
|
||||
@@ -52,13 +54,14 @@ static bool set_options(Device* device, gpio_pin_t pin, gpio_flags_t options) {
|
||||
#endif
|
||||
};
|
||||
|
||||
return gpio_config(&esp_config) == ESP_OK;
|
||||
auto esp_error = gpio_config(&esp_config);
|
||||
return esp_err_to_error(esp_error);
|
||||
}
|
||||
|
||||
static bool get_options(Device* device, gpio_pin_t pin, gpio_flags_t* options) {
|
||||
static int get_options(Device* device, gpio_pin_t pin, gpio_flags_t* options) {
|
||||
gpio_io_config_t esp_config;
|
||||
if (gpio_get_io_config((gpio_num_t)pin, &esp_config) != ESP_OK) {
|
||||
return false;
|
||||
if (gpio_get_io_config(static_cast<gpio_num_t>(pin), &esp_config) != ESP_OK) {
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
gpio_flags_t output = 0;
|
||||
@@ -84,17 +87,17 @@ static bool get_options(Device* device, gpio_pin_t pin, gpio_flags_t* options) {
|
||||
}
|
||||
|
||||
*options = output;
|
||||
return true;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static int start(Device* device) {
|
||||
static error_t start(Device* device) {
|
||||
ESP_LOGI(TAG, "start %s", device->name);
|
||||
return 0;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static int stop(Device* device) {
|
||||
static error_t stop(Device* device) {
|
||||
ESP_LOGI(TAG, "stop %s", device->name);
|
||||
return 0;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
const static GpioControllerApi esp32_gpio_api = {
|
||||
@@ -107,10 +110,10 @@ const static GpioControllerApi esp32_gpio_api = {
|
||||
Driver esp32_gpio_driver = {
|
||||
.name = "esp32_gpio",
|
||||
.compatible = (const char*[]) { "espressif,esp32-gpio", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.startDevice = start,
|
||||
.stopDevice = stop,
|
||||
.api = (void*)&esp32_gpio_api,
|
||||
.device_type = nullptr,
|
||||
.deviceType = nullptr,
|
||||
.internal = { 0 }
|
||||
};
|
||||
|
||||
+22
-19
@@ -3,8 +3,11 @@
|
||||
|
||||
#include <Tactility/Driver.h>
|
||||
#include <Tactility/drivers/Esp32I2c.h>
|
||||
#include <Tactility/drivers/I2cController.h>
|
||||
|
||||
#include "Tactility/ErrorEsp32.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/drivers/I2cController.h>
|
||||
|
||||
#define TAG LOG_TAG(esp32_i2c)
|
||||
|
||||
@@ -28,41 +31,41 @@ struct InternalData {
|
||||
|
||||
extern "C" {
|
||||
|
||||
static bool read(Device* device, uint8_t address, uint8_t* data, size_t data_size, TickType_t timeout) {
|
||||
static int read(Device* device, uint8_t address, uint8_t* data, size_t data_size, TickType_t timeout) {
|
||||
vPortAssertIfInISR();
|
||||
auto* driver_data = GET_DATA(device);
|
||||
lock(driver_data);
|
||||
const esp_err_t result = i2c_master_read_from_device(GET_CONFIG(device)->port, address, data, data_size, timeout);
|
||||
const esp_err_t esp_error = i2c_master_read_from_device(GET_CONFIG(device)->port, address, data, data_size, timeout);
|
||||
unlock(driver_data);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
||||
return result == ESP_OK;
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_error);
|
||||
return esp_err_to_error(esp_error);
|
||||
}
|
||||
|
||||
static bool write(Device* device, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
static int write(Device* device, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
vPortAssertIfInISR();
|
||||
auto* driver_data = GET_DATA(device);
|
||||
lock(driver_data);
|
||||
const esp_err_t result = i2c_master_write_to_device(GET_CONFIG(device)->port, address, data, dataSize, timeout);
|
||||
const esp_err_t esp_error = i2c_master_write_to_device(GET_CONFIG(device)->port, address, data, dataSize, timeout);
|
||||
unlock(driver_data);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
||||
return result == ESP_OK;
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_error);
|
||||
return esp_err_to_error(esp_error);
|
||||
}
|
||||
|
||||
static bool write_read(Device* device, uint8_t address, const uint8_t* write_data, size_t write_data_size, uint8_t* read_data, size_t read_data_size, TickType_t timeout) {
|
||||
static int write_read(Device* device, uint8_t address, const uint8_t* write_data, size_t write_data_size, uint8_t* read_data, size_t read_data_size, TickType_t timeout) {
|
||||
vPortAssertIfInISR();
|
||||
auto* driver_data = GET_DATA(device);
|
||||
lock(driver_data);
|
||||
const esp_err_t result = i2c_master_write_read_device(GET_CONFIG(device)->port, address, write_data, write_data_size, read_data, read_data_size, timeout);
|
||||
const esp_err_t esp_error = i2c_master_write_read_device(GET_CONFIG(device)->port, address, write_data, write_data_size, read_data, read_data_size, timeout);
|
||||
unlock(driver_data);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
||||
return result == ESP_OK;
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_error);
|
||||
return esp_err_to_error(esp_error);
|
||||
}
|
||||
|
||||
static int start(Device* device) {
|
||||
ESP_LOGI(TAG, "start %s", device->name);
|
||||
auto* data = new InternalData();
|
||||
device_set_driver_data(device, data);
|
||||
return 0;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static int stop(Device* device) {
|
||||
@@ -70,10 +73,10 @@ static int stop(Device* device) {
|
||||
auto* driver_data = static_cast<InternalData*>(device_get_driver_data(device));
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete driver_data;
|
||||
return 0;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
const I2cControllerApi esp32_i2c_api = {
|
||||
const static I2cControllerApi esp32_i2c_api = {
|
||||
.read = read,
|
||||
.write = write,
|
||||
.write_read = write_read
|
||||
@@ -82,10 +85,10 @@ const I2cControllerApi esp32_i2c_api = {
|
||||
Driver esp32_i2c_driver = {
|
||||
.name = "esp32_i2c",
|
||||
.compatible = (const char*[]) { "espressif,esp32-i2c", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.startDevice = start,
|
||||
.stopDevice = stop,
|
||||
.api = (void*)&esp32_i2c_api,
|
||||
.device_type = &I2C_CONTROLLER_TYPE,
|
||||
.deviceType = &I2C_CONTROLLER_TYPE,
|
||||
.internal = { 0 }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user