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.

173 lines
6.9 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
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
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
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 <stddef.h>
  2. #include <stdio.h>
  3. #include "board.h"
  4. #include "sdk\components\subcanmodule\zcancmder_subboard_initer.hpp"
  5. /*******************************************************************************
  6. * PROJECT_INCLUDE *
  7. *******************************************************************************/
  8. #include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
  9. #include "sdk\components\mini_servo_motor\feite_servo_motor.hpp"
  10. #include "sdk\components\mini_servo_motor\mini_servo_motor_ctrl_module.hpp"
  11. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  12. #define TAG "main"
  13. using namespace iflytop;
  14. using namespace std;
  15. static ZCancmderSubboardIniter initer;
  16. extern void umain();
  17. extern "C" {
  18. void StartDefaultTask(void const* argument) { umain(); }
  19. }
  20. /*******************************************************************************
  21. * GET_DEVICE_ID *
  22. *******************************************************************************/
  23. static int32_t getDeviceId() { return BOARD_ID; }
  24. /*******************************************************************************
  25. * INIT_SUBMODULE *
  26. *******************************************************************************/
  27. void nvs_init_cb() {}
  28. static void initsubmodule() {
  29. /**
  30. * @brief
  31. */
  32. {
  33. static TMC5130 motor;
  34. static StepMotorCtrlModule stepMotorCtrlModule;
  35. TMC5130::cfg_t cfg = {
  36. .spi = &TMC_MOTOR_SPI, //
  37. .csgpio = MOTOR1_CSN, //
  38. .ennPin = MOTOR1_ENN, //
  39. .spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
  40. };
  41. motor.initialize(&cfg);
  42. motor.setMotorShaft(false);
  43. ZLOGI(TAG, "motor1 initialize 5160:%x ", motor.readICVersion());
  44. static ZGPIO input[2];
  45. input[0].initAsInput(MOTOR1_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  46. input[1].initAsInput(MOTOR1_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  47. I_StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  48. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  49. smcm_cfg.base_param.distance_scale = 200;
  50. smcm_cfg.base_param.distance_scale_denominator = 1;
  51. smcm_cfg.base_param.irun = 24;
  52. smcm_cfg.base_param.ihold = 1;
  53. smcm_cfg.base_param.x_shaft = false;
  54. smcm_cfg.base_param.maxspeed = 150;
  55. stepMotorCtrlModule.initialize(initer.get_module_id(1), &motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  56. initer.register_module(&stepMotorCtrlModule);
  57. }
  58. /**
  59. * @brief ƽ
  60. */
  61. {
  62. static TMC5130 motor;
  63. static StepMotorCtrlModule stepMotorCtrlModule;
  64. TMC5130::cfg_t cfg = {
  65. .spi = &TMC_MOTOR_SPI, //
  66. .csgpio = MOTOR2_CSN, //
  67. .ennPin = MOTOR2_ENN, //
  68. .spi_mode_select = MOTOR2_SPI_MODE_SELECT, //
  69. };
  70. motor.initialize(&cfg);
  71. motor.setMotorShaft(false);
  72. ZLOGI(TAG, "motor2 initialize 5160:%x ", motor.readICVersion());
  73. static ZGPIO input[2];
  74. input[0].initAsInput(MOTOR2_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  75. input[1].initAsInput(MOTOR2_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  76. I_StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  77. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  78. smcm_cfg.base_param.distance_scale = 100;
  79. smcm_cfg.base_param.distance_scale_denominator = 1;
  80. smcm_cfg.base_param.irun = 24;
  81. smcm_cfg.base_param.ihold = 1;
  82. smcm_cfg.base_param.x_shaft = true;
  83. smcm_cfg.base_param.maxspeed = 50;
  84. smcm_cfg.base_param.run_to_zero_speed = 50;
  85. stepMotorCtrlModule.initialize(initer.get_module_id(2), &motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  86. initer.register_module(&stepMotorCtrlModule);
  87. }
  88. /**
  89. * @brief
  90. */
  91. {
  92. static TMC5130 motor;
  93. static StepMotorCtrlModule stepMotorCtrlModule;
  94. TMC5130::cfg_t cfg = {
  95. .spi = &TMC_MOTOR_SPI, //
  96. .csgpio = MOTOR3_CSN, //
  97. .ennPin = MOTOR3_ENN, //
  98. .spi_mode_select = MOTOR3_SPI_MODE_SELECT, //
  99. };
  100. motor.initialize(&cfg);
  101. motor.setMotorShaft(false);
  102. ZLOGI(TAG, "motor3 initialize 5160:%x ", motor.readICVersion());
  103. static ZGPIO input[2];
  104. input[0].initAsInput(MOTOR3_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  105. input[1].initAsInput(MOTOR3_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  106. I_StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  107. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  108. smcm_cfg.base_param.distance_scale = 100;
  109. smcm_cfg.base_param.distance_scale_denominator = 1;
  110. smcm_cfg.base_param.irun = 24;
  111. smcm_cfg.base_param.ihold = 1;
  112. smcm_cfg.base_param.x_shaft = true;
  113. smcm_cfg.base_param.maxspeed = 50;
  114. smcm_cfg.base_param.run_to_zero_speed = 50;
  115. stepMotorCtrlModule.initialize(initer.get_module_id(3), &motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  116. initer.register_module(&stepMotorCtrlModule);
  117. }
  118. #if 0
  119. {
  120. static M3078CodeScanner codescanner;
  121. static M3078CodeScanner::hardware_config_t cfg = {
  122. .uart = &huart3,
  123. .hdma_rx = nullptr,
  124. .hdma_tx = nullptr,
  125. .codeReadOkPin = PinNull,
  126. .rstPin = PinNull,
  127. .triggerPin = PE15,
  128. };
  129. codescanner.initialize(BOARD_ID * 10 + 4, &cfg);
  130. g_ziProtocolParser.registerModule(&codescanner);
  131. }
  132. #endif
  133. }
  134. /*******************************************************************************
  135. * MAIN *
  136. *******************************************************************************/
  137. void umain() {
  138. ZCancmderSubboardIniter::cfg_t cfg = //
  139. {
  140. .deviceId = getDeviceId(),
  141. .input_gpio =
  142. {
  143. {.pin = PD0, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  144. {.pin = PD1, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  145. {.pin = PD2, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  146. {.pin = PD3, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  147. {.pin = PD4, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true},
  148. },
  149. .output_gpio = {},
  150. };
  151. initer.init(&cfg);
  152. initsubmodule();
  153. initer.loop();
  154. }