Загрузка данных


import sys

def mirror_entire_bitstream(input_path, output_path):
    with open(input_path, 'rb') as f:
        content = f.read()
        
    print(f"[LATTICE TOOL] Original file loaded: {len(content)} bytes.")
    print("[LATTICE TOOL] Processing full Byte-Wide Bit Mirroring for Slave I2C...")
    
    # Mirror EVERY single byte of the original file, keeping the LSCC and comments intact
    # but flipped horizontally for the i.MX95 I2C hardware bus transmission.
    mirrored_bytes = bytearray()
    for byte in content:
        flipped = int('{:08b}'.format(byte)[::-1], 2)
        mirrored_bytes.append(flipped)
        
    # Append 4KB of 0xFF padding to flush the internal FPGA FIFO at the end of transfer
    padding = b'\xff' * 4096
    final_output = mirrored_bytes + padding
    
    with open(output_path, 'wb') as f:
        f.write(final_output)
        
    print(f"[LATTICE TOOL] Success! Added 4KB padding. Total ready file size: {len(final_output)} bytes.")

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print("Usage: python3 lpc_mirror_tool.py <input.bit> <output.bin>")
        sys.exit(1)
    mirror_entire_bitstream(sys.argv, sys.argv)