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