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.

123 lines
4.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
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
  4. #include "sdk/os/zos.hpp"
  5. #include "sdk\components\flash\zsimple_flash.hpp"
  6. #include "sdk\components\mini_servo_motor\feite_servo_motor.hpp"
  7. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  8. #include "sdk\components\xy_robot_ctrl_module\xy_robot_ctrl_module.hpp"
  9. #include "sdk\components\zcancmder\zcan_board_module.hpp"
  10. #include "sdk\components\zcancmder\zcanreceiver.hpp"
  11. #include "sdk\components\zcancmder_module\zcan_basic_order_module.hpp"
  12. #include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp"
  13. //
  14. #include "board.h"
  15. #include "sdk\components\flash\znvs.hpp"
  16. #include "sdk\components\subcanmodule\zcancmder_subboard_initer.hpp"
  17. //
  18. #define TAG "main"
  19. using namespace iflytop;
  20. using namespace std;
  21. static ZCancmderSubboardIniter initer;
  22. extern void umain();
  23. extern "C" {
  24. void StartDefaultTask(void const* argument) { umain(); }
  25. }
  26. #define FLASH_MASK_XYRobotCtrlModule1 "XYRobotCtrlModule_1"
  27. void initmodule() {}
  28. static int32_t getDeviceId() { return BOARD_ID; }
  29. void nvs_init_cb() {
  30. /**
  31. * @brief ʼãϵͳҪöҪгʼ
  32. */
  33. static I_XYRobotCtrlModule::flash_config_t cfg;
  34. XYRobotCtrlModule::create_default_cfg(cfg);
  35. ZNVS::ins().alloc_config(FLASH_MASK_XYRobotCtrlModule1, (uint8_t*)&cfg, sizeof(cfg));
  36. }
  37. static void initsubmodule() {
  38. static XYRobotCtrlModule xyRobotCtrlModule;
  39. static TMC4361A motora;
  40. static TMC4361A motorb;
  41. {
  42. TMC4361A::cfg_t cfg = {
  43. .spi = &TMC_MOTOR_SPI, //
  44. .csgpio = TMC_MOTOR1_SPI_SELECT1_IO, //
  45. .resetPin = TMC_MOTOR1_nRESET_IO, //
  46. .fREEZEPin = TMC_MOTOR1_nFREEZE_IO, //
  47. .ennPin = PinNull, //
  48. .driverIC_ennPin = TMC_MOTOR1_SUB_IC_ENN_IO, //
  49. .driverIC_resetPin = PinNull, //
  50. };
  51. motora.initialize(&cfg);
  52. motora.setMotorShaft(false);
  53. ZLOGI(TAG, "motora initialize TMC4361A:%x DriverIC:%x", motora.readICVersion(), motora.readSubICVersion());
  54. }
  55. {
  56. TMC4361A::cfg_t cfg = {
  57. .spi = &TMC_MOTOR_SPI, //
  58. .csgpio = TMC_MOTOR2_SPI_SELECT1_IO, //
  59. .resetPin = TMC_MOTOR2_nRESET_IO, //
  60. .fREEZEPin = TMC_MOTOR2_nFREEZE_IO, //
  61. .ennPin = PinNull, //
  62. .driverIC_ennPin = TMC_MOTOR2_SUB_IC_ENN_IO, //
  63. .driverIC_resetPin = PinNull, //
  64. };
  65. motorb.initialize(&cfg);
  66. motorb.setMotorShaft(false);
  67. ZLOGI(TAG, "motorb initialize TMC4361A:%x DriverIC:%x", motorb.readICVersion(), motorb.readSubICVersion());
  68. }
  69. motora.setAcceleration(300);
  70. motora.setDeceleration(300);
  71. motora.setIHOLD_IRUN(0, 4, 10);
  72. motorb.setAcceleration(300);
  73. motorb.setDeceleration(300);
  74. motorb.setIHOLD_IRUN(0, 4, 10);
  75. motora.rotate(0);
  76. motorb.rotate(0);
  77. /*******************************************************************************
  78. * zcanXYRobotCtrlModule *
  79. *******************************************************************************/
  80. ZGPIO input[8];
  81. input[0].initAsInput(ARM_SENSOR1_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  82. input[1].initAsInput(ARM_SENSOR2_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  83. input[2].initAsInput(ARM_SENSOR3_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  84. input[3].initAsInput(ARM_SENSOR4_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  85. input[4].initAsInput(ARM_SENSOR5_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  86. input[5].initAsInput(ARM_SENSOR6_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  87. input[6].initAsInput(ARM_SENSOR7_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  88. input[7].initAsInput(ARM_SENSOR8_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  89. xyRobotCtrlModule.initialize(initer.get_module_id(1), &motora, &motorb, &input[0], 8, FLASH_MASK_XYRobotCtrlModule1);
  90. xyRobotCtrlModule.dumpcfg();
  91. initer.register_module(&xyRobotCtrlModule);
  92. }
  93. void umain() {
  94. ZCancmderSubboardIniter::cfg_t cfg = //
  95. {
  96. .deviceId = getDeviceId(),
  97. .input_gpio =
  98. {
  99. // {PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
  100. },
  101. .output_gpio =
  102. {
  103. // {PD0, ZGPIO::kMode_nopull, false, false},
  104. },
  105. };
  106. initer.init(&cfg);
  107. initer.loop();
  108. }