2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2021-03-18 11:07:22 -07:00
|
|
|
|
|
|
|
#if EFI_USB_SERIAL
|
|
|
|
|
|
|
|
#include "usbconsole.h"
|
|
|
|
#include "thread_controller.h"
|
|
|
|
#include "tunerstudio.h"
|
|
|
|
|
|
|
|
|
|
|
|
// Assert that the USB tx/rx buffers are large enough to fit one full packet
|
|
|
|
static_assert(SERIAL_USB_BUFFERS_SIZE >= BLOCKING_FACTOR + 10);
|
|
|
|
|
|
|
|
extern SerialUSBDriver EFI_CONSOLE_USB_DEVICE;
|
2021-03-19 14:05:04 -07:00
|
|
|
|
|
|
|
class UsbChannel : public TsChannelBase {
|
|
|
|
public:
|
|
|
|
UsbChannel(SerialUSBDriver& driver)
|
2021-09-18 12:33:14 -07:00
|
|
|
: TsChannelBase("USB"), m_channel(reinterpret_cast<BaseChannel*>(&driver))
|
2021-03-19 14:05:04 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isReady() const override {
|
|
|
|
return is_usb_serial_ready();
|
|
|
|
}
|
|
|
|
|
2021-10-18 16:59:08 -07:00
|
|
|
void write(const uint8_t* buffer, size_t size, bool) override {
|
2021-03-19 14:05:04 -07:00
|
|
|
chnWriteTimeout(m_channel, buffer, size, BINARY_IO_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t readTimeout(uint8_t* buffer, size_t size, int timeout) override {
|
|
|
|
return chnReadTimeout(m_channel, buffer, size, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BaseChannel* const m_channel;
|
|
|
|
};
|
|
|
|
|
|
|
|
static UsbChannel usbChannel(EFI_CONSOLE_USB_DEVICE);
|
2021-03-18 11:07:22 -07:00
|
|
|
|
|
|
|
struct UsbThread : public TunerstudioThread {
|
|
|
|
UsbThread() : TunerstudioThread("USB Console") { }
|
|
|
|
|
|
|
|
TsChannelBase* setupChannel() override {
|
|
|
|
// Start the port's USB stack
|
|
|
|
usb_serial_start();
|
|
|
|
|
|
|
|
return &usbChannel;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static UsbThread usbConsole;
|
|
|
|
|
|
|
|
void startUsbConsole() {
|
2022-07-21 12:17:32 -07:00
|
|
|
usbConsole.start();
|
2021-03-18 11:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // EFI_USB_SERIAL
|