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.

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