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.

125 lines
5.5 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
  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\pipette_module\pipette_ctrl_module_v2.hpp"
  12. #include "sdk\components\sensors\m3078\m3078_code_scaner.hpp"
  13. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  14. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  15. #define TAG "main"
  16. using namespace iflytop;
  17. using namespace std;
  18. static ZCancmderSubboardIniter initer;
  19. extern void umain();
  20. extern "C" {
  21. void StartDefaultTask(void const* argument) { umain(); }
  22. }
  23. /*******************************************************************************
  24. * GET_DEVICE_ID *
  25. *******************************************************************************/
  26. static int32_t getDeviceId() { return BOARD_ID; }
  27. /*******************************************************************************
  28. * INIT_SUBMODULE *
  29. *******************************************************************************/
  30. void nvs_init_cb() {}
  31. static void initsubmodule() {
  32. osDelay(1000);
  33. {
  34. static TMC5130 g_motor;
  35. static StepMotorCtrlModule g_stepMotorCtrlModule;
  36. TMC5130::cfg_t cfg = {
  37. .spi = &TMC_MOTOR_SPI, //
  38. .csgpio = MOTOR0_CSN, //
  39. .ennPin = MOTOR0_ENN, //
  40. .spi_mode_select = MOTOR0_SPI_MODE_SELECT, //
  41. };
  42. g_motor.initialize(&cfg);
  43. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  44. g_motor.setMotorShaft(false);
  45. g_motor.setAcceleration(100);
  46. g_motor.setDeceleration(100);
  47. g_motor.setIHOLD_IRUN(0, 8, 10);
  48. static ZGPIO input[10];
  49. input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  50. input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  51. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  52. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  53. smcm_cfg.base_param.motor_one_circle_pulse = 100;
  54. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  55. smcm_cfg.base_param.stepmotor_ihold = 1;
  56. smcm_cfg.base_param.stepmotor_irun = 8;
  57. smcm_cfg.base_param.motor_shaft = false;
  58. smcm_cfg.base_param.motor_default_velocity = 200;
  59. smcm_cfg.base_param.motor_run_to_zero_speed = 100;
  60. smcm_cfg.base_param.max_d = 0;
  61. smcm_cfg.base_param.min_d = 0;
  62. g_stepMotorCtrlModule.initialize(initer.get_module_id(1), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  63. initer.register_module(&g_stepMotorCtrlModule);
  64. }
  65. {
  66. static TMC5130 g_motor;
  67. static StepMotorCtrlModule g_stepMotorCtrlModule;
  68. TMC5130::cfg_t cfg = {
  69. .spi = &TMC_MOTOR_SPI, //
  70. .csgpio = MOTOR1_CSN, //
  71. .ennPin = MOTOR1_ENN, //
  72. .spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
  73. };
  74. g_motor.initialize(&cfg);
  75. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  76. g_motor.setMotorShaft(false);
  77. g_motor.setAcceleration(100);
  78. g_motor.setDeceleration(100);
  79. g_motor.setIHOLD_IRUN(0, 8, 10);
  80. static ZGPIO input[10];
  81. input[0].initAsInput(MOTOR1_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  82. input[1].initAsInput(MOTOR1_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  83. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  84. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  85. smcm_cfg.base_param.motor_one_circle_pulse = 100;
  86. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  87. smcm_cfg.base_param.stepmotor_ihold = 1;
  88. smcm_cfg.base_param.stepmotor_irun = 20;
  89. smcm_cfg.base_param.motor_shaft = false;
  90. smcm_cfg.base_param.motor_default_velocity = 100;
  91. smcm_cfg.base_param.motor_run_to_zero_speed = 50;
  92. smcm_cfg.base_param.max_d = 0;
  93. smcm_cfg.base_param.min_d = 0;
  94. g_stepMotorCtrlModule.initialize(initer.get_module_id(2), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  95. initer.register_module(&g_stepMotorCtrlModule);
  96. }
  97. }
  98. /*******************************************************************************
  99. * MAIN *
  100. *******************************************************************************/
  101. void umain() {
  102. ZCancmderSubboardIniter::cfg_t cfg = //
  103. {
  104. .deviceId = getDeviceId(),
  105. .input_gpio = {},
  106. .output_gpio = {},
  107. };
  108. initer.init(&cfg);
  109. initsubmodule();
  110. initer.loop();
  111. }