MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / configurePort

Method configurePort

external/floppybridge/src/SerialIO.cpp:572–747  ·  view source on GitHub ↗

Changes the configuration on the port

Source from the content-addressed store, hash-verified

570
571// Changes the configuration on the port
572SerialIO::Response SerialIO::configurePort(const Configuration& configuration) {
573 if (!isPortOpen()) return Response::rUnknownError;
574
575#ifdef FTDI_D2XX_AVAILABLE
576 if (m_ftdi.isOpen()) {
577 if (m_ftdi.FT_SetFlowControl(configuration.ctsFlowControl ? FT_FLOW_RTS_CTS : FT_FLOW_NONE, 0, 0) != FTDI::FT_STATUS::FT_OK) return SerialIO::Response::rUnknownError;
578 if (m_ftdi.FT_SetDataCharacteristics(FTDI::FT_BITS::_8, FTDI::FT_STOP_BITS::_1, FTDI::FT_PARITY::NONE) != FTDI::FT_STATUS::FT_OK) return SerialIO::Response::rUnknownError;
579 if (m_ftdi.FT_SetBaudRate(configuration.baudRate) != FTDI::FT_STATUS::FT_OK) return SerialIO::Response::rUnknownError;
580 m_ftdi.FT_SetLatencyTimer(2);
581 m_ftdi.FT_ClrDtr();
582 m_ftdi.FT_ClrRts();
583 return SerialIO::Response::rOK;
584 }
585#endif
586
587#ifdef _WIN32
588 // Configure the port
589 COMMCONFIG config;
590 DWORD comConfigSize = sizeof(config);
591 memset(&config, 0, sizeof(config));
592
593 GetCommConfig(m_portHandle, &config, &comConfigSize);
594 config.dwSize = sizeof(config);
595 config.dcb.DCBlength = sizeof(config.dcb);
596 config.dcb.BaudRate = configuration.baudRate;
597 config.dcb.ByteSize = 8;
598 config.dcb.fBinary = true;
599 config.dcb.Parity = false;
600 config.dcb.fOutxCtsFlow = configuration.ctsFlowControl;
601 config.dcb.fOutxDsrFlow = false;
602 config.dcb.fDtrControl = DTR_CONTROL_ENABLE;
603 config.dcb.fDsrSensitivity = false;
604 config.dcb.fNull = false;
605 config.dcb.fTXContinueOnXoff = false;
606 config.dcb.fRtsControl = RTS_CONTROL_ENABLE;
607 config.dcb.fAbortOnError = false;
608 config.dcb.StopBits = 0;
609 config.dcb.fOutX = 0;
610 config.dcb.fInX = 0;
611 config.dcb.fErrorChar = 0;
612 config.dcb.fAbortOnError = 0;
613 config.dcb.fInX = 0;
614 return SetCommConfig(m_portHandle, &config, sizeof(config)) ? Response::rOK : Response::rUnknownError;
615
616#else
617 if (tcgetattr(m_portHandle, &term) < 0) return Response::rUnknownError;
618#ifdef cfmakeraw
619 cfmakeraw(&term);
620#endif
621 term.c_iflag &= ~ (IXON | IXOFF | IXANY | IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL);
622 term.c_lflag &= ~ (ISIG | ICANON | ECHO | ECHOE | ECHONL | IEXTEN);
623 term.c_oflag &= ~ (OPOST | ONLCR | OCRNL | ONOCR | ONLRET);
624 term.c_cflag &= ~(HUPCL | CSIZE | PARENB | PARODD | CSTOPB);
625 term.c_cflag |= CREAD | CLOCAL | CS8;
626 term.c_iflag |= IGNPAR;
627
628#ifdef XCASE
629 term.c_lflag &= ~XCASE;

Callers 3

openPortMethod · 0.80
openPortMethod · 0.80
internalOpenPortMethod · 0.80

Calls 7

FT_SetFlowControlMethod · 0.80
FT_SetBaudRateMethod · 0.80
FT_SetLatencyTimerMethod · 0.80
FT_ClrDtrMethod · 0.80
FT_ClrRtsMethod · 0.80
isOpenMethod · 0.45

Tested by

no test coverage detected