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.

203 lines
7.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
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 "sdk/os/zos.hpp"
  4. #include "sdk\components\flash\zsimple_flash.hpp"
  5. #include "sdk\components\zcancmder\zcanreceiver.hpp"
  6. #include "sdk\components\zcancmder_module\zcan_basic_order_module.hpp"
  7. #include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp"
  8. //
  9. #include "sdk\components\flash\znvs.hpp"
  10. //
  11. #include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
  12. #include "sdk\components\mini_servo_motor\mini_servo_motor_ctrl_module.hpp"
  13. #include "sdk\components\pipette_module\pipette_ctrl_module_v2.hpp"
  14. #include "sdk\components\sensors\m3078\m3078_code_scaner.hpp"
  15. #include "sdk\components\sensors\tmp117\tmp117.hpp"
  16. #include "sdk\components\ti\drv8710.hpp"
  17. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  18. #include "sdk\components\water_cooling_temperature_control_module\pwm_ctrl_module.hpp"
  19. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module.hpp"
  20. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.cpp"
  21. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.hpp"
  22. #include "sdk\components\zcancmder\zcan_board_module.hpp"
  23. // #include "M3078CodeScanner"
  24. #define TAG "main"
  25. using namespace iflytop;
  26. using namespace std;
  27. extern void umain();
  28. extern "C" {
  29. void StartDefaultTask(void const* argument) { umain(); }
  30. }
  31. extern "C" {
  32. extern DMA_HandleTypeDef hdma_usart2_rx;
  33. extern DMA_HandleTypeDef hdma_usart2_tx;
  34. }
  35. static ZCanCmder g_zcanCmder;
  36. static ZIProtocolParser g_ziProtocolParser;
  37. //
  38. static TMC5130 g_motor[3];
  39. //
  40. static PipetteModule g_pipetteModule;
  41. // USART4_TX
  42. void initmodule() {
  43. osDelay(1000);
  44. {
  45. static ZCanBoardModule::hardware_config_t cfg = {
  46. .input =
  47. {
  48. {PD0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  49. {PD1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  50. {PD2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  51. {PD3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  52. {PD4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  53. {PD5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  54. {PD6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  55. {PD7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  56. {PD8, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false},
  57. },
  58. };
  59. static ZCanBoardModule boardmodule;
  60. boardmodule.initialize(BOARD_ID * 10 + 0, &cfg);
  61. g_ziProtocolParser.registerModule(&boardmodule);
  62. }
  63. {
  64. static TMC5130 motor;
  65. static StepMotorCtrlModule stepMotorCtrlModule;
  66. TMC5130::cfg_t cfg = {
  67. .spi = &TMC_MOTOR_SPI, //
  68. .csgpio = MOTOR0_CSN, //
  69. .ennPin = MOTOR0_ENN, //
  70. .spi_mode_select = MOTOR0_SPI_MODE_SELECT, //
  71. };
  72. motor.initialize(&cfg);
  73. motor.setMotorShaft(false);
  74. ZLOGI(TAG, "motora initialize 5160:%x ", motor.readICVersion());
  75. static ZGPIO input[2];
  76. input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  77. input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  78. stepMotorCtrlModule.initialize(BOARD_ID * 10 + 1, &motor, input, ZARRAY_SIZE(input), nullptr);
  79. g_ziProtocolParser.registerModule(&stepMotorCtrlModule);
  80. }
  81. {
  82. static TMC5130 motor;
  83. static StepMotorCtrlModule stepMotorCtrlModule;
  84. TMC5130::cfg_t cfg = {
  85. .spi = &TMC_MOTOR_SPI, //
  86. .csgpio = MOTOR1_CSN, //
  87. .ennPin = MOTOR1_ENN, //
  88. .spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
  89. };
  90. motor.initialize(&cfg);
  91. motor.setMotorShaft(false);
  92. ZLOGI(TAG, "motora initialize 5160:%x ", motor.readICVersion());
  93. static ZGPIO input[2];
  94. input[0].initAsInput(MOTOR1_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  95. input[1].initAsInput(MOTOR1_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  96. stepMotorCtrlModule.initialize(BOARD_ID * 10 + 2, &motor, input, ZARRAY_SIZE(input), nullptr);
  97. g_ziProtocolParser.registerModule(&stepMotorCtrlModule);
  98. }
  99. {
  100. static TMC5130 motor;
  101. static StepMotorCtrlModule stepMotorCtrlModule;
  102. TMC5130::cfg_t cfg = {
  103. .spi = &TMC_MOTOR_SPI, //
  104. .csgpio = MOTOR2_CSN, //
  105. .ennPin = MOTOR2_ENN, //
  106. .spi_mode_select = MOTOR2_SPI_MODE_SELECT, //
  107. };
  108. motor.initialize(&cfg);
  109. motor.setMotorShaft(false);
  110. ZLOGI(TAG, "motora initialize 5160:%x ", motor.readICVersion());
  111. static ZGPIO input[2];
  112. input[0].initAsInput(MOTOR2_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  113. input[1].initAsInput(MOTOR2_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  114. stepMotorCtrlModule.initialize(BOARD_ID * 10 + 3, &motor, input, ZARRAY_SIZE(input), nullptr);
  115. g_ziProtocolParser.registerModule(&stepMotorCtrlModule);
  116. }
  117. {
  118. static M3078CodeScanner codescanner;
  119. static M3078CodeScanner::hardware_config_t cfg = {
  120. .uart = &huart3,
  121. .hdma_rx = nullptr,
  122. .hdma_tx = nullptr,
  123. .codeReadOkPin = PinNull,
  124. .rstPin = PinNull,
  125. .triggerPin = PE15,
  126. };
  127. codescanner.initialize(BOARD_ID * 10 + 4, &cfg);
  128. g_ziProtocolParser.registerModule(&codescanner);
  129. }
  130. {
  131. // 115200
  132. static FeiTeServoMotor feiteservomotor_bus; // ���ض�������
  133. static MiniRobotCtrlModule mini_servo[4];
  134. ZASSERT(huart2.Init.BaudRate == 115200); // ���ض�������
  135. feiteservomotor_bus.initialize(&huart2, &hdma_usart2_rx, &hdma_usart2_tx); // ���ض�������
  136. mini_servo[0].initialize(BOARD_ID * 10 + 5, &feiteservomotor_bus, 1);
  137. mini_servo[1].initialize(BOARD_ID * 10 + 6, &feiteservomotor_bus, 2);
  138. mini_servo[2].initialize(BOARD_ID * 10 + 7, &feiteservomotor_bus, 3);
  139. mini_servo[3].initialize(BOARD_ID * 10 + 8, &feiteservomotor_bus, 4);
  140. g_ziProtocolParser.registerModule(&mini_servo[0]);
  141. g_ziProtocolParser.registerModule(&mini_servo[1]);
  142. g_ziProtocolParser.registerModule(&mini_servo[2]);
  143. g_ziProtocolParser.registerModule(&mini_servo[3]);
  144. }
  145. }
  146. void umain() {
  147. chip_cfg_t chipcfg;
  148. chipcfg.us_dleay_tim = &DELAY_US_TIMER;
  149. chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
  150. chipcfg.huart = &DEBUG_UART;
  151. chipcfg.debuglight = DEBUG_LIGHT_GPIO;
  152. chip_init(&chipcfg);
  153. zos_cfg_t zoscfg;
  154. zos_init(&zoscfg);
  155. ZLOGI(TAG, "boardId:%d", BOARD_ID);
  156. /*******************************************************************************
  157. * NVSINIT *
  158. *******************************************************************************/
  159. ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR);
  160. {
  161. static I_StepMotorCtrlModule::flash_config_t cfg;
  162. StepMotorCtrlModule::create_default_cfg(cfg);
  163. ZNVS::ins().alloc_config(MOTOR_CFG_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg));
  164. }
  165. ZNVS::ins().init_config();
  166. auto zcanCmder_cfg = g_zcanCmder.createCFG(BOARD_ID);
  167. g_zcanCmder.init(zcanCmder_cfg);
  168. g_ziProtocolParser.initialize(&g_zcanCmder);
  169. initmodule();
  170. while (true) {
  171. OSDefaultSchduler::getInstance()->loop();
  172. g_zcanCmder.loop();
  173. }
  174. };