Skip to content
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

Updated/added config options for all Due Serial #2006

Closed

Conversation

bluesign2k
Copy link
Contributor

For USART based Serial (Serial1, Serial2, Serail3), expanded config
options to include 1.5 stop bits and mark & space parity modes. Also
added defines ready for 9-bit implementation - currently commented out
until serial read/write supports it.

For UART based Serial, added ability to set config. Due to UART module
limitations, mode is fixed with 8-bit, 1 stop but parity is selectable
(none, odd, even, mark, space).

In both classes, user configs are masked to prevent bad mode
configuration.

For USART based Serial (Serial1, Serial2, Serail3), expanded config
options to include 1.5 stop bits and mark & space parity modes. Also
added defines ready for 9-bit implementation - currently commented out
until serial read/write supports it.

For UART based Serial, added ability to set config. Due to UART module
limitations, mode is fixed with 8-bit, 1 stop but parity is selectable
(none, odd, even, mark, space).

In both classes, user configs are masked to prevent bad mode
configuration.
@cmaglie
Copy link
Member

cmaglie commented May 19, 2014

@bluesign2k
AFAIR only 8 bit data modes are supported in hardware, currently the compiler doesn't show any error and users may be a bit puzzled why the serial ports doesn't behave as expected (until they look at the documentation of course).

Is there a way to place static assertions to prevent users from doing:

Serial.begin(9600, SERIAL_7N1);

?

@matthijskooijman
Copy link
Collaborator

Not sure if that's possible. You could of course not define SERIAL_7N1, though that doesn't give a very clear error message...

C++11 has static_assert, but I think that's only useful for actual constant expressions, not for expressions that might also be variable.

@bluesign2k
Copy link
Contributor Author

To be honest, I was aware of this issue and did have a look at the possibility of getting the compiler to throw some sort of error if the user tried to set an invalid mode. However, I never managed to find a suitable solution. I debated making the options some sort of child of the class, so the user would have to do something along the line of:

Serial.begin(9600, Serial.SERIAL_8N1);

and therefore the following would throw an error as SERIAL_7N1 isn't a child of Serial:

Serial.begin(9600, Serial.SERIAL_7N1);

...but it seemed messy.

Truth be told, I figured it either would be a problem as users could read the documentation, or someone with better knowledge might have a solution.

@cmaglie
Copy link
Member

cmaglie commented May 19, 2014

What about:

#define SERIAL_8N1 UART_Modes.SERIAL_8N1
[....]
#define SERIAL_7N1 USART_Modes.SERIAL_7N1

where USART_Modes is a child class of UART_Modes?

@cmaglie
Copy link
Member

cmaglie commented Jan 19, 2015

Thanks!

@cmaglie cmaglie closed this Jan 19, 2015
@bluesign2k bluesign2k deleted the ide-1.5.x_serial_config branch January 19, 2015 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants