1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- /*
- * commprt.c
- *
- * Created on: Jan 25, 2022
- * Author: radioman
- */
- #include <string.h>
- #include "stm32l1xx_hal.h"
- #include "commprt.h"
- #include "uartio.h"
- #include "usbd_cdc_if.h"
- #define COMM_HEADER_BYTE 0x55;
- #define COMM_BUFFER_SIZE 260
- extern UART_HandleTypeDef huart1;
- static uint8_t comm_buffer[COMM_BUFFER_SIZE];
- uint8_t COMM_Checksum(const uint8_t *data, uint8_t len)
- {
- uint8_t chk = 0;
- while(len--)
- chk ^= data[len];
- return chk;
- }
- COMM_StatusTypeDef COMM_Receive(uint8_t *buf, COMM_IfaceTypeDef iface)
- {
- return COMM_OK;
- }
- COMM_StatusTypeDef COMM_Transmit(uint8_t *data, uint8_t len, COMM_IfaceTypeDef iface)
- {
- comm_buffer[0] = COMM_HEADER_BYTE;
- comm_buffer[1] = len;
- memcpy(&comm_buffer[2], data, len);
- comm_buffer[len + 2] = COMM_Checksum(comm_buffer, len + 2);
- switch(iface)
- {
- case COMM_BT:
- UARTIO_Transmit(&huart1, comm_buffer, len + 3);
- break;
- case COMM_USB:
- CDC_Transmit_FS(comm_buffer, len + 3);
- break;
- default:
- return COMM_FAIL;
- }
- return COMM_OK;
- }
|