rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
usb_console.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#if EFI_USB_SERIAL
4
5#include "usbconsole.h"
6#include "thread_controller.h"
7#include "tunerstudio.h"
8
9// Assert that the USB tx/rx buffers are large enough to fit one full packet
10// Lets don't care about underlying driver. If driver has no enough free
11// space in buffers it will block chnWriteTimeout() until buffers available
12// or timeout happens.
13//static_assert(SERIAL_USB_BUFFERS_TX_SIZE >= BLOCKING_FACTOR + 10);
14
15extern SerialUSBDriver EFI_CONSOLE_USB_DEVICE;
16
17class UsbChannel final : public TsChannelBase {
18public:
19 UsbChannel(SerialUSBDriver& driver)
20 : TsChannelBase("USB"), m_channel(reinterpret_cast<BaseChannel*>(&driver))
21 {
22 }
23
24 bool isReady() const override {
25 return is_usb_serial_ready();
26 }
27
28 void write(const uint8_t* buffer, size_t size, bool /*isEndOfPacket*/) override {
29 size_t transferred = chnWriteTimeout(m_channel, buffer, size, BINARY_IO_TIMEOUT);
30 bytesOut += transferred;
31 }
32
33 size_t readTimeout(uint8_t* buffer, size_t size, int timeout) override {
34 size_t transferred = chnReadTimeout(m_channel, buffer, size, timeout);
35 bytesIn += transferred;
36 return transferred;
37 }
38
39private:
40 BaseChannel* const m_channel;
41};
42
44
45struct UsbThread : public TunerstudioThread {
46 UsbThread() : TunerstudioThread("USB Console") { }
47
48 TsChannelBase* setupChannel() override {
49 // Start the port's USB stack
51
52 return &usbChannel;
53 }
54};
55
56static UsbThread usbConsole;
57
59 usbConsole.start();
60}
61
64
65#endif // EFI_USB_SERIAL
virtual bool isReady() const
virtual void write(const uint8_t *buffer, size_t size, bool isEndOfPacket=false)=0
virtual size_t readTimeout(uint8_t *buffer, size_t size, int timeout)=0
virtual TsChannelBase * setupChannel()=0
bool is_usb_serial_ready()
void usb_serial_start(void)
Main function of PDL.
composite packet size
static BigBufferHandle buffer
static UsbChannel usbChannel(EFI_CONSOLE_USB_DEVICE)
SerialUSBDriver EFI_CONSOLE_USB_DEVICE
void printUsbConnectorStats()
void startUsbConsole()
static UsbThread usbConsole