Library to use Arduino USB host shield on mbed

Dependents:   USBHOST_PS5

ArduinoのUSB Host Shield 2.0をmbedで使えるようにしたライブラリです。
大体のコードがArduinoからそのまま移植可能です。

Arduino UNOやMega用のホストシールド以外にもミニサイズのホストシールドでも使用可能です https://os.mbed.com/media/uploads/kotakku/dffgfddswa.png

シールドについて

3.3VのI/O用にシールドの改造が必要になりますがネット上に記事がたくさんあるのでそちらを参考にしてください

接続例

https://os.mbed.com/media/uploads/kotakku/esgsvfvhjrekldkcjxvb.png

使い方

Arduinoのコードと違うのはUSBのインスタンスの宣言部分のみです。
ピンを自分で指定できるようにしたので使いやすくなりました。

仕様

  • Arduinoのmillis関数、micros関数の移植のために内部でTimerクラスを使用しています。

main.cpp

#include "mbed.h"
#include <PS3BT.h>
#include <usbhub.h>

Serial pc(USBTX, USBRX, 115200);

//Nucleo f303k8用
USB Usb(A6, A5, A4, A3, A2); // mosi, miso, sclk, ssel, intr
BTD Btd(&Usb);
PS3BT PS3(&Btd);

int main()
{
    bool printAngle = false;

    if (Usb.Init() == -1)
    {
        pc.printf("\r\nOSC did not start");
        while (1); // Halt
    }
    pc.printf("\r\nPS3 USB Library Started");

    while (1)
    {
        Usb.Task();
        
        if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
            if (PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117)
            {
                pc.printf("\r\nLeftHatX: %d", PS3.getAnalogHat(LeftHatX));
                pc.printf("\tLeftHatY: %d", PS3.getAnalogHat(LeftHatY));
                if (PS3.PS3Connected)
                { // The Navigation controller only have one joystick
                    pc.printf("\tRightHatX: %d", PS3.getAnalogHat(RightHatX));
                    pc.printf("\tRightHatY: %d", PS3.getAnalogHat(RightHatY));
                }
            }
            // Analog button values can be read from almost all buttons
            if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2))
            {
                pc.printf("\r\nL2: %d", PS3.getAnalogButton(L2));
                if (!PS3.PS3NavigationConnected)
                {
                    pc.printf("\tR2: %d", PS3.getAnalogButton(R2));
                }
            }
            if (PS3.getButtonClick(PS))
            {
                PS3.disconnect();
                pc.printf("\r\nPS");
            }
    
            if (PS3.getButtonClick(TRIANGLE))
                pc.printf("\r\nTriangle");
            if (PS3.getButtonClick(CIRCLE))
                pc.printf("\r\nCircle");
            if (PS3.getButtonClick(CROSS))
                pc.printf("\r\nCross");
            if (PS3.getButtonClick(SQUARE))
                pc.printf("\r\nSquare");
    
            if (PS3.getButtonClick(UP))
            {
                pc.printf("\r\nUp");
                PS3.setLedOff();
                PS3.setLedOn(CONTROLLER_LED4);
            }
            if (PS3.getButtonClick(RIGHT))
            {
                pc.printf("\r\nRight");
                PS3.setLedOff();
                PS3.setLedOn(CONTROLLER_LED1);
            }
            if (PS3.getButtonClick(DOWN))
            {
                pc.printf("\r\nDown");
                PS3.setLedOff();
                PS3.setLedOn(CONTROLLER_LED2);
            }
            if (PS3.getButtonClick(LEFT))
            {
                pc.printf("\r\nLeft");
                PS3.setLedOff();
                PS3.setLedOn(CONTROLLER_LED3);
            }
    
            if (PS3.getButtonClick(L1))
                pc.printf("\r\nL1");
            if (PS3.getButtonClick(L3))
                pc.printf("\r\nL3");
            if (PS3.getButtonClick(R1))
                pc.printf("\r\nR1");
            if (PS3.getButtonClick(R3))
                pc.printf("\r\nR3");
    
            if (PS3.getButtonClick(SELECT))
            {
                pc.printf("\r\nSelect - ");
                PS3.printStatusString();
            }
            if (PS3.getButtonClick(START))
            {
                pc.printf("\r\nStart");
                printAngle = !printAngle;
            }
            if (printAngle)
            {
                pc.printf("\r\nPitch: %.3lf", PS3.getAngle(Pitch));
                pc.printf("\tRoll: %.3lf", PS3.getAngle(Roll));
            }
        }
        else
        {
            pc.printf("not connect\n");
        }
    }
}
Committer:
robo_ichinoseki_a
Date:
Sat May 02 05:56:48 2020 +0000
Revision:
1:da31140f2a1c
Parent:
0:b1ce54272580
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kotakku 0:b1ce54272580 1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
kotakku 0:b1ce54272580 2
kotakku 0:b1ce54272580 3 This program is free software; you can redistribute it and/or modify
kotakku 0:b1ce54272580 4 it under the terms of the GNU General Public License as published by
kotakku 0:b1ce54272580 5 the Free Software Foundation; either version 2 of the License, or
kotakku 0:b1ce54272580 6 (at your option) any later version.
kotakku 0:b1ce54272580 7
kotakku 0:b1ce54272580 8 This program is distributed in the hope that it will be useful,
kotakku 0:b1ce54272580 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
kotakku 0:b1ce54272580 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kotakku 0:b1ce54272580 11 GNU General Public License for more details.
kotakku 0:b1ce54272580 12
kotakku 0:b1ce54272580 13 You should have received a copy of the GNU General Public License
kotakku 0:b1ce54272580 14 along with this program; if not, write to the Free Software
kotakku 0:b1ce54272580 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
kotakku 0:b1ce54272580 16
kotakku 0:b1ce54272580 17 Contact information
kotakku 0:b1ce54272580 18 -------------------
kotakku 0:b1ce54272580 19
kotakku 0:b1ce54272580 20 Circuits At Home, LTD
kotakku 0:b1ce54272580 21 Web : http://www.circuitsathome.com
kotakku 0:b1ce54272580 22 e-mail : support@circuitsathome.com
kotakku 0:b1ce54272580 23 */
kotakku 0:b1ce54272580 24
kotakku 0:b1ce54272580 25 #if !defined(__MASSTORAGE_H__)
kotakku 0:b1ce54272580 26 #define __MASSTORAGE_H__
kotakku 0:b1ce54272580 27
kotakku 0:b1ce54272580 28 // Cruft removal, makes driver smaller, faster.
kotakku 0:b1ce54272580 29 #ifndef MS_WANT_PARSER
kotakku 0:b1ce54272580 30 #define MS_WANT_PARSER 0
kotakku 0:b1ce54272580 31 #endif
kotakku 0:b1ce54272580 32
kotakku 0:b1ce54272580 33 #include "Usb.h"
kotakku 0:b1ce54272580 34
kotakku 0:b1ce54272580 35 #define bmREQ_MASSOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
kotakku 0:b1ce54272580 36 #define bmREQ_MASSIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
kotakku 0:b1ce54272580 37
kotakku 0:b1ce54272580 38 // Mass Storage Subclass Constants
kotakku 0:b1ce54272580 39 #define MASS_SUBCLASS_SCSI_NOT_REPORTED 0x00 // De facto use
kotakku 0:b1ce54272580 40 #define MASS_SUBCLASS_RBC 0x01
kotakku 0:b1ce54272580 41 #define MASS_SUBCLASS_ATAPI 0x02 // MMC-5 (ATAPI)
kotakku 0:b1ce54272580 42 #define MASS_SUBCLASS_OBSOLETE1 0x03 // Was QIC-157
kotakku 0:b1ce54272580 43 #define MASS_SUBCLASS_UFI 0x04 // Specifies how to interface Floppy Disk Drives to USB
kotakku 0:b1ce54272580 44 #define MASS_SUBCLASS_OBSOLETE2 0x05 // Was SFF-8070i
kotakku 0:b1ce54272580 45 #define MASS_SUBCLASS_SCSI 0x06 // SCSI Transparent Command Set
kotakku 0:b1ce54272580 46 #define MASS_SUBCLASS_LSDFS 0x07 // Specifies how host has to negotiate access before trying SCSI
kotakku 0:b1ce54272580 47 #define MASS_SUBCLASS_IEEE1667 0x08
kotakku 0:b1ce54272580 48
kotakku 0:b1ce54272580 49 // Mass Storage Class Protocols
kotakku 0:b1ce54272580 50 #define MASS_PROTO_CBI 0x00 // CBI (with command completion interrupt)
kotakku 0:b1ce54272580 51 #define MASS_PROTO_CBI_NO_INT 0x01 // CBI (without command completion interrupt)
kotakku 0:b1ce54272580 52 #define MASS_PROTO_OBSOLETE 0x02
kotakku 0:b1ce54272580 53 #define MASS_PROTO_BBB 0x50 // Bulk Only Transport
kotakku 0:b1ce54272580 54 #define MASS_PROTO_UAS 0x62
kotakku 0:b1ce54272580 55
kotakku 0:b1ce54272580 56 // Request Codes
kotakku 0:b1ce54272580 57 #define MASS_REQ_ADSC 0x00
kotakku 0:b1ce54272580 58 #define MASS_REQ_GET 0xFC
kotakku 0:b1ce54272580 59 #define MASS_REQ_PUT 0xFD
kotakku 0:b1ce54272580 60 #define MASS_REQ_GET_MAX_LUN 0xFE
kotakku 0:b1ce54272580 61 #define MASS_REQ_BOMSR 0xFF // Bulk-Only Mass Storage Reset
kotakku 0:b1ce54272580 62
kotakku 0:b1ce54272580 63 #define MASS_CBW_SIGNATURE 0x43425355
kotakku 0:b1ce54272580 64 #define MASS_CSW_SIGNATURE 0x53425355
kotakku 0:b1ce54272580 65
kotakku 0:b1ce54272580 66 #define MASS_CMD_DIR_OUT 0 // (0 << 7)
kotakku 0:b1ce54272580 67 #define MASS_CMD_DIR_IN 0x80 //(1 << 7)
kotakku 0:b1ce54272580 68
kotakku 0:b1ce54272580 69 /*
kotakku 0:b1ce54272580 70 * Reference documents from T10 (http://www.t10.org)
kotakku 0:b1ce54272580 71 * SCSI Primary Commands - 3 (SPC-3)
kotakku 0:b1ce54272580 72 * SCSI Block Commands - 2 (SBC-2)
kotakku 0:b1ce54272580 73 * Multi-Media Commands - 5 (MMC-5)
kotakku 0:b1ce54272580 74 */
kotakku 0:b1ce54272580 75
kotakku 0:b1ce54272580 76 /* Group 1 commands (CDB's here are should all be 6-bytes) */
kotakku 0:b1ce54272580 77 #define SCSI_CMD_TEST_UNIT_READY 0x00
kotakku 0:b1ce54272580 78 #define SCSI_CMD_REQUEST_SENSE 0x03
kotakku 0:b1ce54272580 79 #define SCSI_CMD_FORMAT_UNIT 0x04
kotakku 0:b1ce54272580 80 #define SCSI_CMD_READ_6 0x08
kotakku 0:b1ce54272580 81 #define SCSI_CMD_WRITE_6 0x0A
kotakku 0:b1ce54272580 82 #define SCSI_CMD_INQUIRY 0x12
kotakku 0:b1ce54272580 83 #define SCSI_CMD_MODE_SELECT_6 0x15
kotakku 0:b1ce54272580 84 #define SCSI_CMD_MODE_SENSE_6 0x1A
kotakku 0:b1ce54272580 85 #define SCSI_CMD_START_STOP_UNIT 0x1B
kotakku 0:b1ce54272580 86 #define SCSI_CMD_PREVENT_REMOVAL 0x1E
kotakku 0:b1ce54272580 87 /* Group 2 Commands (CDB's here are 10-bytes) */
kotakku 0:b1ce54272580 88 #define SCSI_CMD_READ_FORMAT_CAPACITIES 0x23
kotakku 0:b1ce54272580 89 #define SCSI_CMD_READ_CAPACITY_10 0x25
kotakku 0:b1ce54272580 90 #define SCSI_CMD_READ_10 0x28
kotakku 0:b1ce54272580 91 #define SCSI_CMD_WRITE_10 0x2A
kotakku 0:b1ce54272580 92 #define SCSI_CMD_SEEK_10 0x2B
kotakku 0:b1ce54272580 93 #define SCSI_CMD_ERASE_10 0x2C
kotakku 0:b1ce54272580 94 #define SCSI_CMD_WRITE_AND_VERIFY_10 0x2E
kotakku 0:b1ce54272580 95 #define SCSI_CMD_VERIFY_10 0x2F
kotakku 0:b1ce54272580 96 #define SCSI_CMD_SYNCHRONIZE_CACHE 0x35
kotakku 0:b1ce54272580 97 #define SCSI_CMD_WRITE_BUFFER 0x3B
kotakku 0:b1ce54272580 98 #define SCSI_CMD_READ_BUFFER 0x3C
kotakku 0:b1ce54272580 99 #define SCSI_CMD_READ_SUBCHANNEL 0x42
kotakku 0:b1ce54272580 100 #define SCSI_CMD_READ_TOC 0x43
kotakku 0:b1ce54272580 101 #define SCSI_CMD_READ_HEADER 0x44
kotakku 0:b1ce54272580 102 #define SCSI_CMD_PLAY_AUDIO_10 0x45
kotakku 0:b1ce54272580 103 #define SCSI_CMD_GET_CONFIGURATION 0x46
kotakku 0:b1ce54272580 104 #define SCSI_CMD_PLAY_AUDIO_MSF 0x47
kotakku 0:b1ce54272580 105 #define SCSI_CMD_PLAY_AUDIO_TI 0x48
kotakku 0:b1ce54272580 106 #define SCSI_CMD_PLAY_TRACK_REL_10 0x49
kotakku 0:b1ce54272580 107 #define SCSI_CMD_GET_EVENT_STATUS 0x4A
kotakku 0:b1ce54272580 108 #define SCSI_CMD_PAUSE_RESUME 0x4B
kotakku 0:b1ce54272580 109 #define SCSI_CMD_READ_DISC_INFORMATION 0x51
kotakku 0:b1ce54272580 110 #define SCSI_CMD_READ_TRACK_INFORMATION 0x52
kotakku 0:b1ce54272580 111 #define SCSI_CMD_RESERVE_TRACK 0x53
kotakku 0:b1ce54272580 112 #define SCSI_CMD_SEND_OPC_INFORMATION 0x54
kotakku 0:b1ce54272580 113 #define SCSI_CMD_MODE_SELECT_10 0x55
kotakku 0:b1ce54272580 114 #define SCSI_CMD_REPAIR_TRACK 0x58
kotakku 0:b1ce54272580 115 #define SCSI_CMD_MODE_SENSE_10 0x5A
kotakku 0:b1ce54272580 116 #define SCSI_CMD_CLOSE_TRACK_SESSION 0x5B
kotakku 0:b1ce54272580 117 #define SCSI_CMD_READ_BUFFER_CAPACITY 0x5C
kotakku 0:b1ce54272580 118 #define SCSI_CMD_SEND_CUE_SHEET 0x5D
kotakku 0:b1ce54272580 119 /* Group 5 Commands (CDB's here are 12-bytes) */
kotakku 0:b1ce54272580 120 #define SCSI_CMD_REPORT_LUNS 0xA0
kotakku 0:b1ce54272580 121 #define SCSI_CMD_BLANK 0xA1
kotakku 0:b1ce54272580 122 #define SCSI_CMD_SECURITY_PROTOCOL_IN 0xA2
kotakku 0:b1ce54272580 123 #define SCSI_CMD_SEND_KEY 0xA3
kotakku 0:b1ce54272580 124 #define SCSI_CMD_REPORT_KEY 0xA4
kotakku 0:b1ce54272580 125 #define SCSI_CMD_PLAY_AUDIO_12 0xA5
kotakku 0:b1ce54272580 126 #define SCSI_CMD_LOAD_UNLOAD 0xA6
kotakku 0:b1ce54272580 127 #define SCSI_CMD_SET_READ_AHEAD 0xA7
kotakku 0:b1ce54272580 128 #define SCSI_CMD_READ_12 0xA8
kotakku 0:b1ce54272580 129 #define SCSI_CMD_PLAY_TRACK_REL_12 0xA9
kotakku 0:b1ce54272580 130 #define SCSI_CMD_WRITE_12 0xAA
kotakku 0:b1ce54272580 131 #define SCSI_CMD_READ_MEDIA_SERIAL_12 0xAB
kotakku 0:b1ce54272580 132 #define SCSI_CMD_GET_PERFORMANCE 0xAC
kotakku 0:b1ce54272580 133 #define SCSI_CMD_READ_DVD_STRUCTURE 0xAD
kotakku 0:b1ce54272580 134 #define SCSI_CMD_SECURITY_PROTOCOL_OUT 0xB5
kotakku 0:b1ce54272580 135 #define SCSI_CMD_SET_STREAMING 0xB6
kotakku 0:b1ce54272580 136 #define SCSI_CMD_READ_MSF 0xB9
kotakku 0:b1ce54272580 137 #define SCSI_CMD_SET_SPEED 0xBB
kotakku 0:b1ce54272580 138 #define SCSI_CMD_MECHANISM_STATUS 0xBD
kotakku 0:b1ce54272580 139 #define SCSI_CMD_READ_CD 0xBE
kotakku 0:b1ce54272580 140 #define SCSI_CMD_SEND_DISC_STRUCTURE 0xBF
kotakku 0:b1ce54272580 141 /* Vendor-unique Commands, included for completeness */
kotakku 0:b1ce54272580 142 #define SCSI_CMD_CD_PLAYBACK_STATUS 0xC4 /* SONY unique */
kotakku 0:b1ce54272580 143 #define SCSI_CMD_PLAYBACK_CONTROL 0xC9 /* SONY unique */
kotakku 0:b1ce54272580 144 #define SCSI_CMD_READ_CDDA 0xD8 /* Vendor unique */
kotakku 0:b1ce54272580 145 #define SCSI_CMD_READ_CDXA 0xDB /* Vendor unique */
kotakku 0:b1ce54272580 146 #define SCSI_CMD_READ_ALL_SUBCODES 0xDF /* Vendor unique */
kotakku 0:b1ce54272580 147
kotakku 0:b1ce54272580 148 /* SCSI error codes */
kotakku 0:b1ce54272580 149 #define SCSI_S_NOT_READY 0x02
kotakku 0:b1ce54272580 150 #define SCSI_S_MEDIUM_ERROR 0x03
kotakku 0:b1ce54272580 151 #define SCSI_S_ILLEGAL_REQUEST 0x05
kotakku 0:b1ce54272580 152 #define SCSI_S_UNIT_ATTENTION 0x06
kotakku 0:b1ce54272580 153 #define SCSI_ASC_LBA_OUT_OF_RANGE 0x21
kotakku 0:b1ce54272580 154 #define SCSI_ASC_MEDIA_CHANGED 0x28
kotakku 0:b1ce54272580 155 #define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3A
kotakku 0:b1ce54272580 156
kotakku 0:b1ce54272580 157 /* USB error codes */
kotakku 0:b1ce54272580 158 #define MASS_ERR_SUCCESS 0x00
kotakku 0:b1ce54272580 159 #define MASS_ERR_PHASE_ERROR 0x02
kotakku 0:b1ce54272580 160 #define MASS_ERR_UNIT_NOT_READY 0x03
kotakku 0:b1ce54272580 161 #define MASS_ERR_UNIT_BUSY 0x04
kotakku 0:b1ce54272580 162 #define MASS_ERR_STALL 0x05
kotakku 0:b1ce54272580 163 #define MASS_ERR_CMD_NOT_SUPPORTED 0x06
kotakku 0:b1ce54272580 164 #define MASS_ERR_INVALID_CSW 0x07
kotakku 0:b1ce54272580 165 #define MASS_ERR_NO_MEDIA 0x08
kotakku 0:b1ce54272580 166 #define MASS_ERR_BAD_LBA 0x09
kotakku 0:b1ce54272580 167 #define MASS_ERR_MEDIA_CHANGED 0x0A
kotakku 0:b1ce54272580 168 #define MASS_ERR_DEVICE_DISCONNECTED 0x11
kotakku 0:b1ce54272580 169 #define MASS_ERR_UNABLE_TO_RECOVER 0x12 // Reset recovery error
kotakku 0:b1ce54272580 170 #define MASS_ERR_INVALID_LUN 0x13
kotakku 0:b1ce54272580 171 #define MASS_ERR_WRITE_STALL 0x14
kotakku 0:b1ce54272580 172 #define MASS_ERR_READ_NAKS 0x15
kotakku 0:b1ce54272580 173 #define MASS_ERR_WRITE_NAKS 0x16
kotakku 0:b1ce54272580 174 #define MASS_ERR_WRITE_PROTECTED 0x17
kotakku 0:b1ce54272580 175 #define MASS_ERR_NOT_IMPLEMENTED 0xFD
kotakku 0:b1ce54272580 176 #define MASS_ERR_GENERAL_SCSI_ERROR 0xFE
kotakku 0:b1ce54272580 177 #define MASS_ERR_GENERAL_USB_ERROR 0xFF
kotakku 0:b1ce54272580 178 #define MASS_ERR_USER 0xA0 // For subclasses to define their own error codes
kotakku 0:b1ce54272580 179
kotakku 0:b1ce54272580 180 #define MASS_TRANS_FLG_CALLBACK 0x01 // Callback is involved
kotakku 0:b1ce54272580 181 #define MASS_TRANS_FLG_NO_STALL_CHECK 0x02 // STALL condition is not checked
kotakku 0:b1ce54272580 182 #define MASS_TRANS_FLG_NO_PHASE_CHECK 0x04 // PHASE_ERROR is not checked
kotakku 0:b1ce54272580 183
kotakku 0:b1ce54272580 184 #define MASS_MAX_ENDPOINTS 3
kotakku 0:b1ce54272580 185
kotakku 0:b1ce54272580 186 struct Capacity {
kotakku 0:b1ce54272580 187 uint8_t data[8];
kotakku 0:b1ce54272580 188 //uint32_t dwBlockAddress;
kotakku 0:b1ce54272580 189 //uint32_t dwBlockLength;
kotakku 0:b1ce54272580 190 } __attribute__((packed));
kotakku 0:b1ce54272580 191
kotakku 0:b1ce54272580 192 struct BASICCDB {
kotakku 0:b1ce54272580 193 uint8_t Opcode;
kotakku 0:b1ce54272580 194
kotakku 0:b1ce54272580 195 unsigned unused : 5;
kotakku 0:b1ce54272580 196 unsigned LUN : 3;
kotakku 0:b1ce54272580 197
kotakku 0:b1ce54272580 198 uint8_t info[12];
kotakku 0:b1ce54272580 199 } __attribute__((packed));
kotakku 0:b1ce54272580 200
kotakku 0:b1ce54272580 201 typedef BASICCDB BASICCDB_t;
kotakku 0:b1ce54272580 202
kotakku 0:b1ce54272580 203 struct CDB6 {
kotakku 0:b1ce54272580 204 uint8_t Opcode;
kotakku 0:b1ce54272580 205
kotakku 0:b1ce54272580 206 unsigned LBAMSB : 5;
kotakku 0:b1ce54272580 207 unsigned LUN : 3;
kotakku 0:b1ce54272580 208
kotakku 0:b1ce54272580 209 uint8_t LBAHB;
kotakku 0:b1ce54272580 210 uint8_t LBALB;
kotakku 0:b1ce54272580 211 uint8_t AllocationLength;
kotakku 0:b1ce54272580 212 uint8_t Control;
kotakku 0:b1ce54272580 213
kotakku 0:b1ce54272580 214 public:
kotakku 0:b1ce54272580 215
kotakku 0:b1ce54272580 216 CDB6(uint8_t _Opcode, uint8_t _LUN, uint32_t LBA, uint8_t _AllocationLength, uint8_t _Control) :
kotakku 0:b1ce54272580 217 Opcode(_Opcode), LBAMSB(BGRAB2(LBA) & 0x1f), LUN(_LUN), LBAHB(BGRAB1(LBA)), LBALB(BGRAB0(LBA)),
kotakku 0:b1ce54272580 218 AllocationLength(_AllocationLength), Control(_Control) {
kotakku 0:b1ce54272580 219 }
kotakku 0:b1ce54272580 220
kotakku 0:b1ce54272580 221 CDB6(uint8_t _Opcode, uint8_t _LUN, uint8_t _AllocationLength, uint8_t _Control) :
kotakku 0:b1ce54272580 222 Opcode(_Opcode), LBAMSB(0), LUN(_LUN), LBAHB(0), LBALB(0),
kotakku 0:b1ce54272580 223 AllocationLength(_AllocationLength), Control(_Control) {
kotakku 0:b1ce54272580 224 }
kotakku 0:b1ce54272580 225 } __attribute__((packed));
kotakku 0:b1ce54272580 226
kotakku 0:b1ce54272580 227 typedef CDB6 CDB6_t;
kotakku 0:b1ce54272580 228
kotakku 0:b1ce54272580 229 struct CDB10 {
kotakku 0:b1ce54272580 230 uint8_t Opcode;
kotakku 0:b1ce54272580 231
kotakku 0:b1ce54272580 232 unsigned Service_Action : 5;
kotakku 0:b1ce54272580 233 unsigned LUN : 3;
kotakku 0:b1ce54272580 234
kotakku 0:b1ce54272580 235 uint8_t LBA_L_M_MB;
kotakku 0:b1ce54272580 236 uint8_t LBA_L_M_LB;
kotakku 0:b1ce54272580 237 uint8_t LBA_L_L_MB;
kotakku 0:b1ce54272580 238 uint8_t LBA_L_L_LB;
kotakku 0:b1ce54272580 239
kotakku 0:b1ce54272580 240 uint8_t Misc2;
kotakku 0:b1ce54272580 241
kotakku 0:b1ce54272580 242 uint8_t ALC_MB;
kotakku 0:b1ce54272580 243 uint8_t ALC_LB;
kotakku 0:b1ce54272580 244
kotakku 0:b1ce54272580 245 uint8_t Control;
kotakku 0:b1ce54272580 246 public:
kotakku 0:b1ce54272580 247
kotakku 0:b1ce54272580 248 CDB10(uint8_t _Opcode, uint8_t _LUN) :
kotakku 0:b1ce54272580 249 Opcode(_Opcode), Service_Action(0), LUN(_LUN),
kotakku 0:b1ce54272580 250 LBA_L_M_MB(0), LBA_L_M_LB(0), LBA_L_L_MB(0), LBA_L_L_LB(0),
kotakku 0:b1ce54272580 251 Misc2(0), ALC_MB(0), ALC_LB(0), Control(0) {
kotakku 0:b1ce54272580 252 }
kotakku 0:b1ce54272580 253
kotakku 0:b1ce54272580 254 CDB10(uint8_t _Opcode, uint8_t _LUN, uint16_t xflen, uint32_t _LBA) :
kotakku 0:b1ce54272580 255 Opcode(_Opcode), Service_Action(0), LUN(_LUN),
kotakku 0:b1ce54272580 256 LBA_L_M_MB(BGRAB3(_LBA)), LBA_L_M_LB(BGRAB2(_LBA)), LBA_L_L_MB(BGRAB1(_LBA)), LBA_L_L_LB(BGRAB0(_LBA)),
kotakku 0:b1ce54272580 257 Misc2(0), ALC_MB(BGRAB1(xflen)), ALC_LB(BGRAB0(xflen)), Control(0) {
kotakku 0:b1ce54272580 258 }
kotakku 0:b1ce54272580 259 } __attribute__((packed));
kotakku 0:b1ce54272580 260
kotakku 0:b1ce54272580 261 typedef CDB10 CDB10_t;
kotakku 0:b1ce54272580 262
kotakku 0:b1ce54272580 263 struct CDB12 {
kotakku 0:b1ce54272580 264 uint8_t Opcode;
kotakku 0:b1ce54272580 265
kotakku 0:b1ce54272580 266 unsigned Service_Action : 5;
kotakku 0:b1ce54272580 267 unsigned Misc : 3;
kotakku 0:b1ce54272580 268
kotakku 0:b1ce54272580 269 uint8_t LBA_L_M_LB;
kotakku 0:b1ce54272580 270 uint8_t LBA_L_L_MB;
kotakku 0:b1ce54272580 271 uint8_t LBA_L_L_LB;
kotakku 0:b1ce54272580 272
kotakku 0:b1ce54272580 273 uint8_t ALC_M_LB;
kotakku 0:b1ce54272580 274 uint8_t ALC_L_MB;
kotakku 0:b1ce54272580 275 uint8_t ALC_L_LB;
kotakku 0:b1ce54272580 276 uint8_t Control;
kotakku 0:b1ce54272580 277 } __attribute__((packed));
kotakku 0:b1ce54272580 278
kotakku 0:b1ce54272580 279 typedef CDB12 CDB12_t;
kotakku 0:b1ce54272580 280
kotakku 0:b1ce54272580 281 struct CDB_LBA32_16 {
kotakku 0:b1ce54272580 282 uint8_t Opcode;
kotakku 0:b1ce54272580 283
kotakku 0:b1ce54272580 284 unsigned Service_Action : 5;
kotakku 0:b1ce54272580 285 unsigned Misc : 3;
kotakku 0:b1ce54272580 286
kotakku 0:b1ce54272580 287 uint8_t LBA_L_M_MB;
kotakku 0:b1ce54272580 288 uint8_t LBA_L_M_LB;
kotakku 0:b1ce54272580 289 uint8_t LBA_L_L_MB;
kotakku 0:b1ce54272580 290 uint8_t LBA_L_L_LB;
kotakku 0:b1ce54272580 291
kotakku 0:b1ce54272580 292 uint8_t A_M_M_MB;
kotakku 0:b1ce54272580 293 uint8_t A_M_M_LB;
kotakku 0:b1ce54272580 294 uint8_t A_M_L_MB;
kotakku 0:b1ce54272580 295 uint8_t A_M_L_LB;
kotakku 0:b1ce54272580 296
kotakku 0:b1ce54272580 297 uint8_t ALC_M_MB;
kotakku 0:b1ce54272580 298 uint8_t ALC_M_LB;
kotakku 0:b1ce54272580 299 uint8_t ALC_L_MB;
kotakku 0:b1ce54272580 300 uint8_t ALC_L_LB;
kotakku 0:b1ce54272580 301
kotakku 0:b1ce54272580 302 uint8_t Misc2;
kotakku 0:b1ce54272580 303 uint8_t Control;
kotakku 0:b1ce54272580 304 } __attribute__((packed));
kotakku 0:b1ce54272580 305
kotakku 0:b1ce54272580 306 struct CDB_LBA64_16 {
kotakku 0:b1ce54272580 307 uint8_t Opcode;
kotakku 0:b1ce54272580 308 uint8_t Misc;
kotakku 0:b1ce54272580 309
kotakku 0:b1ce54272580 310 uint8_t LBA_M_M_MB;
kotakku 0:b1ce54272580 311 uint8_t LBA_M_M_LB;
kotakku 0:b1ce54272580 312 uint8_t LBA_M_L_MB;
kotakku 0:b1ce54272580 313 uint8_t LBA_M_L_LB;
kotakku 0:b1ce54272580 314
kotakku 0:b1ce54272580 315 uint8_t LBA_L_M_MB;
kotakku 0:b1ce54272580 316 uint8_t LBA_L_M_LB;
kotakku 0:b1ce54272580 317 uint8_t LBA_L_L_MB;
kotakku 0:b1ce54272580 318 uint8_t LBA_L_L_LB;
kotakku 0:b1ce54272580 319
kotakku 0:b1ce54272580 320 uint8_t ALC_M_MB;
kotakku 0:b1ce54272580 321 uint8_t ALC_M_LB;
kotakku 0:b1ce54272580 322 uint8_t ALC_L_MB;
kotakku 0:b1ce54272580 323 uint8_t ALC_L_LB;
kotakku 0:b1ce54272580 324
kotakku 0:b1ce54272580 325 uint8_t Misc2;
kotakku 0:b1ce54272580 326 uint8_t Control;
kotakku 0:b1ce54272580 327 } __attribute__((packed));
kotakku 0:b1ce54272580 328
kotakku 0:b1ce54272580 329 struct InquiryResponse {
kotakku 0:b1ce54272580 330 uint8_t DeviceType : 5;
kotakku 0:b1ce54272580 331 uint8_t PeripheralQualifier : 3;
kotakku 0:b1ce54272580 332
kotakku 0:b1ce54272580 333 unsigned Reserved : 7;
kotakku 0:b1ce54272580 334 unsigned Removable : 1;
kotakku 0:b1ce54272580 335
kotakku 0:b1ce54272580 336 uint8_t Version;
kotakku 0:b1ce54272580 337
kotakku 0:b1ce54272580 338 unsigned ResponseDataFormat : 4;
kotakku 0:b1ce54272580 339 unsigned HISUP : 1;
kotakku 0:b1ce54272580 340 unsigned NormACA : 1;
kotakku 0:b1ce54272580 341 unsigned TrmTsk : 1;
kotakku 0:b1ce54272580 342 unsigned AERC : 1;
kotakku 0:b1ce54272580 343
kotakku 0:b1ce54272580 344 uint8_t AdditionalLength;
kotakku 0:b1ce54272580 345 //uint8_t Reserved3[2];
kotakku 0:b1ce54272580 346
kotakku 0:b1ce54272580 347 unsigned PROTECT : 1;
kotakku 0:b1ce54272580 348 unsigned Res : 2;
kotakku 0:b1ce54272580 349 unsigned ThreePC : 1;
kotakku 0:b1ce54272580 350 unsigned TPGS : 2;
kotakku 0:b1ce54272580 351 unsigned ACC : 1;
kotakku 0:b1ce54272580 352 unsigned SCCS : 1;
kotakku 0:b1ce54272580 353
kotakku 0:b1ce54272580 354 unsigned ADDR16 : 1;
kotakku 0:b1ce54272580 355 unsigned R1 : 1;
kotakku 0:b1ce54272580 356 unsigned R2 : 1;
kotakku 0:b1ce54272580 357 unsigned MCHNGR : 1;
kotakku 0:b1ce54272580 358 unsigned MULTIP : 1;
kotakku 0:b1ce54272580 359 unsigned VS : 1;
kotakku 0:b1ce54272580 360 unsigned ENCSERV : 1;
kotakku 0:b1ce54272580 361 unsigned BQUE : 1;
kotakku 0:b1ce54272580 362
kotakku 0:b1ce54272580 363 unsigned SoftReset : 1;
kotakku 0:b1ce54272580 364 unsigned CmdQue : 1;
kotakku 0:b1ce54272580 365 unsigned Reserved4 : 1;
kotakku 0:b1ce54272580 366 unsigned Linked : 1;
kotakku 0:b1ce54272580 367 unsigned Sync : 1;
kotakku 0:b1ce54272580 368 unsigned WideBus16Bit : 1;
kotakku 0:b1ce54272580 369 unsigned WideBus32Bit : 1;
kotakku 0:b1ce54272580 370 unsigned RelAddr : 1;
kotakku 0:b1ce54272580 371
kotakku 0:b1ce54272580 372 uint8_t VendorID[8];
kotakku 0:b1ce54272580 373 uint8_t ProductID[16];
kotakku 0:b1ce54272580 374 uint8_t RevisionID[4];
kotakku 0:b1ce54272580 375 } __attribute__((packed));
kotakku 0:b1ce54272580 376
kotakku 0:b1ce54272580 377 struct CommandBlockWrapperBase {
kotakku 0:b1ce54272580 378 uint32_t dCBWSignature;
kotakku 0:b1ce54272580 379 uint32_t dCBWTag;
kotakku 0:b1ce54272580 380 uint32_t dCBWDataTransferLength;
kotakku 0:b1ce54272580 381 uint8_t bmCBWFlags;
kotakku 0:b1ce54272580 382 public:
kotakku 0:b1ce54272580 383
kotakku 0:b1ce54272580 384 CommandBlockWrapperBase() {
kotakku 0:b1ce54272580 385 }
kotakku 0:b1ce54272580 386
kotakku 0:b1ce54272580 387 CommandBlockWrapperBase(uint32_t tag, uint32_t xflen, uint8_t flgs) :
kotakku 0:b1ce54272580 388 dCBWSignature(MASS_CBW_SIGNATURE), dCBWTag(tag), dCBWDataTransferLength(xflen), bmCBWFlags(flgs) {
kotakku 0:b1ce54272580 389 }
kotakku 0:b1ce54272580 390 } __attribute__((packed));
kotakku 0:b1ce54272580 391
kotakku 0:b1ce54272580 392 struct CommandBlockWrapper : public CommandBlockWrapperBase {
kotakku 0:b1ce54272580 393
kotakku 0:b1ce54272580 394 struct {
kotakku 0:b1ce54272580 395 uint8_t bmCBWLUN : 4;
kotakku 0:b1ce54272580 396 uint8_t bmReserved1 : 4;
kotakku 0:b1ce54272580 397 };
kotakku 0:b1ce54272580 398
kotakku 0:b1ce54272580 399 struct {
kotakku 0:b1ce54272580 400 uint8_t bmCBWCBLength : 4;
kotakku 0:b1ce54272580 401 uint8_t bmReserved2 : 4;
kotakku 0:b1ce54272580 402 };
kotakku 0:b1ce54272580 403
kotakku 0:b1ce54272580 404 uint8_t CBWCB[16];
kotakku 0:b1ce54272580 405
kotakku 0:b1ce54272580 406 public:
kotakku 0:b1ce54272580 407 // All zeroed.
kotakku 0:b1ce54272580 408
kotakku 0:b1ce54272580 409 CommandBlockWrapper() :
kotakku 0:b1ce54272580 410 CommandBlockWrapperBase(0, 0, 0), bmReserved1(0), bmReserved2(0) {
kotakku 0:b1ce54272580 411 for(int i = 0; i < 16; i++) CBWCB[i] = 0;
kotakku 0:b1ce54272580 412 }
kotakku 0:b1ce54272580 413
kotakku 0:b1ce54272580 414 // Generic Wrap, CDB zeroed.
kotakku 0:b1ce54272580 415
kotakku 0:b1ce54272580 416 CommandBlockWrapper(uint32_t tag, uint32_t xflen, uint8_t flgs, uint8_t lu, uint8_t cmdlen, uint8_t cmd) :
kotakku 0:b1ce54272580 417 CommandBlockWrapperBase(tag, xflen, flgs),
kotakku 0:b1ce54272580 418 bmCBWLUN(lu), bmReserved1(0), bmCBWCBLength(cmdlen), bmReserved2(0) {
kotakku 0:b1ce54272580 419 for(int i = 0; i < 16; i++) CBWCB[i] = 0;
kotakku 0:b1ce54272580 420 // Type punning can cause optimization problems and bugs.
kotakku 0:b1ce54272580 421 // Using reinterpret_cast to a dreinterpretifferent object is the proper way to do this.
kotakku 0:b1ce54272580 422 //(((BASICCDB_t *) CBWCB)->LUN) = cmd;
kotakku 0:b1ce54272580 423 BASICCDB_t *x = reinterpret_cast<BASICCDB_t *>(CBWCB);
kotakku 0:b1ce54272580 424 x->LUN = cmd;
kotakku 0:b1ce54272580 425 }
kotakku 0:b1ce54272580 426
kotakku 0:b1ce54272580 427 // Wrap for CDB of 6
kotakku 0:b1ce54272580 428
kotakku 0:b1ce54272580 429 CommandBlockWrapper(uint32_t tag, uint32_t xflen, CDB6_t *cdb, uint8_t dir) :
kotakku 0:b1ce54272580 430 CommandBlockWrapperBase(tag, xflen, dir),
kotakku 0:b1ce54272580 431 bmCBWLUN(cdb->LUN), bmReserved1(0), bmCBWCBLength(6), bmReserved2(0) {
kotakku 0:b1ce54272580 432 memcpy(&CBWCB, cdb, 6);
kotakku 0:b1ce54272580 433 }
kotakku 0:b1ce54272580 434 // Wrap for CDB of 10
kotakku 0:b1ce54272580 435
kotakku 0:b1ce54272580 436 CommandBlockWrapper(uint32_t tag, uint32_t xflen, CDB10_t *cdb, uint8_t dir) :
kotakku 0:b1ce54272580 437 CommandBlockWrapperBase(tag, xflen, dir),
kotakku 0:b1ce54272580 438 bmCBWLUN(cdb->LUN), bmReserved1(0), bmCBWCBLength(10), bmReserved2(0) {
kotakku 0:b1ce54272580 439 memcpy(&CBWCB, cdb, 10);
kotakku 0:b1ce54272580 440 }
kotakku 0:b1ce54272580 441 } __attribute__((packed));
kotakku 0:b1ce54272580 442
kotakku 0:b1ce54272580 443 struct CommandStatusWrapper {
kotakku 0:b1ce54272580 444 uint32_t dCSWSignature;
kotakku 0:b1ce54272580 445 uint32_t dCSWTag;
kotakku 0:b1ce54272580 446 uint32_t dCSWDataResidue;
kotakku 0:b1ce54272580 447 uint8_t bCSWStatus;
kotakku 0:b1ce54272580 448 } __attribute__((packed));
kotakku 0:b1ce54272580 449
kotakku 0:b1ce54272580 450 struct RequestSenseResponce {
kotakku 0:b1ce54272580 451 uint8_t bResponseCode;
kotakku 0:b1ce54272580 452 uint8_t bSegmentNumber;
kotakku 0:b1ce54272580 453
kotakku 0:b1ce54272580 454 uint8_t bmSenseKey : 4;
kotakku 0:b1ce54272580 455 uint8_t bmReserved : 1;
kotakku 0:b1ce54272580 456 uint8_t bmILI : 1;
kotakku 0:b1ce54272580 457 uint8_t bmEOM : 1;
kotakku 0:b1ce54272580 458 uint8_t bmFileMark : 1;
kotakku 0:b1ce54272580 459
kotakku 0:b1ce54272580 460 uint8_t Information[4];
kotakku 0:b1ce54272580 461 uint8_t bAdditionalLength;
kotakku 0:b1ce54272580 462 uint8_t CmdSpecificInformation[4];
kotakku 0:b1ce54272580 463 uint8_t bAdditionalSenseCode;
kotakku 0:b1ce54272580 464 uint8_t bAdditionalSenseQualifier;
kotakku 0:b1ce54272580 465 uint8_t bFieldReplaceableUnitCode;
kotakku 0:b1ce54272580 466 uint8_t SenseKeySpecific[3];
kotakku 0:b1ce54272580 467 } __attribute__((packed));
kotakku 0:b1ce54272580 468
kotakku 0:b1ce54272580 469 class BulkOnly : public USBDeviceConfig, public UsbConfigXtracter {
kotakku 0:b1ce54272580 470 protected:
kotakku 0:b1ce54272580 471 static const uint8_t epDataInIndex; // DataIn endpoint index
kotakku 0:b1ce54272580 472 static const uint8_t epDataOutIndex; // DataOUT endpoint index
kotakku 0:b1ce54272580 473 static const uint8_t epInterruptInIndex; // InterruptIN endpoint index
kotakku 0:b1ce54272580 474
kotakku 0:b1ce54272580 475 USB *pUsb;
kotakku 0:b1ce54272580 476 uint8_t bAddress;
kotakku 0:b1ce54272580 477 uint8_t bConfNum; // configuration number
kotakku 0:b1ce54272580 478 uint8_t bIface; // interface value
kotakku 0:b1ce54272580 479 uint8_t bNumEP; // total number of EP in the configuration
kotakku 0:b1ce54272580 480 uint32_t qNextPollTime; // next poll time
kotakku 0:b1ce54272580 481 bool bPollEnable; // poll enable flag
kotakku 0:b1ce54272580 482
kotakku 0:b1ce54272580 483 EpInfo epInfo[MASS_MAX_ENDPOINTS];
kotakku 0:b1ce54272580 484
kotakku 0:b1ce54272580 485 uint32_t dCBWTag; // Tag
kotakku 0:b1ce54272580 486 //uint32_t dCBWDataTransferLength; // Data Transfer Length
kotakku 0:b1ce54272580 487 uint8_t bLastUsbError; // Last USB error
kotakku 0:b1ce54272580 488 uint8_t bMaxLUN; // Max LUN
kotakku 0:b1ce54272580 489 uint8_t bTheLUN; // Active LUN
kotakku 0:b1ce54272580 490 uint32_t CurrentCapacity[MASS_MAX_SUPPORTED_LUN]; // Total sectors
kotakku 0:b1ce54272580 491 uint16_t CurrentSectorSize[MASS_MAX_SUPPORTED_LUN]; // Sector size, clipped to 16 bits
kotakku 0:b1ce54272580 492 bool LUNOk[MASS_MAX_SUPPORTED_LUN]; // use this to check for media changes.
kotakku 0:b1ce54272580 493 bool WriteOk[MASS_MAX_SUPPORTED_LUN];
kotakku 0:b1ce54272580 494 void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
kotakku 0:b1ce54272580 495
kotakku 0:b1ce54272580 496
kotakku 0:b1ce54272580 497 // Additional Initialization Method for Subclasses
kotakku 0:b1ce54272580 498
kotakku 0:b1ce54272580 499 virtual uint8_t OnInit() {
kotakku 0:b1ce54272580 500 return 0;
kotakku 0:b1ce54272580 501 };
kotakku 0:b1ce54272580 502 public:
kotakku 0:b1ce54272580 503 BulkOnly(USB *p);
kotakku 0:b1ce54272580 504
kotakku 0:b1ce54272580 505 uint8_t GetLastUsbError() {
kotakku 0:b1ce54272580 506 return bLastUsbError;
kotakku 0:b1ce54272580 507 };
kotakku 0:b1ce54272580 508
kotakku 0:b1ce54272580 509 uint8_t GetbMaxLUN() {
kotakku 0:b1ce54272580 510 return bMaxLUN; // Max LUN
kotakku 0:b1ce54272580 511 }
kotakku 0:b1ce54272580 512
kotakku 0:b1ce54272580 513 uint8_t GetbTheLUN() {
kotakku 0:b1ce54272580 514 return bTheLUN; // Active LUN
kotakku 0:b1ce54272580 515 }
kotakku 0:b1ce54272580 516
kotakku 0:b1ce54272580 517 bool WriteProtected(uint8_t lun);
kotakku 0:b1ce54272580 518 uint8_t MediaCTL(uint8_t lun, uint8_t ctl);
kotakku 0:b1ce54272580 519 uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, uint8_t *buf);
kotakku 0:b1ce54272580 520 uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, USBReadParser *prs);
kotakku 0:b1ce54272580 521 uint8_t Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t *buf);
kotakku 0:b1ce54272580 522 uint8_t LockMedia(uint8_t lun, uint8_t lock);
kotakku 0:b1ce54272580 523
kotakku 0:b1ce54272580 524 bool LUNIsGood(uint8_t lun);
kotakku 0:b1ce54272580 525 uint32_t GetCapacity(uint8_t lun);
kotakku 0:b1ce54272580 526 uint16_t GetSectorSize(uint8_t lun);
kotakku 0:b1ce54272580 527
kotakku 0:b1ce54272580 528 // USBDeviceConfig implementation
kotakku 0:b1ce54272580 529 uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
kotakku 0:b1ce54272580 530 uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed);
kotakku 0:b1ce54272580 531
kotakku 0:b1ce54272580 532 uint8_t Release();
kotakku 0:b1ce54272580 533 uint8_t Poll();
kotakku 0:b1ce54272580 534
kotakku 0:b1ce54272580 535 virtual uint8_t GetAddress() {
kotakku 0:b1ce54272580 536 return bAddress;
kotakku 0:b1ce54272580 537 };
kotakku 0:b1ce54272580 538
kotakku 0:b1ce54272580 539 // UsbConfigXtracter implementation
kotakku 0:b1ce54272580 540 void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
kotakku 0:b1ce54272580 541
kotakku 0:b1ce54272580 542 virtual bool DEVCLASSOK(uint8_t klass) {
kotakku 0:b1ce54272580 543 return (klass == USB_CLASS_MASS_STORAGE);
kotakku 0:b1ce54272580 544 }
kotakku 0:b1ce54272580 545
kotakku 0:b1ce54272580 546 uint8_t SCSITransaction6(CDB6_t *cdb, uint16_t buf_size, void *buf, uint8_t dir);
kotakku 0:b1ce54272580 547 uint8_t SCSITransaction10(CDB10_t *cdb, uint16_t buf_size, void *buf, uint8_t dir);
kotakku 0:b1ce54272580 548
kotakku 0:b1ce54272580 549 private:
kotakku 0:b1ce54272580 550 uint8_t Inquiry(uint8_t lun, uint16_t size, uint8_t *buf);
kotakku 0:b1ce54272580 551 uint8_t TestUnitReady(uint8_t lun);
kotakku 0:b1ce54272580 552 uint8_t RequestSense(uint8_t lun, uint16_t size, uint8_t *buf);
kotakku 0:b1ce54272580 553 uint8_t ModeSense6(uint8_t lun, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t len, uint8_t *buf);
kotakku 0:b1ce54272580 554 uint8_t GetMaxLUN(uint8_t *max_lun);
kotakku 0:b1ce54272580 555 uint8_t SetCurLUN(uint8_t lun);
kotakku 0:b1ce54272580 556 void Reset();
kotakku 0:b1ce54272580 557 uint8_t ResetRecovery();
kotakku 0:b1ce54272580 558 uint8_t ReadCapacity10(uint8_t lun, uint8_t *buf);
kotakku 0:b1ce54272580 559 void ClearAllEP();
kotakku 0:b1ce54272580 560 void CheckMedia();
kotakku 0:b1ce54272580 561 bool CheckLUN(uint8_t lun);
kotakku 0:b1ce54272580 562 uint8_t Page3F(uint8_t lun);
kotakku 0:b1ce54272580 563 bool IsValidCBW(uint8_t size, uint8_t *pcbw);
kotakku 0:b1ce54272580 564 bool IsMeaningfulCBW(uint8_t size, uint8_t *pcbw);
kotakku 0:b1ce54272580 565
kotakku 0:b1ce54272580 566 bool IsValidCSW(CommandStatusWrapper *pcsw, CommandBlockWrapperBase *pcbw);
kotakku 0:b1ce54272580 567
kotakku 0:b1ce54272580 568 uint8_t ClearEpHalt(uint8_t index);
kotakku 0:b1ce54272580 569 #if MS_WANT_PARSER
kotakku 0:b1ce54272580 570 uint8_t Transaction(CommandBlockWrapper *cbw, uint16_t bsize, void *buf, uint8_t flags);
kotakku 0:b1ce54272580 571 #endif
kotakku 0:b1ce54272580 572 uint8_t Transaction(CommandBlockWrapper *cbw, uint16_t bsize, void *buf);
kotakku 0:b1ce54272580 573 uint8_t HandleUsbError(uint8_t error, uint8_t index);
kotakku 0:b1ce54272580 574 uint8_t HandleSCSIError(uint8_t status);
kotakku 0:b1ce54272580 575
kotakku 0:b1ce54272580 576 };
kotakku 0:b1ce54272580 577
kotakku 0:b1ce54272580 578 #endif // __MASSTORAGE_H__
kotakku 0:b1ce54272580 579