improve usb driver voltage handling

This commit is contained in:
septs 2025-02-26 20:26:08 +08:00
parent c211709344
commit 1f9a9d5f22
Signed by: septs
SSH key fingerprint: SHA256:ElK0p6DNkbsqYUdJ3I9QHDVf21SQD0c2r+hd7s/r5Co
2 changed files with 7 additions and 11 deletions

View file

@ -85,14 +85,10 @@ data class UsbCcidDescription(
private fun hasFeature(feature: Int): Boolean =
(dwFeatures and feature) != 0
val voltages: Array<Voltage>
val voltages: List<Voltage>
get() {
if (hasFeature(FEATURE_AUTOMATIC_VOLTAGE)) {
return arrayOf(Voltage.AUTO)
}
return Voltage.entries
.mapNotNull { if ((it.mask.toInt() and bVoltageSupport.toInt()) != 0) it else null }
.toTypedArray()
if (hasFeature(FEATURE_AUTOMATIC_VOLTAGE)) return listOf(Voltage.AUTO)
return Voltage.entries.filter { (it.mask.toInt() and bVoltageSupport.toInt()) != 0 }
}
val hasAutomaticPps: Boolean

View file

@ -287,13 +287,13 @@ class UsbCcidTransceiver(
val startTime = SystemClock.elapsedRealtime()
skipAvailableInput()
var response: CcidDataBlock? = null
for (v in usbCcidDescription.voltages) {
Log.v(TAG, "CCID: attempting to power on with voltage $v")
for (voltage in usbCcidDescription.voltages) {
Log.v(TAG, "CCID: attempting to power on with voltage $voltage")
response = try {
iccPowerOnVoltage(v.powerOnValue)
iccPowerOnVoltage(voltage.powerOnValue)
} catch (e: UsbCcidErrorException) {
if (e.errorResponse.bError.toInt() == 7) { // Power select error
Log.v(TAG, "CCID: failed to power on with voltage $v")
Log.v(TAG, "CCID: failed to power on with voltage $voltage")
iccPowerOff()
Log.v(TAG, "CCID: powered off")
continue