mini_gateway_master.c 730 B

12345678910111213141516171819202122232425
  1. //
  2. // Created by DELL on 2024/10/16.
  3. //
  4. #include <stdint.h>
  5. #include "mini_gateway_master.h"
  6. #include "usart.h"
  7. static int32_t uart_read(uint8_t *buf, uint16_t count, int32_t byte_timeout_ms,
  8. void *arg) {
  9. HAL_StatusTypeDef status = HAL_UART_Receive(&huart2, buf, count, byte_timeout_ms);
  10. if (status == HAL_OK) {
  11. return count;
  12. } else {
  13. return 0;
  14. }
  15. }
  16. static int32_t uart_write(const uint8_t *buf, uint16_t count, int32_t byte_timeout_ms,
  17. void *arg) {
  18. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
  19. HAL_UART_Transmit(&huart2, buf, count, byte_timeout_ms);
  20. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
  21. return count;
  22. }