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.

142 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
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\pipette_module\pipette_ctrl_module_v2.hpp"
  13. #include "sdk\components\sensors\m3078\m3078_code_scaner.hpp"
  14. #include "sdk\components\sensors\tmp117\tmp117.hpp"
  15. #include "sdk\components\ti\drv8710.hpp"
  16. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  17. #include "sdk\components\water_cooling_temperature_control_module\pwm_ctrl_module.hpp"
  18. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module.hpp"
  19. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.cpp"
  20. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.hpp"
  21. // #include "M3078CodeScanner"
  22. #define TAG "main"
  23. using namespace iflytop;
  24. using namespace std;
  25. extern void umain();
  26. extern "C" {
  27. void StartDefaultTask(void const* argument) { umain(); }
  28. }
  29. extern "C" {
  30. extern DMA_HandleTypeDef hdma_usart2_rx;
  31. extern DMA_HandleTypeDef hdma_usart2_tx;
  32. }
  33. static ZCanCmder g_zcanCmder;
  34. static ZIProtocolParser g_ziProtocolParser;
  35. //
  36. static TMC5130 g_motor;
  37. static StepMotorCtrlModule g_stepMotorCtrlModule;
  38. //
  39. static PipetteModule g_pipetteModule;
  40. // USART4_TX
  41. void init_and_reg_motor() {
  42. osDelay(1000);
  43. {
  44. TMC5130::cfg_t cfg = {
  45. .spi = &TMC_MOTOR_SPI, //
  46. .csgpio = MOTOR0_CSN, //
  47. .ennPin = MOTOR0_ENN, //
  48. .spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
  49. };
  50. g_motor.initialize(&cfg);
  51. g_motor.setMotorShaft(false);
  52. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  53. }
  54. g_motor.setAcceleration(100);
  55. g_motor.setDeceleration(100);
  56. g_motor.setIHOLD_IRUN(0, 8, 10);
  57. static ZGPIO input[10];
  58. input[0].initAsInput(PD1 /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  59. input[1].initAsInput(PD2 /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  60. input[2].initAsInput(PD3 /*DIAG0*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  61. input[3].initAsInput(PD4 /*DIAG1*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  62. g_stepMotorCtrlModule.initialize(BOARD_ID * 10 + 1, &g_motor, input, ZARRAY_SIZE(input), MOTOR_CFG_FLASH_MARK);
  63. g_ziProtocolParser.registerModule(&g_stepMotorCtrlModule);
  64. }
  65. void init_and_reg_cliptip_module() {
  66. // # RS232����ѹ����
  67. // /1U2!0R\r
  68. // # ������Һǹ�����г�100,��ֹ�豸��������������Һ�嵽�豸��
  69. // /1u1,100R\r
  70. PipetteModule::config_t cfg = {
  71. .limit_ul = 100,
  72. };
  73. PipetteModule::hardward_config_t hardwarecfg = {
  74. .uart = &huart2,
  75. .hdma_rx = &hdma_usart2_rx,
  76. .hdma_tx = &hdma_usart2_tx,
  77. };
  78. g_pipetteModule.initialize(BOARD_ID * 10 + 2, &cfg, &hardwarecfg);
  79. g_ziProtocolParser.registerModule(&g_pipetteModule);
  80. }
  81. void init_and_reg_m3078() { //
  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(BOARD_ID * 10 + 3, &cfg);
  92. g_ziProtocolParser.registerModule(&codescanner);
  93. }
  94. void umain() {
  95. chip_cfg_t chipcfg;
  96. chipcfg.us_dleay_tim = &DELAY_US_TIMER;
  97. chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
  98. chipcfg.huart = &DEBUG_UART;
  99. chipcfg.debuglight = DEBUG_LIGHT_GPIO;
  100. chip_init(&chipcfg);
  101. zos_cfg_t zoscfg;
  102. zos_init(&zoscfg);
  103. ZLOGI(TAG, "boardId:%d", BOARD_ID);
  104. /*******************************************************************************
  105. * NVSINIT *
  106. *******************************************************************************/
  107. ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR);
  108. {
  109. static I_StepMotorCtrlModule::flash_config_t cfg;
  110. StepMotorCtrlModule::create_default_cfg(cfg);
  111. ZNVS::ins().alloc_config(MOTOR_CFG_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg));
  112. }
  113. ZNVS::ins().init_config();
  114. auto zcanCmder_cfg = g_zcanCmder.createCFG(BOARD_ID);
  115. g_zcanCmder.init(zcanCmder_cfg);
  116. g_ziProtocolParser.initialize(&g_zcanCmder);
  117. init_and_reg_motor();
  118. init_and_reg_cliptip_module();
  119. init_and_reg_m3078();
  120. while (true) {
  121. OSDefaultSchduler::getInstance()->loop();
  122. g_zcanCmder.loop();
  123. }
  124. };