-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linux): Custom baud rates for linux (eg 250k baudrate) (#1464)
* 250k baudrate now works * Generic linux non-standard baudrate setting using termios2 * Tested successfully with an FTDI usb chip with the tx and rx pins bridged. Previous solution using the B38400 hack returned gibberish in same setup. * Test for linux and win32 baudrate setting. Darwin stubbed out. The arbitrary baud interface has been working on darwin up to this point so it's likely that it works properly. The GetBaudRate extension should still get written to be thorough but for now, this will let the CI tests pass properly and still throw a warning about the check being disabled. That is, of course, if anyone's testing with the arduino hardware on darwin, otherwise, these tests never run anyway.
- Loading branch information
Showing
14 changed files
with
223 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#if defined(__linux__) | ||
|
||
#include <sys/ioctl.h> | ||
#include <asm/termbits.h> | ||
|
||
// Uses the termios2 interface to set nonstandard baud rates | ||
int linuxSetCustomBaudRate(const int fd, const unsigned int baudrate) { | ||
struct termios2 t; | ||
|
||
if(ioctl(fd, TCGETS2, &t)) { | ||
return -1; | ||
} | ||
|
||
t.c_cflag &= ~CBAUD; | ||
t.c_cflag |= BOTHER; | ||
t.c_ospeed = t.c_ispeed = baudrate; | ||
|
||
if(ioctl(fd, TCSETS2, &t)) { | ||
return -2; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
// Uses termios2 interface to retrieve system reported baud rate | ||
int linuxGetSystemBaudRate(const int fd, int* const outbaud) { | ||
struct termios2 t; | ||
|
||
if(ioctl(fd, TCGETS2, &t)) { | ||
return -1; | ||
} | ||
|
||
*outbaud = (int)t.c_ospeed; | ||
|
||
return 0; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef CUSTOM_BAUDRATE_H | ||
#define CUSTOM_BAUDRATE_H | ||
|
||
int linuxSetCustomBaudRate(const int fd, const unsigned int baudrate); | ||
int linuxGetSystemBaudRate(const int fd, int* const outbaud); | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters