-
-
Notifications
You must be signed in to change notification settings - Fork 11
Throw exception for illegal tx gpio ports in RMT tx channel #92
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
Throw exception for illegal tx gpio ports in RMT tx channel #92
Conversation
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (2)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
README.md
Outdated
|
|
||
| ## GPIO Pin Restrictions | ||
|
|
||
| The ESP32 MCU restricts which GPIO pins can be used for the Transmit Channel (TX). Ports 34 to 39 (inclusive) cannot be used for TX. Attempting to use these ports will cause the `TransmitChannelSettings` class to throw an `ArgumentOutOfRangeException`. |
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.
- Shouldn't these be referred as pins, instead of ports?
- are these valid for all ESP32 series?
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.
- Absolutely! Sorry about that.. been doing a lot of web dev and networking-related stuff for a while now 😁
- I based this on what I read in the RMT legacy driver code. Essentially
rmt_config(..)callsrmt_set_gpio(..)which performs the following validation:
ESP_RETURN_ON_FALSE(((GPIO_IS_VALID_GPIO(gpio_num) && (mode == RMT_MODE_RX)) ||
(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) && (mode == RMT_MODE_TX))), ESP_ERR_INVALID_ARG, TAG, RMT_GPIO_ERROR_STR);The GPIO_IS_VALID_OUTPUT_GPIO macro is used to make sure the pins are not 34-39:
/// Check whether it can be a valid GPIO number of output mode
#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \
(((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0))There aren't any compiler directive around this validation code which tells me it is applicable to all ESP32 boards. However, The RMT docs on the Espressif website for IDF version 4.4.6 makes no specific mention of this.
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.
Please note that we're currently at IDF v5.4. Not sure if that makes any difference in the API/docs.
|
AdrianSoundy
left a comment
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.
You can't use any hard coded pin numbers to test for a pin that doesn't support output as these won't be correct for other ESP32 series chips.
You need to use the macro GPIO_IS_VALID_OUTPUT_GPIO to make sure correct test is done for the target chip, ESP32_S3, ESP32_C6 etc
i.e.
if (!GPIO_IS_VALID_OUTPUT_GPIO(pin))
Thanks @AdrianSoundy. I suppose then we introduce a new method on the native RMT lib to perform this check and have the managed lib use it and throw an exception accordingly. Would you prefer that or do you have another approach in mind? |
|
The test would need to be done in the native code part. |
|
Thank @AdrianSoundy for the clarification. I am closing this PR now and will submit a new one based on your feedback. |



Description
ArgumentOutOfRangeExceptionas it is clearer thanCLR_E_DRIVER_NOT_REGISTEREDerror from the native lib.Motivation and Context
How Has This Been Tested?
Tested by creating a sample RMT nf app and testing TX channels configured with illegal ports and observing the exception being thrown as expected.
Screenshots
Types of changes
Checklist: