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.

387 lines
18 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
  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. extern DMA_HandleTypeDef hdma_usart3_rx;
  23. extern DMA_HandleTypeDef hdma_usart3_tx;
  24. }
  25. /*******************************************************************************
  26. * GET_DEVICE_ID *
  27. *******************************************************************************/
  28. static int32_t getDeviceId() {
  29. static bool init = false;
  30. static ZGPIO ID0;
  31. static ZGPIO ID1;
  32. static ZGPIO ID2;
  33. static ZGPIO ID3;
  34. static ZGPIO ID4;
  35. if (!init) {
  36. ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  37. ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  38. ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  39. ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  40. ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  41. init = true;
  42. }
  43. uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
  44. return id;
  45. }
  46. /*******************************************************************************
  47. * INIT_SUBMODULE *
  48. *******************************************************************************/
  49. void nvs_init_cb() {}
  50. static void initsubmodule() {
  51. osDelay(1000);
  52. {
  53. static TMC5130 g_motor;
  54. static StepMotorCtrlModule g_stepMotorCtrlModule;
  55. TMC5130::cfg_t cfg = {
  56. .spi = &TMC_MOTOR_SPI, //
  57. .csgpio = MOTO1_CSN, //
  58. .ennPin = MOTO1_DRV_ENN, //
  59. };
  60. g_motor.initialize(&cfg);
  61. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  62. g_motor.enable(true);
  63. g_motor.setMotorShaft(false);
  64. static ZGPIO input[10];
  65. // input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  66. // input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  67. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  68. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  69. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  70. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  71. smcm_cfg.base_param.stepmotor_ihold = 1;
  72. smcm_cfg.base_param.stepmotor_irun = 1;
  73. smcm_cfg.base_param.motor_shaft = 0;
  74. smcm_cfg.base_param.motor_default_velocity = 1;
  75. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  76. smcm_cfg.base_param.max_d = 0;
  77. smcm_cfg.base_param.min_d = 0;
  78. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  79. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  80. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  81. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  82. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  83. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  84. g_stepMotorCtrlModule.initialize(initer.get_module_id(1), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  85. g_stepMotorCtrlModule.enable(false);
  86. initer.register_module(&g_stepMotorCtrlModule);
  87. }
  88. {
  89. static TMC5130 g_motor;
  90. static StepMotorCtrlModule g_stepMotorCtrlModule;
  91. TMC5130::cfg_t cfg = {
  92. .spi = &TMC_MOTOR_SPI, //
  93. .csgpio = MOTO2_CSN, //
  94. .ennPin = MOTO2_DRV_ENN, //
  95. };
  96. g_motor.initialize(&cfg);
  97. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  98. g_motor.enable(true);
  99. g_motor.setMotorShaft(false);
  100. static ZGPIO input[10];
  101. // input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  102. // input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  103. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  104. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  105. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  106. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  107. smcm_cfg.base_param.stepmotor_ihold = 1;
  108. smcm_cfg.base_param.stepmotor_irun = 1;
  109. smcm_cfg.base_param.motor_shaft = 0;
  110. smcm_cfg.base_param.motor_default_velocity = 1;
  111. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  112. smcm_cfg.base_param.max_d = 0;
  113. smcm_cfg.base_param.min_d = 0;
  114. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  115. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  116. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  117. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  118. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  119. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  120. g_stepMotorCtrlModule.initialize(initer.get_module_id(2), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  121. g_stepMotorCtrlModule.enable(false);
  122. initer.register_module(&g_stepMotorCtrlModule);
  123. }
  124. {
  125. static TMC5130 g_motor;
  126. static StepMotorCtrlModule g_stepMotorCtrlModule;
  127. TMC5130::cfg_t cfg = {
  128. .spi = &TMC_MOTOR_SPI, //
  129. .csgpio = MOTO3_CSN, //
  130. .ennPin = MOTO3_DRV_ENN, //
  131. };
  132. g_motor.initialize(&cfg);
  133. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  134. g_motor.enable(true);
  135. g_motor.setMotorShaft(false);
  136. static ZGPIO input[10];
  137. // input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  138. // input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  139. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  140. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  141. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  142. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  143. smcm_cfg.base_param.stepmotor_ihold = 1;
  144. smcm_cfg.base_param.stepmotor_irun = 1;
  145. smcm_cfg.base_param.motor_shaft = 0;
  146. smcm_cfg.base_param.motor_default_velocity = 1;
  147. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  148. smcm_cfg.base_param.max_d = 0;
  149. smcm_cfg.base_param.min_d = 0;
  150. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  151. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  152. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  153. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  154. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  155. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  156. g_stepMotorCtrlModule.initialize(initer.get_module_id(3), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  157. g_stepMotorCtrlModule.enable(false);
  158. initer.register_module(&g_stepMotorCtrlModule);
  159. }
  160. {
  161. static TMC5130 g_motor;
  162. static StepMotorCtrlModule g_stepMotorCtrlModule;
  163. TMC5130::cfg_t cfg = {
  164. .spi = &TMC_MOTOR_SPI, //
  165. .csgpio = MOTO4_CSN, //
  166. .ennPin = MOTO4_DRV_ENN, //
  167. };
  168. g_motor.initialize(&cfg);
  169. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  170. g_motor.enable(true);
  171. g_motor.setMotorShaft(false);
  172. static ZGPIO input[10];
  173. // input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  174. // input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  175. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  176. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  177. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  178. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  179. smcm_cfg.base_param.stepmotor_ihold = 1;
  180. smcm_cfg.base_param.stepmotor_irun = 1;
  181. smcm_cfg.base_param.motor_shaft = 0;
  182. smcm_cfg.base_param.motor_default_velocity = 1;
  183. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  184. smcm_cfg.base_param.max_d = 0;
  185. smcm_cfg.base_param.min_d = 0;
  186. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  187. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  188. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  189. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  190. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  191. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  192. g_stepMotorCtrlModule.initialize(initer.get_module_id(4), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  193. g_stepMotorCtrlModule.enable(false);
  194. initer.register_module(&g_stepMotorCtrlModule);
  195. }
  196. {
  197. static TMC5130 g_motor;
  198. static StepMotorCtrlModule g_stepMotorCtrlModule;
  199. TMC5130::cfg_t cfg = {
  200. .spi = &TMC_MOTOR_SPI, //
  201. .csgpio = MOTO5_CSN, //
  202. .ennPin = MOTO5_DRV_ENN, //
  203. };
  204. g_motor.initialize(&cfg);
  205. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  206. g_motor.enable(true);
  207. g_motor.setMotorShaft(false);
  208. static ZGPIO input[10];
  209. // input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  210. // input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  211. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  212. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  213. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  214. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  215. smcm_cfg.base_param.stepmotor_ihold = 1;
  216. smcm_cfg.base_param.stepmotor_irun = 1;
  217. smcm_cfg.base_param.motor_shaft = 0;
  218. smcm_cfg.base_param.motor_default_velocity = 1;
  219. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  220. smcm_cfg.base_param.max_d = 0;
  221. smcm_cfg.base_param.min_d = 0;
  222. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  223. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  224. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  225. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  226. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  227. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  228. g_stepMotorCtrlModule.initialize(initer.get_module_id(5), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  229. g_stepMotorCtrlModule.enable(false);
  230. initer.register_module(&g_stepMotorCtrlModule);
  231. }
  232. {
  233. static TMC5130 g_motor;
  234. static StepMotorCtrlModule g_stepMotorCtrlModule;
  235. TMC5130::cfg_t cfg = {
  236. .spi = &TMC_MOTOR_SPI, //
  237. .csgpio = MOTO6_CSN, //
  238. .ennPin = MOTO6_DRV_ENN, //
  239. };
  240. g_motor.initialize(&cfg);
  241. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  242. g_motor.enable(true);
  243. g_motor.setMotorShaft(false);
  244. static ZGPIO input[10];
  245. // input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  246. // input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  247. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  248. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  249. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  250. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  251. smcm_cfg.base_param.stepmotor_ihold = 1;
  252. smcm_cfg.base_param.stepmotor_irun = 1;
  253. smcm_cfg.base_param.motor_shaft = 0;
  254. smcm_cfg.base_param.motor_default_velocity = 1;
  255. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  256. smcm_cfg.base_param.max_d = 0;
  257. smcm_cfg.base_param.min_d = 0;
  258. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  259. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  260. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  261. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  262. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  263. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  264. g_stepMotorCtrlModule.initialize(initer.get_module_id(6), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  265. g_stepMotorCtrlModule.enable(false);
  266. initer.register_module(&g_stepMotorCtrlModule);
  267. }
  268. {
  269. static TMC5130 g_motor;
  270. static StepMotorCtrlModule g_stepMotorCtrlModule;
  271. TMC5130::cfg_t cfg = {
  272. .spi = &TMC_MOTOR_SPI, //
  273. .csgpio = MOTO7_CSN, //
  274. .ennPin = MOTO7_DRV_ENN, //
  275. };
  276. g_motor.initialize(&cfg);
  277. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  278. g_motor.enable(true);
  279. g_motor.setMotorShaft(false);
  280. static ZGPIO input[10];
  281. // input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  282. // input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  283. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  284. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  285. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  286. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  287. smcm_cfg.base_param.stepmotor_ihold = 1;
  288. smcm_cfg.base_param.stepmotor_irun = 1;
  289. smcm_cfg.base_param.motor_shaft = 0;
  290. smcm_cfg.base_param.motor_default_velocity = 1;
  291. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  292. smcm_cfg.base_param.max_d = 0;
  293. smcm_cfg.base_param.min_d = 0;
  294. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  295. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  296. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  297. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  298. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  299. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  300. g_stepMotorCtrlModule.initialize(initer.get_module_id(7), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  301. g_stepMotorCtrlModule.enable(false);
  302. initer.register_module(&g_stepMotorCtrlModule);
  303. }
  304. {
  305. static TMC5130 g_motor;
  306. static StepMotorCtrlModule g_stepMotorCtrlModule;
  307. TMC5130::cfg_t cfg = {
  308. .spi = &TMC_MOTOR_SPI, //
  309. .csgpio = MOTO8_CSN, //
  310. .ennPin = MOTO8_DRV_ENN, //
  311. };
  312. g_motor.initialize(&cfg);
  313. ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion());
  314. g_motor.enable(true);
  315. g_motor.setMotorShaft(false);
  316. static ZGPIO input[10];
  317. // input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  318. // input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  319. StepMotorCtrlModule::flash_config_t smcm_cfg = {0};
  320. StepMotorCtrlModule::create_default_cfg(smcm_cfg);
  321. smcm_cfg.base_param.motor_one_circle_pulse = 1000;
  322. smcm_cfg.base_param.motor_one_circle_pulse_denominator = 1;
  323. smcm_cfg.base_param.stepmotor_ihold = 1;
  324. smcm_cfg.base_param.stepmotor_irun = 1;
  325. smcm_cfg.base_param.motor_shaft = 0;
  326. smcm_cfg.base_param.motor_default_velocity = 1;
  327. smcm_cfg.base_param.motor_run_to_zero_speed = 0;
  328. smcm_cfg.base_param.max_d = 0;
  329. smcm_cfg.base_param.min_d = 0;
  330. smcm_cfg.base_param.motor_run_to_zero_max_d = 0;
  331. smcm_cfg.base_param.motor_run_to_zero_speed = 1;
  332. smcm_cfg.base_param.motor_run_to_zero_dec = 0;
  333. smcm_cfg.base_param.motor_look_zero_edge_max_d = 0;
  334. smcm_cfg.base_param.motor_look_zero_edge_speed = 1;
  335. smcm_cfg.base_param.motor_look_zero_edge_dec = 0;
  336. g_stepMotorCtrlModule.initialize(initer.get_module_id(8), &g_motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg);
  337. g_stepMotorCtrlModule.enable(false);
  338. initer.register_module(&g_stepMotorCtrlModule);
  339. }
  340. }
  341. /*******************************************************************************
  342. * MAIN *
  343. *******************************************************************************/
  344. void umain() {
  345. ZCancmderSubboardIniter::cfg_t cfg = //
  346. {
  347. .deviceId = getDeviceId(),
  348. .input_gpio = {},
  349. .output_gpio = {},
  350. };
  351. initer.init(&cfg);
  352. initsubmodule();
  353. initer.loop();
  354. }