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.

121 lines
4.7 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
  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 = MOTOR1_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(PD1 /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  50. input[1].initAsInput(PD2 /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  51. input[2].initAsInput(PD3 /*DIAG0*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  52. input[3].initAsInput(PD4 /*DIAG1*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  53. I_StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  54. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  55. smcm_cfg.base_param.distance_scale = 100;
  56. smcm_cfg.base_param.distance_scale_denominator = 1;
  57. smcm_cfg.base_param.ihold = 1;
  58. smcm_cfg.base_param.irun = 8;
  59. smcm_cfg.base_param.x_shaft = true;
  60. smcm_cfg.base_param.maxspeed = 300;
  61. smcm_cfg.base_param.run_to_zero_speed = 50;
  62. smcm_cfg.base_param.max_x = 0;
  63. smcm_cfg.base_param.min_x = 0;
  64. g_stepMotorCtrlModule.initialize(initer.get_module_id(1), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  65. initer.register_module(&g_stepMotorCtrlModule);
  66. }
  67. {
  68. static PipetteModule g_pipetteModule;
  69. PipetteModule::config_t cfg = {
  70. .limit_ul = 100,
  71. };
  72. PipetteModule::hardward_config_t hardwarecfg = {
  73. .uart = &huart2,
  74. .hdma_rx = &hdma_usart2_rx,
  75. .hdma_tx = &hdma_usart2_tx,
  76. };
  77. g_pipetteModule.initialize(initer.get_module_id(2), &cfg, &hardwarecfg);
  78. initer.register_module(&g_pipetteModule);
  79. }
  80. {
  81. //
  82. static M3078CodeScanner codescanner;
  83. static M3078CodeScanner::hardware_config_t cfg = {
  84. .uart = &huart2,
  85. .hdma_rx = nullptr,
  86. .hdma_tx = nullptr,
  87. .codeReadOkPin = PinNull,
  88. .rstPin = PinNull,
  89. .triggerPin = PD15,
  90. };
  91. codescanner.initialize(initer.get_module_id(3), &cfg);
  92. initer.register_module(&codescanner);
  93. }
  94. }
  95. /*******************************************************************************
  96. * MAIN *
  97. *******************************************************************************/
  98. void umain() {
  99. ZCancmderSubboardIniter::cfg_t cfg = //
  100. {
  101. .deviceId = getDeviceId(),
  102. .input_gpio = {},
  103. .output_gpio = {},
  104. };
  105. initer.init(&cfg);
  106. initsubmodule();
  107. initer.loop();
  108. }