@@ -66,12 +66,48 @@ Push to GitHub, enable Pages, and your users can flash from `https://you.github.
6666
6767---
6868
69- ### Option 3: Library for Custom Integration
69+ ### Option 3: Library Integration
7070
7171``` bash
7272npm install esp-webflash-toolkit
7373```
7474
75+ ** Simple API** — flash a device in one call:
76+
77+ ``` javascript
78+ import { flashDevice } from ' esp-webflash-toolkit' ;
79+
80+ await flashDevice ({
81+ firmware: ' https://example.com/firmware.bin' ,
82+ config: {
83+ wifi_ssid: ' MyNetwork' ,
84+ wifi_pass: ' MyPassword'
85+ },
86+ onProgress : (percent ) => console .log (` ${ percent} %` )
87+ });
88+ ```
89+
90+ ** Advanced API** — full control for custom UIs:
91+
92+ ``` javascript
93+ import { ESPFlasher } from ' esp-webflash-toolkit' ;
94+
95+ const flasher = new ESPFlasher ({
96+ chip: ' esp32' ,
97+ firmwareUrl: ' https://example.com/firmware.bin' ,
98+ fields: [' wifi' ]
99+ });
100+
101+ flasher .addEventListener (' progress' , e => updateProgressBar (e .detail .percent ));
102+ flasher .addEventListener (' log' , e => appendToConsole (e .detail .message ));
103+
104+ await flasher .connect ();
105+ flasher .setConfig ({ wifi_ssid: ' MyNetwork' , wifi_pass: ' secret' });
106+ await flasher .flash ();
107+ ```
108+
109+ ** NVS Generation** — generate partition binaries directly:
110+
75111``` javascript
76112import { NVSGenerator } from ' esp-webflash-toolkit/nvs-generator' ;
77113
@@ -103,7 +139,8 @@ You've built an ESP32 project. Now you need users to flash it.
103139
104140- ** Browser-based flashing** via Web Serial API
105141- ** NVS partition generation** — WiFi credentials, device config, custom settings
106- - ** Partition table generation** — custom flash layouts
142+ - ** Simple and advanced APIs** — one-liner or full event-driven control
143+ - ** Field presets** — ` 'wifi' ` , ` 'mqtt' ` , ` 'device_name' ` expand to common config patterns
107144- ** Works with:** ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP8266
108145
109146---
@@ -180,26 +217,47 @@ Safari and Firefox don't support Web Serial.
180217
181218---
182219
183- ## Advanced: Module Reference
220+ ## API Reference
221+
222+ ### flashDevice(options)
223+
224+ Flash a device in one call.
225+
226+ ``` javascript
227+ await flashDevice ({
228+ firmware: ' https://...' , // Required: firmware URL
229+ config: { key: ' value' }, // Optional: NVS config
230+ chip: ' esp32' , // Optional: expected chip type
231+ onProgress : (percent ) => {}, // Optional: progress callback
232+ onLog : (msg , level ) => {}, // Optional: log callback
233+ firmwareOffset: 0x10000 , // Optional: firmware offset
234+ nvsOffset: 0x9000 // Optional: NVS offset
235+ });
236+ ```
184237
185- For custom integrations:
238+ ### ESPFlasher
186239
187- | Module | Purpose |
188- | --------| ---------|
189- | ` nvs-generator ` | Generate NVS partition binaries |
190- | ` partition-table-generator ` | Generate custom partition tables |
191- | ` device-connection ` | Web Serial connection handling |
192- | ` firmware-flasher ` | Flash operations |
193- | ` config-manager ` | Form/config state management |
240+ Event-driven flasher for custom UIs.
194241
195242``` javascript
196- import { PartitionTableGenerator } from ' esp-webflash-toolkit/partition-table-generator ' ;
243+ const flasher = new ESPFlasher (options) ;
197244
198- const gen = new PartitionTableGenerator ();
199- const table = gen .generate ([
200- { name: ' nvs' , type: ' data' , subtype: ' nvs' , offset: 0x9000 , size: 0x6000 },
201- { name: ' app' , type: ' app' , subtype: ' factory' , offset: 0x10000 , size: 0x100000 }
202- ]);
245+ // Events: 'progress', 'log', 'status', 'connected', 'disconnected', 'error', 'complete'
246+ flasher .addEventListener (' progress' , e => console .log (e .detail .percent ));
247+
248+ await flasher .connect ();
249+ flasher .setConfig ({ wifi_ssid: ' test' });
250+ await flasher .flash ();
251+ flasher .dispose ();
252+ ```
253+
254+ ### NVSGenerator
255+
256+ Generate NVS partition binaries.
257+
258+ ``` javascript
259+ const nvs = new NVSGenerator ();
260+ const binary = nvs .generate ({ namespace: { key: ' value' } }, 0x6000 );
203261```
204262
205263---
0 commit comments