Skip to content

Commit

Permalink
Serial: Attempt to fix the macOS work
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohlstand committed May 6, 2024
1 parent 1f033a5 commit e8c0869
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/opl/chips/opl_serial_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef __unix__
#if defined( __unix__) || defined(__APPLE__)
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#endif
Expand All @@ -29,6 28,8 @@
#include <windows.h>
#endif

#include <string>


class ChipSerialPortBase
{
Expand Down Expand Up @@ -56,7 57,7 @@ class ChipSerialPortBase



#ifdef __unix__
#if defined( __unix__) || defined(__APPLE__)
class ChipSerialPort : public ChipSerialPortBase
{
int m_port;
Expand Down Expand Up @@ -139,20 140,36 @@ class ChipSerialPort : public ChipSerialPortBase

if(m_port < 0)
{
fprintf(stderr, "-- OPL Serial ERROR: failed to open tty device `%s': %s\n", portPath.c_str(), strerror(errno));
fflush(stderr);
m_port = 0;
return false;
}

if(tcgetattr(m_port, &m_portSetup) != 0)
{
fprintf(stderr, "-- OPL Serial ERROR: failed to retrieve setup `%s': %s\n", portPath.c_str(), strerror(errno));
fflush(stderr);
close();
return false;
}

m_portSetup.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
m_portSetup.c_oflag &= ~OPOST;
m_portSetup.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
m_portSetup.c_cflag &= ~(CSIZE | PARENB);
m_portSetup.c_cflag |= CS8;

#if defined (__linux__) || defined (__CYGWIN__)
m_portSetup.c_cflag &= ~CBAUD;
#endif

cfsetospeed(&m_portSetup, baud2enum(baudRate));

if(tcsetattr(m_port, TCSANOW, &m_portSetup) != 0)
{
fprintf(stderr, "-- OPL Serial ERROR: failed to apply setup `%s': %s\n", portPath.c_str(), strerror(errno));
fflush(stderr);
close();
return false;
}
Expand Down

0 comments on commit e8c0869

Please sign in to comment.