Dcodes.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. #include "Dcodes.h"
  2. //#include "Marlin.h"
  3. #include "language.h"
  4. #include "cmdqueue.h"
  5. #include <stdio.h>
  6. #include <avr/pgmspace.h>
  7. #define DBG(args...) printf_P(args)
  8. inline void print_hex_nibble(uint8_t val)
  9. {
  10. putchar((val > 9)?(val - 10 + 'a'):(val + '0'));
  11. }
  12. void print_hex_byte(uint8_t val)
  13. {
  14. print_hex_nibble(val >> 4);
  15. print_hex_nibble(val & 15);
  16. }
  17. void print_hex_word(uint16_t val)
  18. {
  19. print_hex_byte(val >> 8);
  20. print_hex_byte(val & 255);
  21. }
  22. void print_eeprom(uint16_t address, uint16_t count, uint8_t countperline = 16)
  23. {
  24. while (count)
  25. {
  26. print_hex_word(address);
  27. putchar(' ');
  28. uint8_t count_line = countperline;
  29. while (count && count_line)
  30. {
  31. uint8_t data = 0;
  32. putchar(' ');
  33. print_hex_byte(eeprom_read_byte((uint8_t*)address++));
  34. count_line--;
  35. count--;
  36. }
  37. putchar('\n');
  38. }
  39. }
  40. int parse_hex(char* hex, uint8_t* data, int count)
  41. {
  42. int parsed = 0;
  43. while (*hex)
  44. {
  45. if (count && (parsed >= count)) break;
  46. char c = *(hex++);
  47. if (c == ' ') continue;
  48. if (c == '\n') break;
  49. uint8_t val = 0x00;
  50. if ((c >= '0') && (c <= '9')) val |= ((c - '0') << 4);
  51. else if ((c >= 'a') && (c <= 'f')) val |= ((c - 'a' + 10) << 4);
  52. else return -parsed;
  53. c = *(hex++);
  54. if ((c >= '0') && (c <= '9')) val |= (c - '0');
  55. else if ((c >= 'a') && (c <= 'f')) val |= (c - 'a' + 10);
  56. else return -parsed;
  57. data[parsed] = val;
  58. parsed++;
  59. }
  60. return parsed;
  61. }
  62. void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperline = 16)
  63. {
  64. while (count)
  65. {
  66. if (type == 2)
  67. print_hex_nibble(address >> 16);
  68. print_hex_word(address);
  69. putchar(' ');
  70. uint8_t count_line = countperline;
  71. while (count && count_line)
  72. {
  73. uint8_t data = 0;
  74. switch (type)
  75. {
  76. case 0: data = *((uint8_t*)address++); break;
  77. case 1: data = eeprom_read_byte((uint8_t*)address++); break;
  78. case 2: data = pgm_read_byte_far((uint8_t*)address++); break;
  79. }
  80. putchar(' ');
  81. print_hex_byte(data);
  82. count_line--;
  83. count--;
  84. }
  85. putchar('\n');
  86. }
  87. }
  88. #ifdef DEBUG_DCODE3
  89. #define EEPROM_SIZE 0x1000
  90. void dcode_3()
  91. {
  92. DBG(_N("D3 - Read/Write EEPROM\n"));
  93. uint16_t address = 0x0000; //default 0x0000
  94. uint16_t count = EEPROM_SIZE; //default 0x1000 (entire eeprom)
  95. if (code_seen('A')) // Address (0x0000-0x0fff)
  96. address = (strchr_pointer[1] == 'x')?strtol(strchr_pointer + 2, 0, 16):(int)code_value();
  97. if (code_seen('C')) // Count (0x0001-0x1000)
  98. count = (int)code_value();
  99. address &= 0x1fff;
  100. if (count > EEPROM_SIZE) count = EEPROM_SIZE;
  101. if ((address + count) > EEPROM_SIZE) count = EEPROM_SIZE - address;
  102. if (code_seen('X')) // Data
  103. {
  104. uint8_t data[16];
  105. count = parse_hex(strchr_pointer + 1, data, 16);
  106. if (count > 0)
  107. {
  108. for (int i = 0; i < count; i++)
  109. eeprom_write_byte((uint8_t*)(address + i), data[i]);
  110. printf_P(_N("%d bytes written to EEPROM at address 0x%04x"), count, address);
  111. putchar('\n');
  112. }
  113. else
  114. count = 0;
  115. }
  116. print_mem(address, count, 1);
  117. /* while (count)
  118. {
  119. print_hex_word(address);
  120. putchar(' ');
  121. uint8_t countperline = 16;
  122. while (count && countperline)
  123. {
  124. uint8_t data = eeprom_read_byte((uint8_t*)address++);
  125. putchar(' ');
  126. print_hex_byte(data);
  127. countperline--;
  128. count--;
  129. }
  130. putchar('\n');
  131. }*/
  132. }
  133. #endif //DEBUG_DCODE3
  134. #ifdef DEBUG_DCODES
  135. #include "ConfigurationStore.h"
  136. #include "cmdqueue.h"
  137. #include "pat9125.h"
  138. #include "adc.h"
  139. #include "temperature.h"
  140. #include <avr/wdt.h>
  141. #define FLASHSIZE 0x40000
  142. #define RAMSIZE 0x2000
  143. #define boot_src_addr (*((uint32_t*)(RAMSIZE - 16)))
  144. #define boot_dst_addr (*((uint32_t*)(RAMSIZE - 12)))
  145. #define boot_copy_size (*((uint16_t*)(RAMSIZE - 8)))
  146. #define boot_reserved (*((uint8_t*)(RAMSIZE - 6)))
  147. #define boot_app_flags (*((uint8_t*)(RAMSIZE - 5)))
  148. #define boot_app_magic (*((uint32_t*)(RAMSIZE - 4)))
  149. #define BOOT_APP_FLG_ERASE 0x01
  150. #define BOOT_APP_FLG_COPY 0x02
  151. #define BOOT_APP_FLG_FLASH 0x04
  152. extern uint8_t fsensor_log;
  153. extern float current_temperature_pinda;
  154. extern float axis_steps_per_unit[NUM_AXIS];
  155. //#define LOG(args...) printf(args)
  156. #define LOG(args...)
  157. void dcode__1()
  158. {
  159. printf("D-1 - Endless loop\n");
  160. cli();
  161. while (1);
  162. }
  163. void dcode_0()
  164. {
  165. if (*(strchr_pointer + 1) == 0) return;
  166. LOG("D0 - Reset\n");
  167. if (code_seen('B')) //bootloader
  168. {
  169. cli();
  170. wdt_enable(WDTO_15MS);
  171. while(1);
  172. }
  173. else //reset
  174. {
  175. #ifndef _NO_ASM
  176. asm volatile("jmp 0x00000");
  177. #endif //_NO_ASM
  178. }
  179. }
  180. void dcode_1()
  181. {
  182. LOG("D1 - Clear EEPROM and RESET\n");
  183. cli();
  184. for (int i = 0; i < 8192; i++)
  185. eeprom_write_byte((unsigned char*)i, (unsigned char)0xff);
  186. wdt_enable(WDTO_15MS);
  187. while(1);
  188. }
  189. void dcode_2()
  190. {
  191. LOG("D2 - Read/Write RAM\n");
  192. uint16_t address = 0x0000; //default 0x0000
  193. uint16_t count = 0x2000; //default 0x2000 (entire ram)
  194. if (code_seen('A')) // Address (0x0000-0x1fff)
  195. address = (strchr_pointer[1] == 'x')?strtol(strchr_pointer + 2, 0, 16):(int)code_value();
  196. if (code_seen('C')) // Count (0x0001-0x2000)
  197. count = (int)code_value();
  198. address &= 0x1fff;
  199. if (count > 0x2000) count = 0x2000;
  200. if ((address + count) > 0x2000) count = 0x2000 - address;
  201. if (code_seen('X')) // Data
  202. {
  203. uint8_t data[16];
  204. count = parse_hex(strchr_pointer + 1, data, 16);
  205. if (count > 0)
  206. {
  207. for (int i = 0; i < count; i++)
  208. *((uint8_t*)(address + i)) = data[i];
  209. LOG("%d bytes written to RAM at address %04x", count, address);
  210. }
  211. else
  212. count = 0;
  213. }
  214. print_mem(address, count, 0);
  215. /* while (count)
  216. {
  217. print_hex_word(address);
  218. putchar(' ');
  219. uint8_t countperline = 16;
  220. while (count && countperline)
  221. {
  222. uint8_t data = *((uint8_t*)address++);
  223. putchar(' ');
  224. print_hex_byte(data);
  225. countperline--;
  226. count--;
  227. }
  228. putchar('\n');
  229. }*/
  230. }
  231. void dcode_4()
  232. {
  233. LOG("D4 - Read/Write PIN\n");
  234. if (code_seen('P')) // Pin (0-255)
  235. {
  236. int pin = (int)code_value();
  237. if ((pin >= 0) && (pin <= 255))
  238. {
  239. if (code_seen('F')) // Function in/out (0/1)
  240. {
  241. int fnc = (int)code_value();
  242. if (fnc == 0) pinMode(pin, INPUT);
  243. else if (fnc == 1) pinMode(pin, OUTPUT);
  244. }
  245. if (code_seen('V')) // Value (0/1)
  246. {
  247. int val = (int)code_value();
  248. if (val == 0) digitalWrite(pin, LOW);
  249. else if (val == 1) digitalWrite(pin, HIGH);
  250. }
  251. else
  252. {
  253. int val = (digitalRead(pin) != LOW)?1:0;
  254. printf("PIN%d=%d", pin, val);
  255. }
  256. }
  257. }
  258. }
  259. /*
  260. void dcode_5()
  261. {
  262. LOG("D5 - Read/Write FLASH\n");
  263. uint32_t address = 0x0000; //default 0x0000
  264. uint16_t count = 0x0400; //default 0x0400 (1kb block)
  265. if (code_seen('A')) // Address (0x00000-0x3ffff)
  266. address = (strchr_pointer[1] == 'x')?strtol(strchr_pointer + 2, 0, 16):(int)code_value();
  267. if (code_seen('C')) // Count (0x0001-0x2000)
  268. count = (int)code_value();
  269. address &= 0x3ffff;
  270. if (count > 0x2000) count = 0x2000;
  271. if ((address + count) > 0x40000) count = 0x40000 - address;
  272. bool bErase = false;
  273. bool bCopy = false;
  274. if (code_seen('E')) //Erase
  275. bErase = true;
  276. uint8_t data[16];
  277. if (code_seen('X')) // Data
  278. {
  279. count = parse_hex(strchr_pointer + 1, data, 16);
  280. if (count > 0) bCopy = true;
  281. }
  282. if (bErase || bCopy)
  283. {
  284. if (bErase)
  285. {
  286. LOG(count, DEC);
  287. LOG(" bytes of FLASH at address ");
  288. print_hex_word(address);
  289. putchar(" will be erased\n");
  290. }
  291. if (bCopy)
  292. {
  293. LOG(count, DEC);
  294. LOG(" bytes will be written to FLASH at address ");
  295. print_hex_word(address);
  296. putchar('\n');
  297. }
  298. cli();
  299. boot_app_magic = 0x55aa55aa;
  300. boot_app_flags = (bErase?(BOOT_APP_FLG_ERASE):0) | (bCopy?(BOOT_APP_FLG_COPY):0);
  301. boot_copy_size = (uint16_t)count;
  302. boot_dst_addr = (uint32_t)address;
  303. boot_src_addr = (uint32_t)(&data);
  304. wdt_enable(WDTO_15MS);
  305. while(1);
  306. }
  307. while (count)
  308. {
  309. print_hex_nibble(address >> 16);
  310. print_hex_word(address);
  311. putchar(' ');
  312. uint8_t countperline = 16;
  313. while (count && countperline)
  314. {
  315. uint8_t data = pgm_read_byte_far((uint8_t*)address++);
  316. putchar(' ');
  317. print_hex_byte(data);
  318. countperline--;
  319. count--;
  320. }
  321. putchar('\n');
  322. }
  323. }
  324. */
  325. void dcode_6()
  326. {
  327. LOG("D6 - Read/Write external FLASH\n");
  328. }
  329. void dcode_7()
  330. {
  331. LOG("D7 - Read/Write Bootloader\n");
  332. /*
  333. cli();
  334. boot_app_magic = 0x55aa55aa;
  335. boot_app_flags = BOOT_APP_FLG_ERASE | BOOT_APP_FLG_COPY | BOOT_APP_FLG_FLASH;
  336. boot_copy_size = (uint16_t)0xc00;
  337. boot_src_addr = (uint32_t)0x0003e400;
  338. boot_dst_addr = (uint32_t)0x0003f400;
  339. wdt_enable(WDTO_15MS);
  340. while(1);
  341. */
  342. }
  343. void dcode_8()
  344. {
  345. printf_P(PSTR("D8 - Read/Write PINDA\n"));
  346. uint8_t cal_status = calibration_status_pinda();
  347. float temp_pinda = current_temperature_pinda;
  348. float offset_z = temp_compensation_pinda_thermistor_offset(temp_pinda);
  349. if ((strchr_pointer[1+1] == '?') || (strchr_pointer[1+1] == 0))
  350. {
  351. printf_P(PSTR("cal_status=%d\n"), cal_status?1:0);
  352. for (uint8_t i = 0; i < 6; i++)
  353. {
  354. uint16_t offs = 0;
  355. if (i > 0) offs = eeprom_read_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + (i - 1));
  356. float foffs = ((float)offs) / axis_steps_per_unit[Z_AXIS];
  357. offs = 1000 * foffs;
  358. printf_P(PSTR("temp_pinda=%dC temp_shift=%dum\n"), 35 + i * 5, offs);
  359. }
  360. }
  361. else if (strchr_pointer[1+1] == '!')
  362. {
  363. cal_status = 1;
  364. eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, cal_status);
  365. eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 0, 8); //40C - 20um - 8usteps
  366. eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 1, 24); //45C - 60um - 24usteps
  367. eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 2, 48); //50C - 120um - 48usteps
  368. eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 3, 80); //55C - 200um - 80usteps
  369. eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 4, 120); //60C - 300um - 120usteps
  370. }
  371. else
  372. {
  373. if (code_seen('P')) // Pinda temperature [C]
  374. temp_pinda = code_value();
  375. offset_z = temp_compensation_pinda_thermistor_offset(temp_pinda);
  376. if (code_seen('Z')) // Z Offset [mm]
  377. {
  378. offset_z = code_value();
  379. }
  380. }
  381. printf_P(PSTR("temp_pinda=%d offset_z=%d.%03d\n"), (int)temp_pinda, (int)offset_z, ((int)(1000 * offset_z) % 1000));
  382. }
  383. const char* dcode_9_ADC_name(uint8_t i)
  384. {
  385. switch (i)
  386. {
  387. case 0: return PSTR("TEMP_HEATER0");
  388. case 1: return PSTR("TEMP_HEATER1");
  389. case 2: return PSTR("TEMP_BED");
  390. case 3: return PSTR("TEMP_PINDA");
  391. case 4: return PSTR("VOLT_PWR");
  392. case 5: return PSTR("TEMP_AMBIENT");
  393. case 6: return PSTR("VOLT_BED");
  394. }
  395. return 0;
  396. }
  397. extern int current_temperature_raw[EXTRUDERS];
  398. extern int current_temperature_bed_raw;
  399. extern int current_temperature_raw_pinda;
  400. #ifdef AMBIENT_THERMISTOR
  401. extern int current_temperature_raw_ambient;
  402. #endif //AMBIENT_THERMISTOR
  403. #ifdef VOLT_PWR_PIN
  404. extern int current_voltage_raw_pwr;
  405. #endif //VOLT_PWR_PIN
  406. #ifdef VOLT_BED_PIN
  407. extern int current_voltage_raw_bed;
  408. #endif //VOLT_BED_PIN
  409. uint16_t dcode_9_ADC_val(uint8_t i)
  410. {
  411. switch (i)
  412. {
  413. case 0: return current_temperature_raw[0];
  414. case 1: return 0;
  415. case 2: return current_temperature_bed_raw;
  416. case 3: return current_temperature_raw_pinda;
  417. #ifdef VOLT_PWR_PIN
  418. case 4: return current_voltage_raw_pwr;
  419. #endif //VOLT_PWR_PIN
  420. #ifdef AMBIENT_THERMISTOR
  421. case 5: return current_temperature_raw_ambient;
  422. #endif //AMBIENT_THERMISTOR
  423. #ifdef VOLT_BED_PIN
  424. case 6: return current_voltage_raw_bed;
  425. #endif //VOLT_BED_PIN
  426. }
  427. return 0;
  428. }
  429. void dcode_9()
  430. {
  431. printf_P(PSTR("D9 - Read/Write ADC\n"));
  432. if ((strchr_pointer[1+1] == '?') || (strchr_pointer[1+1] == 0))
  433. {
  434. for (uint8_t i = 0; i < ADC_CHAN_CNT; i++)
  435. printf_P(PSTR("\tADC%d=%4d\t(%S)\n"), i, dcode_9_ADC_val(i) >> 4, dcode_9_ADC_name(i));
  436. }
  437. else
  438. {
  439. uint8_t index = 0xff;
  440. if (code_seen('I')) // index (index of used channel, not avr channel index)
  441. index = code_value();
  442. if (index < ADC_CHAN_CNT)
  443. {
  444. if (code_seen('V')) // value to be written as simulated
  445. {
  446. adc_sim_mask |= (1 << index);
  447. adc_values[index] = (((int)code_value()) << 4);
  448. printf_P(PSTR("ADC%d=%4d\n"), index, adc_values[index] >> 4);
  449. }
  450. }
  451. }
  452. }
  453. void dcode_10()
  454. {//Tell the printer that XYZ calibration went OK
  455. LOG("D10 - XYZ calibration = OK\n");
  456. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  457. }
  458. void dcode_12()
  459. {//Time
  460. LOG("D12 - Time\n");
  461. }
  462. #ifdef TMC2130
  463. #include "planner.h"
  464. #include "tmc2130.h"
  465. extern void st_synchronize();
  466. /**
  467. * @brief D2130 Trinamic stepper controller
  468. * D2130<axis><command>[subcommand][value]
  469. * * Axis
  470. * * * 'X'
  471. * * * 'Y'
  472. * * * 'Z'
  473. * * * 'E'
  474. * * command
  475. * * * '0' current off
  476. * * * '1' current on
  477. * * * '+' single step
  478. * * * * value sereval steps
  479. * * * '-' dtto oposite direction
  480. * * * '?' read register
  481. * * * * "mres"
  482. * * * * "step"
  483. * * * * "mscnt"
  484. * * * * "mscuract"
  485. * * * * "wave"
  486. * * * '!' set register
  487. * * * * "mres"
  488. * * * * "step"
  489. * * * * "wave"
  490. * * * * *0, 180..250 meaning: off, 0.9..1.25, recommended value is 1.1
  491. * * * '@' home calibrate axis
  492. *
  493. * Example:
  494. * D2130E?wave //print extruder microstep linearity compensation curve
  495. * D2130E!wave0 //disable extruder linearity compensation curve, (sine curve is used)
  496. * D2130E!wave220 // (sin(x))^1.1 extruder microstep compensation curve used
  497. */
  498. void dcode_2130()
  499. {
  500. printf_P(PSTR("D2130 - TMC2130\n"));
  501. uint8_t axis = 0xff;
  502. switch (strchr_pointer[1+4])
  503. {
  504. case 'X': axis = X_AXIS; break;
  505. case 'Y': axis = Y_AXIS; break;
  506. case 'Z': axis = Z_AXIS; break;
  507. case 'E': axis = E_AXIS; break;
  508. }
  509. if (axis != 0xff)
  510. {
  511. char ch_axis = strchr_pointer[1+4];
  512. if (strchr_pointer[1+5] == '0') { tmc2130_set_pwr(axis, 0); }
  513. else if (strchr_pointer[1+5] == '1') { tmc2130_set_pwr(axis, 1); }
  514. else if (strchr_pointer[1+5] == '+')
  515. {
  516. if (strchr_pointer[1+6] == 0)
  517. {
  518. tmc2130_set_dir(axis, 0);
  519. tmc2130_do_step(axis);
  520. }
  521. else
  522. {
  523. uint8_t steps = atoi(strchr_pointer + 1 + 6);
  524. tmc2130_do_steps(axis, steps, 0, 1000);
  525. }
  526. }
  527. else if (strchr_pointer[1+5] == '-')
  528. {
  529. if (strchr_pointer[1+6] == 0)
  530. {
  531. tmc2130_set_dir(axis, 1);
  532. tmc2130_do_step(axis);
  533. }
  534. else
  535. {
  536. uint8_t steps = atoi(strchr_pointer + 1 + 6);
  537. tmc2130_do_steps(axis, steps, 1, 1000);
  538. }
  539. }
  540. else if (strchr_pointer[1+5] == '?')
  541. {
  542. if (strcmp(strchr_pointer + 7, "mres") == 0) printf_P(PSTR("%c mres=%d\n"), ch_axis, tmc2130_mres[axis]);
  543. else if (strcmp(strchr_pointer + 7, "step") == 0) printf_P(PSTR("%c step=%d\n"), ch_axis, tmc2130_rd_MSCNT(axis) >> tmc2130_mres[axis]);
  544. else if (strcmp(strchr_pointer + 7, "mscnt") == 0) printf_P(PSTR("%c MSCNT=%d\n"), ch_axis, tmc2130_rd_MSCNT(axis));
  545. else if (strcmp(strchr_pointer + 7, "mscuract") == 0)
  546. {
  547. uint32_t val = tmc2130_rd_MSCURACT(axis);
  548. int curA = (val & 0xff);
  549. int curB = ((val >> 16) & 0xff);
  550. if ((val << 7) & 0x8000) curA -= 256;
  551. if ((val >> 9) & 0x8000) curB -= 256;
  552. printf_P(PSTR("%c MSCURACT=0x%08lx A=%d B=%d\n"), ch_axis, val, curA, curB);
  553. }
  554. else if (strcmp(strchr_pointer + 7, "wave") == 0)
  555. {
  556. tmc2130_get_wave(axis, 0, stdout);
  557. }
  558. }
  559. else if (strchr_pointer[1+5] == '!')
  560. {
  561. if (strncmp(strchr_pointer + 7, "step", 4) == 0)
  562. {
  563. uint8_t step = atoi(strchr_pointer + 11);
  564. uint16_t res = tmc2130_get_res(axis);
  565. tmc2130_goto_step(axis, step & (4*res - 1), 2, 1000, res);
  566. }
  567. else if (strncmp(strchr_pointer + 7, "mres", 4) == 0)
  568. {
  569. uint8_t mres = strchr_pointer[11] - '0';
  570. if ((mres >= 0) && (mres <= 8))
  571. {
  572. st_synchronize();
  573. uint16_t res = tmc2130_get_res(axis);
  574. uint16_t res_new = tmc2130_mres2usteps(mres);
  575. tmc2130_set_res(axis, res_new);
  576. if (res_new > res)
  577. axis_steps_per_unit[axis] *= (res_new / res);
  578. else
  579. axis_steps_per_unit[axis] /= (res / res_new);
  580. }
  581. }
  582. else if (strncmp(strchr_pointer + 7, "wave", 4) == 0)
  583. {
  584. uint8_t fac1000 = atoi(strchr_pointer + 11) & 0xffff;
  585. if (fac1000 < TMC2130_WAVE_FAC1000_MIN) fac1000 = 0;
  586. if (fac1000 > TMC2130_WAVE_FAC1000_MAX) fac1000 = TMC2130_WAVE_FAC1000_MAX;
  587. tmc2130_set_wave(axis, 247, fac1000);
  588. tmc2130_wave_fac[axis] = fac1000;
  589. }
  590. }
  591. else if (strchr_pointer[1+5] == '@')
  592. {
  593. tmc2130_home_calibrate(axis);
  594. }
  595. }
  596. }
  597. #endif //TMC2130
  598. #ifdef PAT9125
  599. void dcode_9125()
  600. {
  601. LOG("D9125 - PAT9125\n");
  602. if ((strchr_pointer[1+4] == '?') || (strchr_pointer[1+4] == 0))
  603. {
  604. // printf("res_x=%d res_y=%d x=%d y=%d b=%d s=%d\n", pat9125_xres, pat9125_yres, pat9125_x, pat9125_y, pat9125_b, pat9125_s);
  605. printf("x=%d y=%d b=%d s=%d\n", pat9125_x, pat9125_y, pat9125_b, pat9125_s);
  606. return;
  607. }
  608. if (strchr_pointer[1+4] == '!')
  609. {
  610. pat9125_update();
  611. printf("x=%d y=%d b=%d s=%d\n", pat9125_x, pat9125_y, pat9125_b, pat9125_s);
  612. return;
  613. }
  614. /*
  615. if (code_seen('R'))
  616. {
  617. unsigned char res = (int)code_value();
  618. LOG("pat9125_init(xres=yres=%d)=%d\n", res, pat9125_init(res, res));
  619. }
  620. */
  621. if (code_seen('X'))
  622. {
  623. pat9125_x = (int)code_value();
  624. LOG("pat9125_x=%d\n", pat9125_x);
  625. }
  626. if (code_seen('Y'))
  627. {
  628. pat9125_y = (int)code_value();
  629. LOG("pat9125_y=%d\n", pat9125_y);
  630. }
  631. if (code_seen('L'))
  632. {
  633. fsensor_log = (int)code_value();
  634. LOG("fsensor_log=%d\n", fsensor_log);
  635. }
  636. }
  637. #endif //PAT9125
  638. #endif //DEBUG_DCODES