summaryrefslogtreecommitdiff
path: root/software/vendor/go.bug.st/serial/serial_darwin.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-30 16:00:32 +0200
committerxengineering <me@xengineering.eu>2024-05-30 16:00:32 +0200
commitb8ef4d11fe0d00ce0884ccf982675845b20c3ce9 (patch)
tree3beb57ff849ed74569ce325225bc819791c25a6a /software/vendor/go.bug.st/serial/serial_darwin.go
parenteab833271eeaa8d54991c11eccec9445f662a191 (diff)
downloadiot-core-b8ef4d11fe0d00ce0884ccf982675845b20c3ce9.tar
iot-core-b8ef4d11fe0d00ce0884ccf982675845b20c3ce9.tar.zst
iot-core-b8ef4d11fe0d00ce0884ccf982675845b20c3ce9.zip
software: Implement serial port detection
Diffstat (limited to 'software/vendor/go.bug.st/serial/serial_darwin.go')
-rw-r--r--software/vendor/go.bug.st/serial/serial_darwin.go41
1 files changed, 41 insertions, 0 deletions
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)
+}