node-ch347 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +234 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.js +110 -0
- package/dist/constants.d.ts +83 -0
- package/dist/constants.js +107 -0
- package/dist/flash.d.ts +134 -0
- package/dist/flash.js +597 -0
- package/dist/gpio.d.ts +67 -0
- package/dist/gpio.js +196 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.js +222 -0
- package/dist/spi.d.ts +66 -0
- package/dist/spi.js +227 -0
- package/dist/types.d.ts +74 -0
- package/dist/types.js +45 -0
- package/dist/uart.d.ts +81 -0
- package/dist/uart.js +343 -0
- package/dist/usb.d.ts +80 -0
- package/dist/usb.js +422 -0
- package/package.json +49 -0
package/dist/flash.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CH347 SPI Flash Programmer
|
|
3
|
+
*
|
|
4
|
+
* Supports common SPI flash chips (W25Qxx, GD25Qxx, MX25Lxx, etc.)
|
|
5
|
+
*/
|
|
6
|
+
import { CH347SPI } from './spi';
|
|
7
|
+
import { FlashInfo, FlashProgressCallback } from './types';
|
|
8
|
+
export declare class CH347Flash {
|
|
9
|
+
private spi;
|
|
10
|
+
private flashInfo;
|
|
11
|
+
constructor(spi: CH347SPI);
|
|
12
|
+
/**
|
|
13
|
+
* Read JEDEC ID from flash chip
|
|
14
|
+
*/
|
|
15
|
+
readJedecId(): Promise<FlashInfo>;
|
|
16
|
+
/**
|
|
17
|
+
* Read SFDP (Serial Flash Discoverable Parameters) data
|
|
18
|
+
* @param address 24-bit address in SFDP space
|
|
19
|
+
* @param length Number of bytes to read
|
|
20
|
+
*/
|
|
21
|
+
readSFDP(address: number, length: number): Promise<Buffer>;
|
|
22
|
+
/**
|
|
23
|
+
* Estimate erase timeout based on block size
|
|
24
|
+
*/
|
|
25
|
+
private estimateEraseTimeout;
|
|
26
|
+
/**
|
|
27
|
+
* Read and parse SFDP Basic Flash Parameter Table
|
|
28
|
+
* Populates flashInfo with discovered erase types and page size
|
|
29
|
+
*/
|
|
30
|
+
private readSFDPBasicParams;
|
|
31
|
+
/**
|
|
32
|
+
* Read status register
|
|
33
|
+
*/
|
|
34
|
+
readStatus(): Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* Wait for flash to be ready (WIP bit cleared)
|
|
37
|
+
*/
|
|
38
|
+
waitReady(timeoutMs?: number): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Enable write operations
|
|
41
|
+
*/
|
|
42
|
+
writeEnable(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Disable write operations
|
|
45
|
+
*/
|
|
46
|
+
writeDisable(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Read data from flash
|
|
49
|
+
*/
|
|
50
|
+
read(address: number, length: number, onProgress?: FlashProgressCallback): Promise<Buffer>;
|
|
51
|
+
/**
|
|
52
|
+
* Write a single page (up to 256 bytes)
|
|
53
|
+
*/
|
|
54
|
+
private writePage;
|
|
55
|
+
/**
|
|
56
|
+
* Write data to flash (handles page boundaries)
|
|
57
|
+
*/
|
|
58
|
+
write(address: number, data: Buffer, onProgress?: FlashProgressCallback): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Erase a 4KB sector
|
|
61
|
+
*/
|
|
62
|
+
eraseSector(address: number): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Erase a 32KB block
|
|
65
|
+
*/
|
|
66
|
+
eraseBlock32K(address: number): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Erase a 64KB block
|
|
69
|
+
*/
|
|
70
|
+
eraseBlock64K(address: number): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Erase entire chip
|
|
73
|
+
*/
|
|
74
|
+
eraseChip(onProgress?: FlashProgressCallback): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Erase using a specific erase type (from SFDP discovery)
|
|
77
|
+
*/
|
|
78
|
+
private eraseWithType;
|
|
79
|
+
/**
|
|
80
|
+
* Get default erase types (fallback when SFDP not available)
|
|
81
|
+
*/
|
|
82
|
+
private getDefaultEraseTypes;
|
|
83
|
+
/**
|
|
84
|
+
* Erase range (uses optimal erase commands from SFDP or defaults)
|
|
85
|
+
*/
|
|
86
|
+
eraseRange(address: number, length: number, onProgress?: FlashProgressCallback): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Verify data matches flash contents
|
|
89
|
+
*/
|
|
90
|
+
verify(address: number, data: Buffer, onProgress?: FlashProgressCallback): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Check if a sector needs to be erased to write new data
|
|
93
|
+
* Flash can only program 1→0, so we need to erase if any bit needs to go 0→1
|
|
94
|
+
*/
|
|
95
|
+
private sectorNeedsErase;
|
|
96
|
+
/**
|
|
97
|
+
* Check if a sector has any changes
|
|
98
|
+
*/
|
|
99
|
+
private sectorHasChanges;
|
|
100
|
+
/**
|
|
101
|
+
* Program flash (smart erase + write + verify)
|
|
102
|
+
* Only erases and writes sectors that have actual changes
|
|
103
|
+
*/
|
|
104
|
+
program(address: number, data: Buffer, options?: {
|
|
105
|
+
erase?: boolean;
|
|
106
|
+
verify?: boolean;
|
|
107
|
+
onProgress?: FlashProgressCallback;
|
|
108
|
+
}): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Program flash from a binary file
|
|
111
|
+
* @param filePath Path to the binary file to write
|
|
112
|
+
* @param address Starting address in flash (default: 0, requires file size to match flash size)
|
|
113
|
+
* @param options Programming options (erase, verify, progress callback)
|
|
114
|
+
*/
|
|
115
|
+
programFile(filePath: string, address?: number, options?: {
|
|
116
|
+
erase?: boolean;
|
|
117
|
+
verify?: boolean;
|
|
118
|
+
onProgress?: FlashProgressCallback;
|
|
119
|
+
}): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* Read flash contents and save to a binary file
|
|
122
|
+
* @param filePath Path to save the binary file
|
|
123
|
+
* @param address Starting address in flash (default: 0)
|
|
124
|
+
* @param length Number of bytes to read (if not specified, reads entire flash based on JEDEC ID)
|
|
125
|
+
* @param onProgress Progress callback
|
|
126
|
+
*/
|
|
127
|
+
readToFile(filePath: string, address?: number, length?: number, onProgress?: FlashProgressCallback): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Get flash info (call readJedecId first)
|
|
130
|
+
*/
|
|
131
|
+
getFlashInfo(): FlashInfo | null;
|
|
132
|
+
private delay;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=flash.d.ts.map
|