Remove vcp_receiver
This commit is contained in:
parent
70e3d52dea
commit
6864761acf
@ -1,53 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
extern "C" void vcpReceiveCallback(uint8_t*, uint32_t);
|
||||
|
||||
namespace detail {
|
||||
|
||||
constexpr auto VCP_RECEIVE_BUFFER_SIZE = 64;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
class VcpReceiver {
|
||||
public:
|
||||
static inline bool rxByte(uint8_t& data)
|
||||
{
|
||||
if(m_receiveBuffer.head == m_receiveBuffer.tail)
|
||||
return false;
|
||||
|
||||
const uint8_t newTail = (m_receiveBuffer.tail + 1) % detail::VCP_RECEIVE_BUFFER_SIZE;
|
||||
data = m_receiveBuffer.data[newTail];
|
||||
m_receiveBuffer.tail = newTail;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
friend void vcpReceiveCallback(uint8_t*, uint32_t);
|
||||
|
||||
template<size_t Size>
|
||||
struct RingBuffer {
|
||||
size_t head = 0;
|
||||
size_t tail = 0;
|
||||
uint8_t data[Size];
|
||||
};
|
||||
|
||||
static volatile RingBuffer<detail::VCP_RECEIVE_BUFFER_SIZE> m_receiveBuffer;
|
||||
|
||||
static inline void rxHandler(const uint8_t& data)
|
||||
{
|
||||
const uint8_t newHead = (m_receiveBuffer.head + 1) % detail::VCP_RECEIVE_BUFFER_SIZE;
|
||||
|
||||
if(newHead != m_receiveBuffer.tail) {
|
||||
m_receiveBuffer.head = newHead;
|
||||
m_receiveBuffer.data[newHead] = data;
|
||||
}
|
||||
else {
|
||||
// TODO: Handle overflow
|
||||
}
|
||||
}
|
||||
};
|
@ -74,8 +74,7 @@ Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c
|
||||
# C++ sources
|
||||
CXX_SOURCES = \
|
||||
Src/main.cpp \
|
||||
Src/uart_vcp.cpp \
|
||||
Src/vcp_receiver.cpp
|
||||
Src/uart_vcp.cpp
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
|
@ -1,10 +0,0 @@
|
||||
#include "vcp_receiver.hpp"
|
||||
|
||||
extern "C" void vcpReceiveCallback(uint8_t* buf, uint32_t len)
|
||||
{
|
||||
for(uint32_t i = 0; i < len; ++i) {
|
||||
VcpReceiver::rxHandler(buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
volatile VcpReceiver::RingBuffer<detail::VCP_RECEIVE_BUFFER_SIZE> VcpReceiver::m_receiveBuffer;
|
Loading…
Reference in New Issue
Block a user