10. /15
USB CDCクラスドライバを作る
?CDC: Communication Device Class
?電話回線やイーサネットなどでの通信を行うデバイ
スを包括するクラス
?ACM: Abstract Control Model subclass
?ATコマンド(電話をかけたり切ったりするコマン
ド)で制御できる機器
xHCIドライバ
USBバスドライバ
クラスドライバ
PCIバスドライバ
USB
ホスト
USB
デバイス
Endpoint 0
Endpoint x
Endpoint y
Communication Class interface: 機器の管理と発信(call)の管理
Data Class interface: データの送受信
10
11. /15
CDCドライバの実装(簡易版)
Error CDCDriver::SendSerial(const void* buf, int len) {
uint8_t* buf_out = new uint8_t[len];
memcpy(buf_out, buf, len);
ParentDevice()->NormalOut(ep_bulk_out_, buf_out, len);
uint8_t* buf_in = new uint8_t[8];
ParentDevice()->NormalIn(ep_bulk_in_, buf_in, 8);
return MAKE_ERROR(Error::kSuccess);
}
int CDCDriver::ReceiveSerial(void* buf, int len) {
const auto recv_len =
std::min(len, static_cast<int>(receive_buf_.size()));
auto buf8 = reinterpret_cast<uint8_t*>(buf);
for (int i = 0; i < recv_len; ++i) {
buf8[i] = receive_buf_.front();
receive_buf_.pop_front();
}
return recv_len;
}
Out方向のエンドポイント
でデータを送信する
In方向のエンドポイント
に対し受信をかけておく
デバイスからデータが
受信されていれば
receive_buf_に
データが書かれている
11