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.

83 lines
2.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #include "port.h"
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include "main.h"
  5. // #include "modbus_processer.h"
  6. #include "tim.h"
  7. #include "usart.h"
  8. //
  9. #include "../../../iflytop_microcontroller/sdk/stm32/pwm.h"
  10. #include "../../../iflytop_microcontroller/sdk/stm32/stm32sdk.h"
  11. /**********************************************************************************************************************
  12. * ===================================================printf重定向=================================================== *
  13. **********************************************************************************************************************/
  14. int fputc(int ch, FILE* stream) {
  15. uint8_t c = ch;
  16. HAL_UART_Transmit(&DEBUG_UART, &c, 1, 100);
  17. return ch;
  18. }
  19. /***********************************************************************************************************************
  20. * ========================================================================================================= *
  21. ***********************************************************************************************************************/
  22. void port_do_debug_light_state(void) {
  23. static uint32_t lastprocess = 0;
  24. if (sys_haspassedms(lastprocess) > 300) {
  25. lastprocess = HAL_GetTick();
  26. HAL_GPIO_TogglePin(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN);
  27. }
  28. }
  29. /***********************************************************************************************************************
  30. * =========================================================================================================== *
  31. ***********************************************************************************************************************/
  32. static uart_t m_uarts[] = {
  33. {&DEBUG_UART, 0},
  34. // {&MODBUS_UART, 0},
  35. };
  36. __weak void port_mock_on_uart_rx(uart_t* uart) {}
  37. static void uarts_start_receive(uart_t* uart) { HAL_UART_Receive_IT(uart->uarthandler, &uart->rxbuf, 1); }
  38. void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
  39. for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) {
  40. if (m_uarts[i].uarthandler == huart) {
  41. port_mock_on_uart_rx(&m_uarts[i]);
  42. uarts_start_receive(&m_uarts[i]);
  43. return;
  44. }
  45. }
  46. }
  47. void HAL_UART_ErrorCallback(UART_HandleTypeDef* huart) {
  48. for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) {
  49. if (m_uarts[i].uarthandler == huart) {
  50. uarts_start_receive(&m_uarts[i]);
  51. return;
  52. }
  53. }
  54. }
  55. // export
  56. void port_uart_start_all_uart_receive(void) {
  57. for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) {
  58. uarts_start_receive(&m_uarts[i]);
  59. }
  60. }
  61. bool port_electric_relay_get_state(int relayindex) {
  62. /*
  63. example:
  64. if (relayindex == 1) {
  65. return GPIO_GET(C, 8, !!);
  66. }
  67. */
  68. return false;
  69. }
  70. void port_electric_relay_set_state(int relayindex, bool state) {
  71. /*
  72. example:
  73. if (relayindex == 1) {
  74. GPIO_SET(C, 8, !!, state);
  75. }
  76. */
  77. }