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.

207 lines
8.3 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
1 year ago
2 years ago
2 years ago
1 year 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 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year 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\modbus\modbus_client.hpp"
  12. #include "sdk\components\pipette_module\pipette_ctrl_module_v2.hpp"
  13. #include "sdk\components\sensors\m3078\m3078_code_scaner.hpp"
  14. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  15. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  16. //
  17. #include "sdk\components\hardware\uart\zuart_dma_receiver.hpp"
  18. #include "serial485_to_analog.hpp"
  19. #include "temperature_sensor.hpp"
  20. #define TAG "main"
  21. using namespace iflytop;
  22. using namespace std;
  23. static ZCancmderSubboardIniter initer;
  24. static Serial485ToAnalog serial485_to_analog;
  25. extern void umain();
  26. extern "C" {
  27. void StartDefaultTask(void const* argument) { umain(); }
  28. class UARTSender : public ZIUartSender {
  29. UART_HandleTypeDef* m_huart;
  30. public:
  31. void init(UART_HandleTypeDef* huart) { m_huart = huart; }
  32. virtual void send(const uint8_t* data, size_t len) { HAL_UART_Transmit(m_huart, (uint8_t*)data, len, 1000); }
  33. };
  34. extern DMA_HandleTypeDef hdma_usart3_rx;
  35. extern DMA_HandleTypeDef hdma_usart3_tx;
  36. }
  37. /*******************************************************************************
  38. * GET_DEVICE_ID *
  39. *******************************************************************************/
  40. static int32_t getDeviceId() {
  41. static bool init = false;
  42. static ZGPIO ID0;
  43. static ZGPIO ID1;
  44. static ZGPIO ID2;
  45. static ZGPIO ID3;
  46. static ZGPIO ID4;
  47. if (!init) {
  48. ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  49. ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  50. ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  51. ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  52. ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
  53. init = true;
  54. }
  55. uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
  56. return id;
  57. }
  58. /*******************************************************************************
  59. * INIT_SUBMODULE *
  60. *******************************************************************************/
  61. void nvs_init_cb() {}
  62. TemperatureSensor m_temperature_sensor[8];
  63. static void initsubmodule() {
  64. osDelay(1000);
  65. {
  66. m_temperature_sensor[0].initialize(&hadc1, ADC_CHANNEL_10);
  67. m_temperature_sensor[1].initialize(&hadc1, ADC_CHANNEL_11);
  68. m_temperature_sensor[2].initialize(&hadc1, ADC_CHANNEL_12);
  69. m_temperature_sensor[3].initialize(&hadc1, ADC_CHANNEL_13);
  70. m_temperature_sensor[4].initialize(&hadc1, ADC_CHANNEL_14);
  71. }
  72. {
  73. /*******************************************************************************
  74. * 4->20MAת485 *
  75. *******************************************************************************/
  76. /**
  77. * @brief
  78. * ڲ:
  79. * 115200
  80. * żУλ:У
  81. * ֹͣλ:һֹͣλ
  82. */
  83. ZASSERT(PC_MODBUS_UART.Init.BaudRate == 115200);
  84. ZASSERT(PC_MODBUS_UART.Init.Parity == UART_PARITY_NONE);
  85. ZASSERT(PC_MODBUS_UART.Init.StopBits == UART_STOPBITS_1);
  86. serial485_to_analog.initialize(&PC_MODBUS_UART, NULL, NULL);
  87. serial485_to_analog.reg(&m_temperature_sensor[0]);
  88. serial485_to_analog.reg(&m_temperature_sensor[1]);
  89. serial485_to_analog.reg(&m_temperature_sensor[2]);
  90. serial485_to_analog.reg(&m_temperature_sensor[3]);
  91. serial485_to_analog.reg(&m_temperature_sensor[4]);
  92. serial485_to_analog.start();
  93. // static ZUARTDmaReceiver dmaUartReceiver;
  94. // static ZUARTDmaReceiver::hardware_config_t cfg = {
  95. // .huart = &PC_MODBUS_UART,
  96. // .dma_rx = &PC_MODBUS_UART_DMA_HANDLER,
  97. // .rxbuffersize = PC_MODBUS_UART_RX_BUF_SIZE,
  98. // .rxovertime_ms = 1,
  99. // };
  100. // dmaUartReceiver.initialize(&cfg);
  101. // static UARTSender uartSender;
  102. // uartSender.init(&PC_MODBUS_UART);
  103. // ModulebusClient::Inst()->init(
  104. // &dmaUartReceiver, &uartSender, 1, //
  105. // [](uint16_t regadd, uint16_t& val) {
  106. // int32_t sendval = 0;
  107. // if (regadd == 11) {
  108. // m_temperature_sensor[0].getTemperature(sendval);
  109. // val = sendval;
  110. // } else if (regadd == 12) {
  111. // m_temperature_sensor[1].getTemperature(sendval);
  112. // val = sendval;
  113. // } else if (regadd == 13) {
  114. // m_temperature_sensor[2].getTemperature(sendval);
  115. // val = sendval;
  116. // } else if (regadd == 14) {
  117. // m_temperature_sensor[3].getTemperature(sendval);
  118. // val = sendval;
  119. // } else if (regadd == 15) {
  120. // m_temperature_sensor[4].getTemperature(sendval);
  121. // val = sendval;
  122. // }
  123. // }, //
  124. // [](uint16_t regadd, uint16_t val) {});
  125. // OSDefaultSchduler::getInstance()->regPeriodJob([](OSDefaultSchduler::Context& context) { ModulebusClient::Inst()->loop(); }, 1);
  126. }
  127. {
  128. // 115200
  129. /*******************************************************************************
  130. * Թñж *
  131. *******************************************************************************/
  132. static FeiTeServoMotor feiteservomotor_bus; // ���ض�������
  133. // ���ض�������
  134. ZASSERT(huart3.Init.BaudRate == 115200);
  135. feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
  136. {
  137. static MiniRobotCtrlModule mini_servo;
  138. static MiniRobotCtrlModule::flash_config_t cfg = {0};
  139. cfg.default_torque = 330;
  140. mini_servo.initialize(initer.get_module_id(1), &feiteservomotor_bus, 1, &cfg);
  141. initer.register_module(&mini_servo);
  142. }
  143. {
  144. static MiniRobotCtrlModule mini_servo;
  145. static MiniRobotCtrlModule::flash_config_t cfg = {0};
  146. cfg.default_torque = 330;
  147. mini_servo.initialize(initer.get_module_id(2), &feiteservomotor_bus, 2, &cfg);
  148. initer.register_module(&mini_servo);
  149. }
  150. {
  151. static MiniRobotCtrlModule mini_servo;
  152. static MiniRobotCtrlModule::flash_config_t cfg = {0};
  153. cfg.default_torque = 330;
  154. mini_servo.initialize(initer.get_module_id(3), &feiteservomotor_bus, 3, &cfg);
  155. initer.register_module(&mini_servo);
  156. }
  157. {
  158. static MiniRobotCtrlModule mini_servo;
  159. static MiniRobotCtrlModule::flash_config_t cfg = {0};
  160. cfg.default_torque = 330;
  161. mini_servo.initialize(initer.get_module_id(4), &feiteservomotor_bus, 4, &cfg);
  162. initer.register_module(&mini_servo);
  163. }
  164. {
  165. static MiniRobotCtrlModule mini_servo;
  166. static MiniRobotCtrlModule::flash_config_t cfg = {0};
  167. cfg.default_torque = 330;
  168. mini_servo.initialize(initer.get_module_id(5), &feiteservomotor_bus, 5, &cfg);
  169. initer.register_module(&mini_servo);
  170. }
  171. }
  172. }
  173. /*******************************************************************************
  174. * MAIN *
  175. *******************************************************************************/
  176. void umain() {
  177. ZCancmderSubboardIniter::cfg_t cfg = //
  178. {
  179. .deviceId = getDeviceId(),
  180. .input_gpio = {},
  181. .output_gpio = {},
  182. .temperature_sensor =
  183. {
  184. &m_temperature_sensor[0],
  185. &m_temperature_sensor[1],
  186. &m_temperature_sensor[2],
  187. &m_temperature_sensor[3],
  188. &m_temperature_sensor[4],
  189. },
  190. };
  191. initer.init(&cfg);
  192. initsubmodule();
  193. initer.loop();
  194. }