mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
Partial reimplementation of TactilityC GPIO (#469)
* **New Features** * Added a GPIO hardware abstraction layer for reading pin levels from applications. * Applications can now query the number of available GPIO pins so they can adapt to different devices. * **Chores** * Integrations updated so GPIO capabilities are discoverable and exported to running applications.
This commit is contained in:
parent
c9185740d7
commit
399dca5e14
@ -90,6 +90,11 @@ static int get_options(Device* device, gpio_pin_t pin, gpio_flags_t* options) {
|
|||||||
return ERROR_NONE;
|
return ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_t get_pin_count(struct Device* device, uint32_t* count) {
|
||||||
|
*count = GET_CONFIG(device)->gpioCount;
|
||||||
|
return ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
return ERROR_NONE;
|
return ERROR_NONE;
|
||||||
@ -104,7 +109,8 @@ const static GpioControllerApi esp32_gpio_api = {
|
|||||||
.set_level = set_level,
|
.set_level = set_level,
|
||||||
.get_level = get_level,
|
.get_level = get_level,
|
||||||
.set_options = set_options,
|
.set_options = set_options,
|
||||||
.get_options = get_options
|
.get_options = get_options,
|
||||||
|
.get_pin_count = get_pin_count
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct Module platform_module;
|
extern struct Module platform_module;
|
||||||
@ -115,7 +121,7 @@ Driver esp32_gpio_driver = {
|
|||||||
.startDevice = start,
|
.startDevice = start,
|
||||||
.stopDevice = stop,
|
.stopDevice = stop,
|
||||||
.api = (void*)&esp32_gpio_api,
|
.api = (void*)&esp32_gpio_api,
|
||||||
.deviceType = nullptr,
|
.deviceType = &GPIO_CONTROLLER_TYPE,
|
||||||
.owner = &platform_module,
|
.owner = &platform_module,
|
||||||
.driver_private = nullptr
|
.driver_private = nullptr
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,7 @@ if (DEFINED ENV{ESP_IDF_VERSION})
|
|||||||
INCLUDE_DIRS "Include/"
|
INCLUDE_DIRS "Include/"
|
||||||
PRIV_INCLUDE_DIRS "Private/"
|
PRIV_INCLUDE_DIRS "Private/"
|
||||||
REQUIRES lvgl
|
REQUIRES lvgl
|
||||||
PRIV_REQUIRES Tactility TactilityCore elf_loader
|
PRIV_REQUIRES Tactility TactilityCore elf_loader TactilityKernel
|
||||||
)
|
)
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
@ -28,6 +28,7 @@ else()
|
|||||||
target_link_libraries(TactilityC
|
target_link_libraries(TactilityC
|
||||||
PRIVATE Tactility
|
PRIVATE Tactility
|
||||||
PRIVATE TactilityCore
|
PRIVATE TactilityCore
|
||||||
|
PRIVATE TactilityKernel
|
||||||
PUBLIC lvgl
|
PUBLIC lvgl
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
30
TactilityC/Include/tt_hal_gpio.h
Normal file
30
TactilityC/Include/tt_hal_gpio.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Logical GPIO pin identifier used by the HAL. Typically maps to the SoC GPIO number. */
|
||||||
|
typedef unsigned int GpioPin;
|
||||||
|
/** Value indicating that no GPIO pin is used/applicable. */
|
||||||
|
#define GPIO_NO_PIN -1
|
||||||
|
|
||||||
|
/** Read the current logic level of a pin.
|
||||||
|
* The pin should be configured for input or input/output.
|
||||||
|
* @param[in] pin The pin to read.
|
||||||
|
* @return true if the level is high, false if low. If the pin is invalid, the
|
||||||
|
* behavior is implementation-defined and may return false.
|
||||||
|
*/
|
||||||
|
bool tt_hal_gpio_get_level(GpioPin pin);
|
||||||
|
|
||||||
|
/** Get the number of GPIO pins available on this platform.
|
||||||
|
* @return The count of valid GPIO pins.
|
||||||
|
*/
|
||||||
|
int tt_hal_gpio_get_pin_count();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
39
TactilityC/Source/tt_hal_gpio.cpp
Normal file
39
TactilityC/Source/tt_hal_gpio.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "tt_hal_gpio.h"
|
||||||
|
#include <Tactility/hal/gpio/Gpio.h>
|
||||||
|
#include <tactility/device.h>
|
||||||
|
#include <tactility/drivers/gpio_controller.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
using namespace tt::hal;
|
||||||
|
|
||||||
|
static Device* find_first_gpio_controller() {
|
||||||
|
Device* device_result = nullptr;
|
||||||
|
for_each_device_of_type(&GPIO_CONTROLLER_TYPE, &device_result, [](Device* device, void* context) {
|
||||||
|
if (device_is_ready(device)) {
|
||||||
|
auto** device_result_ptr = static_cast<Device**>(context);
|
||||||
|
*device_result_ptr = device;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return device_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tt_hal_gpio_get_level(GpioPin pin) {
|
||||||
|
Device* device_result = find_first_gpio_controller();
|
||||||
|
if (device_result == nullptr) return false;
|
||||||
|
bool pin_state = false;
|
||||||
|
if (!gpio_controller_get_level(device_result, pin, &pin_state)) return false;
|
||||||
|
return pin_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tt_hal_gpio_get_pin_count() {
|
||||||
|
Device* device_result = find_first_gpio_controller();
|
||||||
|
if (device_result == nullptr) return 0;
|
||||||
|
uint32_t pin_count = 0;
|
||||||
|
if (!gpio_controller_get_pin_count(device_result, &pin_count)) return 0;
|
||||||
|
return (int)pin_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@
|
|||||||
#include "tt_hal.h"
|
#include "tt_hal.h"
|
||||||
#include "tt_hal_device.h"
|
#include "tt_hal_device.h"
|
||||||
#include "tt_hal_display.h"
|
#include "tt_hal_display.h"
|
||||||
|
#include "tt_hal_gpio.h"
|
||||||
#include "tt_hal_touch.h"
|
#include "tt_hal_touch.h"
|
||||||
#include "tt_hal_uart.h"
|
#include "tt_hal_uart.h"
|
||||||
#include <tt_lock.h>
|
#include <tt_lock.h>
|
||||||
@ -217,6 +218,8 @@ const esp_elfsym main_symbols[] {
|
|||||||
ESP_ELFSYM_EXPORT(tt_hal_display_driver_lock),
|
ESP_ELFSYM_EXPORT(tt_hal_display_driver_lock),
|
||||||
ESP_ELFSYM_EXPORT(tt_hal_display_driver_unlock),
|
ESP_ELFSYM_EXPORT(tt_hal_display_driver_unlock),
|
||||||
ESP_ELFSYM_EXPORT(tt_hal_display_driver_supported),
|
ESP_ELFSYM_EXPORT(tt_hal_display_driver_supported),
|
||||||
|
ESP_ELFSYM_EXPORT(tt_hal_gpio_get_level),
|
||||||
|
ESP_ELFSYM_EXPORT(tt_hal_gpio_get_pin_count),
|
||||||
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_supported),
|
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_supported),
|
||||||
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_alloc),
|
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_alloc),
|
||||||
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_free),
|
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_free),
|
||||||
|
|||||||
@ -45,6 +45,14 @@ struct GpioControllerApi {
|
|||||||
* @return ERROR_NONE if successful
|
* @return ERROR_NONE if successful
|
||||||
*/
|
*/
|
||||||
error_t (*get_options)(struct Device* device, gpio_pin_t pin, gpio_flags_t* options);
|
error_t (*get_options)(struct Device* device, gpio_pin_t pin, gpio_flags_t* options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the number of pins supported by the controller.
|
||||||
|
* @param[in] device the GPIO controller device
|
||||||
|
* @param[out] count pointer to store the number of pins
|
||||||
|
* @return ERROR_NONE if successful
|
||||||
|
*/
|
||||||
|
error_t (*get_pin_count)(struct Device* device, uint32_t* count);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,6 +91,14 @@ error_t gpio_controller_set_options(struct Device* device, gpio_pin_t pin, gpio_
|
|||||||
*/
|
*/
|
||||||
error_t gpio_controller_get_options(struct Device* device, gpio_pin_t pin, gpio_flags_t* options);
|
error_t gpio_controller_get_options(struct Device* device, gpio_pin_t pin, gpio_flags_t* options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the number of pins supported by the controller.
|
||||||
|
* @param[in] device the GPIO controller device
|
||||||
|
* @param[out] count pointer to store the number of pins
|
||||||
|
* @return ERROR_NONE if successful
|
||||||
|
*/
|
||||||
|
error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configures the options for a GPIO pin using a pin configuration structure.
|
* @brief Configures the options for a GPIO pin using a pin configuration structure.
|
||||||
* @param[in] device the GPIO controller device
|
* @param[in] device the GPIO controller device
|
||||||
@ -93,6 +109,8 @@ static inline error_t gpio_set_options_config(struct Device* device, const struc
|
|||||||
return gpio_controller_set_options(device, config->pin, config->flags);
|
return gpio_controller_set_options(device, config->pin, config->flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern const struct DeviceType GPIO_CONTROLLER_TYPE;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -27,4 +27,11 @@ error_t gpio_controller_get_options(Device* device, gpio_pin_t pin, gpio_flags_t
|
|||||||
return GPIO_DRIVER_API(driver)->get_options(device, pin, options);
|
return GPIO_DRIVER_API(driver)->get_options(device, pin, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) {
|
||||||
|
const auto* driver = device_get_driver(device);
|
||||||
|
return GPIO_DRIVER_API(driver)->get_pin_count(device, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct DeviceType GPIO_CONTROLLER_TYPE { 0 };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user