MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / write_row

Function write_row

framework_lib/src/ccgx/hid.rs:450–473  ·  view source on GitHub ↗
(device: &HidDevice, row_no: u16, row: &[u8])

Source from the content-addressed store, hash-verified

448}
449
450fn write_row(device: &HidDevice, row_no: u16, row: &[u8]) -> Result<usize, HidError> {
451 let row_no_bytes = row_no.to_le_bytes();
452 trace!("Writing row {:04X}. Data: {:X?}", row_no, row);
453
454 // First image start 0x1800 (row 0x30)
455 // row from 0x0030 to 0x01fb
456 // 0x30*128 (row size) = 0x1800, which is Image 1 start = 00001800
457 // 0x01fb-0x30+1 = 460
458 // OH! This must be the metadata
459 // And another one at 03ff, which adds up to 461 rows
460 //
461 // Second Image start 0x10000 (row 0x200)
462 // Last one if 0x03cb
463 // And another one at 03fe
464
465 // I think 0x46 might be CY_PD_FLASH_READ_WRITE_CMD_SIG
466 let mut buffer = [0; 132];
467 buffer[0] = ReportIdCmd::E2WriteRow as u8;
468 buffer[1] = CmdParam::FlashWrite as u8;
469 buffer[2] = row_no_bytes[0];
470 buffer[3] = row_no_bytes[1];
471 buffer[4..].copy_from_slice(row);
472 device.write(&buffer)
473}
474
475/// Wait for the specific card to reappear
476/// Waiting a maximum timeout, if it hasn't appeared by then, return None

Callers 1

flash_firmware_imageFunction · 0.85

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected