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.

144 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
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 "main.hpp"
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "main.h"
  5. #include "project.hpp"
  6. //
  7. #include "sdk/hal/zhal.hpp"
  8. #include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
  9. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  10. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  11. #define TAG "main"
  12. namespace iflytop {
  13. Main gmain;
  14. };
  15. using namespace iflytop;
  16. IflytopCanProtocolStackProcesser m_protocolStack;
  17. TMC5130 m_tj_motor;
  18. TMC5130 m_py_motor;
  19. // ZGPIO arm_sensor1_gpio;
  20. // ZGPIO arm_sensor2_gpio;
  21. // ZGPIO arm_sensor3_gpio;
  22. // ZGPIO arm_sensor4_gpio;
  23. // ZGPIO arm_sensor5_gpio;
  24. // ZGPIO arm_sensor6_gpio;
  25. // ZGPIO arm_sensor7_gpio;
  26. // ZGPIO arm_sensor8_gpio;
  27. ZGPIO debuglight;
  28. ZGPIO tmc_motor1_spi_select1_io;
  29. ZGPIO tmc_motor1_nfreeze_io;
  30. ZGPIO tmc_motor1_nreset_io;
  31. ZGPIO tmc_motor1_sub_ic_enn_io;
  32. ZGPIO tmc_motor2_spi_select1_io;
  33. ZGPIO tmc_motor2_nfreeze_io;
  34. ZGPIO tmc_motor2_nreset_io;
  35. ZGPIO tmc_motor2_sub_ic_enn_io;
  36. void input_sensors_init() {
  37. // arm_sensor1_gpio.initAsInput(ARM_SENSOR1_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true);
  38. // arm_sensor2_gpio.initAsInput(ARM_SENSOR2_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true);
  39. // arm_sensor3_gpio.initAsInput(ARM_SENSOR3_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  40. // arm_sensor4_gpio.initAsInput(ARM_SENSOR4_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  41. // arm_sensor5_gpio.initAsInput(ARM_SENSOR5_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  42. // arm_sensor6_gpio.initAsInput(ARM_SENSOR6_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false);
  43. // arm_sensor7_gpio.initAsInput(ARM_SENSOR7_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true);
  44. // arm_sensor8_gpio.initAsInput(ARM_SENSOR8_GPIO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true);
  45. }
  46. uint32_t intput_sensors_get_table0() {
  47. uint32_t val = 0;
  48. // val |= arm_sensor1_gpio.getStateUint32() << 1;
  49. // val |= arm_sensor2_gpio.getStateUint32() << 2;
  50. // val |= arm_sensor3_gpio.getStateUint32() << 3;
  51. // val |= arm_sensor4_gpio.getStateUint32() << 4;
  52. // val |= arm_sensor5_gpio.getStateUint32() << 5;
  53. // val |= arm_sensor6_gpio.getStateUint32() << 6;
  54. // val |= arm_sensor7_gpio.getStateUint32() << 7;
  55. // val |= arm_sensor8_gpio.getStateUint32() << 8;
  56. return val;
  57. }
  58. icps::error_t Main::onHostRegisterWriteEvent(IflytopCanProtocolStackProcesser *processer, icps::WriteEvent *event) { return icps::kSuccess; }
  59. icps::error_t Main::onHostRegisterReadEvent(IflytopCanProtocolStackProcesser *processer, icps::ReadEvent *event) { return icps::kSuccess; }
  60. void Main::onHostRegisterReportEvent(IflytopCanProtocolStackProcesser *processer, icps::ReportEvent *event) {}
  61. void Main::run() {
  62. ZHALCORE::cfg_t oscfg = {
  63. .delayhtim = &DELAY_US_TIMER,
  64. .debuguart = &DEBUG_UART,
  65. };
  66. ZHALCORE::getInstance()->initialize(oscfg);
  67. ZLOGI(TAG, "zapp:%s", VERSION);
  68. printf("int32_t %d int %d longint %d\n", sizeof(int32_t), sizeof(int), sizeof(long int));
  69. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  70. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  71. /*******************************************************************************
  72. * GPIO输入初始化 *
  73. *******************************************************************************/
  74. input_sensors_init();
  75. intput_sensors_get_table0();
  76. /*******************************************************************************
  77. * *
  78. *******************************************************************************/
  79. {
  80. TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR0_ENN, .csn_pin = MOTOR0_CSN};
  81. m_py_motor.initialize(&cfg);
  82. int32_t chipv = m_py_motor.readChipVERSION();
  83. ZLOGI(TAG, "m_py_motor:%lx", chipv);
  84. }
  85. {
  86. TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR1_ENN, .csn_pin = MOTOR1_CSN};
  87. m_tj_motor.initialize(&cfg);
  88. int32_t chipv = m_tj_motor.readChipVERSION();
  89. ZLOGI(TAG, "m_tj_motor:%lx", chipv);
  90. }
  91. /*******************************************************************************
  92. * *
  93. *******************************************************************************/
  94. {
  95. // static ZUART uart;
  96. // PB6.initAsOutput(STM32_GPIO::kOutput_nopull, true, false);
  97. // ZUART::cfg_t cfg = {
  98. // .name = "CODE_SCANER_UART",
  99. // .huart = &CODE_SCANER_UART,
  100. // .rxbuffersize = 300,
  101. // .rxovertime_ms = 10,
  102. // };
  103. // uart.initialize(&cfg,[](){})
  104. // uart.initialize_basic("CODE_SCANER_UART", &m_hardware, &CODE_SCANER_UART);
  105. // uart.initialize_setRxBuffer(300);
  106. // uart.initialize_setRxOvertime(33);
  107. // uart.initialize_finished();
  108. }
  109. /*******************************************************************************
  110. * *
  111. *******************************************************************************/
  112. {
  113. auto *cfg = IflytopCanProtocolStackProcesser::createDefaultConfig(DEVICE_ID, 128);
  114. m_protocolStack.initialize(cfg);
  115. m_protocolStack.setDumpPacketFlag(false);
  116. m_protocolStack.registerListener(this);
  117. m_protocolStack.activeReg(REG_GPIO_INPUT0, icps::kwr, 0);
  118. }
  119. while (1) {
  120. ZHALCORE::getInstance()->loop();
  121. }
  122. }