You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "main.hpp"
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "main.h"
  5. #include "project.hpp"
  6. //
  7. #include "sdk/hal/zhal.hpp"
  8. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  9. #define TAG "main"
  10. namespace iflytop {
  11. Main gmain;
  12. };
  13. using namespace iflytop;
  14. void Main::run() {
  15. iflytop_no_os_cfg_t oscfg = {
  16. .delayhtim = &DELAY_US_TIMER,
  17. .debuguart = &DEBUG_UART,
  18. };
  19. iflytop_no_os_init(&oscfg);
  20. ZLOGI(TAG, "robotic_core_xy:%s", VERSION);
  21. DEBUG_LIGHT_GPIO.initAsOutput(true);
  22. ZHAL_CORE_REG(200, { DEBUG_LIGHT_GPIO.toggleState(); });
  23. // while (true) {
  24. // chip_delay_us(1000 * 1000);
  25. // ZLOGI(TAG, ".....");
  26. // }
  27. TMC4361A motora;
  28. TMC4361A motorb;
  29. TMC_MOTOR1_SPI_SELECT1_IO.initAsOutput(true);
  30. TMC_MOTOR1_nFREEZE_IO.initAsOutput(true);
  31. TMC_MOTOR1_nRESET_IO.initAsOutput(true);
  32. TMC_MOTOR1_SUB_IC_ENN_IO.initAsOutput(true);
  33. TMC_MOTOR2_SPI_SELECT1_IO.initAsOutput(true);
  34. TMC_MOTOR2_nFREEZE_IO.initAsOutput(true);
  35. TMC_MOTOR2_nRESET_IO.initAsOutput(true);
  36. TMC_MOTOR2_SUB_IC_ENN_IO.initAsOutput(true);
  37. {
  38. TMC4361A::cfg_t motora_cfg = {.spi = &TMC_MOTOR_SPI,
  39. .csgpio = &TMC_MOTOR1_SPI_SELECT1_IO,
  40. .resetPin = &TMC_MOTOR1_nRESET_IO,
  41. .fREEZEPin = &TMC_MOTOR1_nFREEZE_IO,
  42. .ennPin = NULL,
  43. .driverIC_ennPin = &TMC_MOTOR1_SUB_IC_ENN_IO,
  44. .driverIC_resetPin = NULL};
  45. motora.initialize(&motora_cfg);
  46. int32_t ic4361Version = motora.readICVersion();
  47. int32_t ic2160Version = motora.readSubICVersion();
  48. ZLOGI(TAG, "motora:TMC4361Version:%lx TMC2160VERSION:%lx", ic4361Version, ic2160Version);
  49. }
  50. {
  51. TMC4361A::cfg_t motorb_cfg = {.spi = &TMC_MOTOR_SPI,
  52. .csgpio = &TMC_MOTOR2_SPI_SELECT1_IO,
  53. .resetPin = &TMC_MOTOR2_nRESET_IO,
  54. .fREEZEPin = &TMC_MOTOR2_nFREEZE_IO,
  55. .ennPin = NULL,
  56. .driverIC_ennPin = &TMC_MOTOR2_SUB_IC_ENN_IO,
  57. .driverIC_resetPin = NULL};
  58. motorb.initialize(&motorb_cfg);
  59. int32_t ic4361Version = motorb.readICVersion();
  60. int32_t ic2160Version = motorb.readSubICVersion();
  61. ZLOGI(TAG, "motorb:TMC4361Version:%lx TMC2160VERSION:%lx", ic4361Version, ic2160Version);
  62. }
  63. motora.setIHOLD_IRUN(1, 12, 0); // 小臂
  64. motora.setMotorShaft(0);
  65. motorb.setIHOLD_IRUN(1, 12, 0); // 小臂
  66. motorb.setMotorShaft(0);
  67. motora.rotate(1200000);
  68. motorb.rotate(1200000);
  69. while (1) {
  70. ZHALCORE::getInstance()->loop();
  71. }
  72. }