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.

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