正点原子开发板 alientek_develop_board cancmder
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.

145 lines
4.1 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
  1. #include "main.hpp"
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. //
  5. #include "sdk/os/zos.hpp"
  6. #include "sdk\components\cmdscheduler\cmd_scheduler.hpp"
  7. #include "sdk\components\step_motor_45\step_motor_45.hpp"
  8. #include "sdk\components\step_motor_45\step_motor_45_scheduler.hpp"
  9. #define TAG "main"
  10. namespace iflytop {
  11. Main gmain;
  12. };
  13. using namespace iflytop;
  14. using namespace std;
  15. extern "C" {
  16. void StartDefaultTask(void const* argument) { umain(); }
  17. }
  18. /*******************************************************************************
  19. * *
  20. *******************************************************************************/
  21. static chip_cfg_t chipcfg = {
  22. .us_dleay_tim = &DELAY_US_TIMER,
  23. .tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER,
  24. .huart = &DEBUG_UART,
  25. .debuglight = DEBUG_LIGHT_GPIO,
  26. };
  27. static StepMotor45::cfg_t cfg1 = {
  28. .max_pos = -1,
  29. .enable_zero_limit = false,
  30. .enable_max_pos_limit = false,
  31. .mirror = false,
  32. .zeroPin = PinNull,
  33. .zeroPinMirror = false,
  34. .driverPin = {PB15, PD11, PD12, PD13},
  35. .driverPinMirror = false,
  36. };
  37. static StepMotor45::cfg_t cfg2 = {
  38. .max_pos = -1,
  39. .enable_zero_limit = false,
  40. .enable_max_pos_limit = false,
  41. .mirror = false,
  42. .zeroPin = PinNull,
  43. .zeroPinMirror = false,
  44. .driverPin = {PG2, PG3, PG4, PG5},
  45. .driverPinMirror = false,
  46. };
  47. static StepMotor45::cfg_t cfg3 = {
  48. .max_pos = -1,
  49. .enable_zero_limit = false,
  50. .enable_max_pos_limit = false,
  51. .mirror = false,
  52. .zeroPin = PinNull,
  53. .zeroPinMirror = false,
  54. .driverPin = {PG6, PG7, PG8, PC6},
  55. .driverPinMirror = false,
  56. };
  57. static StepMotor45::cfg_t cfg4 = {
  58. .max_pos = -1,
  59. .enable_zero_limit = false,
  60. .enable_max_pos_limit = false,
  61. .mirror = false,
  62. .zeroPin = PinNull,
  63. .zeroPinMirror = false,
  64. .driverPin = {PC7, PC8, PC9, PA8},
  65. .driverPinMirror = false,
  66. };
  67. static StepMotor45::cfg_t cfg5 = {
  68. .max_pos = -1,
  69. .enable_zero_limit = false,
  70. .enable_max_pos_limit = false,
  71. .mirror = false,
  72. .zeroPin = PinNull,
  73. .zeroPinMirror = false,
  74. .driverPin = {PA13, PA14, PA15, PC10},
  75. .driverPinMirror = false,
  76. };
  77. /*******************************************************************************
  78. * *
  79. *******************************************************************************/
  80. static StepMotor45 g_step_motor45_1;
  81. static StepMotor45 g_step_motor45_2;
  82. static StepMotor45 g_step_motor45_3;
  83. static StepMotor45 g_step_motor45_4;
  84. static StepMotor45 g_step_motor45_5;
  85. void Main::run() {
  86. /*******************************************************************************
  87. * ϵͳʼ *
  88. *******************************************************************************/
  89. chip_init(&chipcfg);
  90. zos_cfg_t zoscfg;
  91. zos_init(&zoscfg);
  92. g_step_motor45_1.initialize(cfg1);
  93. g_step_motor45_2.initialize(cfg2);
  94. g_step_motor45_3.initialize(cfg3);
  95. g_step_motor45_4.initialize(cfg4);
  96. g_step_motor45_5.initialize(cfg5);
  97. StepMotor45Scheduler step_motor45_scheduler;
  98. step_motor45_scheduler.initialize(&htim10, 1000);
  99. step_motor45_scheduler.addMotor(&g_step_motor45_1);
  100. step_motor45_scheduler.addMotor(&g_step_motor45_2);
  101. step_motor45_scheduler.addMotor(&g_step_motor45_3);
  102. step_motor45_scheduler.addMotor(&g_step_motor45_4);
  103. step_motor45_scheduler.addMotor(&g_step_motor45_5);
  104. // g_step_motor45_1.rotate(true, 1000);
  105. step_motor45_scheduler.start();
  106. CmdScheduler cmdScheduler;
  107. cmdScheduler.initialize(&DEBUG_UART, 1000);
  108. cmdScheduler.registerCmd("help", //
  109. [this](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { ZLOGI(TAG, "do_help"); });
  110. while (true) {
  111. OSDefaultSchduler::getInstance()->loop();
  112. cmdScheduler.schedule();
  113. osDelay(1);
  114. }
  115. }