0002-async-class-method-esploader.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. --- a/node_modules/esptool-js/ESPLoader.js
  2. +++ b/node_modules/esptool-js/ESPLoader.js
  3. @@ -127,14 +127,14 @@ class ESPLoader {
  4. return u8_array;
  5. }
  6. - flush_input = async () => {
  7. + async flush_input() {
  8. try {
  9. await this.transport.readRaw({timeout:200});
  10. } catch(e) {
  11. }
  12. }
  13. - command = async ({op=null, data=[], chk=0, wait_response=true, timeout=3000} = {}) => {
  14. + async command({op=null, data=[], chk=0, wait_response=true, timeout=3000} = {}) {
  15. //console.log("command "+ op + " " + wait_response + " " + timeout);
  16. if (op != null) {
  17. var pkt = new Uint8Array(8 + data.length);
  18. @@ -179,14 +179,14 @@ class ESPLoader {
  19. }
  20. }
  21. - read_reg = async({addr, timeout = 3000} = {}) => {
  22. + async read_reg({addr, timeout = 3000} = {}) {
  23. var val, data;
  24. var pkt = this._int_to_bytearray(addr);
  25. val = await this.command({op:this.ESP_READ_REG, data:pkt, timeout:timeout});
  26. return val[0];
  27. }
  28. - write_reg = async({addr, value, mask = 0xFFFFFFFF, delay_us = 0, delay_after_us = 0} = {}) => {
  29. + async write_reg({addr, value, mask = 0xFFFFFFFF, delay_us = 0, delay_after_us = 0} = {}) {
  30. var pkt = this._appendArray(this._int_to_bytearray(addr), this._int_to_bytearray(value));
  31. pkt = this._appendArray(pkt, this._int_to_bytearray(mask));
  32. pkt = this._appendArray(pkt, this._int_to_bytearray(delay_us));
  33. @@ -201,7 +201,7 @@ class ESPLoader {
  34. await this.check_command({op_description: "write target memory", op: this.ESP_WRITE_REG, data: pkt});
  35. }
  36. - sync = async () => {
  37. + async sync() {
  38. console.log("Sync");
  39. var cmd = new Uint8Array(36);
  40. var i;
  41. @@ -222,7 +222,7 @@ class ESPLoader {
  42. }
  43. }
  44. - _connect_attempt = async ({mode='default_reset', esp32r0_delay=false} = {}) => {
  45. + async _connect_attempt({mode='default_reset', esp32r0_delay=false} = {}) {
  46. console.log("_connect_attempt " + mode + " " + esp32r0_delay);
  47. if (mode !== 'no_reset') {
  48. await this.transport.setDTR(false);
  49. @@ -275,7 +275,7 @@ class ESPLoader {
  50. return "error";
  51. }
  52. - connect = async ({mode='default_reset', attempts=7, detecting=false} = {}) => {
  53. + async connect({mode='default_reset', attempts=7, detecting=false} = {}) {
  54. var i;
  55. var resp;
  56. this.chip = null;
  57. @@ -311,7 +311,7 @@ class ESPLoader {
  58. }
  59. - detect_chip = async ({mode='default_reset'} = {}) => {
  60. + async detect_chip({mode='default_reset'} = {}) {
  61. await this.connect({mode:mode});
  62. this.write_char("Detecting chip type... ");
  63. if (this.chip != null) {
  64. @@ -319,7 +319,7 @@ class ESPLoader {
  65. }
  66. }
  67. - check_command = async ({op_description="", op=null, data=[], chk=0, timeout=3000} = {}) => {
  68. + async check_command({op_description="", op=null, data=[], chk=0, timeout=3000} = {}) {
  69. console.log("check_command " + op_description) ;
  70. var resp = await this.command({op:op, data:data, chk:chk, timeout:timeout});
  71. if (resp[1].length > 4) {
  72. @@ -329,7 +329,7 @@ class ESPLoader {
  73. }
  74. }
  75. - mem_begin = async (size, blocks, blocksize, offset) => {
  76. + async mem_begin(size, blocks, blocksize, offset) {
  77. /* XXX: Add check to ensure that STUB is not getting overwritten */
  78. console.log("mem_begin " + size + " " + blocks + " " + blocksize + " " + offset.toString(16));
  79. var pkt = this._appendArray(this._int_to_bytearray(size), this._int_to_bytearray(blocks));
  80. @@ -348,7 +348,7 @@ class ESPLoader {
  81. return chk;
  82. }
  83. - mem_block = async (buffer, seq) => {
  84. + async mem_block(buffer, seq) {
  85. var pkt = this._appendArray(this._int_to_bytearray(buffer.length), this._int_to_bytearray(seq));
  86. pkt = this._appendArray(pkt, this._int_to_bytearray(0));
  87. pkt = this._appendArray(pkt, this._int_to_bytearray(0));
  88. @@ -357,13 +357,13 @@ class ESPLoader {
  89. await this.check_command({op_description: "write to target RAM", op: this.ESP_MEM_DATA, data: pkt, chk: checksum});
  90. }
  91. - mem_finish = async (entrypoint) => {
  92. + async mem_finish(entrypoint) {
  93. var is_entry = (entrypoint === 0) ? 1 : 0;
  94. var pkt = this._appendArray(this._int_to_bytearray(is_entry), this._int_to_bytearray(entrypoint));
  95. await this.check_command({op_description: "leave RAM download mode", op: this.ESP_MEM_END, data: pkt, timeout: 50}); // XXX: handle non-stub with diff timeout
  96. }
  97. - flash_spi_attach = async (hspi_arg) => {
  98. + async flash_spi_attach(hspi_arg) {
  99. var pkt = this._int_to_bytearray(hspi_arg);
  100. await this.check_command({op_description: "configure SPI flash pins", op: this.ESP_SPI_ATTACH, data: pkt});
  101. }
  102. @@ -377,7 +377,7 @@ class ESPLoader {
  103. }
  104. }
  105. - flash_begin = async (size, offset) => {
  106. + async flash_begin(size, offset) {
  107. var num_blocks = Math.floor((size + this.FLASH_WRITE_SIZE - 1) / this.FLASH_WRITE_SIZE);
  108. var erase_size = this.chip.get_erase_size(offset, size);
  109. @@ -406,7 +406,7 @@ class ESPLoader {
  110. return num_blocks;
  111. }
  112. - flash_defl_begin = async (size, compsize, offset) => {
  113. + async flash_defl_begin(size, compsize, offset) {
  114. var num_blocks = Math.floor((compsize + this.FLASH_WRITE_SIZE - 1) / this.FLASH_WRITE_SIZE);
  115. var erase_blocks = Math.floor((size + this.FLASH_WRITE_SIZE - 1) / this.FLASH_WRITE_SIZE);
  116. @@ -438,7 +438,7 @@ class ESPLoader {
  117. return num_blocks;
  118. }
  119. - flash_block = async (data, seq, timeout) => {
  120. + async flash_block(data, seq, timeout) {
  121. var pkt = this._appendArray(this._int_to_bytearray(data.length), this._int_to_bytearray(seq));
  122. pkt = this._appendArray(pkt, this._int_to_bytearray(0));
  123. pkt = this._appendArray(pkt, this._int_to_bytearray(0));
  124. @@ -449,7 +449,7 @@ class ESPLoader {
  125. await this.check_command({op_description:"write to target Flash after seq " + seq, op: this.ESP_FLASH_DATA, data: pkt, chk: checksum, timeout: timeout});
  126. }
  127. - flash_defl_block = async (data, seq, timeout) => {
  128. + async flash_defl_block(data, seq, timeout) {
  129. var pkt = this._appendArray(this._int_to_bytearray(data.length), this._int_to_bytearray(seq));
  130. pkt = this._appendArray(pkt, this._int_to_bytearray(0));
  131. pkt = this._appendArray(pkt, this._int_to_bytearray(0));
  132. @@ -462,21 +462,21 @@ class ESPLoader {
  133. }
  134. - flash_finish = async ({reboot = false } = {}) => {
  135. + async flash_finish({reboot = false } = {}) {
  136. var val = reboot ? 0 : 1;
  137. var pkt = this._int_to_bytearray(val);
  138. await this.check_command({op_description:"leave Flash mode", op: this.ESP_FLASH_END, data: pkt});
  139. }
  140. - flash_defl_finish = async ({reboot = false } = {}) => {
  141. + async flash_defl_finish({reboot = false } = {}) {
  142. var val = reboot ? 0 : 1;
  143. var pkt = this._int_to_bytearray(val);
  144. await this.check_command({op_description:"leave compressed flash mode", op: this.ESP_FLASH_DEFL_END, data: pkt});
  145. }
  146. - run_spiflash_command = async (spiflash_command, data, read_bits) => {
  147. + async run_spiflash_command(spiflash_command, data, read_bits) {
  148. // SPI_USR register flags
  149. var SPI_USR_COMMAND = (1 << 31);
  150. var SPI_USR_MISO = (1 << 28);
  151. @@ -568,13 +568,13 @@ class ESPLoader {
  152. return stat;
  153. }
  154. - read_flash_id = async() => {
  155. + async read_flash_id() {
  156. var SPIFLASH_RDID = 0x9F;
  157. var pkt = new Uint8Array(0);
  158. return await this.run_spiflash_command(SPIFLASH_RDID, pkt, 24);
  159. }
  160. - erase_flash = async() => {
  161. + async erase_flash() {
  162. this.log("Erasing flash (this may take a while)...");
  163. var d = new Date();
  164. let t1 = d.getTime();
  165. @@ -589,7 +589,7 @@ class ESPLoader {
  166. return Array.prototype.map.call(buffer, x => ('00' + x.toString(16)).slice(-2)).join('');
  167. }
  168. - flash_md5sum = async(addr, size) => {
  169. + async flash_md5sum(addr, size) {
  170. let timeout = this.timeout_per_mb(this.MD5_TIMEOUT_PER_MB, size);
  171. var pkt = this._appendArray(this._int_to_bytearray(addr), this._int_to_bytearray(size));
  172. pkt = this._appendArray(pkt, this._int_to_bytearray(0));
  173. @@ -603,7 +603,7 @@ class ESPLoader {
  174. return strmd5;
  175. }
  176. - run_stub = async () => {
  177. + async run_stub() {
  178. this.log("Uploading stub...");
  179. var decoded = atob(this.chip.ROM_TEXT);
  180. @@ -649,7 +649,7 @@ class ESPLoader {
  181. throw new ESPError("Failed to start stub. Unexpected response");
  182. }
  183. - change_baud = async() => {
  184. + async change_baud() {
  185. this.log("Changing baudrate to " + this.baudrate);
  186. let second_arg = this.IS_STUB ? this.transport.baudrate : 0;
  187. let pkt = this._appendArray(this._int_to_bytearray(this.baudrate), this._int_to_bytearray(second_arg));
  188. @@ -664,7 +664,7 @@ class ESPLoader {
  189. }
  190. }
  191. - main_fn = async ({mode='default_reset'} = {}) => {
  192. + async main_fn({mode='default_reset'} = {}) {
  193. await this.detect_chip({mode});
  194. var chip = await this.chip.get_chip_description(this);
  195. @@ -749,7 +749,7 @@ class ESPLoader {
  196. return image;
  197. }
  198. - write_flash = async ({
  199. + async write_flash({
  200. fileArray=[],
  201. flash_size='keep',
  202. flash_mode='keep',
  203. @@ -760,7 +760,7 @@ class ESPLoader {
  204. reportProgress=undefined,
  205. /* function(image: string) => string */
  206. calculateMD5Hash=undefined
  207. - }) => {
  208. + }) {
  209. console.log("EspLoader program");
  210. if (flash_size !== 'keep') {
  211. let flash_end = this.flash_size_bytes(flash_size);
  212. @@ -872,7 +872,7 @@ class ESPLoader {
  213. }
  214. }
  215. - flash_id = async() => {
  216. + async flash_id() {
  217. console.log("flash_id");
  218. var flashid = await this.read_flash_id();
  219. this.log("Manufacturer: " + (flashid & 0xff).toString(16));
  220. @@ -881,13 +881,13 @@ class ESPLoader {
  221. this.log("Detected flash size: " + this.DETECTED_FLASH_SIZES[flid_lowbyte]);
  222. }
  223. - hard_reset = async() => {
  224. + async hard_reset() {
  225. this.transport.setRTS(true); // EN->LOW
  226. await this._sleep(100);
  227. this.transport.setRTS(false);
  228. }
  229. - soft_reset = async() => {
  230. + async soft_reset() {
  231. if (!this.IS_STUB) {
  232. // 'run user code' is as close to a soft reset as we can do
  233. this.flash_begin(0, 0);