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.

155 lines
5.6 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 "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. //
  16. #include "driver.hpp"
  17. #include "sdk\components\sensors\tmp117\tmp117.hpp"
  18. #include "sdk\components\ti\drv8710.hpp"
  19. #include "sdk\components\water_cooling_temperature_control_module\pwm_ctrl_module.hpp"
  20. #include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module.hpp"
  21. #include "sdk\components\zcancmder_module\zcan_fan_ctrl_module.hpp"
  22. #define TAG "main"
  23. using namespace iflytop;
  24. using namespace std;
  25. static ZCancmderSubboardIniter initer;
  26. extern void umain();
  27. extern "C" {
  28. void StartDefaultTask(void const* argument) { umain(); }
  29. }
  30. /*******************************************************************************
  31. * GET_DEVICE_ID *
  32. *******************************************************************************/
  33. static int32_t getDeviceId() {
  34. static bool init = false;
  35. static ZGPIO ID0;
  36. static ZGPIO ID1;
  37. static ZGPIO ID2;
  38. static ZGPIO ID3;
  39. if (!init) {
  40. ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  41. ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  42. ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  43. ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  44. init = true;
  45. }
  46. // uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
  47. if (ID0.getState() == 0) {
  48. return 4;
  49. } else {
  50. return 5;
  51. }
  52. }
  53. static int32_t getPeltierNum() {
  54. static bool init = false;
  55. static ZGPIO ID4;
  56. if (!init) {
  57. ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  58. init = true;
  59. }
  60. if (ID4.getState() == 0) {
  61. return 1;
  62. } else {
  63. return 2;
  64. }
  65. }
  66. static bool m_onefan = false;
  67. /*******************************************************************************
  68. * INIT_SUBMODULE *
  69. *******************************************************************************/
  70. void nvs_init_cb() {}
  71. // ZIPWMFanCtrlModule* fan_ctrl;
  72. // ZIDcMotorCtrlModule* pelter_ctrl;
  73. // ZIPWMPumpCtrlModule* pump_ctrl;
  74. static void initsubmodule() {
  75. #define TIMER1_FREQ 1000
  76. #define HEART_SHAFT false
  77. {
  78. static TMP117 temp[4];
  79. static FanCtrlModule fan;
  80. static PumpCtrlModule pump;
  81. static PeltierCtrlModule peltier;
  82. temp[0].initializate(&hi2c1, TMP117::ID0);
  83. temp[1].initializate(&hi2c1, TMP117::ID1);
  84. temp[2].initializate(&hi2c1, TMP117::ID2);
  85. temp[3].initializate(&hi2c1, TMP117::ID3);
  86. if (getPeltierNum() == 1) {
  87. fan.initialize(FanCtrlModule::kfan0);
  88. peltier.initialize(PeltierCtrlModule::kpeltier0);
  89. } else {
  90. fan.initialize(FanCtrlModule::kfan0and1);
  91. peltier.initialize(PeltierCtrlModule::kpeltier0and1);
  92. }
  93. pump.initialize();
  94. /*******************************************************************************
  95. * ģʼ *
  96. *******************************************************************************/
  97. static WaterCoolingTemperatureControlModule waterCoolingTemperatureControlModule;
  98. static WaterCoolingTemperatureControlModule::config_t temp_ctrl_config;
  99. waterCoolingTemperatureControlModule.createDefaultConfig(&temp_ctrl_config);
  100. WaterCoolingTemperatureControlModule::hardwared_config_t hardwared_config = //
  101. {
  102. .temperature_sensor = {&temp[0], &temp[1], &temp[2], &temp[3]},
  103. .temp_fb_index = 1,
  104. .fan_ctrl = &fan,
  105. .pelter_ctrl = &peltier,
  106. .pump_ctrl = &pump,
  107. };
  108. waterCoolingTemperatureControlModule.initialize(initer.get_module_id(1), &temp_ctrl_config, &hardwared_config);
  109. initer.register_module(&waterCoolingTemperatureControlModule);
  110. }
  111. if (getPeltierNum() == 1) {
  112. static FanCtrlModule fan;
  113. static ZcanFanCtrlModule fan_ctrl_module;
  114. fan.initialize(FanCtrlModule::kfan1);
  115. fan_ctrl_module.initialize(initer.get_module_id(2), &fan, 50);
  116. initer.register_module(&fan_ctrl_module);
  117. }
  118. }
  119. /*******************************************************************************
  120. * MAIN *
  121. *******************************************************************************/
  122. void umain() {
  123. ZCancmderSubboardIniter::cfg_t cfg = //
  124. {
  125. .deviceId = getDeviceId(),
  126. .input_gpio =
  127. {
  128. {PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  129. {PC7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  130. },
  131. .output_gpio =
  132. {
  133. {PD0, ZGPIO::kMode_nopull, false, false},
  134. },
  135. };
  136. initer.init(&cfg);
  137. initsubmodule();
  138. initer.loop();
  139. }