refactoring & pro/max base guessing#8
Conversation
2567db5 to
38146f4
Compare
Signed-off-by: Yureka <yuka@yuka.dev>
a9d5f26 to
1fbd565
Compare
94b9eb8 to
fe371d1
Compare
| let pam_ep = KisPortal::Pam.endpoint_id(self.device_version).ok_or( | ||
| DebugUsbError::MissingEndpoint(KisPortal::Pam, self.device_version), | ||
| )?; | ||
| let padding_bytes = (4 - (data.len() % 4)) % 4; |
There was a problem hiding this comment.
following reads easier
let payload_len = data.len().next_multiple_of(4);
let padding_bytes = payload_len - data.len();
and then use payload_len instead of data.len() + padding_bytes below
| 2 => DATA_TX16, | ||
| 3 => DATA_TX24, | ||
| n if (n % 4) == 0 => DATA_TX32, | ||
| _ => return Err(DebugUsbError::Alignment), |
There was a problem hiding this comment.
I would move the alignment error for data.len() > 4 && !is_multiple_of(4) at the beginning of the function
| dbgusb.capacity = dbgusb.uart_tx_free().await.map_err(std::io::Error::other)?; | ||
| } | ||
| let batch = b.split_to(std::cmp::min(payload_size, dbgusb.capacity) & !3); | ||
| dbgusb.capacity -= batch.len(); |
There was a problem hiding this comment.
uart_tx could update dbgusb.capacity, that would be just a single line
| if dbgusb.capacity < payload_size { | ||
| dbgusb.capacity = dbgusb.uart_tx_free().await.map_err(std::io::Error::other)?; | ||
| } | ||
| let batch = b.split_to(std::cmp::min(payload_size, dbgusb.capacity) & !3); |
There was a problem hiding this comment.
with the more complex function we coud do the following:
if dbgusb.capacity < 4 {
continue;
}
if payload_size <= 4 {
dbgusb.uart_tx(b).await.map_err(std::io::Error::other)?;
b.clear();
} else {
let batch = b.split_to(std::cmp::min(payload_size, dbgusb.capacity) & !3);
dbgusb.uart_tx(batch).await.map_err(std::io::Error::other)?;
}
and the while b.len() >= 4 can be changed to while !b.is_empty(). This would avoid the extra tail handling. I think I prefer my proposal slightly but feel free to disregard.
There was a problem hiding this comment.
I implemented something similar to this, always using the split_to() path but conditionally aligning the payload size if it is larger than 4.
be2abc9 to
e4fc8d7
Compare
Signed-off-by: Yureka <yuka@yuka.dev>
Signed-off-by: Yureka <yuka@yuka.dev>
Left all devices as auto-detected = yes where the first attempted address is the correct one Changed the ones which were previously not detected to question mark Signed-off-by: Yureka <yuka@yuka.dev>
Signed-off-by: Yureka <yuka@yuka.dev>
Signed-off-by: Yureka <yuka@yuka.dev>
Signed-off-by: Yureka <yuka@yuka.dev>
e4fc8d7 to
5c9915a
Compare
Base guessing tested on M3 Max:
The refactors focus on reliability and preventing data loss.