Dcodes.cpp 17 KB

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