Skip to content
4 changes: 4 additions & 0 deletions Devices/lilygo-tdeck/Source/Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "devices/TrackballDevice.h"

#include <Tactility/hal/gps/GpsConfiguration.h>
#include <Tactility/kernel/Kernel.h>
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/Logger.h>
#include <Tactility/LogMessages.h>
Expand Down Expand Up @@ -30,6 +31,9 @@ static bool powerOn() {
return false;
}

// Avoids crash when no SD card is inserted. It's unknown why, but likely is related to power draw.
tt::kernel::delayMillis(100);

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions Devices/lilygo-tlora-pager/Source/drivers/TloraPager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ static int stop(Device* device) {
Driver tlora_pager_driver = {
.name = "T-Lora Pager",
.compatible = (const char*[]) { "lilygo,tlora-pager", nullptr },
.start_device = start,
.stop_device = stop,
.startDevice = start,
.stopDevice = stop,
.api = nullptr,
.device_type = nullptr,
.deviceType = nullptr,
.internal = { 0 }
};

Expand Down
7 changes: 7 additions & 0 deletions Platforms/PlatformEsp32/Include/Tactility/ErrorEsp32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <esp_err.h>

#include <Tactility/Error.h>

error_t esp_err_to_error(esp_err_t error);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
#include <stdint.h>

struct Esp32GpioConfig {
uint8_t gpio_count;
uint8_t gpioCount;
};

#ifdef __cplusplus
Expand Down
6 changes: 3 additions & 3 deletions Platforms/PlatformEsp32/Include/Tactility/drivers/Esp32I2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
16 changes: 16 additions & 0 deletions Platforms/PlatformEsp32/Source/ErrorEsp32.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,33 @@

#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)

#define GET_CONFIG(device) ((struct Esp32GpioConfig*)device->internal.driver_data)

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;
Expand All @@ -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 = {
Expand All @@ -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;
Expand All @@ -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 = {
Expand All @@ -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 }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -28,52 +31,52 @@ 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) {
ESP_LOGI(TAG, "stop %s", device->name);
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
Expand All @@ -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 }
};

Expand Down
2 changes: 1 addition & 1 deletion Tactility/Source/service/gui/GuiService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int32_t GuiService::guiMain() {

while (true) {
uint32_t flags = 0;
if (service->threadFlags.wait(GUI_THREAD_FLAG_ALL, false, true, portMAX_DELAY, &flags)) {
if (service->threadFlags.wait(GUI_THREAD_FLAG_ALL, false, true, &flags, portMAX_DELAY)) {
// When service not started or starting -> exit
State service_state = getState(manifest.id);
if (service_state != State::Started && service_state != State::Starting) {
Expand Down
8 changes: 4 additions & 4 deletions Tactility/Source/service/wifi/WifiEsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,11 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT)
* or connection failed for the maximum number of re-tries (WIFI_FAIL_BIT).
* The bits are set by wifi_event_handler() */
uint32_t bits;
if (wifi_singleton->connection_wait_flags.wait(WIFI_FAIL_BIT | WIFI_CONNECTED_BIT, false, true, kernel::MAX_TICKS, &bits)) {
uint32_t flags;
if (wifi_singleton->connection_wait_flags.wait(WIFI_FAIL_BIT | WIFI_CONNECTED_BIT, false, true, &flags, kernel::MAX_TICKS)) {
LOGGER.info("Waiting for EventGroup by event_handler()");

if (bits & WIFI_CONNECTED_BIT) {
if (flags & WIFI_CONNECTED_BIT) {
wifi->setSecureConnection(config.sta.password[0] != 0x00U);
wifi->setRadioState(RadioState::ConnectionActive);
publish_event(wifi, WifiEvent::ConnectionSuccess);
Expand All @@ -815,7 +815,7 @@ static void dispatchConnect(std::shared_ptr<Wifi> wifi) {
LOGGER.info("Stored credentials");
}
}
} else if (bits & WIFI_FAIL_BIT) {
} else if (flags & WIFI_FAIL_BIT) {
wifi->setRadioState(RadioState::On);
publish_event(wifi, WifiEvent::ConnectionFailed);
LOGGER.info("Failed to connect to {}", wifi->connection_target.ssid.c_str());
Expand Down
5 changes: 3 additions & 2 deletions TactilityFreeRtos/Include/Tactility/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Dispatcher final {
}

if (shutdown) {
mutex.unlock();
return false;
}

Expand All @@ -86,14 +87,14 @@ class Dispatcher final {
}

/**
* Consume 1 or more dispatched function (if any) until the queue is empty.
* Consume 1 or more dispatched functions (if any) until the queue is empty.
* @warning The timeout is only the wait time before consuming the message! It is not a limit to the total execution time when calling this method.
* @param[in] timeout the ticks to wait for a message
* @return the amount of messages that were consumed
*/
uint32_t consume(TickType_t timeout = kernel::MAX_TICKS) {
// Wait for signal
if (!eventFlag.wait(WAIT_FLAG, false, true, timeout)) {
if (!eventFlag.wait(WAIT_FLAG, false, true, nullptr, timeout)) {
return 0;
}

Expand Down
Loading