20 #include "FtdiSerialDevice.h" 21 #include "modules/system/usb/UsbConstants.h" 22 #include "modules/system/usb/UsbDevice.h" 23 #include "pedigree/kernel/Log.h" 24 #include "pedigree/kernel/utilities/PointerGuard.h" 25 #include "pedigree/kernel/utilities/Vector.h" 26 #include "pedigree/kernel/utilities/new" 28 #define FTDI_BAUD_RATE 9600 30 static uint8_t nSubdivisors[8] = {0, 3, 2, 4, 1, 5, 6, 7};
32 FtdiSerialDevice::FtdiSerialDevice(
UsbDevice *dev)
37 FtdiSerialDevice::~FtdiSerialDevice()
44 controlRequest(UsbRequestType::Vendor, 0, 0, 0);
47 uint16_t nDivisor = (48000000 / 2) / FTDI_BAUD_RATE,
48 nSubdivisor = nSubdivisors[nDivisor % 8];
53 UsbRequestType::Vendor, 3, (nSubdivisor & 3) << 14 | nDivisor,
57 for (
size_t i = 0; i < m_pInterface->endpointList.count(); i++)
59 Endpoint *pEndpoint = m_pInterface->endpointList[i];
60 if (!m_pInEndpoint && (pEndpoint->nTransferType == Endpoint::Bulk) &&
62 m_pInEndpoint = pEndpoint;
63 if (!m_pOutEndpoint && (pEndpoint->nTransferType == Endpoint::Bulk) &&
65 m_pOutEndpoint = pEndpoint;
66 if (m_pInEndpoint && m_pOutEndpoint)
72 ERROR(
"USB: FTDI: No IN endpoint");
78 ERROR(
"USB: FTDI: No OUT endpoint");
82 m_UsbState = HasDriver;
85 char FtdiSerialDevice::read()
87 char *pChar =
new char(0);
89 syncIn(m_pInEndpoint, reinterpret_cast<uintptr_t>(pChar), 1);
93 void FtdiSerialDevice::write(
char c)
95 char *pChar =
new char(c);
97 syncOut(m_pOutEndpoint, reinterpret_cast<uintptr_t>(pChar), 1);
virtual void initialiseDriver()
Implemented by the driver class, initialises driver-specific stuff.