Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions FineTune/Audio/DDC/DDCService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,18 @@ final class DDCService: @unchecked Sendable {
}

/// Writes a DDC packet without reading a response.
///
/// Send all write cycles; some displays only apply the second write.
private func i2cWrite(packet: [UInt8]) throws {
var lastResult: IOReturn = kIOReturnError
for _ in 0..<numWriteCycles {
usleep(writeSleepTime)
let result = packet.withUnsafeBufferPointer { buf in
lastResult = packet.withUnsafeBufferPointer { buf in
IOAVServiceLoader.writeI2C(service: service, chipAddress: chipAddress,
dataAddress: writeAddress, buffer: buf.baseAddress!, size: UInt32(buf.count))
}
if result == kIOReturnSuccess { return }
}
throw DDCError.writeFailed(kIOReturnError)
guard lastResult == kIOReturnSuccess else { throw DDCError.writeFailed(lastResult) }
}

// MARK: - VCP Commands
Expand Down