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.

128 lines
5.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
  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\tmc\ic\ztmc4361A.hpp"
  12. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  13. #include "sdk\components\step_motor_ctrl_module\tmc51x0_motor.hpp"
  14. #define TAG "main"
  15. using namespace iflytop;
  16. using namespace std;
  17. static ZCancmderSubboardIniter initer;
  18. extern void umain();
  19. extern "C" {
  20. void StartDefaultTask(void const* argument) { umain(); }
  21. extern DMA_HandleTypeDef hdma_usart3_rx;
  22. extern DMA_HandleTypeDef hdma_usart3_tx;
  23. }
  24. /*******************************************************************************
  25. * GET_DEVICE_ID *
  26. *******************************************************************************/
  27. static int32_t getDeviceId() {
  28. static bool init = false;
  29. static ZGPIO ID0;
  30. static ZGPIO ID1;
  31. static ZGPIO ID2;
  32. static ZGPIO ID3;
  33. static ZGPIO ID4;
  34. if (!init) {
  35. ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  36. ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  37. ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  38. ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  39. ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  40. init = true;
  41. }
  42. uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
  43. return id;
  44. }
  45. /*******************************************************************************
  46. * INIT_SUBMODULE *
  47. *******************************************************************************/
  48. void nvs_init_cb() {}
  49. static void initsubmodule() {
  50. osDelay(1000);
  51. {
  52. static TMC5130 g_motor;
  53. static TMC51X0Motor g_stepMotorCtrlModule;
  54. TMC5130::cfg_t cfg = {
  55. .spi = &TMC_MOTOR_SPI, //
  56. .csgpio = MOTOR0_CSN, //
  57. .ennPin = MOTOR0_ENN, //
  58. .spi_mode_select = MOTOR0_SPI_MODE_SELECT, //
  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. TMC51X0Motor::flash_config_t smcm_cfg = {0};
  68. TMC51X0Motor::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. // 115200
  90. /*******************************************************************************
  91. * Թñж *
  92. *******************************************************************************/
  93. static FeiTeServoMotor feiteservomotor_bus; // ���ض�������
  94. static MiniRobotCtrlModule mini_servo;
  95. // ���ض�������
  96. ZASSERT(huart3.Init.BaudRate == 115200);
  97. feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  98. static MiniRobotCtrlModule::flash_config_t cfg = {0};
  99. cfg.default_torque = 330;
  100. mini_servo.initialize(initer.get_module_id(2), &feiteservomotor_bus, 1, &cfg);
  101. initer.register_module(&mini_servo);
  102. }
  103. }
  104. /*******************************************************************************
  105. * MAIN *
  106. *******************************************************************************/
  107. void umain() {
  108. ZCancmderSubboardIniter::cfg_t cfg = //
  109. {
  110. .deviceId = getDeviceId(),
  111. .input_gpio = {},
  112. .output_gpio = {},
  113. };
  114. initer.init(&cfg);
  115. initsubmodule();
  116. initer.loop();
  117. }