From b8ef4d11fe0d00ce0884ccf982675845b20c3ce9 Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 30 May 2024 16:00:32 +0200 Subject: software: Implement serial port detection --- software/vendor/go.bug.st/serial/serial_darwin.go | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 software/vendor/go.bug.st/serial/serial_darwin.go (limited to 'software/vendor/go.bug.st/serial/serial_darwin.go') diff --git a/software/vendor/go.bug.st/serial/serial_darwin.go b/software/vendor/go.bug.st/serial/serial_darwin.go new file mode 100644 index 0000000..2817041 --- /dev/null +++ b/software/vendor/go.bug.st/serial/serial_darwin.go @@ -0,0 +1,41 @@ +// +// Copyright 2014-2023 Cristian Maglie. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// + +package serial + +import "golang.org/x/sys/unix" + +const devFolder = "/dev" +const regexFilter = "^(cu|tty)\\..*" + +const ioctlTcgetattr = unix.TIOCGETA +const ioctlTcsetattr = unix.TIOCSETA +const ioctlTcflsh = unix.TIOCFLUSH +const ioctlTioccbrk = unix.TIOCCBRK +const ioctlTiocsbrk = unix.TIOCSBRK + +func setTermSettingsBaudrate(speed int, settings *unix.Termios) (error, bool) { + baudrate, ok := baudrateMap[speed] + if !ok { + return nil, true + } + settings.Ispeed = toTermiosSpeedType(baudrate) + settings.Ospeed = toTermiosSpeedType(baudrate) + return nil, false +} + +func (port *unixPort) setSpecialBaudrate(speed uint32) error { + const kIOSSIOSPEED = 0x80045402 + return unix.IoctlSetPointerInt(port.handle, kIOSSIOSPEED, int(speed)) +} + +func (port *unixPort) ResetInputBuffer() error { + return unix.IoctlSetPointerInt(port.handle, ioctlTcflsh, unix.TCIFLUSH) +} + +func (port *unixPort) ResetOutputBuffer() error { + return unix.IoctlSetPointerInt(port.handle, ioctlTcflsh, unix.TCOFLUSH) +} -- cgit v1.2.3-70-g09d2