|
| 1 | +// referenced from the avrdude.conf |
| 2 | + |
| 3 | +interface CPUData { |
| 4 | + signature: Buffer; |
| 5 | + pageSize: number; |
| 6 | + numPages: number; |
| 7 | + timeout: number; |
| 8 | + protocol: string; |
| 9 | + delay1?: number; |
| 10 | + delay2?: number; |
| 11 | + stabDelay?: number; |
| 12 | + cmdexeDelay?: number; |
| 13 | + synchLoops?: number; |
| 14 | + byteDelay?: number; |
| 15 | + pollValue?: number; |
| 16 | + pollIndex?: number; |
| 17 | +} |
| 18 | + |
| 19 | +interface CPUDefinitions { |
| 20 | + [key: string]: CPUData; |
| 21 | +} |
| 22 | + |
| 23 | +const cpuDefs = { |
| 24 | + atmega328p: { |
| 25 | + signature: Buffer.from([0x1e, 0x95, 0x0f]), |
| 26 | + pageSize: 128, |
| 27 | + numPages: 256, |
| 28 | + timeout: 400, |
| 29 | + protocol: 'stk500v1', |
| 30 | + } as CPUData, |
| 31 | + atmega168: { |
| 32 | + signature: Buffer.from([0x1e, 0x94, 0x06]), |
| 33 | + pageSize: 128, |
| 34 | + numPages: 128, |
| 35 | + timeout: 400, |
| 36 | + protocol: 'stk500v1', |
| 37 | + } as CPUData, |
| 38 | + atmega8: { |
| 39 | + signature: Buffer.from([0x1e, 0x93, 0x07]), |
| 40 | + pageSize: 64, |
| 41 | + numPages: 128, |
| 42 | + timeout: 400, |
| 43 | + protocol: 'stk500v1', |
| 44 | + } as CPUData, |
| 45 | + atmega2560: { |
| 46 | + signature: Buffer.from([0x1e, 0x98, 0x01]), |
| 47 | + pageSize: 256, |
| 48 | + numPages: 1024, |
| 49 | + delay1: 10, |
| 50 | + delay2: 1, |
| 51 | + timeout: 0xc8, // 200 |
| 52 | + stabDelay: 0x64, // 100 |
| 53 | + cmdexeDelay: 0x19, // 25 |
| 54 | + synchLoops: 0x20, // 32 |
| 55 | + byteDelay: 0x00, // 0 |
| 56 | + pollValue: 0x53, |
| 57 | + pollIndex: 0x03, // 3 |
| 58 | + protocol: 'stk500v2', |
| 59 | + } as CPUData, |
| 60 | + atmega1280: { |
| 61 | + signature: Buffer.from([0x1e, 0x97, 0x03]), |
| 62 | + pageSize: 256, |
| 63 | + numPages: 512, |
| 64 | + delay1: 10, |
| 65 | + delay2: 1, |
| 66 | + timeout: 0xc8, // 200 |
| 67 | + stabDelay: 0x64, // 100 |
| 68 | + cmdexeDelay: 0x19, // 25 |
| 69 | + synchLoops: 0x20, // 32 |
| 70 | + byteDelay: 0x00, // 0 |
| 71 | + pollValue: 0x53, |
| 72 | + pollIndex: 0x03, // 3 |
| 73 | + protocol: 'stk500v2', |
| 74 | + } as CPUData, |
| 75 | + atmega32u4: { |
| 76 | + signature: Buffer.from([0x43, 0x41, 0x54, 0x45, 0x52, 0x49, 0x4e]), |
| 77 | + protocol: 'avr109', |
| 78 | + } as CPUData, |
| 79 | +} as CPUDefinitions; |
| 80 | + |
| 81 | +export default (cpu?: string): CPUData => { |
| 82 | + const cpuData = cpuDefs[cpu || '']; |
| 83 | + if (!cpuData) throw new Error(`Unknown CPU: ${cpu}`); |
| 84 | + return cpuData; |
| 85 | +}; |
0 commit comments