-
-
Notifications
You must be signed in to change notification settings - Fork 81
GPIO refactored #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
GPIO refactored #495
Changes from all commits
e750ec1
e017b74
2edeb4f
a0d097b
a7ee917
420fdfd
d3c6e52
801eace
a34e059
adb23a0
5605c3c
0569c6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,104 +12,127 @@ extern "C" { | |||||||||||||||||||||||||||||||||||||||||||
| struct Device; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| struct GpioControllerApi { | ||||||||||||||||||||||||||||||||||||||||||||
| struct GpioDescriptor* (*acquire_descriptor)( | ||||||||||||||||||||||||||||||||||||||||||||
| struct Device* controller, | ||||||||||||||||||||||||||||||||||||||||||||
| gpio_pin_t pin_number, | ||||||||||||||||||||||||||||||||||||||||||||
| enum GpioOwnerType owner, | ||||||||||||||||||||||||||||||||||||||||||||
| void* owner_context | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| error_t (*release_descriptor)(struct GpioDescriptor* descriptor); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Gets the pin number associated with a descriptor. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[out] pin pointer to store the pin number | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t (*get_pin_number)(struct GpioDescriptor* descriptor, gpio_pin_t* pin); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Sets the logical level of a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] pin the pin index | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in,out] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] high true to set the pin high, false to set it low | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t (*set_level)(struct Device* device, gpio_pin_t pin, bool high); | ||||||||||||||||||||||||||||||||||||||||||||
| error_t (*set_level)(struct GpioDescriptor* descriptor, bool high); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Gets the logical level of a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] pin the pin index | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[out] high pointer to store the pin level | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t (*get_level)(struct Device* device, gpio_pin_t pin, bool* high); | ||||||||||||||||||||||||||||||||||||||||||||
| error_t (*get_level)(struct GpioDescriptor* descriptor, bool* high); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Configures the options for a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] pin the pin index | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in,out] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] options configuration flags (direction, pull-up/down, etc.) | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t (*set_options)(struct Device* device, gpio_pin_t pin, gpio_flags_t options); | ||||||||||||||||||||||||||||||||||||||||||||
| error_t (*set_options)(struct GpioDescriptor* descriptor, gpio_flags_t options); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Gets the configuration options for a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] pin the pin index | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[out] options pointer to store the configuration flags | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| 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); | ||||||||||||||||||||||||||||||||||||||||||||
| error_t (*get_options)(struct GpioDescriptor* descriptor, gpio_flags_t* options); | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| struct GpioDescriptor* acquire_descriptor( | ||||||||||||||||||||||||||||||||||||||||||||
| struct Device* controller, | ||||||||||||||||||||||||||||||||||||||||||||
| gpio_pin_t pin_number, | ||||||||||||||||||||||||||||||||||||||||||||
| enum GpioOwnerType owner, | ||||||||||||||||||||||||||||||||||||||||||||
| void* owner_context | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| error_t release_descriptor(struct GpioDescriptor* descriptor); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Sets the logical level of a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Gets the number of pins supported by the controller. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] pin the pin index | ||||||||||||||||||||||||||||||||||||||||||||
| * @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 Gets the pin number associated with a descriptor. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[out] pin pointer to store the pin number | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_descriptor_pin_number(struct GpioDescriptor* descriptor, gpio_pin_t* pin); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+82
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function name mismatch: declaration vs implementation. This declares Pick one name and use it consistently across the header, implementation, and symbol table. |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Sets the logical level of a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] high true to set the pin high, false to set it low | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_controller_set_level(struct Device* device, gpio_pin_t pin, bool high); | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_descriptor_set_level(struct GpioDescriptor* descriptor, bool high); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Gets the logical level of a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] pin the pin index | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[out] high pointer to store the pin level | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_controller_get_level(struct Device* device, gpio_pin_t pin, bool* high); | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_descriptor_get_level(struct GpioDescriptor* descriptor, bool* high); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Configures the options for a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] pin the pin index | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] options configuration flags (direction, pull-up/down, etc.) | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_controller_set_options(struct Device* device, gpio_pin_t pin, gpio_flags_t options); | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_descriptor_set_options(struct GpioDescriptor* descriptor, gpio_flags_t options); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Gets the configuration options for a GPIO pin. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] pin the pin index | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] descriptor the pin descriptor | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[out] options pointer to store the configuration flags | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_controller_get_options(struct Device* device, gpio_pin_t pin, gpio_flags_t* options); | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_descriptor_get_options(struct GpioDescriptor* descriptor, 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 Initializes GPIO descriptors for a controller. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in,out] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] owner_data pointer to store in the descriptor's owner_data field | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* owner_data); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
122
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misleading parameter name and documentation for The header declares the third parameter as Align the parameter name and doc with the implementation: Proposed fix /**
- * `@brief` Initializes GPIO descriptors for a controller.
- * `@param`[in,out] device the GPIO controller device
- * `@param`[in] owner_data pointer to store in the descriptor's owner_data field
- * `@return` ERROR_NONE if successful
+ * `@brief` Initializes GPIO descriptors for a controller.
+ * `@param`[in,out] device the GPIO controller device
+ * `@param`[in] pin_count number of GPIO pins to allocate descriptors for
+ * `@param`[in] controller_context implementation-specific context stored in each descriptor
+ * `@return` ERROR_NONE if successful
*/
-error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* owner_data);
+error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context);📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Configures the options for a GPIO pin using a pin configuration structure. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in] config the pin configuration structure | ||||||||||||||||||||||||||||||||||||||||||||
| * @brief Deinitializes GPIO descriptors for a controller. | ||||||||||||||||||||||||||||||||||||||||||||
| * @param[in,out] device the GPIO controller device | ||||||||||||||||||||||||||||||||||||||||||||
| * @return ERROR_NONE if successful | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| static inline error_t gpio_set_options_config(struct Device* device, const struct GpioPinConfig* config) { | ||||||||||||||||||||||||||||||||||||||||||||
| return gpio_controller_set_options(device, config->pin, config->flags); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| error_t gpio_controller_deinit_descriptors(struct Device* device); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| extern const struct DeviceType GPIO_CONTROLLER_TYPE; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #pragma once | ||
|
|
||
| #include "gpio.h" | ||
|
|
||
| struct GpioDescriptor { | ||
| /** @brief The controller that owns this pin */ | ||
| struct Device* controller; | ||
| /** @brief Physical pin number */ | ||
| gpio_pin_t pin; | ||
| /** @brief Current owner */ | ||
| enum GpioOwnerType owner_type; | ||
| /** @brief Owner identity for validation */ | ||
| void* owner_context; | ||
| /** @brief Pin level */ | ||
| gpio_level_t level; | ||
| /** @brief Pin configuration flags */ | ||
| gpio_flags_t flags; | ||
| /** @brief Implementation-specific context (e.g. from esp32 controller internally) */ | ||
| void* controller_context; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stubbed functions silently return incorrect values — callers will get wrong behavior with no indication.
Returning hardcoded
false/0makes these functions silently broken rather than properly deprecated. Any existing caller will observe incorrect GPIO state without any signal that the API is non-functional. This is worse than a loud failure.Consider at minimum one of:
TT_LOG_W(or equivalent) so usage is visible at runtime.[[deprecated("Use GpioDescriptor API")]]) on the declarations.Example: add runtime warning
bool tt_hal_gpio_get_level(GpioPin pin) { + TT_LOG_W("gpio", "tt_hal_gpio_get_level is deprecated and non-functional"); return false; } int tt_hal_gpio_get_pin_count() { + TT_LOG_W("gpio", "tt_hal_gpio_get_pin_count is deprecated and non-functional"); return 0; }