├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── other-issue.md └── PULL_REQUEST_TEMPLATE.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Class ├── AUDIO │ ├── Inc │ │ └── usbh_audio.h │ └── Src │ │ └── usbh_audio.c ├── CDC │ ├── Inc │ │ └── usbh_cdc.h │ └── Src │ │ └── usbh_cdc.c ├── HID │ ├── Inc │ │ ├── usbh_hid.h │ │ ├── usbh_hid_keybd.h │ │ ├── usbh_hid_mouse.h │ │ ├── usbh_hid_parser.h │ │ └── usbh_hid_usage.h │ └── Src │ │ ├── usbh_hid.c │ │ ├── usbh_hid_keybd.c │ │ ├── usbh_hid_mouse.c │ │ └── usbh_hid_parser.c ├── MSC │ ├── Inc │ │ ├── usbh_msc.h │ │ ├── usbh_msc_bot.h │ │ └── usbh_msc_scsi.h │ └── Src │ │ ├── usbh_msc.c │ │ ├── usbh_msc_bot.c │ │ └── usbh_msc_scsi.c ├── MTP │ ├── Inc │ │ ├── usbh_mtp.h │ │ └── usbh_mtp_ptp.h │ └── Src │ │ ├── usbh_mtp.c │ │ └── usbh_mtp_ptp.c └── Template │ ├── Inc │ └── usbh_template.h │ └── Src │ └── usbh_template.c ├── Core ├── Inc │ ├── usbh_conf_template.h │ ├── usbh_core.h │ ├── usbh_ctlreq.h │ ├── usbh_def.h │ ├── usbh_ioreq.h │ └── usbh_pipes.h └── Src │ ├── usbh_conf_template.c │ ├── usbh_core.c │ ├── usbh_ctlreq.c │ ├── usbh_ioreq.c │ └── usbh_pipes.c ├── LICENSE.md ├── README.md ├── Release_Notes.html └── _htmresc ├── favicon.png ├── mini-st.css └── st_logo_2020.png /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve the quality of our software 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Caution** 11 | The Issues are strictly limited for the reporting of problem encountered with the software provided in this project. 12 | For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post a topic in the [ST Community/STM32 MCUs forum](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus). 13 | 14 | **Describe the set-up** 15 | * The board (either ST RPN reference or your custom board). 16 | * IDE or at least the compiler and its version. 17 | 18 | **Describe the bug** 19 | A clear and concise description of what the bug is. 20 | 21 | **How To Reproduce** 22 | 1. Indicate the global behavior of your application project. 23 | 24 | 2. The modules that you suspect to be the cause of the problem (Driver, BSP, MW ...). 25 | 26 | 3. The use case that generates the problem. 27 | 28 | 4. How we can reproduce the problem. 29 | 30 | 31 | **Additional context** 32 | If you have a first analysis or patch correction, thank you to share your proposal. 33 | 34 | **Screenshots** 35 | If applicable, add screenshots to help explain your problem. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/other-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Other Issue ' 3 | about: Generic issue description 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Caution** 11 | The Issues are strictly limited for the reporting of problem encountered with the software provided in this project. 12 | For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post a topic in the [ST Community/STM32 MCUs forum](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus). 13 | 14 | **Describe the set-up** 15 | * The board (either ST RPN reference or your custom board). 16 | * IDE or at least the compiler and its version. 17 | 18 | **Additional context** 19 | If you have a first analysis or a patch proposal, thank you to share your proposal. 20 | 21 | **Screenshots** 22 | If applicable, add screenshots to help explain your problem. 23 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## IMPORTANT INFORMATION 2 | 3 | ### Contributor License Agreement (CLA) 4 | * The Pull Request feature will be considered by STMicroelectronics after the signature of a **Contributor License Agreement (CLA)** by the submitter. 5 | * If you did not sign such agreement, please follow the steps mentioned in the [CONTRIBUTING.md](https://github.com/STMicroelectronics/stm32_mw_usb_host/blob/master/CONTRIBUTING.md) file. 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at https://www.st.com/content/st_com/en/contact-us.html. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing guide 2 | This document serves as a checklist before contributing to this repository. 3 | It includes links to read up on if topics are unclear to you. 4 | 5 | This guide mainly focuses on the proper use of Git. 6 | 7 | ### 1. Before opening an issue 8 | Please check the following boxes before posting an issue: 9 | - [ ] `Make sure you are using the latest commit (major releases are Tagged, but corrections are available as new commits).` 10 | - [ ] `Make sure your issue is a question/feedback/suggestions RELATED TO the software provided in this repository.` Otherwise, it should be discussed on the [ST Community/STM32 MCUs forum](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus). 11 | - [ ] `Make sure your issue is not already reported/fixed on GitHub or discussed on a previous issue.` Please refer to this [dashboard](https://github.com/orgs/STMicroelectronics/projects/5) for the list of issues and pull-requests. Do not forget to browse into the **closed** issues. 12 | 13 | ### 2. Posting the issue 14 | When you have checked the previous boxes. You will find two templates (Bug Report or Other Issue) available in the **Issues** tab of the repository ([link](https://github.com/STMicroelectronics/stm32_mw_usb_host/issues/new/choose)). 15 | 16 | ### 3. Pull Requests 17 | STMicrolectronics is happy to receive contributions from the community, based on an initial Contributor License Agreement (CLA) procedure. 18 | 19 | * If you are an individual writing original source code and you are sure **you own the intellectual property**, then you need to sign an Individual CLA (https://cla.st.com). 20 | * If you work for a company that wants also to allow you to contribute with your work, your company needs to provide a Corporate CLA (https://cla.st.com) mentioning your GitHub account name. 21 | * If you are not sure that a CLA (Individual or Corporate) has been signed for your GitHub account you can check here (https://cla.st.com). 22 | 23 | Please note that: 24 | * The Corporate CLA will always take precedence over the Individual CLA. 25 | * One CLA submission is sufficient, for any project proposed by STMicroelectronics. 26 | 27 | #### How to proceed 28 | 29 | * We recommend to engage first a communication thru an issue, in order to present your proposal. Just to confirm that it corresponds to STMicroelectronics domain or scope. 30 | * Then fork the project to your GitHub account to further develop your contribution. Please use the latest commit version. 31 | * Please, submit one Pull Request for one new feature or proposal. This will ease the analysis and the final merge if accepted. 32 | -------------------------------------------------------------------------------- /Class/AUDIO/Inc/usbh_audio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_audio.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the prototypes for the usbh_audio.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_AUDIO_H 21 | #define __USBH_AUDIO_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | 30 | /** @addtogroup USBH_LIB 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup USBH_CLASS 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup USBH_AUDIO_CLASS 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBH_AUDIO_CORE 43 | * @brief This file is the Header file for usbh_audio.c 44 | * @{ 45 | */ 46 | 47 | 48 | /** @defgroup USBH_AUDIO_CORE_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /* States for AUDIO State Machine */ 53 | typedef enum 54 | { 55 | AUDIO_INIT = 0, 56 | AUDIO_IDLE, 57 | AUDIO_CS_REQUESTS, 58 | AUDIO_SET_DEFAULT_FEATURE_UNIT, 59 | AUDIO_SET_INTERFACE, 60 | AUDIO_SET_STREAMING_INTERFACE, 61 | AUDIO_SET_CUR1, 62 | AUDIO_GET_MIN, 63 | AUDIO_GET_MAX, 64 | AUDIO_GET_RES, 65 | AUDIO_GET_CUR1, 66 | AUDIO_SET_CUR2, 67 | AUDIO_GET_CUR2, 68 | AUDIO_SET_CUR3, 69 | AUDIO_SET_INTERFACE0, 70 | AUDIO_SET_INTERFACE1, 71 | AUDIO_SET_INTERFACE2, 72 | AUDIO_ISOC_OUT, 73 | AUDIO_ISOC_IN, 74 | AUDIO_ISOC_POLL, 75 | AUDIO_ERROR, 76 | } 77 | AUDIO_StateTypeDef; 78 | 79 | typedef enum 80 | { 81 | AUDIO_REQ_INIT = 1, 82 | AUDIO_REQ_IDLE, 83 | AUDIO_REQ_SET_DEFAULT_IN_INTERFACE, 84 | AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE, 85 | AUDIO_REQ_SET_IN_INTERFACE, 86 | AUDIO_REQ_SET_OUT_INTERFACE, 87 | AUDIO_REQ_CS_REQUESTS, 88 | } 89 | AUDIO_ReqStateTypeDef; 90 | 91 | typedef enum 92 | { 93 | AUDIO_REQ_SET_VOLUME = 1, 94 | AUDIO_REQ_SET_MUTE, 95 | AUDIO_REQ_GET_CURR_VOLUME, 96 | AUDIO_REQ_GET_MIN_VOLUME, 97 | AUDIO_REQ_GET_MAX_VOLUME, 98 | AUDIO_REQ_GET_VOLUME, 99 | AUDIO_REQ_GET_RESOLUTION, 100 | AUDIO_REQ_CS_IDLE, 101 | } 102 | AUDIO_CSReqStateTypeDef; 103 | 104 | typedef enum 105 | { 106 | AUDIO_PLAYBACK_INIT = 1, 107 | AUDIO_PLAYBACK_SET_EP, 108 | AUDIO_PLAYBACK_SET_EP_FREQ, 109 | AUDIO_PLAYBACK_PLAY, 110 | AUDIO_PLAYBACK_IDLE, 111 | } 112 | AUDIO_PlayStateTypeDef; 113 | 114 | typedef enum 115 | { 116 | VOLUME_UP = 1, 117 | VOLUME_DOWN = 2, 118 | } 119 | AUDIO_VolumeCtrlTypeDef; 120 | 121 | typedef enum 122 | { 123 | AUDIO_CONTROL_INIT = 1, 124 | AUDIO_CONTROL_CHANGE, 125 | AUDIO_CONTROL_IDLE, 126 | AUDIO_CONTROL_VOLUME_UP, 127 | AUDIO_CONTROL_VOLUME_DOWN, 128 | } 129 | AUDIO_ControlStateTypeDef; 130 | 131 | 132 | typedef enum 133 | { 134 | AUDIO_DATA_START_OUT = 1, 135 | AUDIO_DATA_OUT, 136 | } 137 | AUDIO_ProcessingTypeDef; 138 | 139 | /* Structure for AUDIO process */ 140 | typedef struct 141 | { 142 | uint8_t Channels; 143 | uint8_t Bits; 144 | uint32_t SampleRate; 145 | } 146 | AUDIO_FormatTypeDef; 147 | 148 | typedef struct 149 | { 150 | uint8_t Ep; 151 | uint16_t EpSize; 152 | uint8_t AltSettings; 153 | uint8_t interface; 154 | uint8_t valid; 155 | uint16_t Poll; 156 | } 157 | AUDIO_STREAMING_IN_HandleTypeDef; 158 | 159 | typedef struct 160 | { 161 | uint8_t Ep; 162 | uint16_t EpSize; 163 | uint8_t AltSettings; 164 | uint8_t interface; 165 | uint8_t valid; 166 | uint16_t Poll; 167 | } 168 | AUDIO_STREAMING_OUT_HandleTypeDef; 169 | 170 | 171 | typedef struct 172 | { 173 | uint8_t mute; 174 | uint32_t volumeMin; 175 | uint32_t volumeMax; 176 | uint32_t volume; 177 | uint32_t resolution; 178 | } 179 | AUDIO_ControlAttributeTypeDef; 180 | 181 | typedef struct 182 | { 183 | 184 | uint8_t Ep; 185 | uint16_t EpSize; 186 | uint8_t interface; 187 | uint8_t AltSettings; 188 | uint8_t supported; 189 | 190 | uint8_t Pipe; 191 | uint8_t Poll; 192 | uint32_t timer; 193 | 194 | uint8_t asociated_as; 195 | uint8_t asociated_mixer; 196 | uint8_t asociated_selector; 197 | uint8_t asociated_feature; 198 | uint8_t asociated_terminal; 199 | uint8_t asociated_channels; 200 | 201 | uint32_t frequency; 202 | uint8_t *buf; 203 | uint8_t *cbuf; 204 | uint32_t partial_ptr; 205 | 206 | uint32_t global_ptr; 207 | uint16_t frame_length; 208 | uint32_t total_length; 209 | 210 | AUDIO_ControlAttributeTypeDef attribute; 211 | } 212 | AUDIO_InterfaceStreamPropTypeDef; 213 | 214 | typedef struct 215 | { 216 | 217 | uint8_t Ep; 218 | uint16_t EpSize; 219 | uint8_t interface; 220 | uint8_t supported; 221 | 222 | uint8_t Pipe; 223 | uint8_t Poll; 224 | uint32_t timer; 225 | } 226 | AUDIO_InterfaceControlPropTypeDef; 227 | 228 | 229 | #define AUDIO_MAX_AUDIO_STD_INTERFACE 5U 230 | #define AUDIO_MAX_FREQ_SUPPORTED 5U 231 | #define AUDIO_MAX_STREAMING_INTERFACE 5U 232 | #define AUDIO_MAX_NUM_IN_TERMINAL 4U 233 | #define AUDIO_MAX_NUM_OUT_TERMINAL 4U 234 | #define AUDIO_MAX_NUM_FEATURE_UNIT 4U 235 | #define AUDIO_MAX_NUM_MIXER_UNIT 4U 236 | #define AUDIO_MAX_NUM_SELECTOR_UNIT 4U 237 | 238 | #define HEADPHONE_SUPPORTED 1U 239 | #define MICROPHONE_SUPPORTED 2U 240 | #define HEADSET_SUPPORTED 3U 241 | 242 | #define AUDIO_MAX_SAMFREQ_NBR 5U 243 | #define AUDIO_MAX_INTERFACE_NBR 5U 244 | #define AUDIO_MAX_CONTROLS_NBR 5U 245 | 246 | /*Class-Specific AS(Audio Streaming) Interface Descriptor*/ 247 | typedef struct 248 | { 249 | uint8_t bLength; 250 | uint8_t bDescriptorType; 251 | uint8_t bDescriptorSubtype; 252 | uint8_t bTerminalLink; 253 | uint8_t bDelay; 254 | uint8_t wFormatTag[2]; 255 | } 256 | AUDIO_ASGeneralDescTypeDef; 257 | 258 | /*Class-Specific AS(Audio Streaming) Format Type Descriptor*/ 259 | typedef struct 260 | { 261 | uint8_t bLength; 262 | uint8_t bDescriptorType; 263 | uint8_t bDescriptorSubtype; 264 | uint8_t bFormatType; 265 | uint8_t bNrChannels; 266 | uint8_t bSubframeSize; 267 | uint8_t bBitResolution; 268 | uint8_t bSamFreqType; 269 | uint8_t tSamFreq[AUDIO_MAX_SAMFREQ_NBR][3]; 270 | } 271 | AUDIO_ASFormatTypeDescTypeDef; 272 | 273 | /*Class-Specific AS(Audio Streaming) Interface Descriptor*/ 274 | typedef struct 275 | { 276 | AUDIO_ASGeneralDescTypeDef *GeneralDesc; 277 | AUDIO_ASFormatTypeDescTypeDef *FormatTypeDesc; 278 | } 279 | AUDIO_ASDescTypeDef; 280 | 281 | /* 4.3.2 Class-Specific AC Interface Descriptor */ 282 | 283 | typedef struct 284 | { 285 | uint8_t bLength; 286 | uint8_t bDescriptorType; 287 | uint8_t bDescriptorSubtype; 288 | uint8_t bcdADC[2]; 289 | uint8_t wTotalLength[2]; 290 | uint8_t bInCollection; 291 | uint8_t baInterfaceNr[AUDIO_MAX_INTERFACE_NBR]; 292 | } 293 | AUDIO_HeaderDescTypeDef; 294 | 295 | /* 4.3.2.1 Input Terminal Descriptor */ 296 | typedef struct 297 | { 298 | uint8_t bLength; 299 | uint8_t bDescriptorType; 300 | uint8_t bDescriptorSubtype; 301 | uint8_t bTerminalID; 302 | uint8_t wTerminalType[2]; 303 | uint8_t bAssocTerminal; 304 | uint8_t bNrChannels; 305 | uint8_t wChannelConfig[2]; 306 | uint8_t iChannelNames; 307 | uint8_t iTerminal; 308 | } 309 | AUDIO_ITDescTypeDef; 310 | 311 | /* 4.3.2.2 Output Terminal Descriptor */ 312 | typedef struct 313 | { 314 | uint8_t bLength; 315 | uint8_t bDescriptorType; 316 | uint8_t bDescriptorSubtype; 317 | uint8_t bTerminalID; 318 | uint8_t wTerminalType[2]; 319 | uint8_t bAssocTerminal; 320 | uint8_t bSourceID; 321 | uint8_t iTerminal; 322 | } 323 | AUDIO_OTDescTypeDef; 324 | 325 | /* 4.3.2.3 Feature Descriptor */ 326 | typedef struct 327 | { 328 | uint8_t bLength; 329 | uint8_t bDescriptorType; 330 | uint8_t bDescriptorSubtype; 331 | uint8_t bUnitID; 332 | uint8_t bSourceID; 333 | uint8_t bControlSize; 334 | uint8_t bmaControls[AUDIO_MAX_CONTROLS_NBR][2]; 335 | } 336 | AUDIO_FeatureDescTypeDef; 337 | 338 | 339 | /* 4.3.2.3 Feature Descriptor */ 340 | typedef struct 341 | { 342 | uint8_t bLength; 343 | uint8_t bDescriptorType; 344 | uint8_t bDescriptorSubtype; 345 | uint8_t bUnitID; 346 | uint8_t bNrInPins; 347 | uint8_t bSourceID0; 348 | uint8_t bSourceID1; 349 | uint8_t bNrChannels; 350 | uint8_t bmChannelsConfig[2]; 351 | uint8_t iChannelsNames; 352 | uint8_t bmaControls; 353 | uint8_t iMixer; 354 | } 355 | AUDIO_MixerDescTypeDef; 356 | 357 | 358 | 359 | /* 4.3.2.3 Feature Descriptor */ 360 | typedef struct 361 | { 362 | uint8_t bLength; 363 | uint8_t bDescriptorType; 364 | uint8_t bDescriptorSubtype; 365 | uint8_t bUnitID; 366 | uint8_t bNrInPins; 367 | uint8_t bSourceID0; 368 | uint8_t iSelector; 369 | } 370 | AUDIO_SelectorDescTypeDef; 371 | 372 | /*Class-Specific AC(Audio Control) Interface Descriptor*/ 373 | typedef struct 374 | { 375 | AUDIO_HeaderDescTypeDef *HeaderDesc; 376 | AUDIO_ITDescTypeDef *InputTerminalDesc [AUDIO_MAX_NUM_IN_TERMINAL]; 377 | AUDIO_OTDescTypeDef *OutputTerminalDesc[AUDIO_MAX_NUM_OUT_TERMINAL]; 378 | AUDIO_FeatureDescTypeDef *FeatureUnitDesc [AUDIO_MAX_NUM_FEATURE_UNIT]; 379 | AUDIO_MixerDescTypeDef *MixerUnitDesc [AUDIO_MAX_NUM_MIXER_UNIT]; 380 | AUDIO_SelectorDescTypeDef *SelectorUnitDesc [AUDIO_MAX_NUM_SELECTOR_UNIT]; 381 | } 382 | AUDIO_ACDescTypeDef; 383 | 384 | /*Class-Specific AC : Global descriptor*/ 385 | 386 | typedef struct 387 | { 388 | AUDIO_ACDescTypeDef cs_desc; /* Only one control descriptor*/ 389 | AUDIO_ASDescTypeDef as_desc[AUDIO_MAX_STREAMING_INTERFACE]; 390 | 391 | uint16_t ASNum; 392 | uint16_t InputTerminalNum; 393 | uint16_t OutputTerminalNum; 394 | uint16_t FeatureUnitNum; 395 | uint16_t SelectorUnitNum; 396 | uint16_t MixerUnitNum; 397 | } 398 | AUDIO_ClassSpecificDescTypedef; 399 | 400 | 401 | typedef struct _AUDIO_Process 402 | { 403 | AUDIO_ReqStateTypeDef req_state; 404 | AUDIO_CSReqStateTypeDef cs_req_state; 405 | AUDIO_PlayStateTypeDef play_state; 406 | AUDIO_ControlStateTypeDef control_state; 407 | AUDIO_ProcessingTypeDef processing_state; 408 | 409 | AUDIO_STREAMING_IN_HandleTypeDef stream_in[AUDIO_MAX_AUDIO_STD_INTERFACE]; 410 | AUDIO_STREAMING_OUT_HandleTypeDef stream_out[AUDIO_MAX_AUDIO_STD_INTERFACE]; 411 | AUDIO_ClassSpecificDescTypedef class_desc; 412 | 413 | AUDIO_InterfaceStreamPropTypeDef headphone; 414 | AUDIO_InterfaceStreamPropTypeDef microphone; 415 | AUDIO_InterfaceControlPropTypeDef control; 416 | uint16_t mem [8]; 417 | uint8_t temp_feature; 418 | uint8_t temp_channels; 419 | } 420 | AUDIO_HandleTypeDef; 421 | 422 | /** 423 | * @} 424 | */ 425 | 426 | /** @defgroup USBH_AUDIO_CORE_Exported_Defines 427 | * @{ 428 | */ 429 | 430 | 431 | /*Audio Interface Subclass Codes*/ 432 | #define AC_CLASS 0x01U 433 | 434 | /* A.2 Audio Interface Subclass Codes */ 435 | #define USB_SUBCLASS_AUDIOCONTROL 0x01U 436 | #define USB_SUBCLASS_AUDIOSTREAMING 0x02U 437 | #define USB_SUBCLASS_MIDISTREAMING 0x03U 438 | 439 | #define USB_DESC_TYPE_CS_INTERFACE 0x24U 440 | #define USB_DESC_TYPE_CS_ENDPOINT 0x25U 441 | 442 | /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */ 443 | #define UAC_HEADER 0x01U 444 | #define UAC_INPUT_TERMINAL 0x02U 445 | #define UAC_OUTPUT_TERMINAL 0x03U 446 | #define UAC_MIXER_UNIT 0x04U 447 | #define UAC_SELECTOR_UNIT 0x05U 448 | #define UAC_FEATURE_UNIT 0x06U 449 | #define UAC_PROCESSING_UNIT 0x07U 450 | #define UAC_EXTENSION_UNIT 0x08U 451 | 452 | /*Audio Class-Specific Endpoint Descriptor Subtypes*/ 453 | #define EP_CONTROL_UNDEFINED 0x00U 454 | #define SAMPLING_FREQ_CONTROL 0x01U 455 | #define PITCH_CONTROL 0x02U 456 | 457 | /*Feature unit control selector*/ 458 | #define FU_CONTROL_UNDEFINED 0x00U 459 | #define MUTE_CONTROL 0x01U 460 | #define VOLUME_CONTROL 0x02U 461 | #define BASS_CONTROL 0x03U 462 | #define MID_CONTROL 0x04U 463 | #define TREBLE_CONTROL 0x05U 464 | #define GRAPHIC_EQUALIZER_CONTROL 0x06U 465 | #define AUTOMATIC_GAIN_CONTROL 0x07U 466 | #define DELAY_CONTROL 0x08U 467 | #define BASS_BOOST_CONTROL 0x09U 468 | #define LOUDNESS_CONTROL 0x0AU 469 | 470 | /*Terminal control selector*/ 471 | #define TE_CONTROL_UNDEFINED 0x00U 472 | #define COPY_PROTECT_CONTROL 0x01U 473 | 474 | 475 | /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */ 476 | #define UAC_AS_GENERAL 0x01U 477 | #define UAC_FORMAT_TYPE 0x02U 478 | #define UAC_FORMAT_SPECIFIC 0x03U 479 | 480 | /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */ 481 | #define UAC_EP_GENERAL 0x01U 482 | 483 | /* A.9 Audio Class-Specific Request Codes */ 484 | #define UAC_SET_ 0x00U 485 | #define UAC_GET_ 0x80U 486 | 487 | #define UAC__CUR 0x01U 488 | #define UAC__MIN 0x02U 489 | #define UAC__MAX 0x03U 490 | #define UAC__RES 0x04U 491 | #define UAC__MEM 0x05U 492 | 493 | #define UAC_SET_CUR (UAC_SET_ | UAC__CUR) 494 | #define UAC_GET_CUR (UAC_GET_ | UAC__CUR) 495 | #define UAC_SET_MIN (UAC_SET_ | UAC__MIN) 496 | #define UAC_GET_MIN (UAC_GET_ | UAC__MIN) 497 | #define UAC_SET_MAX (UAC_SET_ | UAC__MAX) 498 | #define UAC_GET_MAX (UAC_GET_ | UAC__MAX) 499 | #define UAC_SET_RES (UAC_SET_ | UAC__RES) 500 | #define UAC_GET_RES (UAC_GET_ | UAC__RES) 501 | #define UAC_SET_MEM (UAC_SET_ | UAC__MEM) 502 | #define UAC_GET_MEM (UAC_GET_ | UAC__MEM) 503 | 504 | #define UAC_GET_STAT 0xffU 505 | 506 | /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */ 507 | #define UAC_MS_HEADER 0x01U 508 | #define UAC_MIDI_IN_JACK 0x02U 509 | #define UAC_MIDI_OUT_JACK 0x03U 510 | 511 | /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */ 512 | #define UAC_MS_GENERAL 0x01U 513 | 514 | /* Terminals - 2.1 USB Terminal Types */ 515 | #define UAC_TERMINAL_UNDEFINED 0x100U 516 | #define UAC_TERMINAL_STREAMING 0x101U 517 | #define UAC_TERMINAL_VENDOR_SPEC 0x1FFU 518 | 519 | /** 520 | * @} 521 | */ 522 | 523 | /** @defgroup USBH_AUDIO_CORE_Exported_Macros 524 | * @{ 525 | */ 526 | /** 527 | * @} 528 | */ 529 | 530 | /** @defgroup USBH_AUDIO_CORE_Exported_Variables 531 | * @{ 532 | */ 533 | extern USBH_ClassTypeDef AUDIO_Class; 534 | #define USBH_AUDIO_CLASS &AUDIO_Class 535 | /** 536 | * @} 537 | */ 538 | 539 | /** @defgroup USBH_AUDIO_CORE_Exported_FunctionsPrototype 540 | * @{ 541 | */ 542 | USBH_StatusTypeDef USBH_AUDIO_SetFrequency(USBH_HandleTypeDef *phost, 543 | uint16_t SampleRate, 544 | uint8_t NbrChannels, 545 | uint8_t BitPerSample); 546 | 547 | USBH_StatusTypeDef USBH_AUDIO_Play(USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length); 548 | USBH_StatusTypeDef USBH_AUDIO_Stop(USBH_HandleTypeDef *phost); 549 | USBH_StatusTypeDef USBH_AUDIO_Suspend(USBH_HandleTypeDef *phost); 550 | USBH_StatusTypeDef USBH_AUDIO_Resume(USBH_HandleTypeDef *phost); 551 | USBH_StatusTypeDef USBH_AUDIO_SetVolume(USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl); 552 | USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer(USBH_HandleTypeDef *phost, uint8_t *buf); 553 | int32_t USBH_AUDIO_GetOutOffset(USBH_HandleTypeDef *phost); 554 | 555 | void USBH_AUDIO_FrequencySet(USBH_HandleTypeDef *phost); 556 | 557 | #define USBH_AUDIO_FrequencySetCallback USBH_AUDIO_FrequencySet 558 | void USBH_AUDIO_BufferEmptyCallback(USBH_HandleTypeDef *phost); 559 | /** 560 | * @} 561 | */ 562 | 563 | #ifdef __cplusplus 564 | } 565 | #endif 566 | 567 | #endif /* __USBH_AUDIO_H */ 568 | 569 | /** 570 | * @} 571 | */ 572 | 573 | /** 574 | * @} 575 | */ 576 | 577 | /** 578 | * @} 579 | */ 580 | 581 | /** 582 | * @} 583 | */ 584 | 585 | -------------------------------------------------------------------------------- /Class/CDC/Inc/usbh_cdc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_cdc.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the prototypes for the usbh_cdc.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_CDC_H 21 | #define __USBH_CDC_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | 30 | 31 | /** @addtogroup USBH_LIB 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup USBH_CLASS 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup USBH_CDC_CLASS 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBH_CDC_CORE 44 | * @brief This file is the Header file for usbh_core.c 45 | * @{ 46 | */ 47 | 48 | 49 | 50 | 51 | /*Communication Class codes*/ 52 | #define USB_CDC_CLASS 0x02U 53 | #define COMMUNICATION_INTERFACE_CLASS_CODE 0x02U 54 | 55 | /*Data Interface Class Codes*/ 56 | #define DATA_INTERFACE_CLASS_CODE 0x0AU 57 | 58 | /*Communication sub class codes*/ 59 | #define RESERVED 0x00U 60 | #define DIRECT_LINE_CONTROL_MODEL 0x01U 61 | #define ABSTRACT_CONTROL_MODEL 0x02U 62 | #define TELEPHONE_CONTROL_MODEL 0x03U 63 | #define MULTICHANNEL_CONTROL_MODEL 0x04U 64 | #define CAPI_CONTROL_MODEL 0x05U 65 | #define ETHERNET_NETWORKING_CONTROL_MODEL 0x06U 66 | #define ATM_NETWORKING_CONTROL_MODEL 0x07U 67 | 68 | 69 | /*Communication Interface Class Control Protocol Codes*/ 70 | #define NO_CLASS_SPECIFIC_PROTOCOL_CODE 0x00U 71 | #define COMMON_AT_COMMAND 0x01U 72 | #define VENDOR_SPECIFIC 0xFFU 73 | 74 | 75 | #define CS_INTERFACE 0x24U 76 | #define CDC_PAGE_SIZE_64 0x40U 77 | 78 | /*Class-Specific Request Codes*/ 79 | #define CDC_SEND_ENCAPSULATED_COMMAND 0x00U 80 | #define CDC_GET_ENCAPSULATED_RESPONSE 0x01U 81 | #define CDC_SET_COMM_FEATURE 0x02U 82 | #define CDC_GET_COMM_FEATURE 0x03U 83 | #define CDC_CLEAR_COMM_FEATURE 0x04U 84 | 85 | #define CDC_SET_AUX_LINE_STATE 0x10U 86 | #define CDC_SET_HOOK_STATE 0x11U 87 | #define CDC_PULSE_SETUP 0x12U 88 | #define CDC_SEND_PULSE 0x13U 89 | #define CDC_SET_PULSE_TIME 0x14U 90 | #define CDC_RING_AUX_JACK 0x15U 91 | 92 | #define CDC_SET_LINE_CODING 0x20U 93 | #define CDC_GET_LINE_CODING 0x21U 94 | #define CDC_SET_CONTROL_LINE_STATE 0x22U 95 | #define CDC_SEND_BREAK 0x23U 96 | 97 | #define CDC_SET_RINGER_PARMS 0x30U 98 | #define CDC_GET_RINGER_PARMS 0x31U 99 | #define CDC_SET_OPERATION_PARMS 0x32U 100 | #define CDC_GET_OPERATION_PARMS 0x33U 101 | #define CDC_SET_LINE_PARMS 0x34U 102 | #define CDC_GET_LINE_PARMS 0x35U 103 | #define CDC_DIAL_DIGITS 0x36U 104 | #define CDC_SET_UNIT_PARAMETER 0x37U 105 | #define CDC_GET_UNIT_PARAMETER 0x38U 106 | #define CDC_CLEAR_UNIT_PARAMETER 0x39U 107 | #define CDC_GET_PROFILE 0x3AU 108 | 109 | #define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40U 110 | #define CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x41U 111 | #define CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x42U 112 | #define CDC_SET_ETHERNET_PACKET_FILTER 0x43U 113 | #define CDC_GET_ETHERNET_STATISTIC 0x44U 114 | 115 | #define CDC_SET_ATM_DATA_FORMAT 0x50U 116 | #define CDC_GET_ATM_DEVICE_STATISTICS 0x51U 117 | #define CDC_SET_ATM_DEFAULT_VC 0x52U 118 | #define CDC_GET_ATM_VC_STATISTICS 0x53U 119 | 120 | 121 | /* wValue for SetControlLineState*/ 122 | #define CDC_ACTIVATE_CARRIER_SIGNAL_RTS 0x0002U 123 | #define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS 0x0000U 124 | #define CDC_ACTIVATE_SIGNAL_DTR 0x0001U 125 | #define CDC_DEACTIVATE_SIGNAL_DTR 0x0000U 126 | 127 | #define LINE_CODING_STRUCTURE_SIZE 0x07U 128 | /** 129 | * @} 130 | */ 131 | 132 | /** @defgroup USBH_CDC_CORE_Exported_Types 133 | * @{ 134 | */ 135 | 136 | /* States for CDC State Machine */ 137 | typedef enum 138 | { 139 | CDC_IDLE = 0U, 140 | CDC_SEND_DATA, 141 | CDC_SEND_DATA_WAIT, 142 | CDC_RECEIVE_DATA, 143 | CDC_RECEIVE_DATA_WAIT, 144 | } 145 | CDC_DataStateTypeDef; 146 | 147 | typedef enum 148 | { 149 | CDC_IDLE_STATE = 0U, 150 | CDC_SET_LINE_CODING_STATE, 151 | CDC_GET_LAST_LINE_CODING_STATE, 152 | CDC_TRANSFER_DATA, 153 | CDC_ERROR_STATE, 154 | } 155 | CDC_StateTypeDef; 156 | 157 | 158 | /*Line coding structure*/ 159 | typedef union _CDC_LineCodingStructure 160 | { 161 | uint8_t Array[LINE_CODING_STRUCTURE_SIZE]; 162 | 163 | struct 164 | { 165 | 166 | uint32_t dwDTERate; /*Data terminal rate, in bits per second*/ 167 | uint8_t bCharFormat; /*Stop bits 168 | 0 - 1 Stop bit 169 | 1 - 1.5 Stop bits 170 | 2 - 2 Stop bits*/ 171 | uint8_t bParityType; /* Parity 172 | 0 - None 173 | 1 - Odd 174 | 2 - Even 175 | 3 - Mark 176 | 4 - Space*/ 177 | uint8_t bDataBits; /* Data bits (5, 6, 7, 8 or 16). */ 178 | } b; 179 | } 180 | CDC_LineCodingTypeDef; 181 | 182 | 183 | 184 | /* Header Functional Descriptor 185 | -------------------------------------------------------------------------------- 186 | Offset| field | Size | Value | Description 187 | ------|---------------------|-------|------------|------------------------------ 188 | 0 | bFunctionLength | 1 | number | Size of this descriptor. 189 | 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24) 190 | 2 | bDescriptorSubtype | 1 | Constant | Identifier (ID) of functional 191 | | | | | descriptor. 192 | 3 | bcdCDC | 2 | | 193 | | | | Number | USB Class Definitions for 194 | | | | | Communication Devices Specification 195 | | | | | release number in binary-coded 196 | | | | | decimal 197 | ------|---------------------|-------|------------|------------------------------ 198 | */ 199 | typedef struct _FunctionalDescriptorHeader 200 | { 201 | uint8_t bLength; /*Size of this descriptor.*/ 202 | uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/ 203 | uint8_t bDescriptorSubType; /* Header functional descriptor subtype as*/ 204 | uint16_t bcdCDC; /* USB Class Definitions for Communication 205 | Devices Specification release number in 206 | binary-coded decimal. */ 207 | } 208 | CDC_HeaderFuncDesc_TypeDef; 209 | /* Call Management Functional Descriptor 210 | -------------------------------------------------------------------------------- 211 | Offset| field | Size | Value | Description 212 | ------|---------------------|-------|------------|------------------------------ 213 | 0 | bFunctionLength | 1 | number | Size of this descriptor. 214 | 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24) 215 | 2 | bDescriptorSubtype | 1 | Constant | Call Management functional 216 | | | | | descriptor subtype. 217 | 3 | bmCapabilities | 1 | Bitmap | The capabilities that this configuration 218 | | | | | supports: 219 | | | | | D7..D2: RESERVED (Reset to zero) 220 | | | | | D1: 0 - Device sends/receives call 221 | | | | | management information only over 222 | | | | | the Communication Class 223 | | | | | interface. 224 | | | | | 1 - Device can send/receive call 225 | | \ | | management information over a 226 | | | | | Data Class interface. 227 | | | | | D0: 0 - Device does not handle call 228 | | | | | management itself. 229 | | | | | 1 - Device handles call 230 | | | | | management itself. 231 | | | | | The previous bits, in combination, identify 232 | | | | | which call management scenario is used. If bit 233 | | | | | D0 is reset to 0, then the value of bit D1 is 234 | | | | | ignored. In this case, bit D1 is reset to zero for 235 | | | | | future compatibility. 236 | 4 | bDataInterface | 1 | Number | Interface number of Data Class interface 237 | | | | | optionally used for call management. 238 | ------|---------------------|-------|------------|------------------------------ 239 | */ 240 | typedef struct _CallMgmtFunctionalDescriptor 241 | { 242 | uint8_t bLength; /*Size of this functional descriptor, in bytes.*/ 243 | uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/ 244 | uint8_t bDescriptorSubType; /* Call Management functional descriptor subtype*/ 245 | uint8_t bmCapabilities; /* bmCapabilities: D0+D1 */ 246 | uint8_t bDataInterface; /*bDataInterface: 1*/ 247 | } 248 | CDC_CallMgmtFuncDesc_TypeDef; 249 | /* Abstract Control Management Functional Descriptor 250 | -------------------------------------------------------------------------------- 251 | Offset| field | Size | Value | Description 252 | ------|---------------------|-------|------------|------------------------------ 253 | 0 | bFunctionLength | 1 | number | Size of functional descriptor, in bytes. 254 | 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24) 255 | 2 | bDescriptorSubtype | 1 | Constant | Abstract Control Management 256 | | | | | functional descriptor subtype. 257 | 3 | bmCapabilities | 1 | Bitmap | The capabilities that this configuration 258 | | | | | supports ((A bit value of zero means that the 259 | | | | | request is not supported.) ) 260 | D7..D4: RESERVED (Reset to zero) 261 | | | | | D3: 1 - Device supports the notification 262 | | | | | Network_Connection. 263 | | | | | D2: 1 - Device supports the request 264 | | | | | Send_Break 265 | | | | | D1: 1 - Device supports the request 266 | | \ | | combination of Set_Line_Coding, 267 | | | | | Set_Control_Line_State, Get_Line_Coding, and the 268 | notification Serial_State. 269 | | | | | D0: 1 - Device supports the request 270 | | | | | combination of Set_Comm_Feature, 271 | | | | | Clear_Comm_Feature, and Get_Comm_Feature. 272 | | | | | The previous bits, in combination, identify 273 | | | | | which requests/notifications are supported by 274 | | | | | a Communication Class interface with the 275 | | | | | SubClass code of Abstract Control Model. 276 | ------|---------------------|-------|------------|------------------------------ 277 | */ 278 | typedef struct _AbstractCntrlMgmtFunctionalDescriptor 279 | { 280 | uint8_t bLength; /*Size of this functional descriptor, in bytes.*/ 281 | uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/ 282 | uint8_t bDescriptorSubType; /* Abstract Control Management functional 283 | descriptor subtype*/ 284 | uint8_t bmCapabilities; /* The capabilities that this configuration supports */ 285 | } 286 | CDC_AbstCntrlMgmtFuncDesc_TypeDef; 287 | /* Union Functional Descriptor 288 | -------------------------------------------------------------------------------- 289 | Offset| field | Size | Value | Description 290 | ------|---------------------|-------|------------|------------------------------ 291 | 0 | bFunctionLength | 1 | number | Size of this descriptor. 292 | 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24) 293 | 2 | bDescriptorSubtype | 1 | Constant | Union functional 294 | | | | | descriptor subtype. 295 | 3 | bMasterInterface | 1 | Constant | The interface number of the 296 | | | | | Communication or Data Class interface 297 | 4 | bSlaveInterface0 | 1 | Number | nterface number of first slave or associated 298 | | | | | interface in the union. 299 | ------|---------------------|-------|------------|------------------------------ 300 | */ 301 | typedef struct _UnionFunctionalDescriptor 302 | { 303 | uint8_t bLength; /*Size of this functional descriptor, in bytes*/ 304 | uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/ 305 | uint8_t bDescriptorSubType; /* Union functional descriptor SubType*/ 306 | uint8_t bMasterInterface; /* The interface number of the Communication or 307 | Data Class interface,*/ 308 | uint8_t bSlaveInterface0; /*Interface number of first slave*/ 309 | } 310 | CDC_UnionFuncDesc_TypeDef; 311 | 312 | typedef struct _USBH_CDCInterfaceDesc 313 | { 314 | CDC_HeaderFuncDesc_TypeDef CDC_HeaderFuncDesc; 315 | CDC_CallMgmtFuncDesc_TypeDef CDC_CallMgmtFuncDesc; 316 | CDC_AbstCntrlMgmtFuncDesc_TypeDef CDC_AbstCntrlMgmtFuncDesc; 317 | CDC_UnionFuncDesc_TypeDef CDC_UnionFuncDesc; 318 | } 319 | CDC_InterfaceDesc_Typedef; 320 | 321 | 322 | /* Structure for CDC process */ 323 | typedef struct 324 | { 325 | uint8_t NotifPipe; 326 | uint8_t NotifEp; 327 | uint8_t buff[8]; 328 | uint16_t NotifEpSize; 329 | } 330 | CDC_CommItfTypedef; 331 | 332 | typedef struct 333 | { 334 | uint8_t InPipe; 335 | uint8_t OutPipe; 336 | uint8_t OutEp; 337 | uint8_t InEp; 338 | uint8_t buff[8]; 339 | uint16_t OutEpSize; 340 | uint16_t InEpSize; 341 | } 342 | CDC_DataItfTypedef; 343 | 344 | /* Structure for CDC process */ 345 | typedef struct _CDC_Process 346 | { 347 | CDC_CommItfTypedef CommItf; 348 | CDC_DataItfTypedef DataItf; 349 | uint8_t *pTxData; 350 | uint8_t *pRxData; 351 | uint32_t TxDataLength; 352 | uint32_t RxDataLength; 353 | CDC_InterfaceDesc_Typedef CDC_Desc; 354 | CDC_LineCodingTypeDef LineCoding; 355 | CDC_LineCodingTypeDef *pUserLineCoding; 356 | CDC_StateTypeDef state; 357 | CDC_DataStateTypeDef data_tx_state; 358 | CDC_DataStateTypeDef data_rx_state; 359 | uint8_t Rx_Poll; 360 | } 361 | CDC_HandleTypeDef; 362 | 363 | /** 364 | * @} 365 | */ 366 | 367 | /** @defgroup USBH_CDC_CORE_Exported_Defines 368 | * @{ 369 | */ 370 | 371 | /** 372 | * @} 373 | */ 374 | 375 | /** @defgroup USBH_CDC_CORE_Exported_Macros 376 | * @{ 377 | */ 378 | /** 379 | * @} 380 | */ 381 | 382 | /** @defgroup USBH_CDC_CORE_Exported_Variables 383 | * @{ 384 | */ 385 | extern USBH_ClassTypeDef CDC_Class; 386 | #define USBH_CDC_CLASS &CDC_Class 387 | 388 | /** 389 | * @} 390 | */ 391 | 392 | /** @defgroup USBH_CDC_CORE_Exported_FunctionsPrototype 393 | * @{ 394 | */ 395 | 396 | USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost, 397 | CDC_LineCodingTypeDef *linecoding); 398 | 399 | USBH_StatusTypeDef USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost, 400 | CDC_LineCodingTypeDef *linecoding); 401 | 402 | USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost, 403 | uint8_t *pbuff, 404 | uint32_t length); 405 | 406 | USBH_StatusTypeDef USBH_CDC_Receive(USBH_HandleTypeDef *phost, 407 | uint8_t *pbuff, 408 | uint32_t length); 409 | 410 | 411 | uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost); 412 | 413 | USBH_StatusTypeDef USBH_CDC_Stop(USBH_HandleTypeDef *phost); 414 | 415 | void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost); 416 | 417 | void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost); 418 | 419 | void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost); 420 | 421 | /** 422 | * @} 423 | */ 424 | 425 | #ifdef __cplusplus 426 | } 427 | #endif 428 | 429 | #endif /* __USBH_CDC_H */ 430 | 431 | /** 432 | * @} 433 | */ 434 | 435 | /** 436 | * @} 437 | */ 438 | 439 | /** 440 | * @} 441 | */ 442 | 443 | /** 444 | * @} 445 | */ 446 | 447 | -------------------------------------------------------------------------------- /Class/HID/Inc/usbh_hid.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_hid.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the prototypes for the usbh_hid.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_HID_H 21 | #define __USBH_HID_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | #include "usbh_hid_mouse.h" 30 | #include "usbh_hid_keybd.h" 31 | 32 | /** @addtogroup USBH_LIB 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup USBH_CLASS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup USBH_HID_CLASS 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBH_HID_CORE 45 | * @brief This file is the Header file for usbh_hid.c 46 | * @{ 47 | */ 48 | 49 | 50 | /** @defgroup USBH_HID_CORE_Exported_Types 51 | * @{ 52 | */ 53 | 54 | #define HID_MIN_POLL 10U 55 | #define HID_REPORT_SIZE 16U 56 | #define HID_MAX_USAGE 10U 57 | #define HID_MAX_NBR_REPORT_FMT 10U 58 | #define HID_QUEUE_SIZE 10U 59 | 60 | #define HID_ITEM_LONG 0xFEU 61 | 62 | #define HID_ITEM_TYPE_MAIN 0x00U 63 | #define HID_ITEM_TYPE_GLOBAL 0x01U 64 | #define HID_ITEM_TYPE_LOCAL 0x02U 65 | #define HID_ITEM_TYPE_RESERVED 0x03U 66 | 67 | 68 | #define HID_MAIN_ITEM_TAG_INPUT 0x08U 69 | #define HID_MAIN_ITEM_TAG_OUTPUT 0x09U 70 | #define HID_MAIN_ITEM_TAG_COLLECTION 0x0AU 71 | #define HID_MAIN_ITEM_TAG_FEATURE 0x0BU 72 | #define HID_MAIN_ITEM_TAG_ENDCOLLECTION 0x0CU 73 | 74 | 75 | #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0x00U 76 | #define HID_GLOBAL_ITEM_TAG_LOG_MIN 0x01U 77 | #define HID_GLOBAL_ITEM_TAG_LOG_MAX 0x02U 78 | #define HID_GLOBAL_ITEM_TAG_PHY_MIN 0x03U 79 | #define HID_GLOBAL_ITEM_TAG_PHY_MAX 0x04U 80 | #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 0x05U 81 | #define HID_GLOBAL_ITEM_TAG_UNIT 0x06U 82 | #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 0x07U 83 | #define HID_GLOBAL_ITEM_TAG_REPORT_ID 0x08U 84 | #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 0x09U 85 | #define HID_GLOBAL_ITEM_TAG_PUSH 0x0AU 86 | #define HID_GLOBAL_ITEM_TAG_POP 0x0BU 87 | 88 | 89 | #define HID_LOCAL_ITEM_TAG_USAGE 0x00U 90 | #define HID_LOCAL_ITEM_TAG_USAGE_MIN 0x01U 91 | #define HID_LOCAL_ITEM_TAG_USAGE_MAX 0x02U 92 | #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 0x03U 93 | #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MIN 0x04U 94 | #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAX 0x05U 95 | #define HID_LOCAL_ITEM_TAG_STRING_INDEX 0x07U 96 | #define HID_LOCAL_ITEM_TAG_STRING_MIN 0x08U 97 | #define HID_LOCAL_ITEM_TAG_STRING_MAX 0x09U 98 | #define HID_LOCAL_ITEM_TAG_DELIMITER 0x0AU 99 | 100 | 101 | /* States for HID State Machine */ 102 | typedef enum 103 | { 104 | USBH_HID_INIT = 0, 105 | USBH_HID_IDLE, 106 | USBH_HID_SEND_DATA, 107 | USBH_HID_BUSY, 108 | USBH_HID_GET_DATA, 109 | USBH_HID_SYNC, 110 | USBH_HID_POLL, 111 | USBH_HID_ERROR, 112 | } 113 | USBH_HID_StateTypeDef; 114 | 115 | typedef enum 116 | { 117 | USBH_HID_REQ_INIT = 0, 118 | USBH_HID_REQ_IDLE, 119 | USBH_HID_REQ_GET_REPORT_DESC, 120 | USBH_HID_REQ_GET_HID_DESC, 121 | USBH_HID_REQ_SET_IDLE, 122 | USBH_HID_REQ_SET_PROTOCOL, 123 | USBH_HID_REQ_SET_REPORT, 124 | 125 | } 126 | HID_CtlStateTypeDef; 127 | 128 | typedef enum 129 | { 130 | HID_MOUSE = 0x01, 131 | HID_KEYBOARD = 0x02, 132 | HID_UNKNOWN = 0xFF, 133 | } 134 | HID_TypeTypeDef; 135 | 136 | 137 | typedef struct _HID_ReportData 138 | { 139 | uint8_t ReportID; 140 | uint8_t ReportType; 141 | uint16_t UsagePage; 142 | uint32_t Usage[HID_MAX_USAGE]; 143 | uint32_t NbrUsage; 144 | uint32_t UsageMin; 145 | uint32_t UsageMax; 146 | int32_t LogMin; 147 | int32_t LogMax; 148 | int32_t PhyMin; 149 | int32_t PhyMax; 150 | int32_t UnitExp; 151 | uint32_t Unit; 152 | uint32_t ReportSize; 153 | uint32_t ReportCnt; 154 | uint32_t Flag; 155 | uint32_t PhyUsage; 156 | uint32_t AppUsage; 157 | uint32_t LogUsage; 158 | } 159 | HID_ReportDataTypeDef; 160 | 161 | typedef struct _HID_ReportIDTypeDef 162 | { 163 | uint8_t Size; /* Report size return by the device id */ 164 | uint8_t ReportID; /* Report Id */ 165 | uint8_t Type; /* Report Type (INPUT/OUTPUT/FEATURE) */ 166 | } HID_ReportIDTypeDef; 167 | 168 | typedef struct _HID_CollectionTypeDef 169 | { 170 | uint32_t Usage; 171 | uint8_t Type; 172 | struct _HID_CollectionTypeDef *NextPtr; 173 | } HID_CollectionTypeDef; 174 | 175 | 176 | typedef struct _HID_AppCollectionTypeDef 177 | { 178 | uint32_t Usage; 179 | uint8_t Type; 180 | uint8_t NbrReportFmt; 181 | HID_ReportDataTypeDef ReportData[HID_MAX_NBR_REPORT_FMT]; 182 | } HID_AppCollectionTypeDef; 183 | 184 | 185 | typedef struct _HIDDescriptor 186 | { 187 | uint8_t bLength; 188 | uint8_t bDescriptorType; 189 | uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */ 190 | uint8_t bCountryCode; /* specifies the transfer type. */ 191 | uint8_t bNumDescriptors; /* specifies the transfer type. */ 192 | uint8_t bReportDescriptorType; /* Maximum Packet Size this endpoint is capable of sending or receiving */ 193 | uint16_t wItemLength; /* is used to specify the polling interval of certain transfers. */ 194 | } 195 | HID_DescTypeDef; 196 | 197 | 198 | typedef struct 199 | { 200 | uint8_t *buf; 201 | uint16_t head; 202 | uint16_t tail; 203 | uint16_t size; 204 | uint8_t lock; 205 | } FIFO_TypeDef; 206 | 207 | 208 | /* Structure for HID process */ 209 | typedef struct _HID_Process 210 | { 211 | uint8_t OutPipe; 212 | uint8_t InPipe; 213 | USBH_HID_StateTypeDef state; 214 | uint8_t OutEp; 215 | uint8_t InEp; 216 | HID_CtlStateTypeDef ctl_state; 217 | FIFO_TypeDef fifo; 218 | uint8_t *pData; 219 | uint16_t length; 220 | uint8_t ep_addr; 221 | uint16_t poll; 222 | uint32_t timer; 223 | uint8_t DataReady; 224 | HID_DescTypeDef HID_Desc; 225 | USBH_StatusTypeDef(* Init)(USBH_HandleTypeDef *phost); 226 | } 227 | HID_HandleTypeDef; 228 | 229 | /** 230 | * @} 231 | */ 232 | 233 | /** @defgroup USBH_HID_CORE_Exported_Defines 234 | * @{ 235 | */ 236 | 237 | #define USB_HID_GET_REPORT 0x01U 238 | #define USB_HID_GET_IDLE 0x02U 239 | #define USB_HID_GET_PROTOCOL 0x03U 240 | #define USB_HID_SET_REPORT 0x09U 241 | #define USB_HID_SET_IDLE 0x0AU 242 | #define USB_HID_SET_PROTOCOL 0x0BU 243 | 244 | 245 | 246 | 247 | /* HID Class Codes */ 248 | #define USB_HID_CLASS 0x03U 249 | 250 | /* Interface Descriptor field values for HID Boot Protocol */ 251 | #define HID_BOOT_CODE 0x01U 252 | #define HID_KEYBRD_BOOT_CODE 0x01U 253 | #define HID_MOUSE_BOOT_CODE 0x02U 254 | 255 | 256 | /** 257 | * @} 258 | */ 259 | 260 | /** @defgroup USBH_HID_CORE_Exported_Macros 261 | * @{ 262 | */ 263 | /** 264 | * @} 265 | */ 266 | 267 | /** @defgroup USBH_HID_CORE_Exported_Variables 268 | * @{ 269 | */ 270 | extern USBH_ClassTypeDef HID_Class; 271 | #define USBH_HID_CLASS &HID_Class 272 | /** 273 | * @} 274 | */ 275 | 276 | /** @defgroup USBH_HID_CORE_Exported_FunctionsPrototype 277 | * @{ 278 | */ 279 | 280 | USBH_StatusTypeDef USBH_HID_SetReport(USBH_HandleTypeDef *phost, 281 | uint8_t reportType, 282 | uint8_t reportId, 283 | uint8_t *reportBuff, 284 | uint8_t reportLen); 285 | 286 | USBH_StatusTypeDef USBH_HID_GetReport(USBH_HandleTypeDef *phost, 287 | uint8_t reportType, 288 | uint8_t reportId, 289 | uint8_t *reportBuff, 290 | uint8_t reportLen); 291 | 292 | USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor(USBH_HandleTypeDef *phost, 293 | uint16_t length); 294 | 295 | USBH_StatusTypeDef USBH_HID_GetHIDDescriptor(USBH_HandleTypeDef *phost, 296 | uint16_t length); 297 | 298 | USBH_StatusTypeDef USBH_HID_SetIdle(USBH_HandleTypeDef *phost, 299 | uint8_t duration, 300 | uint8_t reportId); 301 | 302 | USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost, 303 | uint8_t protocol); 304 | 305 | void USBH_HID_EventCallback(USBH_HandleTypeDef *phost); 306 | 307 | HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost); 308 | 309 | uint8_t USBH_HID_GetPollInterval(USBH_HandleTypeDef *phost); 310 | 311 | void USBH_HID_FifoInit(FIFO_TypeDef *f, uint8_t *buf, uint16_t size); 312 | 313 | uint16_t USBH_HID_FifoRead(FIFO_TypeDef *f, void *buf, uint16_t nbytes); 314 | 315 | uint16_t USBH_HID_FifoWrite(FIFO_TypeDef *f, void *buf, uint16_t nbytes); 316 | 317 | /** 318 | * @} 319 | */ 320 | 321 | #ifdef __cplusplus 322 | } 323 | #endif 324 | 325 | #endif /* __USBH_HID_H */ 326 | 327 | /** 328 | * @} 329 | */ 330 | 331 | /** 332 | * @} 333 | */ 334 | 335 | /** 336 | * @} 337 | */ 338 | 339 | /** 340 | * @} 341 | */ 342 | 343 | -------------------------------------------------------------------------------- /Class/HID/Inc/usbh_hid_keybd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_hid_keybd.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the prototypes for the usbh_hid_keybd.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive -----------------------------------------------*/ 20 | #ifndef __USBH_HID_KEYBD_H 21 | #define __USBH_HID_KEYBD_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_hid.h" 29 | #include "usbh_hid_keybd.h" 30 | 31 | /** @addtogroup USBH_LIB 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup USBH_CLASS 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup USBH_HID_CLASS 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBH_HID_KEYBD 44 | * @brief This file is the Header file for usbh_hid_keybd.c 45 | * @{ 46 | */ 47 | 48 | 49 | /** @defgroup USBH_HID_KEYBD_Exported_Types 50 | * @{ 51 | */ 52 | #ifndef USBH_HID_KEYBD_REPORT_SIZE 53 | #define USBH_HID_KEYBD_REPORT_SIZE 0x8U 54 | #endif /* USBH_HID_KEYBD_REPORT_SIZE */ 55 | 56 | #define KEY_NONE 0x00 57 | #define KEY_ERRORROLLOVER 0x01 58 | #define KEY_POSTFAIL 0x02 59 | #define KEY_ERRORUNDEFINED 0x03 60 | #define KEY_A 0x04 61 | #define KEY_B 0x05 62 | #define KEY_C 0x06 63 | #define KEY_D 0x07 64 | #define KEY_E 0x08 65 | #define KEY_F 0x09 66 | #define KEY_G 0x0A 67 | #define KEY_H 0x0B 68 | #define KEY_I 0x0C 69 | #define KEY_J 0x0D 70 | #define KEY_K 0x0E 71 | #define KEY_L 0x0F 72 | #define KEY_M 0x10 73 | #define KEY_N 0x11 74 | #define KEY_O 0x12 75 | #define KEY_P 0x13 76 | #define KEY_Q 0x14 77 | #define KEY_R 0x15 78 | #define KEY_S 0x16 79 | #define KEY_T 0x17 80 | #define KEY_U 0x18 81 | #define KEY_V 0x19 82 | #define KEY_W 0x1A 83 | #define KEY_X 0x1B 84 | #define KEY_Y 0x1C 85 | #define KEY_Z 0x1D 86 | #define KEY_1_EXCLAMATION_MARK 0x1E 87 | #define KEY_2_AT 0x1F 88 | #define KEY_3_NUMBER_SIGN 0x20 89 | #define KEY_4_DOLLAR 0x21 90 | #define KEY_5_PERCENT 0x22 91 | #define KEY_6_CARET 0x23 92 | #define KEY_7_AMPERSAND 0x24 93 | #define KEY_8_ASTERISK 0x25 94 | #define KEY_9_OPARENTHESIS 0x26 95 | #define KEY_0_CPARENTHESIS 0x27 96 | #define KEY_ENTER 0x28 97 | #define KEY_ESCAPE 0x29 98 | #define KEY_BACKSPACE 0x2A 99 | #define KEY_TAB 0x2B 100 | #define KEY_SPACEBAR 0x2C 101 | #define KEY_MINUS_UNDERSCORE 0x2D 102 | #define KEY_EQUAL_PLUS 0x2E 103 | #define KEY_OBRACKET_AND_OBRACE 0x2F 104 | #define KEY_CBRACKET_AND_CBRACE 0x30 105 | #define KEY_BACKSLASH_VERTICAL_BAR 0x31 106 | #define KEY_NONUS_NUMBER_SIGN_TILDE 0x32 107 | #define KEY_SEMICOLON_COLON 0x33 108 | #define KEY_SINGLE_AND_DOUBLE_QUOTE 0x34 109 | #define KEY_GRAVE_ACCENT_AND_TILDE 0x35 110 | #define KEY_COMMA_AND_LESS 0x36 111 | #define KEY_DOT_GREATER 0x37 112 | #define KEY_SLASH_QUESTION 0x38 113 | #define KEY_CAPS_LOCK 0x39 114 | #define KEY_F1 0x3A 115 | #define KEY_F2 0x3B 116 | #define KEY_F3 0x3C 117 | #define KEY_F4 0x3D 118 | #define KEY_F5 0x3E 119 | #define KEY_F6 0x3F 120 | #define KEY_F7 0x40 121 | #define KEY_F8 0x41 122 | #define KEY_F9 0x42 123 | #define KEY_F10 0x43 124 | #define KEY_F11 0x44 125 | #define KEY_F12 0x45 126 | #define KEY_PRINTSCREEN 0x46 127 | #define KEY_SCROLL_LOCK 0x47 128 | #define KEY_PAUSE 0x48 129 | #define KEY_INSERT 0x49 130 | #define KEY_HOME 0x4A 131 | #define KEY_PAGEUP 0x4B 132 | #define KEY_DELETE 0x4C 133 | #define KEY_END1 0x4D 134 | #define KEY_PAGEDOWN 0x4E 135 | #define KEY_RIGHTARROW 0x4F 136 | #define KEY_LEFTARROW 0x50 137 | #define KEY_DOWNARROW 0x51 138 | #define KEY_UPARROW 0x52 139 | #define KEY_KEYPAD_NUM_LOCK_AND_CLEAR 0x53 140 | #define KEY_KEYPAD_SLASH 0x54 141 | #define KEY_KEYPAD_ASTERIKS 0x55 142 | #define KEY_KEYPAD_MINUS 0x56 143 | #define KEY_KEYPAD_PLUS 0x57 144 | #define KEY_KEYPAD_ENTER 0x58 145 | #define KEY_KEYPAD_1_END 0x59 146 | #define KEY_KEYPAD_2_DOWN_ARROW 0x5A 147 | #define KEY_KEYPAD_3_PAGEDN 0x5B 148 | #define KEY_KEYPAD_4_LEFT_ARROW 0x5C 149 | #define KEY_KEYPAD_5 0x5D 150 | #define KEY_KEYPAD_6_RIGHT_ARROW 0x5E 151 | #define KEY_KEYPAD_7_HOME 0x5F 152 | #define KEY_KEYPAD_8_UP_ARROW 0x60 153 | #define KEY_KEYPAD_9_PAGEUP 0x61 154 | #define KEY_KEYPAD_0_INSERT 0x62 155 | #define KEY_KEYPAD_DECIMAL_SEPARATOR_DELETE 0x63 156 | #define KEY_NONUS_BACK_SLASH_VERTICAL_BAR 0x64 157 | #define KEY_APPLICATION 0x65 158 | #define KEY_POWER 0x66 159 | #define KEY_KEYPAD_EQUAL 0x67 160 | #define KEY_F13 0x68 161 | #define KEY_F14 0x69 162 | #define KEY_F15 0x6A 163 | #define KEY_F16 0x6B 164 | #define KEY_F17 0x6C 165 | #define KEY_F18 0x6D 166 | #define KEY_F19 0x6E 167 | #define KEY_F20 0x6F 168 | #define KEY_F21 0x70 169 | #define KEY_F22 0x71 170 | #define KEY_F23 0x72 171 | #define KEY_F24 0x73 172 | #define KEY_EXECUTE 0x74 173 | #define KEY_HELP 0x75 174 | #define KEY_MENU 0x76 175 | #define KEY_SELECT 0x77 176 | #define KEY_STOP 0x78 177 | #define KEY_AGAIN 0x79 178 | #define KEY_UNDO 0x7A 179 | #define KEY_CUT 0x7B 180 | #define KEY_COPY 0x7C 181 | #define KEY_PASTE 0x7D 182 | #define KEY_FIND 0x7E 183 | #define KEY_MUTE 0x7F 184 | #define KEY_VOLUME_UP 0x80 185 | #define KEY_VOLUME_DOWN 0x81 186 | #define KEY_LOCKING_CAPS_LOCK 0x82 187 | #define KEY_LOCKING_NUM_LOCK 0x83 188 | #define KEY_LOCKING_SCROLL_LOCK 0x84 189 | #define KEY_KEYPAD_COMMA 0x85 190 | #define KEY_KEYPAD_EQUAL_SIGN 0x86 191 | #define KEY_INTERNATIONAL1 0x87 192 | #define KEY_INTERNATIONAL2 0x88 193 | #define KEY_INTERNATIONAL3 0x89 194 | #define KEY_INTERNATIONAL4 0x8A 195 | #define KEY_INTERNATIONAL5 0x8B 196 | #define KEY_INTERNATIONAL6 0x8C 197 | #define KEY_INTERNATIONAL7 0x8D 198 | #define KEY_INTERNATIONAL8 0x8E 199 | #define KEY_INTERNATIONAL9 0x8F 200 | #define KEY_LANG1 0x90 201 | #define KEY_LANG2 0x91 202 | #define KEY_LANG3 0x92 203 | #define KEY_LANG4 0x93 204 | #define KEY_LANG5 0x94 205 | #define KEY_LANG6 0x95 206 | #define KEY_LANG7 0x96 207 | #define KEY_LANG8 0x97 208 | #define KEY_LANG9 0x98 209 | #define KEY_ALTERNATE_ERASE 0x99 210 | #define KEY_SYSREQ 0x9A 211 | #define KEY_CANCEL 0x9B 212 | #define KEY_CLEAR 0x9C 213 | #define KEY_PRIOR 0x9D 214 | #define KEY_RETURN 0x9E 215 | #define KEY_SEPARATOR 0x9F 216 | #define KEY_OUT 0xA0 217 | #define KEY_OPER 0xA1 218 | #define KEY_CLEAR_AGAIN 0xA2 219 | #define KEY_CRSEL 0xA3 220 | #define KEY_EXSEL 0xA4 221 | #define KEY_KEYPAD_00 0xB0 222 | #define KEY_KEYPAD_000 0xB1 223 | #define KEY_THOUSANDS_SEPARATOR 0xB2 224 | #define KEY_DECIMAL_SEPARATOR 0xB3 225 | #define KEY_CURRENCY_UNIT 0xB4 226 | #define KEY_CURRENCY_SUB_UNIT 0xB5 227 | #define KEY_KEYPAD_OPARENTHESIS 0xB6 228 | #define KEY_KEYPAD_CPARENTHESIS 0xB7 229 | #define KEY_KEYPAD_OBRACE 0xB8 230 | #define KEY_KEYPAD_CBRACE 0xB9 231 | #define KEY_KEYPAD_TAB 0xBA 232 | #define KEY_KEYPAD_BACKSPACE 0xBB 233 | #define KEY_KEYPAD_A 0xBC 234 | #define KEY_KEYPAD_B 0xBD 235 | #define KEY_KEYPAD_C 0xBE 236 | #define KEY_KEYPAD_D 0xBF 237 | #define KEY_KEYPAD_E 0xC0 238 | #define KEY_KEYPAD_F 0xC1 239 | #define KEY_KEYPAD_XOR 0xC2 240 | #define KEY_KEYPAD_CARET 0xC3 241 | #define KEY_KEYPAD_PERCENT 0xC4 242 | #define KEY_KEYPAD_LESS 0xC5 243 | #define KEY_KEYPAD_GREATER 0xC6 244 | #define KEY_KEYPAD_AMPERSAND 0xC7 245 | #define KEY_KEYPAD_LOGICAL_AND 0xC8 246 | #define KEY_KEYPAD_VERTICAL_BAR 0xC9 247 | #define KEY_KEYPAD_LOGIACL_OR 0xCA 248 | #define KEY_KEYPAD_COLON 0xCB 249 | #define KEY_KEYPAD_NUMBER_SIGN 0xCC 250 | #define KEY_KEYPAD_SPACE 0xCD 251 | #define KEY_KEYPAD_AT 0xCE 252 | #define KEY_KEYPAD_EXCLAMATION_MARK 0xCF 253 | #define KEY_KEYPAD_MEMORY_STORE 0xD0 254 | #define KEY_KEYPAD_MEMORY_RECALL 0xD1 255 | #define KEY_KEYPAD_MEMORY_CLEAR 0xD2 256 | #define KEY_KEYPAD_MEMORY_ADD 0xD3 257 | #define KEY_KEYPAD_MEMORY_SUBTRACT 0xD4 258 | #define KEY_KEYPAD_MEMORY_MULTIPLY 0xD5 259 | #define KEY_KEYPAD_MEMORY_DIVIDE 0xD6 260 | #define KEY_KEYPAD_PLUSMINUS 0xD7 261 | #define KEY_KEYPAD_CLEAR 0xD8 262 | #define KEY_KEYPAD_CLEAR_ENTRY 0xD9 263 | #define KEY_KEYPAD_BINARY 0xDA 264 | #define KEY_KEYPAD_OCTAL 0xDB 265 | #define KEY_KEYPAD_DECIMAL 0xDC 266 | #define KEY_KEYPAD_HEXADECIMAL 0xDD 267 | #define KEY_LEFTCONTROL 0xE0 268 | #define KEY_LEFTSHIFT 0xE1 269 | #define KEY_LEFTALT 0xE2 270 | #define KEY_LEFT_GUI 0xE3 271 | #define KEY_RIGHTCONTROL 0xE4 272 | #define KEY_RIGHTSHIFT 0xE5 273 | #define KEY_RIGHTALT 0xE6 274 | #define KEY_RIGHT_GUI 0xE7 275 | 276 | typedef struct 277 | { 278 | uint8_t state; 279 | uint8_t lctrl; 280 | uint8_t lshift; 281 | uint8_t lalt; 282 | uint8_t lgui; 283 | uint8_t rctrl; 284 | uint8_t rshift; 285 | uint8_t ralt; 286 | uint8_t rgui; 287 | uint8_t keys[6]; 288 | } 289 | HID_KEYBD_Info_TypeDef; 290 | 291 | USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost); 292 | HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost); 293 | uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info); 294 | 295 | /** 296 | * @} 297 | */ 298 | 299 | #ifdef __cplusplus 300 | } 301 | #endif 302 | 303 | #endif /* __USBH_HID_KEYBD_H */ 304 | 305 | /** 306 | * @} 307 | */ 308 | 309 | /** 310 | * @} 311 | */ 312 | 313 | /** 314 | * @} 315 | */ 316 | 317 | /** 318 | * @} 319 | */ 320 | 321 | -------------------------------------------------------------------------------- /Class/HID/Inc/usbh_hid_mouse.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_hid_mouse.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the prototypes for the usbh_hid_mouse.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_HID_MOUSE_H 21 | #define __USBH_HID_MOUSE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_hid.h" 29 | 30 | /** @addtogroup USBH_LIB 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup USBH_CLASS 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup USBH_HID_CLASS 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBH_HID_MOUSE 43 | * @brief This file is the Header file for usbh_hid_mouse.c 44 | * @{ 45 | */ 46 | 47 | 48 | /** @defgroup USBH_HID_MOUSE_Exported_Types 49 | * @{ 50 | */ 51 | 52 | typedef struct _HID_MOUSE_Info 53 | { 54 | uint8_t x; 55 | uint8_t y; 56 | uint8_t buttons[3]; 57 | } 58 | HID_MOUSE_Info_TypeDef; 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup USBH_HID_MOUSE_Exported_Defines 65 | * @{ 66 | */ 67 | #ifndef USBH_HID_MOUSE_REPORT_SIZE 68 | #define USBH_HID_MOUSE_REPORT_SIZE 0x8U 69 | #endif /* USBH_HID_MOUSE_REPORT_SIZE */ 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup USBH_HID_MOUSE_Exported_Macros 75 | * @{ 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @defgroup USBH_HID_MOUSE_Exported_Variables 82 | * @{ 83 | */ 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBH_HID_MOUSE_Exported_FunctionsPrototype 89 | * @{ 90 | */ 91 | USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost); 92 | HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost); 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USBH_HID_MOUSE_H */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | -------------------------------------------------------------------------------- /Class/HID/Inc/usbh_hid_parser.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_hid_parser.c 4 | * @author MCD Application Team 5 | * @brief This file is the header file of the usbh_hid_parser.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive -----------------------------------------------*/ 20 | #ifndef __USBH_HID_PARSER_H 21 | #define __USBH_HID_PARSER_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_hid.h" 29 | #include "usbh_hid_usage.h" 30 | 31 | /** @addtogroup USBH_LIB 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup USBH_CLASS 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup USBH_HID_CLASS 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBH_HID_PARSER 44 | * @brief This file is the Header file for usbh_hid_parser.c 45 | * @{ 46 | */ 47 | 48 | 49 | /** @defgroup USBH_HID_PARSER_Exported_Types 50 | * @{ 51 | */ 52 | typedef struct 53 | { 54 | uint8_t *data; 55 | uint32_t size; 56 | uint8_t shift; 57 | uint8_t count; 58 | uint8_t sign; 59 | uint32_t logical_min; /*min value device can return*/ 60 | uint32_t logical_max; /*max value device can return*/ 61 | uint32_t physical_min; /*min vale read can report*/ 62 | uint32_t physical_max; /*max value read can report*/ 63 | uint32_t resolution; 64 | } 65 | HID_Report_ItemTypedef; 66 | 67 | 68 | uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx); 69 | uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx); 70 | 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* __USBH_HID_PARSER_H */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | -------------------------------------------------------------------------------- /Class/HID/Inc/usbh_hid_usage.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_hid_usage.c 4 | * @author MCD Application Team 5 | * @brief This file contain the USAGE page codes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USDH_HID_USAGE_H 21 | #define __USDH_HID_USAGE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** @addtogroup USBH_LIB 28 | * @{ 29 | */ 30 | 31 | /** @addtogroup USBH_CLASS 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup USBH_HID_CLASS 36 | * @{ 37 | */ 38 | 39 | /** @defgroup USBH_HID_USAGE 40 | * @brief This file is the Header file for usbh_hid_usage.c 41 | * @{ 42 | */ 43 | 44 | 45 | /** @defgroup USBH_HID_USAGE_Exported_Types 46 | * @{ 47 | */ 48 | 49 | /****************************************************/ 50 | /* HID 1.11 usage pages */ 51 | /****************************************************/ 52 | 53 | #define HID_USAGE_PAGE_UNDEFINED uint16_t (0x00) /* Undefined */ 54 | /**** Top level pages */ 55 | #define HID_USAGE_PAGE_GEN_DES uint16_t (0x01) /* Generic Desktop Controls*/ 56 | #define HID_USAGE_PAGE_SIM_CTR uint16_t (0x02) /* Simulation Controls */ 57 | #define HID_USAGE_PAGE_VR_CTR uint16_t (0x03) /* VR Controls */ 58 | #define HID_USAGE_PAGE_SPORT_CTR uint16_t (0x04) /* Sport Controls */ 59 | #define HID_USAGE_PAGE_GAME_CTR uint16_t (0x05) /* Game Controls */ 60 | #define HID_USAGE_PAGE_GEN_DEV uint16_t (0x06) /* Generic Device Controls */ 61 | #define HID_USAGE_PAGE_KEYB uint16_t (0x07) /* Keyboard/Keypad */ 62 | #define HID_USAGE_PAGE_LED uint16_t (0x08) /* LEDs */ 63 | #define HID_USAGE_PAGE_BUTTON uint16_t (0x09) /* Button */ 64 | #define HID_USAGE_PAGE_ORDINAL uint16_t (0x0A) /* Ordinal */ 65 | #define HID_USAGE_PAGE_PHONE uint16_t (0x0B) /* Telephony */ 66 | #define HID_USAGE_PAGE_CONSUMER uint16_t (0x0C) /* Consumer */ 67 | #define HID_USAGE_PAGE_DIGITIZER uint16_t (0x0D) /* Digitizer*/ 68 | /* 0E Reserved */ 69 | #define HID_USAGE_PAGE_PID uint16_t (0x0F) /* PID Page (force feedback and related devices) */ 70 | #define HID_USAGE_PAGE_UNICODE uint16_t (0x10) /* Unicode */ 71 | /* 11-13 Reserved */ 72 | #define HID_USAGE_PAGE_ALNUM_DISP uint16_t (0x14) /* Alphanumeric Display */ 73 | /* 15-1f Reserved */ 74 | /**** END of top level pages */ 75 | /* 25-3f Reserved */ 76 | #define HID_USAGE_PAGE_MEDICAL uint16_t (0x40) /* Medical Instruments */ 77 | /* 41-7F Reserved */ 78 | /*80-83 Monitor pages USB Device Class Definition for Monitor Devices 79 | 84-87 Power pages USB Device Class Definition for Power Devices */ 80 | /* 88-8B Reserved */ 81 | #define HID_USAGE_PAGE_BARCODE uint16_t (0x8C) /* Bar Code Scanner page */ 82 | #define HID_USAGE_PAGE_SCALE uint16_t (0x8D) /* Scale page */ 83 | #define HID_USAGE_PAGE_MSR uint16_t (0x8E) /* Magnetic Stripe Reading (MSR) Devices */ 84 | #define HID_USAGE_PAGE_POS uint16_t (0x8F) /* Reserved Point of Sale pages */ 85 | #define HID_USAGE_PAGE_CAMERA_CTR uint16_t (0x90) /* Camera Control Page */ 86 | #define HID_USAGE_PAGE_ARCADE uint16_t (0x91) /* Arcade Page */ 87 | 88 | /****************************************************/ 89 | /* Usage definitions for the "Generic Desktop" page */ 90 | /****************************************************/ 91 | #define HID_USAGE_UNDEFINED uint16_t (0x00) /* Undefined */ 92 | #define HID_USAGE_POINTER uint16_t (0x01) /* Pointer (Physical Collection) */ 93 | #define HID_USAGE_MOUSE uint16_t (0x02) /* Mouse (Application Collection) */ 94 | /* 03 Reserved */ 95 | #define HID_USAGE_JOYSTICK uint16_t (0x04) /* Joystick (Application Collection) */ 96 | #define HID_USAGE_GAMEPAD uint16_t (0x05) /* Game Pad (Application Collection) */ 97 | #define HID_USAGE_KBD uint16_t (0x06) /* Keyboard (Application Collection) */ 98 | #define HID_USAGE_KEYPAD uint16_t (0x07) /* Keypad (Application Collection) */ 99 | #define HID_USAGE_MAX_CTR uint16_t (0x08) /* Multi-axis Controller (Application Collection) */ 100 | /* 09-2F Reserved */ 101 | #define HID_USAGE_X uint16_t (0x30) /* X (Dynamic Value) */ 102 | #define HID_USAGE_Y uint16_t (0x31) /* Y (Dynamic Value) */ 103 | #define HID_USAGE_Z uint16_t (0x32) /* Z (Dynamic Value) */ 104 | #define HID_USAGE_RX uint16_t (0x33) /* Rx (Dynamic Value) */ 105 | #define HID_USAGE_RY uint16_t (0x34) /* Ry (Dynamic Value) */ 106 | #define HID_USAGE_RZ uint16_t (0x35) /* Rz (Dynamic Value) */ 107 | #define HID_USAGE_SLIDER uint16_t (0x36) /* Slider (Dynamic Value) */ 108 | #define HID_USAGE_DIAL uint16_t (0x37) /* Dial (Dynamic Value) */ 109 | #define HID_USAGE_WHEEL uint16_t (0x38) /* Wheel (Dynamic Value) */ 110 | #define HID_USAGE_HATSW uint16_t (0x39) /* Hat switch (Dynamic Value) */ 111 | #define HID_USAGE_COUNTEDBUF uint16_t (0x3A) /* Counted Buffer (Logical Collection) */ 112 | #define HID_USAGE_BYTECOUNT uint16_t (0x3B) /* Byte Count (Dynamic Value) */ 113 | #define HID_USAGE_MOTIONWAKE uint16_t (0x3C) /* Motion Wakeup (One Shot Control) */ 114 | #define HID_USAGE_START uint16_t (0x3D) /* Start (On/Off Control) */ 115 | #define HID_USAGE_SELECT uint16_t (0x3E) /* Select (On/Off Control) */ 116 | /* 3F Reserved */ 117 | #define HID_USAGE_VX uint16_t (0x40) /* Vx (Dynamic Value) */ 118 | #define HID_USAGE_VY uint16_t (0x41) /* Vy (Dynamic Value) */ 119 | #define HID_USAGE_VZ uint16_t (0x42) /* Vz (Dynamic Value) */ 120 | #define HID_USAGE_VBRX uint16_t (0x43) /* Vbrx (Dynamic Value) */ 121 | #define HID_USAGE_VBRY uint16_t (0x44) /* Vbry (Dynamic Value) */ 122 | #define HID_USAGE_VBRZ uint16_t (0x45) /* Vbrz (Dynamic Value) */ 123 | #define HID_USAGE_VNO uint16_t (0x46) /* Vno (Dynamic Value) */ 124 | #define HID_USAGE_FEATNOTIF uint16_t (0x47) /* Feature Notification (Dynamic Value),(Dynamic Flag) */ 125 | /* 48-7F Reserved */ 126 | #define HID_USAGE_SYSCTL uint16_t (0x80) /* System Control (Application Collection) */ 127 | #define HID_USAGE_PWDOWN uint16_t (0x81) /* System Power Down (One Shot Control) */ 128 | #define HID_USAGE_SLEEP uint16_t (0x82) /* System Sleep (One Shot Control) */ 129 | #define HID_USAGE_WAKEUP uint16_t (0x83) /* System Wake Up (One Shot Control) */ 130 | #define HID_USAGE_CONTEXTM uint16_t (0x84) /* System Context Menu (One Shot Control) */ 131 | #define HID_USAGE_MAINM uint16_t (0x85) /* System Main Menu (One Shot Control) */ 132 | #define HID_USAGE_APPM uint16_t (0x86) /* System App Menu (One Shot Control) */ 133 | #define HID_USAGE_MENUHELP uint16_t (0x87) /* System Menu Help (One Shot Control) */ 134 | #define HID_USAGE_MENUEXIT uint16_t (0x88) /* System Menu Exit (One Shot Control) */ 135 | #define HID_USAGE_MENUSELECT uint16_t (0x89) /* System Menu Select (One Shot Control) */ 136 | #define HID_USAGE_SYSM_RIGHT uint16_t (0x8A) /* System Menu Right (Re-Trigger Control) */ 137 | #define HID_USAGE_SYSM_LEFT uint16_t (0x8B) /* System Menu Left (Re-Trigger Control) */ 138 | #define HID_USAGE_SYSM_UP uint16_t (0x8C) /* System Menu Up (Re-Trigger Control) */ 139 | #define HID_USAGE_SYSM_DOWN uint16_t (0x8D) /* System Menu Down (Re-Trigger Control) */ 140 | #define HID_USAGE_COLDRESET uint16_t (0x8E) /* System Cold Restart (One Shot Control) */ 141 | #define HID_USAGE_WARMRESET uint16_t (0x8F) /* System Warm Restart (One Shot Control) */ 142 | #define HID_USAGE_DUP uint16_t (0x90) /* D-pad Up (On/Off Control) */ 143 | #define HID_USAGE_DDOWN uint16_t (0x91) /* D-pad Down (On/Off Control) */ 144 | #define HID_USAGE_DRIGHT uint16_t (0x92) /* D-pad Right (On/Off Control) */ 145 | #define HID_USAGE_DLEFT uint16_t (0x93) /* D-pad Left (On/Off Control) */ 146 | /* 94-9F Reserved */ 147 | #define HID_USAGE_SYS_DOCK uint16_t (0xA0) /* System Dock (One Shot Control) */ 148 | #define HID_USAGE_SYS_UNDOCK uint16_t (0xA1) /* System Undock (One Shot Control) */ 149 | #define HID_USAGE_SYS_SETUP uint16_t (0xA2) /* System Setup (One Shot Control) */ 150 | #define HID_USAGE_SYS_BREAK uint16_t (0xA3) /* System Break (One Shot Control) */ 151 | #define HID_USAGE_SYS_DBGBRK uint16_t (0xA4) /* System Debugger Break (One Shot Control) */ 152 | #define HID_USAGE_APP_BRK uint16_t (0xA5) /* Application Break (One Shot Control) */ 153 | #define HID_USAGE_APP_DBGBRK uint16_t (0xA6) /* Application Debugger Break (One Shot Control) */ 154 | #define HID_USAGE_SYS_SPKMUTE uint16_t (0xA7) /* System Speaker Mute (One Shot Control) */ 155 | #define HID_USAGE_SYS_HIBERN uint16_t (0xA8) /* System Hibernate (One Shot Control) */ 156 | /* A9-AF Reserved */ 157 | #define HID_USAGE_SYS_SIDPINV uint16_t (0xB0) /* System Display Invert (One Shot Control) */ 158 | #define HID_USAGE_SYS_DISPINT uint16_t (0xB1) /* System Display Internal (One Shot Control) */ 159 | #define HID_USAGE_SYS_DISPEXT uint16_t (0xB2) /* System Display External (One Shot Control) */ 160 | #define HID_USAGE_SYS_DISPBOTH uint16_t (0xB3) /* System Display Both (One Shot Control) */ 161 | #define HID_USAGE_SYS_DISPDUAL uint16_t (0xB4) /* System Display Dual (One Shot Control) */ 162 | #define HID_USAGE_SYS_DISPTGLIE uint16_t (0xB5) /* System Display Toggle Int/Ext (One Shot Control) */ 163 | #define HID_USAGE_SYS_DISP_SWAP uint16_t (0xB6) /* System Display Swap Primary/Secondary (One Shot Control) */ 164 | #define HID_USAGE_SYS_DIPS_LCDA uint16_t (0xB7) /* System Display LCD Autoscale (One Shot Control) */ 165 | /* B8-FFFF Reserved */ 166 | 167 | /** 168 | * @} 169 | */ 170 | 171 | #ifdef __cplusplus 172 | } 173 | #endif 174 | 175 | #endif /* __USDH_HID_USAGE_H */ 176 | 177 | /** 178 | * @} 179 | */ 180 | 181 | /** 182 | * @} 183 | */ 184 | 185 | /** 186 | * @} 187 | */ 188 | 189 | /** 190 | * @} 191 | */ 192 | -------------------------------------------------------------------------------- /Class/HID/Src/usbh_hid_keybd.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STMicroelectronics/stm32-mw-usb-host/9d46e44c858a77bf126920b7bcc258d59afa89b1/Class/HID/Src/usbh_hid_keybd.c -------------------------------------------------------------------------------- /Class/HID/Src/usbh_hid_mouse.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_hid_mouse.c 4 | * @author MCD Application Team 5 | * @brief This file is the application layer for USB Host HID Mouse Handling. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* BSPDependencies 20 | - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" 21 | - "stm32xxxxx_{eval}{discovery}_io.c" 22 | - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" 23 | - "stm32xxxxx_{eval}{discovery}_sdram.c" 24 | EndBSPDependencies */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "usbh_hid_mouse.h" 28 | #include "usbh_hid_parser.h" 29 | 30 | 31 | /** @addtogroup USBH_LIB 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup USBH_CLASS 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup USBH_HID_CLASS 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBH_HID_MOUSE 44 | * @brief This file includes HID Layer Handlers for USB Host HID class. 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions 49 | * @{ 50 | */ 51 | /** 52 | * @} 53 | */ 54 | 55 | 56 | /** @defgroup USBH_HID_MOUSE_Private_Defines 57 | * @{ 58 | */ 59 | /** 60 | * @} 61 | */ 62 | 63 | 64 | /** @defgroup USBH_HID_MOUSE_Private_Macros 65 | * @{ 66 | */ 67 | /** 68 | * @} 69 | */ 70 | 71 | /** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes 72 | * @{ 73 | */ 74 | static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost); 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | 81 | /** @defgroup USBH_HID_MOUSE_Private_Variables 82 | * @{ 83 | */ 84 | HID_MOUSE_Info_TypeDef mouse_info; 85 | uint8_t mouse_report_data[USBH_HID_MOUSE_REPORT_SIZE]; 86 | uint8_t mouse_rx_report_buf[USBH_HID_MOUSE_REPORT_SIZE]; 87 | 88 | /* Structures defining how to access items in a HID mouse report */ 89 | /* Access button 1 state. */ 90 | static const HID_Report_ItemTypedef prop_b1 = 91 | { 92 | mouse_report_data, /*data*/ 93 | 1, /*size*/ 94 | 0, /*shift*/ 95 | 0, /*count (only for array items)*/ 96 | 0, /*signed?*/ 97 | 0, /*min value read can return*/ 98 | 1, /*max value read can return*/ 99 | 0, /*min value device can report*/ 100 | 1, /*max value device can report*/ 101 | 1 /*resolution*/ 102 | }; 103 | 104 | /* Access button 2 state. */ 105 | static const HID_Report_ItemTypedef prop_b2 = 106 | { 107 | mouse_report_data, /*data*/ 108 | 1, /*size*/ 109 | 1, /*shift*/ 110 | 0, /*count (only for array items)*/ 111 | 0, /*signed?*/ 112 | 0, /*min value read can return*/ 113 | 1, /*max value read can return*/ 114 | 0, /*min value device can report*/ 115 | 1, /*max value device can report*/ 116 | 1 /*resolution*/ 117 | }; 118 | 119 | /* Access button 3 state. */ 120 | static const HID_Report_ItemTypedef prop_b3 = 121 | { 122 | mouse_report_data, /*data*/ 123 | 1, /*size*/ 124 | 2, /*shift*/ 125 | 0, /*count (only for array items)*/ 126 | 0, /*signed?*/ 127 | 0, /*min value read can return*/ 128 | 1, /*max value read can return*/ 129 | 0, /*min vale device can report*/ 130 | 1, /*max value device can report*/ 131 | 1 /*resolution*/ 132 | }; 133 | 134 | /* Access x coordinate change. */ 135 | static const HID_Report_ItemTypedef prop_x = 136 | { 137 | mouse_report_data + 1U, /*data*/ 138 | 8, /*size*/ 139 | 0, /*shift*/ 140 | 0, /*count (only for array items)*/ 141 | 1, /*signed?*/ 142 | 0, /*min value read can return*/ 143 | 0xFFFF,/*max value read can return*/ 144 | 0, /*min vale device can report*/ 145 | 0xFFFF,/*max value device can report*/ 146 | 1 /*resolution*/ 147 | }; 148 | 149 | /* Access y coordinate change. */ 150 | static const HID_Report_ItemTypedef prop_y = 151 | { 152 | mouse_report_data + 2U, /*data*/ 153 | 8, /*size*/ 154 | 0, /*shift*/ 155 | 0, /*count (only for array items)*/ 156 | 1, /*signed?*/ 157 | 0, /*min value read can return*/ 158 | 0xFFFF,/*max value read can return*/ 159 | 0, /*min vale device can report*/ 160 | 0xFFFF,/*max value device can report*/ 161 | 1 /*resolution*/ 162 | }; 163 | 164 | 165 | /** 166 | * @} 167 | */ 168 | 169 | 170 | /** @defgroup USBH_HID_MOUSE_Private_Functions 171 | * @{ 172 | */ 173 | 174 | /** 175 | * @brief USBH_HID_MouseInit 176 | * The function init the HID mouse. 177 | * @param phost: Host handle 178 | * @retval USBH Status 179 | */ 180 | USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost) 181 | { 182 | uint32_t i; 183 | HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; 184 | 185 | mouse_info.x = 0U; 186 | mouse_info.y = 0U; 187 | mouse_info.buttons[0] = 0U; 188 | mouse_info.buttons[1] = 0U; 189 | mouse_info.buttons[2] = 0U; 190 | 191 | for (i = 0U; i < sizeof(mouse_report_data); i++) 192 | { 193 | mouse_report_data[i] = 0U; 194 | mouse_rx_report_buf[i] = 0U; 195 | } 196 | 197 | if (HID_Handle->length > sizeof(mouse_report_data)) 198 | { 199 | HID_Handle->length = (uint16_t)sizeof(mouse_report_data); 200 | } 201 | HID_Handle->pData = mouse_rx_report_buf; 202 | 203 | if ((HID_QUEUE_SIZE * sizeof(mouse_report_data)) > sizeof(phost->device.Data)) 204 | { 205 | return USBH_FAIL; 206 | } 207 | else 208 | { 209 | USBH_HID_FifoInit(&HID_Handle->fifo, phost->device.Data, (uint16_t)(HID_QUEUE_SIZE * sizeof(mouse_report_data))); 210 | } 211 | 212 | return USBH_OK; 213 | } 214 | 215 | /** 216 | * @brief USBH_HID_GetMouseInfo 217 | * The function return mouse information. 218 | * @param phost: Host handle 219 | * @retval mouse information 220 | */ 221 | HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost) 222 | { 223 | if (USBH_HID_MouseDecode(phost) == USBH_OK) 224 | { 225 | return &mouse_info; 226 | } 227 | else 228 | { 229 | return NULL; 230 | } 231 | } 232 | 233 | /** 234 | * @brief USBH_HID_MouseDecode 235 | * The function decode mouse data. 236 | * @param phost: Host handle 237 | * @retval USBH Status 238 | */ 239 | static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost) 240 | { 241 | HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; 242 | 243 | if ((HID_Handle->length == 0U) || (HID_Handle->fifo.buf == NULL)) 244 | { 245 | return USBH_FAIL; 246 | } 247 | /*Fill report */ 248 | if (USBH_HID_FifoRead(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length) 249 | { 250 | /*Decode report */ 251 | mouse_info.x = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0U); 252 | mouse_info.y = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0U); 253 | 254 | mouse_info.buttons[0] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0U); 255 | mouse_info.buttons[1] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0U); 256 | mouse_info.buttons[2] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0U); 257 | 258 | return USBH_OK; 259 | } 260 | return USBH_FAIL; 261 | } 262 | 263 | /** 264 | * @} 265 | */ 266 | 267 | /** 268 | * @} 269 | */ 270 | 271 | /** 272 | * @} 273 | */ 274 | 275 | /** 276 | * @} 277 | */ 278 | 279 | 280 | /** 281 | * @} 282 | */ 283 | -------------------------------------------------------------------------------- /Class/HID/Src/usbh_hid_parser.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_hid_parser.c 4 | * @author MCD Application Team 5 | * @brief This file is the HID Layer Handlers for USB Host HID class. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* BSPDependencies 20 | - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" 21 | - "stm32xxxxx_{eval}{discovery}_io.c" 22 | - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" 23 | - "stm32xxxxx_{eval}{discovery}_sdram.c" 24 | EndBSPDependencies */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "usbh_hid_parser.h" 28 | 29 | 30 | /** @addtogroup USBH_LIB 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup USBH_CLASS 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup USBH_HID_CLASS 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBH_HID_PARSER 43 | * @brief This file includes HID parsers for USB Host HID class. 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBH_HID_PARSER_Private_TypesDefinitions 48 | * @{ 49 | */ 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @defgroup USBH_HID_PARSER_Private_Defines 56 | * @{ 57 | */ 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @defgroup USBH_HID_PARSER_Private_Macros 64 | * @{ 65 | */ 66 | /** 67 | * @} 68 | */ 69 | 70 | /** @defgroup USBH_HID_PARSER_Private_FunctionPrototypes 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | 79 | /** @defgroup USBH_HID_PARSER_Private_Variables 80 | * @{ 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | 88 | /** @defgroup USBH_HID_PARSER_Private_Functions 89 | * @{ 90 | */ 91 | 92 | /** 93 | * @brief HID_ReadItem 94 | * The function read a report item. 95 | * @param ri: report item 96 | * @param ndx: report index 97 | * @retval status (0 : fail / otherwise: item value) 98 | */ 99 | uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx) 100 | { 101 | uint32_t val = 0U; 102 | uint32_t x = 0U; 103 | uint32_t bofs; 104 | uint8_t *data = ri->data; 105 | uint8_t shift = ri->shift; 106 | 107 | /* get the logical value of the item */ 108 | 109 | /* if this is an array, we may need to offset ri->data.*/ 110 | if (ri->count > 0U) 111 | { 112 | /* If app tries to read outside of the array. */ 113 | if (ri->count <= ndx) 114 | { 115 | return (0U); 116 | } 117 | 118 | /* calculate bit offset */ 119 | bofs = ndx * ri->size; 120 | bofs += shift; 121 | /* calculate byte offset + shift pair from bit offset. */ 122 | data += bofs / 8U; 123 | shift = (uint8_t)(bofs % 8U); 124 | } 125 | /* read data bytes in little endian order */ 126 | for (x = 0U; x < (((ri->size & 0x7U) != 0U) ? ((ri->size / 8U) + 1U) : (ri->size / 8U)); x++) 127 | { 128 | val = (uint32_t)((uint32_t)(*data) << (x * 8U)); 129 | } 130 | val = (val >> shift) & (((uint32_t)1U << ri->size) - 1U); 131 | 132 | if ((val < ri->logical_min) || (val > ri->logical_max)) 133 | { 134 | return (0U); 135 | } 136 | 137 | /* convert logical value to physical value */ 138 | /* See if the number is negative or not. */ 139 | if ((ri->sign != 0U) && ((val & ((uint32_t)1U << (ri->size - 1U))) != 0U)) 140 | { 141 | /* yes, so sign extend value to 32 bits. */ 142 | uint32_t vs = (uint32_t)((0xffffffffU & ~((1U << (ri->size)) - 1U)) | val); 143 | 144 | if (ri->resolution == 1U) 145 | { 146 | return ((uint32_t)vs); 147 | } 148 | return ((uint32_t)(vs * ri->resolution)); 149 | } 150 | else 151 | { 152 | if (ri->resolution == 1U) 153 | { 154 | return (val); 155 | } 156 | return (val * ri->resolution); 157 | } 158 | } 159 | 160 | /** 161 | * @brief HID_WriteItem 162 | * The function write a report item. 163 | * @param ri: report item 164 | * @param ndx: report index 165 | * @retval status (1: fail/ 0 : Ok) 166 | */ 167 | uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx) 168 | { 169 | uint32_t x; 170 | uint32_t mask; 171 | uint32_t bofs; 172 | uint8_t *data = ri->data; 173 | uint8_t shift = ri->shift; 174 | 175 | if ((value < ri->physical_min) || (value > ri->physical_max)) 176 | { 177 | return (1U); 178 | } 179 | 180 | /* if this is an array, we may need to offset ri->data.*/ 181 | if (ri->count > 0U) 182 | { 183 | /* If app tries to read outside of the array. */ 184 | if (ri->count >= ndx) 185 | { 186 | return (0U); 187 | } 188 | /* calculate bit offset */ 189 | bofs = ndx * ri->size; 190 | bofs += shift; 191 | /* calculate byte offset + shift pair from bit offset. */ 192 | data += bofs / 8U; 193 | shift = (uint8_t)(bofs % 8U); 194 | 195 | } 196 | 197 | /* Convert physical value to logical value. */ 198 | if (ri->resolution != 1U) 199 | { 200 | value = value / ri->resolution; 201 | } 202 | 203 | /* Write logical value to report in little endian order. */ 204 | mask = ((uint32_t)1U << ri->size) - 1U; 205 | value = (value & mask) << shift; 206 | 207 | for (x = 0U; x < (((ri->size & 0x7U) != 0U) ? ((ri->size / 8U) + 1U) : (ri->size / 8U)); x++) 208 | { 209 | *(ri->data + x) = (uint8_t)((*(ri->data + x) & ~(mask >> (x * 8U))) | 210 | ((value >> (x * 8U)) & (mask >> (x * 8U)))); 211 | } 212 | 213 | return 0U; 214 | } 215 | 216 | /** 217 | * @} 218 | */ 219 | 220 | /** 221 | * @} 222 | */ 223 | 224 | /** 225 | * @} 226 | */ 227 | 228 | /** 229 | * @} 230 | */ 231 | 232 | 233 | /** 234 | * @} 235 | */ 236 | 237 | -------------------------------------------------------------------------------- /Class/MSC/Inc/usbh_msc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_msc.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the prototypes for the usbh_msc.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_MSC_H 21 | #define __USBH_MSC_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | #include "usbh_msc_bot.h" 30 | #include "usbh_msc_scsi.h" 31 | 32 | /** @addtogroup USBH_LIB 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup USBH_CLASS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup USBH_MSC_CLASS 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBH_MSC_CORE 45 | * @brief This file is the Header file for usbh_msc.c 46 | * @{ 47 | */ 48 | 49 | 50 | /** @defgroup USBH_MSC_CORE_Exported_Types 51 | * @{ 52 | */ 53 | 54 | typedef enum 55 | { 56 | MSC_INIT = 0, 57 | MSC_IDLE, 58 | MSC_TEST_UNIT_READY, 59 | MSC_READ_CAPACITY10, 60 | MSC_READ_INQUIRY, 61 | MSC_REQUEST_SENSE, 62 | MSC_READ, 63 | MSC_WRITE, 64 | MSC_UNRECOVERED_ERROR, 65 | MSC_PERIODIC_CHECK, 66 | MSC_USER_NOTIFY 67 | } 68 | MSC_StateTypeDef; 69 | 70 | typedef enum 71 | { 72 | MSC_OK, 73 | MSC_NOT_READY, 74 | MSC_ERROR, 75 | 76 | } 77 | MSC_ErrorTypeDef; 78 | 79 | typedef enum 80 | { 81 | MSC_REQ_IDLE = 0, 82 | MSC_REQ_RESET, 83 | MSC_REQ_GET_MAX_LUN, 84 | MSC_REQ_ERROR, 85 | } 86 | MSC_ReqStateTypeDef; 87 | 88 | #ifndef MAX_SUPPORTED_LUN 89 | #define MAX_SUPPORTED_LUN 2U 90 | #endif 91 | 92 | 93 | /* Structure for LUN */ 94 | typedef struct 95 | { 96 | MSC_StateTypeDef state; 97 | MSC_ErrorTypeDef error; 98 | USBH_StatusTypeDef prev_ready_state; 99 | SCSI_CapacityTypeDef capacity; 100 | SCSI_SenseTypeDef sense; 101 | SCSI_StdInquiryDataTypeDef inquiry; 102 | uint8_t state_changed; 103 | 104 | } 105 | MSC_LUNTypeDef; 106 | 107 | /* Structure for MSC process */ 108 | typedef struct _MSC_Process 109 | { 110 | uint8_t max_lun; 111 | uint8_t Reserved[3]; 112 | uint8_t InPipe; 113 | uint8_t OutPipe; 114 | uint8_t OutEp; 115 | uint8_t InEp; 116 | uint16_t OutEpSize; 117 | uint16_t InEpSize; 118 | MSC_StateTypeDef state; 119 | MSC_ErrorTypeDef error; 120 | MSC_ReqStateTypeDef req_state; 121 | MSC_ReqStateTypeDef prev_req_state; 122 | BOT_HandleTypeDef hbot; 123 | MSC_LUNTypeDef unit[MAX_SUPPORTED_LUN]; 124 | uint16_t current_lun; 125 | uint16_t lun; 126 | uint16_t rw_lun; 127 | uint32_t timer; 128 | } 129 | MSC_HandleTypeDef; 130 | 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | 137 | 138 | /** @defgroup USBH_MSC_CORE_Exported_Defines 139 | * @{ 140 | */ 141 | 142 | #define USB_REQ_BOT_RESET 0xFFU 143 | #define USB_REQ_GET_MAX_LUN 0xFEU 144 | 145 | 146 | /* MSC Class Codes */ 147 | #define USB_MSC_CLASS 0x08U 148 | 149 | /* Interface Descriptor field values for HID Boot Protocol */ 150 | #define MSC_BOT 0x50U 151 | #define MSC_TRANSPARENT 0x06U 152 | /** 153 | * @} 154 | */ 155 | 156 | /** @defgroup USBH_MSC_CORE_Exported_Macros 157 | * @{ 158 | */ 159 | /** 160 | * @} 161 | */ 162 | 163 | /** @defgroup USBH_MSC_CORE_Exported_Variables 164 | * @{ 165 | */ 166 | extern USBH_ClassTypeDef USBH_msc; 167 | #define USBH_MSC_CLASS &USBH_msc 168 | 169 | /** 170 | * @} 171 | */ 172 | 173 | /** @defgroup USBH_MSC_CORE_Exported_FunctionsPrototype 174 | * @{ 175 | */ 176 | uint8_t USBH_MSC_IsReady(USBH_HandleTypeDef *phost); 177 | uint8_t USBH_MSC_GetMaxLUN(USBH_HandleTypeDef *phost); 178 | uint8_t USBH_MSC_UnitIsReady(USBH_HandleTypeDef *phost, uint8_t lun); 179 | 180 | USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, 181 | MSC_LUNTypeDef *info); 182 | 183 | USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost, uint8_t lun, 184 | uint32_t address, uint8_t *pbuf, uint32_t length); 185 | 186 | USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost, uint8_t lun, 187 | uint32_t address, uint8_t *pbuf, uint32_t length); 188 | /** 189 | * @} 190 | */ 191 | 192 | #ifdef __cplusplus 193 | } 194 | #endif 195 | 196 | #endif /* __USBH_MSC_H */ 197 | 198 | 199 | /** 200 | * @} 201 | */ 202 | 203 | /** 204 | * @} 205 | */ 206 | 207 | /** 208 | * @} 209 | */ 210 | 211 | /** 212 | * @} 213 | */ 214 | 215 | 216 | 217 | -------------------------------------------------------------------------------- /Class/MSC/Inc/usbh_msc_bot.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_msc_bot.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbh_msc_bot.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_MSC_BOT_H 21 | #define __USBH_MSC_BOT_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | 30 | /** @addtogroup USBH_LIB 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup USBH_CLASS 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup USBH_MSC_CLASS 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBH_MSC_BOT 43 | * @brief This file is the Header file for usbh_msc_bot.c 44 | * @{ 45 | */ 46 | 47 | 48 | /** @defgroup USBH_MSC_BOT_Exported_Types 49 | * @{ 50 | */ 51 | 52 | typedef enum 53 | { 54 | BOT_OK = 0, 55 | BOT_FAIL = 1, 56 | BOT_PHASE_ERROR = 2, 57 | BOT_BUSY = 3 58 | } 59 | BOT_StatusTypeDef; 60 | 61 | typedef enum 62 | { 63 | BOT_CMD_IDLE = 0, 64 | BOT_CMD_SEND, 65 | BOT_CMD_WAIT, 66 | } 67 | BOT_CMDStateTypeDef; 68 | 69 | /* CSW Status Definitions */ 70 | typedef enum 71 | { 72 | 73 | BOT_CSW_CMD_PASSED = 0x00, 74 | BOT_CSW_CMD_FAILED = 0x01, 75 | BOT_CSW_PHASE_ERROR = 0x02, 76 | } 77 | BOT_CSWStatusTypeDef; 78 | 79 | typedef enum 80 | { 81 | BOT_SEND_CBW = 1, 82 | BOT_SEND_CBW_WAIT, 83 | BOT_DATA_IN, 84 | BOT_DATA_IN_WAIT, 85 | BOT_DATA_OUT, 86 | BOT_DATA_OUT_WAIT, 87 | BOT_RECEIVE_CSW, 88 | BOT_RECEIVE_CSW_WAIT, 89 | BOT_ERROR_IN, 90 | BOT_ERROR_OUT, 91 | BOT_UNRECOVERED_ERROR 92 | } 93 | BOT_StateTypeDef; 94 | 95 | typedef union 96 | { 97 | struct __CBW 98 | { 99 | uint32_t Signature; 100 | uint32_t Tag; 101 | uint32_t DataTransferLength; 102 | uint8_t Flags; 103 | uint8_t LUN; 104 | uint8_t CBLength; 105 | uint8_t CB[16]; 106 | } field; 107 | uint8_t data[31]; 108 | } 109 | BOT_CBWTypeDef; 110 | 111 | typedef union 112 | { 113 | struct __CSW 114 | { 115 | uint32_t Signature; 116 | uint32_t Tag; 117 | uint32_t DataResidue; 118 | uint8_t Status; 119 | } field; 120 | uint8_t data[13]; 121 | } 122 | BOT_CSWTypeDef; 123 | 124 | typedef struct 125 | { 126 | uint32_t data[16]; 127 | BOT_StateTypeDef state; 128 | BOT_StateTypeDef prev_state; 129 | BOT_CMDStateTypeDef cmd_state; 130 | BOT_CBWTypeDef cbw; 131 | uint8_t Reserved1; 132 | BOT_CSWTypeDef csw; 133 | uint8_t Reserved2[3]; 134 | uint8_t *pbuf; 135 | } 136 | BOT_HandleTypeDef; 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | 143 | 144 | /** @defgroup USBH_MSC_BOT_Exported_Defines 145 | * @{ 146 | */ 147 | #define BOT_CBW_SIGNATURE 0x43425355U 148 | #define BOT_CBW_TAG 0x20304050U 149 | #define BOT_CSW_SIGNATURE 0x53425355U 150 | #define BOT_CBW_LENGTH 31U 151 | #define BOT_CSW_LENGTH 13U 152 | 153 | 154 | 155 | #define BOT_SEND_CSW_DISABLE 0U 156 | #define BOT_SEND_CSW_ENABLE 1U 157 | 158 | #define BOT_DIR_IN 0U 159 | #define BOT_DIR_OUT 1U 160 | #define BOT_DIR_BOTH 2U 161 | 162 | #define BOT_PAGE_LENGTH 512U 163 | 164 | 165 | #define BOT_CBW_CB_LENGTH 16U 166 | 167 | 168 | #define MAX_BULK_STALL_COUNT_LIMIT 0x04U /* If STALL is seen on Bulk 169 | Endpoint continuously, this means 170 | that device and Host has phase error 171 | Hence a Reset is needed */ 172 | 173 | /** 174 | * @} 175 | */ 176 | 177 | /** @defgroup USBH_MSC_BOT_Exported_Macros 178 | * @{ 179 | */ 180 | /** 181 | * @} 182 | */ 183 | 184 | /** @defgroup USBH_MSC_BOT_Exported_Variables 185 | * @{ 186 | */ 187 | 188 | /** 189 | * @} 190 | */ 191 | 192 | /** @defgroup USBH_MSC_BOT_Exported_FunctionsPrototype 193 | * @{ 194 | */ 195 | USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost); 196 | USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun); 197 | 198 | USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost); 199 | USBH_StatusTypeDef USBH_MSC_BOT_Process(USBH_HandleTypeDef *phost, uint8_t lun); 200 | USBH_StatusTypeDef USBH_MSC_BOT_Error(USBH_HandleTypeDef *phost, uint8_t lun); 201 | 202 | 203 | 204 | /** 205 | * @} 206 | */ 207 | 208 | #ifdef __cplusplus 209 | } 210 | #endif 211 | 212 | #endif /* __USBH_MSC_BOT_H__ */ 213 | 214 | 215 | /** 216 | * @} 217 | */ 218 | 219 | /** 220 | * @} 221 | */ 222 | 223 | /** 224 | * @} 225 | */ 226 | 227 | /** 228 | * @} 229 | */ 230 | 231 | -------------------------------------------------------------------------------- /Class/MSC/Inc/usbh_msc_scsi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_msc_scsi.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbh_msc_scsi.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_MSC_SCSI_H 21 | #define __USBH_MSC_SCSI_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | 30 | 31 | /** @addtogroup USBH_LIB 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup USBH_CLASS 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup USBH_MSC_CLASS 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBH_MSC_SCSI 44 | * @brief This file is the Header file for usbh_msc_scsi.c 45 | * @{ 46 | */ 47 | 48 | 49 | /* Capacity data */ 50 | typedef struct 51 | { 52 | uint32_t block_nbr; 53 | uint16_t block_size; 54 | } SCSI_CapacityTypeDef; 55 | 56 | 57 | /* Sense data */ 58 | typedef struct 59 | { 60 | uint8_t key; 61 | uint8_t asc; 62 | uint8_t ascq; 63 | } SCSI_SenseTypeDef; 64 | 65 | /* INQUIRY data */ 66 | typedef struct 67 | { 68 | uint8_t PeripheralQualifier; 69 | uint8_t DeviceType; 70 | uint8_t RemovableMedia; 71 | uint8_t vendor_id[9]; 72 | uint8_t product_id[17]; 73 | uint8_t revision_id[5]; 74 | } SCSI_StdInquiryDataTypeDef; 75 | 76 | /** @defgroup USBH_MSC_SCSI_Exported_Defines 77 | * @{ 78 | */ 79 | #define OPCODE_TEST_UNIT_READY 0x00U 80 | #define OPCODE_READ_CAPACITY10 0x25U 81 | #define OPCODE_READ10 0x28U 82 | #define OPCODE_WRITE10 0x2AU 83 | #define OPCODE_REQUEST_SENSE 0x03U 84 | #define OPCODE_INQUIRY 0x12U 85 | 86 | #define DATA_LEN_MODE_TEST_UNIT_READY 0U 87 | #define DATA_LEN_READ_CAPACITY10 8U 88 | #define DATA_LEN_INQUIRY 36U 89 | #define DATA_LEN_REQUEST_SENSE 14U 90 | 91 | #define CBW_CB_LENGTH 16U 92 | #define CBW_LENGTH 10U 93 | 94 | /** @defgroup USBH_MSC_SCSI_Exported_Defines 95 | * @{ 96 | */ 97 | #define SCSI_SENSE_KEY_NO_SENSE 0x00U 98 | #define SCSI_SENSE_KEY_RECOVERED_ERROR 0x01U 99 | #define SCSI_SENSE_KEY_NOT_READY 0x02U 100 | #define SCSI_SENSE_KEY_MEDIUM_ERROR 0x03U 101 | #define SCSI_SENSE_KEY_HARDWARE_ERROR 0x04U 102 | #define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05U 103 | #define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06U 104 | #define SCSI_SENSE_KEY_DATA_PROTECT 0x07U 105 | #define SCSI_SENSE_KEY_BLANK_CHECK 0x08U 106 | #define SCSI_SENSE_KEY_VENDOR_SPECIFIC 0x09U 107 | #define SCSI_SENSE_KEY_COPY_ABORTED 0x0AU 108 | #define SCSI_SENSE_KEY_ABORTED_COMMAND 0x0BU 109 | #define SCSI_SENSE_KEY_VOLUME_OVERFLOW 0x0DU 110 | #define SCSI_SENSE_KEY_MISCOMPARE 0x0EU 111 | /** 112 | * @} 113 | */ 114 | 115 | 116 | /** @defgroup USBH_MSC_SCSI_Exported_Defines 117 | * @{ 118 | */ 119 | #define SCSI_ASC_NO_ADDITIONAL_SENSE_INFORMATION 0x00 120 | #define SCSI_ASC_LOGICAL_UNIT_NOT_READY 0x04 121 | #define SCSI_ASC_INVALID_FIELD_IN_CDB 0x24 122 | #define SCSI_ASC_WRITE_PROTECTED 0x27 123 | #define SCSI_ASC_FORMAT_ERROR 0x31 124 | #define SCSI_ASC_INVALID_COMMAND_OPERATION_CODE 0x20 125 | #define SCSI_ASC_NOT_READY_TO_READY_CHANGE 0x28 126 | #define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3A 127 | /** 128 | * @} 129 | */ 130 | 131 | 132 | /** @defgroup USBH_MSC_SCSI_Exported_Defines 133 | * @{ 134 | */ 135 | #define SCSI_ASCQ_FORMAT_COMMAND_FAILED 0x01 136 | #define SCSI_ASCQ_INITIALIZING_COMMAND_REQUIRED 0x02 137 | #define SCSI_ASCQ_OPERATION_IN_PROGRESS 0x07 138 | 139 | /** 140 | * @} 141 | */ 142 | 143 | /** @defgroup USBH_MSC_SCSI_Exported_Macros 144 | * @{ 145 | */ 146 | /** 147 | * @} 148 | */ 149 | 150 | /** @defgroup _Exported_Variables 151 | * @{ 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /** @defgroup USBH_MSC_SCSI_Exported_FunctionsPrototype 159 | * @{ 160 | */ 161 | USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady(USBH_HandleTypeDef *phost, 162 | uint8_t lun); 163 | 164 | USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity(USBH_HandleTypeDef *phost, 165 | uint8_t lun, 166 | SCSI_CapacityTypeDef *capacity); 167 | 168 | USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry(USBH_HandleTypeDef *phost, 169 | uint8_t lun, 170 | SCSI_StdInquiryDataTypeDef *inquiry); 171 | 172 | USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense(USBH_HandleTypeDef *phost, 173 | uint8_t lun, 174 | SCSI_SenseTypeDef *sense_data); 175 | 176 | USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost, 177 | uint8_t lun, 178 | uint32_t address, 179 | uint8_t *pbuf, 180 | uint32_t length); 181 | 182 | USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost, 183 | uint8_t lun, 184 | uint32_t address, 185 | uint8_t *pbuf, 186 | uint32_t length); 187 | 188 | 189 | /** 190 | * @} 191 | */ 192 | 193 | #ifdef __cplusplus 194 | } 195 | #endif 196 | 197 | #endif /* __USBH_MSC_SCSI_H */ 198 | 199 | 200 | /** 201 | * @} 202 | */ 203 | 204 | /** 205 | * @} 206 | */ 207 | 208 | /** 209 | * @} 210 | */ 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | -------------------------------------------------------------------------------- /Class/MSC/Src/usbh_msc_scsi.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_msc_scsi.c 4 | * @author MCD Application Team 5 | * @brief This file implements the SCSI commands 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* BSPDependencies 20 | - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" 21 | - "stm32xxxxx_{eval}{discovery}_io.c" 22 | - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" 23 | - "stm32xxxxx_{eval}{discovery}_sdram.c" 24 | EndBSPDependencies */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "usbh_msc.h" 28 | #include "usbh_msc_scsi.h" 29 | #include "usbh_msc_bot.h" 30 | 31 | 32 | /** @addtogroup USBH_LIB 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup USBH_CLASS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup USBH_MSC_CLASS 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBH_MSC_SCSI 45 | * @brief This file includes the mass storage related functions 46 | * @{ 47 | */ 48 | 49 | 50 | /** @defgroup USBH_MSC_SCSI_Private_TypesDefinitions 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup USBH_MSC_SCSI_Private_Defines 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBH_MSC_SCSI_Private_Macros 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | 73 | /** @defgroup USBH_MSC_SCSI_Private_FunctionPrototypes 74 | * @{ 75 | */ 76 | /** 77 | * @} 78 | */ 79 | 80 | 81 | /** @defgroup USBH_MSC_SCSI_Exported_Variables 82 | * @{ 83 | */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | 90 | /** @defgroup USBH_MSC_SCSI_Private_Functions 91 | * @{ 92 | */ 93 | 94 | 95 | /** 96 | * @brief USBH_MSC_SCSI_TestUnitReady 97 | * Issue TestUnitReady command. 98 | * @param phost: Host handle 99 | * @param lun: Logical Unit Number 100 | * @retval USBH Status 101 | */ 102 | USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady(USBH_HandleTypeDef *phost, 103 | uint8_t lun) 104 | { 105 | USBH_StatusTypeDef error = USBH_FAIL; 106 | MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; 107 | 108 | switch (MSC_Handle->hbot.cmd_state) 109 | { 110 | case BOT_CMD_SEND: 111 | 112 | /* Prepare the CBW and relevant field */ 113 | MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_MODE_TEST_UNIT_READY; 114 | MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT; 115 | MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; 116 | 117 | (void)USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); 118 | MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_TEST_UNIT_READY; 119 | 120 | MSC_Handle->hbot.state = BOT_SEND_CBW; 121 | MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; 122 | error = USBH_BUSY; 123 | break; 124 | 125 | case BOT_CMD_WAIT: 126 | error = USBH_MSC_BOT_Process(phost, lun); 127 | break; 128 | 129 | default: 130 | break; 131 | } 132 | 133 | return error; 134 | } 135 | 136 | /** 137 | * @brief USBH_MSC_SCSI_ReadCapacity 138 | * Issue Read Capacity command. 139 | * @param phost: Host handle 140 | * @param lun: Logical Unit Number 141 | * @param capacity: pointer to the capacity structure 142 | * @retval USBH Status 143 | */ 144 | USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity(USBH_HandleTypeDef *phost, 145 | uint8_t lun, 146 | SCSI_CapacityTypeDef *capacity) 147 | { 148 | USBH_StatusTypeDef error = USBH_BUSY; 149 | MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; 150 | 151 | switch (MSC_Handle->hbot.cmd_state) 152 | { 153 | case BOT_CMD_SEND: 154 | 155 | /* Prepare the CBW and relevant field */ 156 | MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_READ_CAPACITY10; 157 | MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; 158 | MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; 159 | 160 | (void)USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); 161 | MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_READ_CAPACITY10; 162 | 163 | MSC_Handle->hbot.state = BOT_SEND_CBW; 164 | 165 | MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; 166 | MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; 167 | error = USBH_BUSY; 168 | break; 169 | 170 | case BOT_CMD_WAIT: 171 | 172 | error = USBH_MSC_BOT_Process(phost, lun); 173 | 174 | if (error == USBH_OK) 175 | { 176 | /* Assign the capacity */ 177 | capacity->block_nbr = MSC_Handle->hbot.pbuf[3] | ((uint32_t)MSC_Handle->hbot.pbuf[2] << 8U) | \ 178 | ((uint32_t)MSC_Handle->hbot.pbuf[1] << 16U) | ((uint32_t)MSC_Handle->hbot.pbuf[0] << 24U); 179 | 180 | /* Assign the page length */ 181 | capacity->block_size = (uint16_t)(MSC_Handle->hbot.pbuf[7] | ((uint32_t)MSC_Handle->hbot.pbuf[6] << 8U)); 182 | } 183 | break; 184 | 185 | default: 186 | break; 187 | } 188 | 189 | return error; 190 | } 191 | 192 | /** 193 | * @brief USBH_MSC_SCSI_Inquiry 194 | * Issue Inquiry command. 195 | * @param phost: Host handle 196 | * @param lun: Logical Unit Number 197 | * @param capacity: pointer to the inquiry structure 198 | * @retval USBH Status 199 | */ 200 | USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry(USBH_HandleTypeDef *phost, uint8_t lun, 201 | SCSI_StdInquiryDataTypeDef *inquiry) 202 | { 203 | USBH_StatusTypeDef error = USBH_FAIL; 204 | MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; 205 | 206 | switch (MSC_Handle->hbot.cmd_state) 207 | { 208 | case BOT_CMD_SEND: 209 | 210 | /* Prepare the CBW and relevant field */ 211 | MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_INQUIRY; 212 | MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; 213 | MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; 214 | 215 | (void)USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_LENGTH); 216 | MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_INQUIRY; 217 | MSC_Handle->hbot.cbw.field.CB[1] = (lun << 5); 218 | MSC_Handle->hbot.cbw.field.CB[2] = 0U; 219 | MSC_Handle->hbot.cbw.field.CB[3] = 0U; 220 | MSC_Handle->hbot.cbw.field.CB[4] = 0x24U; 221 | MSC_Handle->hbot.cbw.field.CB[5] = 0U; 222 | 223 | MSC_Handle->hbot.state = BOT_SEND_CBW; 224 | 225 | MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; 226 | MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; 227 | error = USBH_BUSY; 228 | break; 229 | 230 | case BOT_CMD_WAIT: 231 | 232 | error = USBH_MSC_BOT_Process(phost, lun); 233 | 234 | if (error == USBH_OK) 235 | { 236 | (void)USBH_memset(inquiry, 0, sizeof(SCSI_StdInquiryDataTypeDef)); 237 | /* Assign Inquiry Data */ 238 | inquiry->DeviceType = MSC_Handle->hbot.pbuf[0] & 0x1FU; 239 | inquiry->PeripheralQualifier = MSC_Handle->hbot.pbuf[0] >> 5U; 240 | 241 | if (((uint32_t)MSC_Handle->hbot.pbuf[1] & 0x80U) == 0x80U) 242 | { 243 | inquiry->RemovableMedia = 1U; 244 | } 245 | else 246 | { 247 | inquiry->RemovableMedia = 0U; 248 | } 249 | 250 | (void)USBH_memcpy(inquiry->vendor_id, &MSC_Handle->hbot.pbuf[8], 8U); 251 | (void)USBH_memcpy(inquiry->product_id, &MSC_Handle->hbot.pbuf[16], 16U); 252 | (void)USBH_memcpy(inquiry->revision_id, &MSC_Handle->hbot.pbuf[32], 4U); 253 | } 254 | break; 255 | 256 | default: 257 | break; 258 | } 259 | 260 | return error; 261 | } 262 | 263 | /** 264 | * @brief USBH_MSC_SCSI_RequestSense 265 | * Issue RequestSense command. 266 | * @param phost: Host handle 267 | * @param lun: Logical Unit Number 268 | * @param capacity: pointer to the sense data structure 269 | * @retval USBH Status 270 | */ 271 | USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense(USBH_HandleTypeDef *phost, 272 | uint8_t lun, 273 | SCSI_SenseTypeDef *sense_data) 274 | { 275 | USBH_StatusTypeDef error = USBH_FAIL; 276 | MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; 277 | 278 | switch (MSC_Handle->hbot.cmd_state) 279 | { 280 | case BOT_CMD_SEND: 281 | 282 | /* Prepare the CBW and relevant field */ 283 | MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_REQUEST_SENSE; 284 | MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; 285 | MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; 286 | 287 | (void)USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); 288 | MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_REQUEST_SENSE; 289 | MSC_Handle->hbot.cbw.field.CB[1] = (lun << 5); 290 | MSC_Handle->hbot.cbw.field.CB[2] = 0U; 291 | MSC_Handle->hbot.cbw.field.CB[3] = 0U; 292 | MSC_Handle->hbot.cbw.field.CB[4] = DATA_LEN_REQUEST_SENSE; 293 | MSC_Handle->hbot.cbw.field.CB[5] = 0U; 294 | 295 | MSC_Handle->hbot.state = BOT_SEND_CBW; 296 | MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; 297 | MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; 298 | error = USBH_BUSY; 299 | break; 300 | 301 | case BOT_CMD_WAIT: 302 | 303 | error = USBH_MSC_BOT_Process(phost, lun); 304 | 305 | if (error == USBH_OK) 306 | { 307 | sense_data->key = MSC_Handle->hbot.pbuf[2] & 0x0FU; 308 | sense_data->asc = MSC_Handle->hbot.pbuf[12]; 309 | sense_data->ascq = MSC_Handle->hbot.pbuf[13]; 310 | 311 | if (sense_data->asc == SCSI_ASC_MEDIUM_NOT_PRESENT) 312 | { 313 | USBH_UsrLog("MSC Device MEDIUM not present"); 314 | error = USBH_UNRECOVERED_ERROR; 315 | } 316 | } 317 | break; 318 | 319 | default: 320 | break; 321 | } 322 | 323 | return error; 324 | } 325 | 326 | /** 327 | * @brief USBH_MSC_SCSI_Write 328 | * Issue write10 command. 329 | * @param phost: Host handle 330 | * @param lun: Logical Unit Number 331 | * @param address: sector address 332 | * @param pbuf: pointer to data 333 | * @param length: number of sector to write 334 | * @retval USBH Status 335 | */ 336 | USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost, 337 | uint8_t lun, 338 | uint32_t address, 339 | uint8_t *pbuf, 340 | uint32_t length) 341 | { 342 | USBH_StatusTypeDef error = USBH_FAIL; 343 | 344 | MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; 345 | 346 | switch (MSC_Handle->hbot.cmd_state) 347 | { 348 | case BOT_CMD_SEND: 349 | 350 | /* Prepare the CBW and relevant field */ 351 | MSC_Handle->hbot.cbw.field.DataTransferLength = length * MSC_Handle->unit[lun].capacity.block_size; 352 | MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT; 353 | MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; 354 | 355 | (void)USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); 356 | MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_WRITE10; 357 | 358 | /* Logical block address */ 359 | MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t *)(void *)&address)[3]); 360 | MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t *)(void *)&address)[2]); 361 | MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t *)(void *)&address)[1]); 362 | MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t *)(void *)&address)[0]); 363 | 364 | 365 | /*Transfer length */ 366 | MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)(void *)&length)[1]); 367 | MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)(void *)&length)[0]); 368 | 369 | 370 | MSC_Handle->hbot.state = BOT_SEND_CBW; 371 | MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; 372 | MSC_Handle->hbot.pbuf = pbuf; 373 | error = USBH_BUSY; 374 | break; 375 | 376 | case BOT_CMD_WAIT: 377 | error = USBH_MSC_BOT_Process(phost, lun); 378 | break; 379 | 380 | default: 381 | break; 382 | } 383 | 384 | return error; 385 | } 386 | 387 | /** 388 | * @brief USBH_MSC_SCSI_Read 389 | * Issue Read10 command. 390 | * @param phost: Host handle 391 | * @param lun: Logical Unit Number 392 | * @param address: sector address 393 | * @param pbuf: pointer to data 394 | * @param length: number of sector to read 395 | * @retval USBH Status 396 | */ 397 | USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost, 398 | uint8_t lun, 399 | uint32_t address, 400 | uint8_t *pbuf, 401 | uint32_t length) 402 | { 403 | USBH_StatusTypeDef error = USBH_FAIL; 404 | MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; 405 | 406 | switch (MSC_Handle->hbot.cmd_state) 407 | { 408 | case BOT_CMD_SEND: 409 | 410 | /* Prepare the CBW and relevant field */ 411 | MSC_Handle->hbot.cbw.field.DataTransferLength = length * MSC_Handle->unit[lun].capacity.block_size; 412 | MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; 413 | MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; 414 | 415 | (void)USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); 416 | MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_READ10; 417 | 418 | /* Logical block address */ 419 | MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t *)(void *)&address)[3]); 420 | MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t *)(void *)&address)[2]); 421 | MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t *)(void *)&address)[1]); 422 | MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t *)(void *)&address)[0]); 423 | 424 | 425 | /* Transfer length */ 426 | MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)(void *)&length)[1]); 427 | MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)(void *)&length)[0]); 428 | 429 | 430 | MSC_Handle->hbot.state = BOT_SEND_CBW; 431 | MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; 432 | MSC_Handle->hbot.pbuf = pbuf; 433 | error = USBH_BUSY; 434 | break; 435 | 436 | case BOT_CMD_WAIT: 437 | error = USBH_MSC_BOT_Process(phost, lun); 438 | break; 439 | 440 | default: 441 | break; 442 | } 443 | 444 | return error; 445 | } 446 | 447 | 448 | /** 449 | * @} 450 | */ 451 | 452 | /** 453 | * @} 454 | */ 455 | 456 | /** 457 | * @} 458 | */ 459 | 460 | /** 461 | * @} 462 | */ 463 | 464 | /** 465 | * @} 466 | */ 467 | 468 | 469 | 470 | -------------------------------------------------------------------------------- /Class/MTP/Inc/usbh_mtp.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_mtp.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the prototypes for the usbh_mtp.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_MTP_H 21 | #define __USBH_MTP_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_mtp_ptp.h" 29 | #include "usbh_core.h" 30 | 31 | 32 | /** @addtogroup USBH_LIB 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup USBH_CLASS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup USBH_MTP_CLASS 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBH_MTP_CORE 45 | * @brief This file is the Header file for usbh_mtp.c 46 | * @{ 47 | */ 48 | 49 | 50 | 51 | 52 | /*Communication Class codes*/ 53 | #define USB_MTP_CLASS 0x06U /* Still Image Class)*/ 54 | #define MTP_MAX_STORAGE_UNITS_NBR PTP_MAX_STORAGE_UNITS_NBR 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup USBH_MTP_CORE_Exported_Types 61 | * @{ 62 | */ 63 | typedef enum 64 | { 65 | MTP_IDLE = 0, 66 | MTP_GETDEVICEINFO, 67 | MTP_OPENSESSION, 68 | MTP_CLOSESESSION, 69 | MTP_GETSTORAGEIDS, 70 | MTP_GETSTORAGEINFO, 71 | } 72 | MTP_StateTypeDef; 73 | 74 | 75 | typedef enum 76 | { 77 | MTP_EVENTS_INIT = 0, 78 | MTP_EVENTS_GETDATA, 79 | } 80 | MTP_EventsStateTypeDef; 81 | 82 | 83 | typedef struct 84 | { 85 | MTP_EventsStateTypeDef state; 86 | uint32_t timer; 87 | uint16_t poll; 88 | PTP_EventContainerTypedef container; 89 | } 90 | MTP_EventHandleTypedef; 91 | 92 | typedef struct 93 | { 94 | 95 | uint32_t CurrentStorageId; 96 | uint32_t ObjectFormatCode; 97 | uint32_t CurrentObjectHandler; 98 | uint8_t ObjectHandlerNbr; 99 | uint32_t Objdepth; 100 | } 101 | MTP_ParamsTypedef; 102 | 103 | 104 | typedef struct 105 | { 106 | PTP_DeviceInfoTypedef devinfo; 107 | PTP_StorageIDsTypedef storids; 108 | PTP_StorageInfoTypedef storinfo[MTP_MAX_STORAGE_UNITS_NBR]; 109 | PTP_ObjectHandlesTypedef Handles; 110 | } 111 | MTP_InfoTypedef; 112 | 113 | /* Structure for MTP process */ 114 | typedef struct _MTP_Process 115 | { 116 | MTP_InfoTypedef info; 117 | MTP_ParamsTypedef params; 118 | 119 | uint8_t DataInPipe; 120 | uint8_t DataOutPipe; 121 | uint8_t NotificationPipe; 122 | 123 | uint8_t DataOutEp; 124 | uint8_t DataInEp; 125 | uint8_t NotificationEp; 126 | 127 | uint16_t DataOutEpSize; 128 | uint16_t DataInEpSize; 129 | uint16_t NotificationEpSize; 130 | MTP_StateTypeDef state; 131 | MTP_EventHandleTypedef events; 132 | PTP_HandleTypeDef ptp; 133 | uint32_t current_storage_unit; 134 | uint32_t is_ready; 135 | } 136 | MTP_HandleTypeDef; 137 | 138 | #define MTP_StorageInfoTypedef PTP_StorageInfoTypedef 139 | #define MTP_ObjectHandlesTypedef PTP_ObjectHandlesTypedef 140 | #define MTP_ObjectInfoTypedef PTP_ObjectInfoTypedef 141 | /** 142 | * @} 143 | */ 144 | 145 | /** @defgroup USBH_MTP_CORE_Exported_Defines 146 | * @{ 147 | */ 148 | 149 | /** 150 | * @} 151 | */ 152 | 153 | /** @defgroup USBH_MTP_CORE_Exported_Macros 154 | * @{ 155 | */ 156 | /** 157 | * @} 158 | */ 159 | 160 | /** @defgroup USBH_MTP_CORE_Exported_Variables 161 | * @{ 162 | */ 163 | extern USBH_ClassTypeDef MTP_Class; 164 | #define USBH_MTP_CLASS &MTP_Class 165 | 166 | /** 167 | * @} 168 | */ 169 | 170 | /** @defgroup USBH_MTP_CORE_Exported_FunctionsPrototype 171 | * @{ 172 | */ 173 | uint8_t USBH_MTP_IsReady(USBH_HandleTypeDef *phost); 174 | USBH_StatusTypeDef USBH_MTP_SelectStorage(USBH_HandleTypeDef *phost, uint8_t storage_idx); 175 | USBH_StatusTypeDef USBH_MTP_GetNumStorage(USBH_HandleTypeDef *phost, uint8_t *storage_num); 176 | USBH_StatusTypeDef USBH_MTP_GetNumObjects(USBH_HandleTypeDef *phost, 177 | uint32_t storage_idx, 178 | uint32_t objectformatcode, 179 | uint32_t associationOH, 180 | uint32_t *numobs); 181 | USBH_StatusTypeDef USBH_MTP_GetStorageInfo(USBH_HandleTypeDef *phost, 182 | uint8_t storage_idx, 183 | MTP_StorageInfoTypedef *info); 184 | 185 | USBH_StatusTypeDef USBH_MTP_GetObjectHandles(USBH_HandleTypeDef *phost, 186 | uint32_t storage_idx, 187 | uint32_t objectformatcode, 188 | uint32_t associationOH, 189 | PTP_ObjectHandlesTypedef *objecthandles); 190 | 191 | USBH_StatusTypeDef USBH_MTP_GetObjectInfo(USBH_HandleTypeDef *phost, 192 | uint32_t handle, 193 | PTP_ObjectInfoTypedef *objectinfo); 194 | 195 | USBH_StatusTypeDef USBH_MTP_DeleteObject(USBH_HandleTypeDef *phost, 196 | uint32_t handle, 197 | uint32_t objectformatcode); 198 | 199 | USBH_StatusTypeDef USBH_MTP_GetObject(USBH_HandleTypeDef *phost, 200 | uint32_t handle, 201 | uint8_t *object); 202 | 203 | USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, 204 | uint32_t handle, 205 | uint32_t offset, 206 | uint32_t maxbytes, 207 | uint8_t *object, 208 | uint32_t *len); 209 | 210 | USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported(USBH_HandleTypeDef *phost, 211 | uint16_t ofc, 212 | uint32_t *propnum, 213 | uint16_t *props); 214 | 215 | USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, 216 | uint16_t opc, 217 | uint16_t ofc, 218 | PTP_ObjectPropDescTypeDef *opd); 219 | 220 | USBH_StatusTypeDef USBH_MTP_GetObjectPropList(USBH_HandleTypeDef *phost, 221 | uint32_t handle, 222 | MTP_PropertiesTypedef *pprops, 223 | uint32_t *nrofprops); 224 | 225 | USBH_StatusTypeDef USBH_MTP_SendObject(USBH_HandleTypeDef *phost, 226 | uint32_t handle, 227 | uint8_t *object, 228 | uint32_t size); 229 | 230 | USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc(USBH_HandleTypeDef *phost, 231 | uint16_t propcode, 232 | PTP_DevicePropDescTypdef *devicepropertydesc); 233 | 234 | void USBH_MTP_EventsCallback(USBH_HandleTypeDef *phost, uint32_t event, uint32_t param); 235 | /** 236 | * @} 237 | */ 238 | 239 | #ifdef __cplusplus 240 | } 241 | #endif 242 | 243 | #endif /* __USBH_MTP_H */ 244 | 245 | /** 246 | * @} 247 | */ 248 | 249 | /** 250 | * @} 251 | */ 252 | 253 | /** 254 | * @} 255 | */ 256 | 257 | /** 258 | * @} 259 | */ 260 | 261 | -------------------------------------------------------------------------------- /Class/Template/Inc/usbh_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_template.h 4 | * @author MCD Application Team 5 | * @brief This file contains all the prototypes for the usbh_template.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_TEMPLATE_H 21 | #define __USBH_TEMPLATE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | 30 | 31 | /** @addtogroup USBH_LIB 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup USBH_CLASS 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup USBH_TEMPLATE_CLASS 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBH_TEMPLATE_CLASS 44 | * @brief This file is the Header file for usbh_template.c 45 | * @{ 46 | */ 47 | 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /** @defgroup USBH_TEMPLATE_CLASS_Exported_Types 54 | * @{ 55 | */ 56 | 57 | /* States for TEMPLATE State Machine */ 58 | 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup USBH_TEMPLATE_CLASS_Exported_Defines 65 | * @{ 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBH_TEMPLATE_CLASS_Exported_Macros 73 | * @{ 74 | */ 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @defgroup USBH_TEMPLATE_CLASS_Exported_Variables 80 | * @{ 81 | */ 82 | extern USBH_ClassTypeDef TEMPLATE_Class; 83 | #define USBH_TEMPLATE_CLASS &TEMPLATE_Class 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup USBH_TEMPLATE_CLASS_Exported_FunctionsPrototype 90 | * @{ 91 | */ 92 | USBH_StatusTypeDef USBH_TEMPLATE_IOProcess(USBH_HandleTypeDef *phost); 93 | USBH_StatusTypeDef USBH_TEMPLATE_Init(USBH_HandleTypeDef *phost); 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USBH_TEMPLATE_H */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | -------------------------------------------------------------------------------- /Class/Template/Src/usbh_template.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_mtp.c 4 | * @author MCD Application Team 5 | * @brief This file is the MTP Layer Handlers for USB Host MTP class. 6 | * 7 | * 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * Copyright (c) 2015 STMicroelectronics. 12 | * All rights reserved. 13 | * 14 | * This software is licensed under terms that can be found in the LICENSE file 15 | * in the root directory of this software component. 16 | * If no LICENSE file comes with this software, it is provided AS-IS. 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "usbh_template.h" 23 | 24 | /** @addtogroup USBH_LIB 25 | * @{ 26 | */ 27 | 28 | /** @addtogroup USBH_CLASS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup USBH_TEMPLATE_CLASS 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBH_TEMPLATE_CORE 37 | * @brief This file includes TEMPLATE Layer Handlers for USB Host TEMPLATE class. 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBH_TEMPLATE_CORE_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBH_TEMPLATE_CORE_Private_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBH_TEMPLATE_CORE_Private_Macros 58 | * @{ 59 | */ 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | /** @defgroup USBH_TEMPLATE_CORE_Private_Variables 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | 73 | /** @defgroup USBH_TEMPLATE_CORE_Private_FunctionPrototypes 74 | * @{ 75 | */ 76 | 77 | static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit(USBH_HandleTypeDef *phost); 78 | static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit(USBH_HandleTypeDef *phost); 79 | static USBH_StatusTypeDef USBH_TEMPLATE_Process(USBH_HandleTypeDef *phost); 80 | static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest(USBH_HandleTypeDef *phost); 81 | 82 | 83 | USBH_ClassTypeDef TEMPLATE_Class = 84 | { 85 | "TEMPLATE", 86 | USB_TEMPLATE_CLASS, 87 | USBH_TEMPLATE_InterfaceInit, 88 | USBH_TEMPLATE_InterfaceDeInit, 89 | USBH_TEMPLATE_ClassRequest, 90 | USBH_TEMPLATE_Process 91 | }; 92 | /** 93 | * @} 94 | */ 95 | 96 | 97 | /** @defgroup USBH_TEMPLATE_CORE_Private_Functions 98 | * @{ 99 | */ 100 | 101 | /** 102 | * @brief USBH_TEMPLATE_InterfaceInit 103 | * The function init the TEMPLATE class. 104 | * @param phost: Host handle 105 | * @retval USBH Status 106 | */ 107 | static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit(USBH_HandleTypeDef *phost) 108 | { 109 | /* Prevent unused argument(s) compilation warning */ 110 | UNUSED(phost); 111 | 112 | return USBH_OK; 113 | } 114 | 115 | 116 | /** 117 | * @brief USBH_TEMPLATE_InterfaceDeInit 118 | * The function DeInit the Pipes used for the TEMPLATE class. 119 | * @param phost: Host handle 120 | * @retval USBH Status 121 | */ 122 | USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit(USBH_HandleTypeDef *phost) 123 | { 124 | /* Prevent unused argument(s) compilation warning */ 125 | UNUSED(phost); 126 | 127 | return USBH_OK; 128 | } 129 | 130 | 131 | /** 132 | * @brief USBH_TEMPLATE_ClassRequest 133 | * The function is responsible for handling Standard requests 134 | * for TEMPLATE class. 135 | * @param phost: Host handle 136 | * @retval USBH Status 137 | */ 138 | static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest(USBH_HandleTypeDef *phost) 139 | { 140 | /* Prevent unused argument(s) compilation warning */ 141 | UNUSED(phost); 142 | 143 | return USBH_OK; 144 | } 145 | 146 | 147 | /** 148 | * @brief USBH_TEMPLATE_Process 149 | * The function is for managing state machine for TEMPLATE data transfers 150 | * @param phost: Host handle 151 | * @retval USBH Status 152 | */ 153 | static USBH_StatusTypeDef USBH_TEMPLATE_Process(USBH_HandleTypeDef *phost) 154 | { 155 | /* Prevent unused argument(s) compilation warning */ 156 | UNUSED(phost); 157 | 158 | return USBH_OK; 159 | } 160 | 161 | 162 | /** 163 | * @brief USBH_TEMPLATE_Init 164 | * The function Initialize the TEMPLATE function 165 | * @param phost: Host handle 166 | * @retval USBH Status 167 | */ 168 | USBH_StatusTypeDef USBH_TEMPLATE_Init(USBH_HandleTypeDef *phost) 169 | { 170 | USBH_StatusTypeDef Status = USBH_BUSY; 171 | 172 | #if (USBH_USE_OS == 1U) 173 | osEvent event; 174 | 175 | event = osMessageGet(phost->class_ready_event, osWaitForever); 176 | 177 | if (event.status == osEventMessage) 178 | { 179 | if (event.value.v == USBH_CLASS_EVENT) 180 | { 181 | #else 182 | while ((Status == USBH_BUSY) || (Status == USBH_FAIL)) 183 | { 184 | /* Host background process */ 185 | USBH_Process(phost); 186 | 187 | if (phost->gState == HOST_CLASS) 188 | { 189 | #endif 190 | Status = USBH_OK; 191 | } 192 | } 193 | return Status; 194 | } 195 | 196 | /** 197 | * @brief USBH_TEMPLATE_IOProcess 198 | * TEMPLATE TEMPLATE process 199 | * @param phost: Host handle 200 | * @retval USBH Status 201 | */ 202 | USBH_StatusTypeDef USBH_TEMPLATE_IOProcess(USBH_HandleTypeDef *phost) 203 | { 204 | if (phost->device.is_connected == 1U) 205 | { 206 | if (phost->gState == HOST_CLASS) 207 | { 208 | USBH_TEMPLATE_Process(phost); 209 | } 210 | } 211 | 212 | return USBH_OK; 213 | } 214 | 215 | /** 216 | * @} 217 | */ 218 | 219 | /** 220 | * @} 221 | */ 222 | 223 | /** 224 | * @} 225 | */ 226 | 227 | 228 | /** 229 | * @} 230 | */ 231 | 232 | 233 | /** 234 | * @} 235 | */ 236 | 237 | -------------------------------------------------------------------------------- /Core/Inc/usbh_conf_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_conf_template.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbh_conf_template.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __USBH_CONF_TEMPLATE_H 21 | #define __USBH_CONF_TEMPLATE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32fxxx.h" /* replace 'stm32xxx' with your HAL driver header filename, ex: stm32f4xx.h */ 29 | #include 30 | #include 31 | #include 32 | 33 | /** @addtogroup STM32_USB_HOST_LIBRARY 34 | * @{ 35 | */ 36 | 37 | /** @defgroup USBH_CONF 38 | * @brief usb host low level driver configuration file 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBH_CONF_Exported_Defines 43 | * @{ 44 | */ 45 | 46 | #define USBH_MAX_NUM_ENDPOINTS 2U 47 | #define USBH_MAX_NUM_INTERFACES 2U 48 | #define USBH_MAX_NUM_CONFIGURATION 1U 49 | #define USBH_KEEP_CFG_DESCRIPTOR 1U 50 | #define USBH_MAX_NUM_SUPPORTED_CLASS 1U 51 | #define USBH_MAX_SIZE_CONFIGURATION 0x200U 52 | #define USBH_MAX_DATA_BUFFER 0x200U 53 | #define USBH_DEBUG_LEVEL 2U 54 | #define USBH_USE_OS 1U 55 | #define USBH_IN_NAK_PROCESS 0 56 | 57 | /** @defgroup USBH_Exported_Macros 58 | * @{ 59 | */ 60 | 61 | /* Memory management macros */ 62 | #define USBH_malloc malloc 63 | #define USBH_free free 64 | #define USBH_memset memset 65 | #define USBH_memcpy memcpy 66 | 67 | /* DEBUG macros */ 68 | #if (USBH_DEBUG_LEVEL > 0U) 69 | #define USBH_UsrLog(...) do { \ 70 | printf(__VA_ARGS__); \ 71 | printf("\n"); \ 72 | } while (0) 73 | #else 74 | #define USBH_UsrLog(...) do {} while (0) 75 | #endif 76 | 77 | #if (USBH_DEBUG_LEVEL > 1U) 78 | 79 | #define USBH_ErrLog(...) do { \ 80 | printf("ERROR: "); \ 81 | printf(__VA_ARGS__); \ 82 | printf("\n"); \ 83 | } while (0) 84 | #else 85 | #define USBH_ErrLog(...) do {} while (0) 86 | #endif 87 | 88 | #if (USBH_DEBUG_LEVEL > 2U) 89 | #define USBH_DbgLog(...) do { \ 90 | printf("DEBUG : "); \ 91 | printf(__VA_ARGS__); \ 92 | printf("\n"); \ 93 | } while (0) 94 | #else 95 | #define USBH_DbgLog(...) do {} while (0) 96 | #endif 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | 109 | /** @defgroup USBH_CONF_Exported_Types 110 | * @{ 111 | */ 112 | /** 113 | * @} 114 | */ 115 | 116 | 117 | /** @defgroup USBH_CONF_Exported_Macros 118 | * @{ 119 | */ 120 | /** 121 | * @} 122 | */ 123 | 124 | /** @defgroup USBH_CONF_Exported_Variables 125 | * @{ 126 | */ 127 | /** 128 | * @} 129 | */ 130 | 131 | /** @defgroup USBH_CONF_Exported_FunctionsPrototype 132 | * @{ 133 | */ 134 | /** 135 | * @} 136 | */ 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | 142 | #endif /* __USBH_CONF_TEMPLATE_H */ 143 | 144 | 145 | /** 146 | * @} 147 | */ 148 | 149 | /** 150 | * @} 151 | */ 152 | -------------------------------------------------------------------------------- /Core/Inc/usbh_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_core.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbh_core.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* Define to prevent recursive ----------------------------------------------*/ 19 | #ifndef __USBH_CORE_H 20 | #define __USBH_CORE_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "usbh_conf.h" 28 | #include "usbh_def.h" 29 | #include "usbh_ioreq.h" 30 | #include "usbh_pipes.h" 31 | #include "usbh_ctlreq.h" 32 | 33 | /** @addtogroup USBH_LIB 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup USBH_LIB_CORE 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBH_CORE 42 | * @brief This file is the Header file for usbh_core.c 43 | * @{ 44 | */ 45 | 46 | 47 | /** @defgroup USBH_CORE_Exported_Defines 48 | * @{ 49 | */ 50 | 51 | /** 52 | * @} 53 | */ 54 | #define HOST_USER_SELECT_CONFIGURATION 0x01U 55 | #define HOST_USER_CLASS_ACTIVE 0x02U 56 | #define HOST_USER_CLASS_SELECTED 0x03U 57 | #define HOST_USER_CONNECTION 0x04U 58 | #define HOST_USER_DISCONNECTION 0x05U 59 | #define HOST_USER_UNRECOVERED_ERROR 0x06U 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | 68 | /** @defgroup USBH_CORE_Exported_Macros 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBH_CORE_Exported_Variables 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup USBH_CORE_Exported_FunctionsPrototype 85 | * @{ 86 | */ 87 | USBH_StatusTypeDef USBH_Init(USBH_HandleTypeDef *phost, 88 | void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t id), uint8_t id); 89 | 90 | USBH_StatusTypeDef USBH_DeInit(USBH_HandleTypeDef *phost); 91 | USBH_StatusTypeDef USBH_Start(USBH_HandleTypeDef *phost); 92 | USBH_StatusTypeDef USBH_Stop(USBH_HandleTypeDef *phost); 93 | USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost); 94 | USBH_StatusTypeDef USBH_ReEnumerate(USBH_HandleTypeDef *phost); 95 | USBH_StatusTypeDef USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass); 96 | USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface); 97 | 98 | uint8_t USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, uint8_t interface_number, uint8_t alt_settings); 99 | uint8_t USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t SubClass, uint8_t Protocol); 100 | uint8_t USBH_GetActiveClass(USBH_HandleTypeDef *phost); 101 | uint8_t USBH_IsPortEnabled(USBH_HandleTypeDef *phost); 102 | 103 | /* USBH Low Level Driver */ 104 | USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost); 105 | USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost); 106 | USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost); 107 | USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost); 108 | 109 | USBH_StatusTypeDef USBH_LL_Connect(USBH_HandleTypeDef *phost); 110 | USBH_StatusTypeDef USBH_LL_Disconnect(USBH_HandleTypeDef *phost); 111 | USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef *phost); 112 | USBH_StatusTypeDef USBH_LL_ResetPort(USBH_HandleTypeDef *phost); 113 | uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef *phost, uint8_t pipe); 114 | 115 | USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state); 116 | 117 | USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef *phost, 118 | uint8_t pipe, 119 | uint8_t epnum, 120 | uint8_t dev_address, 121 | uint8_t speed, 122 | uint8_t ep_type, 123 | uint16_t mps); 124 | 125 | USBH_StatusTypeDef USBH_LL_ActivatePipe(USBH_HandleTypeDef *phost, uint8_t pipe); 126 | USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe); 127 | 128 | USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef *phost, 129 | uint8_t pipe, 130 | uint8_t direction, 131 | uint8_t ep_type, 132 | uint8_t token, 133 | uint8_t *pbuff, 134 | uint16_t length, 135 | uint8_t do_ping); 136 | 137 | USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, uint8_t pipe); 138 | 139 | #if (USBH_USE_OS == 1U) 140 | USBH_StatusTypeDef USBH_LL_NotifyURBChange(USBH_HandleTypeDef *phost); 141 | void USBH_OS_PutMessage(USBH_HandleTypeDef *phost, USBH_OSEventTypeDef message, uint32_t timeout, uint32_t priority); 142 | #endif /*(USBH_USE_OS == 1U) */ 143 | 144 | USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle); 145 | 146 | uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t pipe); 147 | 148 | void USBH_LL_PortDisabled(USBH_HandleTypeDef *phost); 149 | void USBH_LL_PortEnabled(USBH_HandleTypeDef *phost); 150 | 151 | /* USBH Time base */ 152 | void USBH_LL_SetTimer(USBH_HandleTypeDef *phost, uint32_t time); 153 | void USBH_LL_IncTimer(USBH_HandleTypeDef *phost); 154 | 155 | void USBH_Delay(uint32_t Delay); 156 | /** 157 | * @} 158 | */ 159 | 160 | #ifdef __cplusplus 161 | } 162 | #endif 163 | 164 | #endif /* __USBH_CORE_H */ 165 | /** 166 | * @} 167 | */ 168 | 169 | /** 170 | * @} 171 | */ 172 | 173 | /** 174 | * @} 175 | */ 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /Core/Inc/usbh_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_ctlreq.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbh_ctlreq.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_CTLREQ_H 21 | #define __USBH_CTLREQ_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | 30 | /** @addtogroup USBH_LIB 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup USBH_LIB_CORE 35 | * @{ 36 | */ 37 | 38 | /** @defgroup USBH_CTLREQ 39 | * @brief This file is the 40 | * @{ 41 | */ 42 | 43 | 44 | /** @defgroup USBH_CTLREQ_Exported_Defines 45 | * @{ 46 | */ 47 | /*Standard Feature Selector for clear feature command*/ 48 | #define FEATURE_SELECTOR_ENDPOINT 0x00U 49 | #define FEATURE_SELECTOR_DEVICE 0x01U 50 | #define FEATURE_SELECTOR_REMOTEWAKEUP 0X01U 51 | 52 | 53 | #define INTERFACE_DESC_TYPE 0x04U 54 | #define ENDPOINT_DESC_TYPE 0x05U 55 | #define INTERFACE_DESC_SIZE 0x09U 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | 62 | /** @defgroup USBH_CTLREQ_Exported_Types 63 | * @{ 64 | */ 65 | /** 66 | * @} 67 | */ 68 | 69 | 70 | /** @defgroup USBH_CTLREQ_Exported_Macros 71 | * @{ 72 | */ 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup USBH_CTLREQ_Exported_Variables 78 | * @{ 79 | */ 80 | extern uint8_t USBH_CfgDesc[512]; 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @defgroup USBH_CTLREQ_Exported_FunctionsPrototype 86 | * @{ 87 | */ 88 | USBH_StatusTypeDef USBH_CtlReq(USBH_HandleTypeDef *phost, uint8_t *buff, 89 | uint16_t length); 90 | 91 | USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost, 92 | uint8_t req_type, uint16_t value_idx, 93 | uint8_t *buff, uint16_t length); 94 | 95 | USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost, uint16_t length); 96 | 97 | USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost, 98 | uint8_t string_index, uint8_t *buff, 99 | uint16_t length); 100 | 101 | USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, uint16_t cfg_idx); 102 | 103 | USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost, uint16_t length); 104 | 105 | USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost, 106 | uint8_t DeviceAddress); 107 | 108 | USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, uint8_t ep_num, 109 | uint8_t altSetting); 110 | 111 | USBH_StatusTypeDef USBH_SetFeature(USBH_HandleTypeDef *phost, uint8_t wValue); 112 | 113 | USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, uint8_t ep_num); 114 | 115 | USBH_DescHeader_t *USBH_GetNextDesc(uint8_t *pbuf, uint16_t *ptr); 116 | /** 117 | * @} 118 | */ 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | #endif /* __USBH_CTLREQ_H */ 125 | 126 | /** 127 | * @} 128 | */ 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /** 135 | * @} 136 | */ 137 | 138 | 139 | -------------------------------------------------------------------------------- /Core/Inc/usbh_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_def.h 4 | * @author MCD Application Team 5 | * @brief Definitions used in the USB host library 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef USBH_DEF_H 21 | #define USBH_DEF_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_conf.h" 29 | 30 | /** @addtogroup USBH_LIB 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup USBH_LIB_CORE 35 | * @{ 36 | */ 37 | 38 | /** @defgroup USBH_DEF 39 | * @brief This file is includes USB descriptors 40 | * @{ 41 | */ 42 | 43 | #ifndef NULL 44 | #define NULL 0U 45 | #endif 46 | 47 | #ifndef FALSE 48 | #define FALSE 0U 49 | #endif 50 | 51 | #ifndef TRUE 52 | #define TRUE 1U 53 | #endif 54 | 55 | #ifndef USBH_DEV_RESET_TIMEOUT 56 | #define USBH_DEV_RESET_TIMEOUT 1000U 57 | #endif 58 | 59 | #define ValBit(VAR,POS) (VAR & (1 << POS)) 60 | #define SetBit(VAR,POS) (VAR |= (1 << POS)) 61 | #define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255)) 62 | 63 | #ifndef MIN 64 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 65 | #endif 66 | 67 | #ifndef MAX 68 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 69 | #endif 70 | 71 | #define LE16(addr) (((uint16_t)(addr)[0]) | \ 72 | ((uint16_t)(((uint32_t)(addr)[1]) << 8))) 73 | 74 | #define LE24(addr) (((uint32_t)(addr)[0]) | \ 75 | (((uint32_t)(addr)[1]) << 8) | \ 76 | (((uint32_t)(addr)[2]) << 16)) 77 | 78 | #define LE32(addr) (((uint32_t)(addr)[0]) | \ 79 | (((uint32_t)(addr)[1]) << 8) | \ 80 | (((uint32_t)(addr)[2]) << 16) | \ 81 | (((uint32_t)(addr)[3]) << 24)) 82 | 83 | #define LE64(addr) (((uint64_t)(addr)[0]) | \ 84 | (((uint64_t)(addr)[1]) << 8) | \ 85 | (((uint64_t)(addr)[2]) << 16) | \ 86 | (((uint64_t)(addr)[3]) << 24) | \ 87 | (((uint64_t)(addr)[4]) << 32) | \ 88 | (((uint64_t)(addr)[5]) << 40) | \ 89 | (((uint64_t)(addr)[6]) << 48) | \ 90 | (((uint64_t)(addr)[7]) << 56)) 91 | 92 | #define LE16S(addr) ((int16_t)(LE16((addr)))) 93 | #define LE24S(addr) ((int32_t)(LE24((addr)))) 94 | #define LE32S(addr) ((int32_t)(LE32((addr)))) 95 | #define LE64S(addr) ((int64_t)(LE64((addr)))) 96 | 97 | #ifndef USBH_MAX_DATA_BUFFER 98 | #define USBH_MAX_DATA_BUFFER 0x400U 99 | #endif 100 | 101 | #define USBH_MAX_EP_PACKET_SIZE 0x400U 102 | 103 | #define USB_LEN_DESC_HDR 0x02U 104 | #define USB_LEN_DEV_DESC 0x12U 105 | #define USB_LEN_CFG_DESC 0x09U 106 | #define USB_LEN_IF_DESC 0x09U 107 | #define USB_LEN_EP_DESC 0x07U 108 | #define USB_LEN_OTG_DESC 0x03U 109 | #define USB_LEN_SETUP_PKT 0x08U 110 | 111 | /* bmRequestType :D7 Data Phase Transfer Direction */ 112 | #define USB_REQ_DIR_MASK 0x80U 113 | #define USB_H2D 0x00U 114 | #define USB_D2H 0x80U 115 | 116 | /* bmRequestType D6..5 Type */ 117 | #define USB_REQ_TYPE_STANDARD 0x00U 118 | #define USB_REQ_TYPE_CLASS 0x20U 119 | #define USB_REQ_TYPE_VENDOR 0x40U 120 | #define USB_REQ_TYPE_RESERVED 0x60U 121 | 122 | /* bmRequestType D4..0 Recipient */ 123 | #define USB_REQ_RECIPIENT_DEVICE 0x00U 124 | #define USB_REQ_RECIPIENT_INTERFACE 0x01U 125 | #define USB_REQ_RECIPIENT_ENDPOINT 0x02U 126 | #define USB_REQ_RECIPIENT_OTHER 0x03U 127 | 128 | /* Table 9-4. Standard Request Codes */ 129 | /* bRequest , Value */ 130 | #define USB_REQ_GET_STATUS 0x00U 131 | #define USB_REQ_CLEAR_FEATURE 0x01U 132 | #define USB_REQ_SET_FEATURE 0x03U 133 | #define USB_REQ_SET_ADDRESS 0x05U 134 | #define USB_REQ_GET_DESCRIPTOR 0x06U 135 | #define USB_REQ_SET_DESCRIPTOR 0x07U 136 | #define USB_REQ_GET_CONFIGURATION 0x08U 137 | #define USB_REQ_SET_CONFIGURATION 0x09U 138 | #define USB_REQ_GET_INTERFACE 0x0AU 139 | #define USB_REQ_SET_INTERFACE 0x0BU 140 | #define USB_REQ_SYNCH_FRAME 0x0CU 141 | 142 | /* Table 9-5. Descriptor Types of USB Specifications */ 143 | #define USB_DESC_TYPE_DEVICE 0x01U 144 | #define USB_DESC_TYPE_CONFIGURATION 0x02U 145 | #define USB_DESC_TYPE_STRING 0x03U 146 | #define USB_DESC_TYPE_INTERFACE 0x04U 147 | #define USB_DESC_TYPE_ENDPOINT 0x05U 148 | #define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U 149 | #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U 150 | #define USB_DESC_TYPE_INTERFACE_POWER 0x08U 151 | #define USB_DESC_TYPE_HID 0x21U 152 | #define USB_DESC_TYPE_HID_REPORT 0x22U 153 | 154 | 155 | #define USB_DEVICE_DESC_SIZE 0x12U 156 | #define USB_CONFIGURATION_DESC_SIZE 0x09U 157 | #define USB_HID_DESC_SIZE 0x09U 158 | #define USB_INTERFACE_DESC_SIZE 0x09U 159 | #define USB_ENDPOINT_DESC_SIZE 0x07U 160 | 161 | /* Descriptor Type and Descriptor Index */ 162 | /* Use the following values when calling the function USBH_GetDescriptor */ 163 | #define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00U) 164 | #define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00U) 165 | #define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00U) 166 | #define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00U) 167 | #define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00U) 168 | #define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00U) 169 | #define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00U) 170 | #define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00U) 171 | #define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00U) 172 | #define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00U) 173 | 174 | 175 | #define USB_EP_TYPE_CTRL 0x00U 176 | #define USB_EP_TYPE_ISOC 0x01U 177 | #define USB_EP_TYPE_BULK 0x02U 178 | #define USB_EP_TYPE_INTR 0x03U 179 | 180 | #define USB_EP_DIR_OUT 0x00U 181 | #define USB_EP_DIR_IN 0x80U 182 | #define USB_EP_DIR_MSK 0x80U 183 | 184 | #ifndef USBH_MAX_PIPES_NBR 185 | #define USBH_MAX_PIPES_NBR 16U 186 | #endif /* USBH_MAX_PIPES_NBR */ 187 | 188 | #ifndef USBH_NAK_SOF_COUNT 189 | #define USBH_NAK_SOF_COUNT 0x01U 190 | #endif /* USBH_NAK_SOF_COUNT */ 191 | 192 | #define USBH_DEVICE_ADDRESS_DEFAULT 0x00U 193 | #define USBH_DEVICE_ADDRESS 0x01U 194 | 195 | #define USBH_MAX_ERROR_COUNT 0x02U 196 | 197 | #if (USBH_USE_OS == 1U) 198 | #define MSGQUEUE_OBJECTS 0x10U 199 | #endif /* (USBH_USE_OS == 1U) */ 200 | 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | 207 | #define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \ 208 | + USB_INTERFACE_DESC_SIZE\ 209 | + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE)) 210 | 211 | 212 | #define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\ 213 | ConfigurationDescriptor.wTotalLength) 214 | 215 | 216 | typedef union 217 | { 218 | uint16_t w; 219 | struct BW 220 | { 221 | uint8_t msb; 222 | uint8_t lsb; 223 | } 224 | bw; 225 | } 226 | uint16_t_uint8_t; 227 | 228 | 229 | typedef union _USB_Setup 230 | { 231 | uint32_t d8[2]; 232 | 233 | struct _SetupPkt_Struc 234 | { 235 | uint8_t bmRequestType; 236 | uint8_t bRequest; 237 | uint16_t_uint8_t wValue; 238 | uint16_t_uint8_t wIndex; 239 | uint16_t_uint8_t wLength; 240 | } b; 241 | } 242 | USB_Setup_TypeDef; 243 | 244 | typedef struct _DescHeader 245 | { 246 | uint8_t bLength; 247 | uint8_t bDescriptorType; 248 | } 249 | USBH_DescHeader_t; 250 | 251 | typedef struct _DeviceDescriptor 252 | { 253 | uint8_t bLength; 254 | uint8_t bDescriptorType; 255 | uint16_t bcdUSB; /* USB Specification Number which device complies too */ 256 | uint8_t bDeviceClass; 257 | uint8_t bDeviceSubClass; 258 | uint8_t bDeviceProtocol; 259 | /* If equal to Zero, each interface specifies its own class 260 | code if equal to 0xFF, the class code is vendor specified. 261 | Otherwise field is valid Class Code.*/ 262 | uint8_t bMaxPacketSize; 263 | uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */ 264 | uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */ 265 | uint16_t bcdDevice; /* Device Release Number */ 266 | uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */ 267 | uint8_t iProduct; /* Index of Product String Descriptor */ 268 | uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */ 269 | uint8_t bNumConfigurations; /* Number of Possible Configurations */ 270 | } 271 | USBH_DevDescTypeDef; 272 | 273 | typedef struct _EndpointDescriptor 274 | { 275 | uint8_t bLength; 276 | uint8_t bDescriptorType; 277 | uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */ 278 | uint8_t bmAttributes; /* specifies the transfer type. */ 279 | uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */ 280 | uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */ 281 | } 282 | USBH_EpDescTypeDef; 283 | 284 | typedef struct _InterfaceDescriptor 285 | { 286 | uint8_t bLength; 287 | uint8_t bDescriptorType; 288 | uint8_t bInterfaceNumber; 289 | uint8_t bAlternateSetting; /* Value used to select alternative setting */ 290 | uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */ 291 | uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */ 292 | uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */ 293 | uint8_t bInterfaceProtocol; /* Protocol Code */ 294 | uint8_t iInterface; /* Index of String Descriptor Describing this interface */ 295 | USBH_EpDescTypeDef Ep_Desc[USBH_MAX_NUM_ENDPOINTS]; 296 | } 297 | USBH_InterfaceDescTypeDef; 298 | 299 | 300 | typedef struct _ConfigurationDescriptor 301 | { 302 | uint8_t bLength; 303 | uint8_t bDescriptorType; 304 | uint16_t wTotalLength; /* Total Length of Data Returned */ 305 | uint8_t bNumInterfaces; /* Number of Interfaces */ 306 | uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/ 307 | uint8_t iConfiguration; /* Index of String Descriptor Describing this configuration */ 308 | uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/ 309 | uint8_t bMaxPower; /* Maximum Power Consumption */ 310 | USBH_InterfaceDescTypeDef Itf_Desc[USBH_MAX_NUM_INTERFACES]; 311 | } 312 | USBH_CfgDescTypeDef; 313 | 314 | 315 | /* Following USB Host status */ 316 | typedef enum 317 | { 318 | USBH_OK = 0, 319 | USBH_BUSY, 320 | USBH_FAIL, 321 | USBH_NOT_SUPPORTED, 322 | USBH_UNRECOVERED_ERROR, 323 | USBH_ERROR_SPEED_UNKNOWN, 324 | } USBH_StatusTypeDef; 325 | 326 | 327 | /** @defgroup USBH_CORE_Exported_Types 328 | * @{ 329 | */ 330 | 331 | typedef enum 332 | { 333 | USBH_SPEED_HIGH = 0U, 334 | USBH_SPEED_FULL = 1U, 335 | USBH_SPEED_LOW = 2U, 336 | 337 | } USBH_SpeedTypeDef; 338 | 339 | /* Following states are used for gState */ 340 | typedef enum 341 | { 342 | HOST_IDLE = 0U, 343 | HOST_DEV_WAIT_FOR_ATTACHMENT, 344 | HOST_DEV_ATTACHED, 345 | HOST_DEV_DISCONNECTED, 346 | HOST_DETECT_DEVICE_SPEED, 347 | HOST_ENUMERATION, 348 | HOST_CLASS_REQUEST, 349 | HOST_INPUT, 350 | HOST_SET_CONFIGURATION, 351 | HOST_SET_WAKEUP_FEATURE, 352 | HOST_CHECK_CLASS, 353 | HOST_CLASS, 354 | HOST_SUSPENDED, 355 | HOST_ABORT_STATE, 356 | } HOST_StateTypeDef; 357 | 358 | /* Following states are used for EnumerationState */ 359 | typedef enum 360 | { 361 | ENUM_IDLE = 0U, 362 | ENUM_GET_FULL_DEV_DESC, 363 | ENUM_SET_ADDR, 364 | ENUM_GET_CFG_DESC, 365 | ENUM_GET_FULL_CFG_DESC, 366 | ENUM_GET_MFC_STRING_DESC, 367 | ENUM_GET_PRODUCT_STRING_DESC, 368 | ENUM_GET_SERIALNUM_STRING_DESC, 369 | } ENUM_StateTypeDef; 370 | 371 | /* Following states are used for CtrlXferStateMachine */ 372 | typedef enum 373 | { 374 | CTRL_IDLE = 0U, 375 | CTRL_SETUP, 376 | CTRL_SETUP_WAIT, 377 | CTRL_DATA_IN, 378 | CTRL_DATA_IN_WAIT, 379 | CTRL_DATA_OUT, 380 | CTRL_DATA_OUT_WAIT, 381 | CTRL_STATUS_IN, 382 | CTRL_STATUS_IN_WAIT, 383 | CTRL_STATUS_OUT, 384 | CTRL_STATUS_OUT_WAIT, 385 | CTRL_ERROR, 386 | CTRL_STALLED, 387 | CTRL_COMPLETE 388 | } CTRL_StateTypeDef; 389 | 390 | 391 | /* Following states are used for RequestState */ 392 | typedef enum 393 | { 394 | CMD_IDLE = 0U, 395 | CMD_SEND, 396 | CMD_WAIT 397 | } CMD_StateTypeDef; 398 | 399 | typedef enum 400 | { 401 | USBH_URB_IDLE = 0U, 402 | USBH_URB_DONE, 403 | USBH_URB_NOTREADY, 404 | USBH_URB_NYET, 405 | USBH_URB_ERROR, 406 | USBH_URB_STALL, 407 | USBH_URB_NAK_WAIT 408 | } USBH_URBStateTypeDef; 409 | 410 | typedef enum 411 | { 412 | USBH_PORT_EVENT = 1U, 413 | USBH_URB_EVENT, 414 | USBH_CONTROL_EVENT, 415 | USBH_CLASS_EVENT, 416 | USBH_STATE_CHANGED_EVENT, 417 | } 418 | USBH_OSEventTypeDef; 419 | 420 | /* Control request structure */ 421 | typedef struct 422 | { 423 | uint8_t pipe_in; 424 | uint8_t pipe_out; 425 | uint8_t pipe_size; 426 | uint8_t *buff; 427 | uint16_t length; 428 | uint16_t timer; 429 | USB_Setup_TypeDef setup; 430 | CTRL_StateTypeDef state; 431 | uint8_t errorcount; 432 | 433 | } USBH_CtrlTypeDef; 434 | 435 | /* Attached device structure */ 436 | typedef struct 437 | { 438 | uint8_t CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION]; 439 | uint8_t Data[USBH_MAX_DATA_BUFFER]; 440 | uint8_t address; 441 | uint8_t speed; 442 | uint8_t EnumCnt; 443 | uint8_t RstCnt; 444 | __IO uint8_t is_connected; 445 | __IO uint8_t is_disconnected; 446 | __IO uint8_t is_ReEnumerated; 447 | __IO uint8_t PortEnabled; 448 | uint8_t current_interface; 449 | USBH_DevDescTypeDef DevDesc; 450 | USBH_CfgDescTypeDef CfgDesc; 451 | } USBH_DeviceTypeDef; 452 | 453 | struct _USBH_HandleTypeDef; 454 | 455 | /* USB Host Class structure */ 456 | typedef struct 457 | { 458 | const char *Name; 459 | uint8_t ClassCode; 460 | USBH_StatusTypeDef(*Init)(struct _USBH_HandleTypeDef *phost); 461 | USBH_StatusTypeDef(*DeInit)(struct _USBH_HandleTypeDef *phost); 462 | USBH_StatusTypeDef(*Requests)(struct _USBH_HandleTypeDef *phost); 463 | USBH_StatusTypeDef(*BgndProcess)(struct _USBH_HandleTypeDef *phost); 464 | USBH_StatusTypeDef(*SOFProcess)(struct _USBH_HandleTypeDef *phost); 465 | void *pData; 466 | } USBH_ClassTypeDef; 467 | 468 | /* USB Host handle structure */ 469 | typedef struct _USBH_HandleTypeDef 470 | { 471 | __IO HOST_StateTypeDef gState; /* Host State Machine Value */ 472 | ENUM_StateTypeDef EnumState; /* Enumeration state Machine */ 473 | CMD_StateTypeDef RequestState; 474 | USBH_CtrlTypeDef Control; 475 | USBH_DeviceTypeDef device; 476 | USBH_ClassTypeDef *pClass[USBH_MAX_NUM_SUPPORTED_CLASS]; 477 | USBH_ClassTypeDef *pActiveClass; 478 | uint32_t ClassNumber; 479 | uint32_t Pipes[16]; 480 | __IO uint32_t Timer; 481 | #if defined (USBH_IN_NAK_PROCESS) && (USBH_IN_NAK_PROCESS == 1U) 482 | uint32_t NakTimer; 483 | uint32_t NakTimeout; 484 | #endif /* defined (USBH_IN_NAK_PROCESS) && (USBH_IN_NAK_PROCESS == 1U) */ 485 | uint32_t Timeout; 486 | uint8_t id; 487 | void *pData; 488 | void (* pUser)(struct _USBH_HandleTypeDef *pHandle, uint8_t id); 489 | 490 | #if (USBH_USE_OS == 1U) 491 | #if osCMSIS < 0x20000 492 | osMessageQId os_event; 493 | osThreadId thread; 494 | #else 495 | osMessageQueueId_t os_event; 496 | osThreadId_t thread; 497 | #endif 498 | uint32_t os_msg; 499 | #endif /* (USBH_USE_OS == 1U) */ 500 | 501 | } USBH_HandleTypeDef; 502 | 503 | 504 | #if defined ( __GNUC__ ) 505 | #ifndef __weak 506 | #define __weak __attribute__((weak)) 507 | #endif /* __weak */ 508 | #ifndef __packed 509 | #define __packed __attribute__((__packed__)) 510 | #endif /* __packed */ 511 | #endif /* __GNUC__ */ 512 | 513 | #ifdef __cplusplus 514 | } 515 | #endif 516 | 517 | #endif /* USBH_DEF_H */ 518 | 519 | 520 | -------------------------------------------------------------------------------- /Core/Inc/usbh_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_ioreq.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbh_ioreq.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_IOREQ_H 21 | #define __USBH_IOREQ_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_conf.h" 29 | #include "usbh_core.h" 30 | 31 | /** @addtogroup USBH_LIB 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup USBH_LIB_CORE 36 | * @{ 37 | */ 38 | 39 | /** @defgroup USBH_IOREQ 40 | * @brief This file is the header file for usbh_ioreq.c 41 | * @{ 42 | */ 43 | 44 | 45 | /** @defgroup USBH_IOREQ_Exported_Defines 46 | * @{ 47 | */ 48 | 49 | #define USBH_PID_SETUP 0U 50 | #define USBH_PID_DATA 1U 51 | 52 | #define USBH_EP_CONTROL 0U 53 | #define USBH_EP_ISO 1U 54 | #define USBH_EP_BULK 2U 55 | #define USBH_EP_INTERRUPT 3U 56 | 57 | #define USBH_SETUP_PKT_SIZE 8U 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @defgroup USBH_IOREQ_Exported_Types 64 | * @{ 65 | */ 66 | /** 67 | * @} 68 | */ 69 | 70 | 71 | /** @defgroup USBH_IOREQ_Exported_Macros 72 | * @{ 73 | */ 74 | /** 75 | * @} 76 | */ 77 | 78 | /** @defgroup USBH_IOREQ_Exported_Variables 79 | * @{ 80 | */ 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @defgroup USBH_IOREQ_Exported_FunctionsPrototype 86 | * @{ 87 | */ 88 | USBH_StatusTypeDef USBH_CtlSendSetup(USBH_HandleTypeDef *phost, 89 | uint8_t *buff, 90 | uint8_t pipe_num); 91 | 92 | USBH_StatusTypeDef USBH_CtlSendData(USBH_HandleTypeDef *phost, 93 | uint8_t *buff, 94 | uint16_t length, 95 | uint8_t pipe_num, 96 | uint8_t do_ping); 97 | 98 | USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, 99 | uint8_t *buff, 100 | uint16_t length, 101 | uint8_t pipe_num); 102 | 103 | USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, 104 | uint8_t *buff, 105 | uint16_t length, 106 | uint8_t pipe_num); 107 | 108 | USBH_StatusTypeDef USBH_BulkSendData(USBH_HandleTypeDef *phost, 109 | uint8_t *buff, 110 | uint16_t length, 111 | uint8_t pipe_num, 112 | uint8_t do_ping); 113 | 114 | USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, 115 | uint8_t *buff, 116 | uint8_t length, 117 | uint8_t pipe_num); 118 | 119 | USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, 120 | uint8_t *buff, 121 | uint8_t length, 122 | uint8_t pipe_num); 123 | 124 | 125 | USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, 126 | uint8_t *buff, 127 | uint32_t length, 128 | uint8_t pipe_num); 129 | 130 | 131 | USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost, 132 | uint8_t *buff, 133 | uint32_t length, 134 | uint8_t pipe_num); 135 | /** 136 | * @} 137 | */ 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __USBH_IOREQ_H */ 144 | 145 | /** 146 | * @} 147 | */ 148 | 149 | /** 150 | * @} 151 | */ 152 | 153 | /** 154 | * @} 155 | */ 156 | 157 | 158 | -------------------------------------------------------------------------------- /Core/Inc/usbh_pipes.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_pipes.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbh_pipes.c 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive ----------------------------------------------*/ 20 | #ifndef __USBH_PIPES_H 21 | #define __USBH_PIPES_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbh_core.h" 29 | 30 | /** @addtogroup USBH_LIB 31 | * @{ 32 | */ 33 | 34 | /** @addtogroup USBH_LIB_CORE 35 | * @{ 36 | */ 37 | 38 | /** @defgroup USBH_PIPES 39 | * @brief This file is the header file for usbh_pipes.c 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBH_PIPES_Exported_Defines 44 | * @{ 45 | */ 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup USBH_PIPES_Exported_Types 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBH_PIPES_Exported_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBH_PIPES_Exported_Variables 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBH_PIPES_Exported_FunctionsPrototype 73 | * @{ 74 | */ 75 | 76 | USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost, 77 | uint8_t pipe_num, 78 | uint8_t epnum, 79 | uint8_t dev_address, 80 | uint8_t speed, 81 | uint8_t ep_type, 82 | uint16_t mps); 83 | 84 | USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost, 85 | uint8_t pipe_num); 86 | 87 | uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost, 88 | uint8_t ep_addr); 89 | 90 | USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost, 91 | uint8_t idx); 92 | 93 | #if defined (USBH_IN_NAK_PROCESS) && (USBH_IN_NAK_PROCESS == 1U) 94 | USBH_StatusTypeDef USBH_ActivatePipe(USBH_HandleTypeDef *phost, 95 | uint8_t pipe_num); 96 | #endif /* defined (USBH_IN_NAK_PROCESS) && (USBH_IN_NAK_PROCESS == 1U) */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* __USBH_PIPES_H */ 108 | 109 | 110 | /** 111 | * @} 112 | */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | 123 | -------------------------------------------------------------------------------- /Core/Src/usbh_conf_template.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_conf.c 4 | * @author MCD Application Team 5 | * @brief This file implements the board support package for the USB host library 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "usbh_core.h" 21 | 22 | /** 23 | * @brief USBH_LL_Init 24 | * Initialize the Low Level portion of the Host driver. 25 | * @param phost: Host handle 26 | * @retval USBH Status 27 | */ 28 | USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost) 29 | { 30 | /* Prevent unused argument(s) compilation warning */ 31 | UNUSED(phost); 32 | 33 | return USBH_OK; 34 | } 35 | 36 | /** 37 | * @brief USBH_LL_DeInit 38 | * De-Initialize the Low Level portion of the Host driver. 39 | * @param phost: Host handle 40 | * @retval USBH Status 41 | */ 42 | USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost) 43 | { 44 | /* Prevent unused argument(s) compilation warning */ 45 | UNUSED(phost); 46 | 47 | return USBH_OK; 48 | } 49 | 50 | /** 51 | * @brief USBH_LL_Start 52 | * Start the Low Level portion of the Host driver. 53 | * @param phost: Host handle 54 | * @retval USBH Status 55 | */ 56 | USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost) 57 | { 58 | /* Prevent unused argument(s) compilation warning */ 59 | UNUSED(phost); 60 | 61 | return USBH_OK; 62 | } 63 | 64 | /** 65 | * @brief USBH_LL_Stop 66 | * Stop the Low Level portion of the Host driver. 67 | * @param phost: Host handle 68 | * @retval USBH Status 69 | */ 70 | USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost) 71 | { 72 | /* Prevent unused argument(s) compilation warning */ 73 | UNUSED(phost); 74 | 75 | return USBH_OK; 76 | } 77 | 78 | /** 79 | * @brief USBH_LL_GetSpeed 80 | * Return the USB Host Speed from the Low Level Driver. 81 | * @param phost: Host handle 82 | * @retval USBH Speeds 83 | */ 84 | USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef *phost) 85 | { 86 | /* Prevent unused argument(s) compilation warning */ 87 | UNUSED(phost); 88 | 89 | USBH_SpeedTypeDef speed = USBH_SPEED_FULL; 90 | 91 | return speed; 92 | } 93 | 94 | /** 95 | * @brief USBH_LL_ResetPort 96 | * Reset the Host Port of the Low Level Driver. 97 | * @param phost: Host handle 98 | * @retval USBH Status 99 | */ 100 | USBH_StatusTypeDef USBH_LL_ResetPort(USBH_HandleTypeDef *phost) 101 | { 102 | /* Prevent unused argument(s) compilation warning */ 103 | UNUSED(phost); 104 | 105 | return USBH_OK; 106 | } 107 | 108 | /** 109 | * @brief USBH_LL_GetLastXferSize 110 | * Return the last transferred packet size. 111 | * @param phost: Host handle 112 | * @param pipe: Pipe index 113 | * @retval Packet Size 114 | */ 115 | uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef *phost, uint8_t pipe) 116 | { 117 | /* Prevent unused argument(s) compilation warning */ 118 | UNUSED(phost); 119 | UNUSED(pipe); 120 | 121 | return 0U; 122 | } 123 | 124 | /** 125 | * @brief USBH_LL_OpenPipe 126 | * Open a pipe of the Low Level Driver. 127 | * @param phost: Host handle 128 | * @param pipe: Pipe index 129 | * @param epnum: Endpoint Number 130 | * @param dev_address: Device USB address 131 | * @param speed: Device Speed 132 | * @param ep_type: Endpoint Type 133 | * @param mps: Endpoint Max Packet Size 134 | * @retval USBH Status 135 | */ 136 | USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef *phost, 137 | uint8_t pipe, 138 | uint8_t epnum, 139 | uint8_t dev_address, 140 | uint8_t speed, 141 | uint8_t ep_type, 142 | uint16_t mps) 143 | { 144 | /* Prevent unused argument(s) compilation warning */ 145 | UNUSED(phost); 146 | UNUSED(pipe); 147 | UNUSED(epnum); 148 | UNUSED(dev_address); 149 | UNUSED(speed); 150 | UNUSED(ep_type); 151 | UNUSED(mps); 152 | 153 | return USBH_OK; 154 | } 155 | 156 | /** 157 | * @brief USBH_LL_ClosePipe 158 | * Close a pipe of the Low Level Driver. 159 | * @param phost: Host handle 160 | * @param pipe: Pipe index 161 | * @retval USBH Status 162 | */ 163 | USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe) 164 | { 165 | /* Prevent unused argument(s) compilation warning */ 166 | UNUSED(phost); 167 | UNUSED(pipe); 168 | 169 | return USBH_OK; 170 | } 171 | 172 | /** 173 | * @brief USBH_LL_ActivatePipe 174 | * Activate a pipe of the Low Level Driver. 175 | * @param phost: Host handle 176 | * @param pipe: Pipe index 177 | * @retval USBH Status 178 | */ 179 | USBH_StatusTypeDef USBH_LL_ActivatePipe(USBH_HandleTypeDef *phost, uint8_t pipe) 180 | { 181 | /* Prevent unused argument(s) compilation warning */ 182 | UNUSED(phost); 183 | UNUSED(pipe); 184 | 185 | return USBH_OK; 186 | } 187 | 188 | /** 189 | * @brief USBH_LL_SubmitURB 190 | * Submit a new URB to the low level driver. 191 | * @param phost: Host handle 192 | * @param pipe: Pipe index 193 | * This parameter can be a value from 1 to 15 194 | * @param direction : Channel number 195 | * This parameter can be one of the these values: 196 | * 0 : Output 197 | * 1 : Input 198 | * @param ep_type : Endpoint Type 199 | * This parameter can be one of the these values: 200 | * @arg EP_TYPE_CTRL: Control type 201 | * @arg EP_TYPE_ISOC: Isochronous type 202 | * @arg EP_TYPE_BULK: Bulk type 203 | * @arg EP_TYPE_INTR: Interrupt type 204 | * @param token : Endpoint Type 205 | * This parameter can be one of the these values: 206 | * @arg 0: PID_SETUP 207 | * @arg 1: PID_DATA 208 | * @param pbuff : pointer to URB data 209 | * @param length : Length of URB data 210 | * @param do_ping : activate do ping protocol (for high speed only) 211 | * This parameter can be one of the these values: 212 | * 0 : do ping inactive 213 | * 1 : do ping active 214 | * @retval Status 215 | */ 216 | USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef *phost, 217 | uint8_t pipe, 218 | uint8_t direction, 219 | uint8_t ep_type, 220 | uint8_t token, 221 | uint8_t *pbuff, 222 | uint16_t length, 223 | uint8_t do_ping) 224 | { 225 | /* Prevent unused argument(s) compilation warning */ 226 | UNUSED(phost); 227 | UNUSED(pipe); 228 | UNUSED(direction); 229 | UNUSED(ep_type); 230 | UNUSED(token); 231 | UNUSED(pbuff); 232 | UNUSED(length); 233 | UNUSED(do_ping); 234 | 235 | return USBH_OK; 236 | } 237 | 238 | /** 239 | * @brief USBH_LL_GetURBState 240 | * Get a URB state from the low level driver. 241 | * @param phost: Host handle 242 | * @param pipe: Pipe index 243 | * This parameter can be a value from 1 to 15 244 | * @retval URB state 245 | * This parameter can be one of the these values: 246 | * @arg URB_IDLE 247 | * @arg URB_DONE 248 | * @arg URB_NOTREADY 249 | * @arg URB_NYET 250 | * @arg URB_ERROR 251 | * @arg URB_STALL 252 | */ 253 | USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, uint8_t pipe) 254 | { 255 | /* Prevent unused argument(s) compilation warning */ 256 | UNUSED(phost); 257 | UNUSED(pipe); 258 | 259 | return USBH_URB_IDLE; 260 | } 261 | 262 | /** 263 | * @brief USBH_LL_DriverVBUS 264 | * Drive VBUS. 265 | * @param phost: Host handle 266 | * @param state : VBUS state 267 | * This parameter can be one of the these values: 268 | * 0 : VBUS Inactive 269 | * 1 : VBUS Active 270 | * @retval Status 271 | */ 272 | USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state) 273 | { 274 | /* Prevent unused argument(s) compilation warning */ 275 | UNUSED(phost); 276 | UNUSED(state); 277 | 278 | return USBH_OK; 279 | } 280 | 281 | /** 282 | * @brief USBH_LL_SetToggle 283 | * Set toggle for a pipe. 284 | * @param phost: Host handle 285 | * @param pipe: Pipe index 286 | * @param pipe_num: Pipe index 287 | * @param toggle: toggle (0/1) 288 | * @retval Status 289 | */ 290 | USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle) 291 | { 292 | /* Prevent unused argument(s) compilation warning */ 293 | UNUSED(phost); 294 | UNUSED(pipe); 295 | UNUSED(toggle); 296 | 297 | return USBH_OK; 298 | } 299 | 300 | /** 301 | * @brief USBH_LL_GetToggle 302 | * Return the current toggle of a pipe. 303 | * @param phost: Host handle 304 | * @param pipe: Pipe index 305 | * @retval toggle (0/1) 306 | */ 307 | uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t pipe) 308 | { 309 | /* Prevent unused argument(s) compilation warning */ 310 | UNUSED(phost); 311 | UNUSED(pipe); 312 | 313 | uint8_t toggle = 0U; 314 | 315 | return toggle; 316 | } 317 | 318 | /** 319 | * @brief USBH_Delay 320 | * Delay routine for the USB Host Library 321 | * @param Delay: Delay in ms 322 | * @retval None 323 | */ 324 | void USBH_Delay(uint32_t Delay) 325 | { 326 | /* Prevent unused argument(s) compilation warning */ 327 | UNUSED(Delay); 328 | } 329 | -------------------------------------------------------------------------------- /Core/Src/usbh_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_ioreq.c 4 | * @author MCD Application Team 5 | * @brief This file handles the issuing of the USB transactions 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "usbh_ioreq.h" 21 | 22 | /** @addtogroup USBH_LIB 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup USBH_LIB_CORE 27 | * @{ 28 | */ 29 | 30 | /** @defgroup USBH_IOREQ 31 | * @brief This file handles the standard protocol processing (USB v2.0) 32 | * @{ 33 | */ 34 | 35 | 36 | /** @defgroup USBH_IOREQ_Private_Defines 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @} 42 | */ 43 | 44 | 45 | /** @defgroup USBH_IOREQ_Private_TypesDefinitions 46 | * @{ 47 | */ 48 | /** 49 | * @} 50 | */ 51 | 52 | 53 | 54 | /** @defgroup USBH_IOREQ_Private_Macros 55 | * @{ 56 | */ 57 | /** 58 | * @} 59 | */ 60 | 61 | 62 | /** @defgroup USBH_IOREQ_Private_Variables 63 | * @{ 64 | */ 65 | /** 66 | * @} 67 | */ 68 | /** @defgroup USBH_IOREQ_Private_FunctionPrototypes 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | 77 | /** @defgroup USBH_IOREQ_Private_Functions 78 | * @{ 79 | */ 80 | 81 | 82 | 83 | /** 84 | * @brief USBH_CtlSendSetup 85 | * Sends the Setup Packet to the Device 86 | * @param phost: Host Handle 87 | * @param buff: Buffer pointer from which the Data will be send to Device 88 | * @param pipe_num: Pipe Number 89 | * @retval USBH Status 90 | */ 91 | USBH_StatusTypeDef USBH_CtlSendSetup(USBH_HandleTypeDef *phost, 92 | uint8_t *buff, 93 | uint8_t pipe_num) 94 | { 95 | 96 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 97 | pipe_num, /* Pipe index */ 98 | 0U, /* Direction : OUT */ 99 | USBH_EP_CONTROL, /* EP type */ 100 | USBH_PID_SETUP, /* Type setup */ 101 | buff, /* data buffer */ 102 | USBH_SETUP_PKT_SIZE, /* data length */ 103 | 0U); 104 | return USBH_OK; 105 | } 106 | 107 | 108 | /** 109 | * @brief USBH_CtlSendData 110 | * Sends a data Packet to the Device 111 | * @param phost: Host Handle 112 | * @param buff: Buffer pointer from which the Data will be sent to Device 113 | * @param length: Length of the data to be sent 114 | * @param pipe_num: Pipe Number 115 | * @retval USBH Status 116 | */ 117 | USBH_StatusTypeDef USBH_CtlSendData(USBH_HandleTypeDef *phost, 118 | uint8_t *buff, 119 | uint16_t length, 120 | uint8_t pipe_num, 121 | uint8_t do_ping) 122 | { 123 | if (phost->device.speed != USBH_SPEED_HIGH) 124 | { 125 | do_ping = 0U; 126 | } 127 | 128 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 129 | pipe_num, /* Pipe index */ 130 | 0U, /* Direction : OUT */ 131 | USBH_EP_CONTROL, /* EP type */ 132 | USBH_PID_DATA, /* Type Data */ 133 | buff, /* data buffer */ 134 | length, /* data length */ 135 | do_ping); /* do ping (HS Only)*/ 136 | 137 | return USBH_OK; 138 | } 139 | 140 | 141 | /** 142 | * @brief USBH_CtlReceiveData 143 | * Receives the Device Response to the Setup Packet 144 | * @param phost: Host Handle 145 | * @param buff: Buffer pointer in which the response needs to be copied 146 | * @param length: Length of the data to be received 147 | * @param pipe_num: Pipe Number 148 | * @retval USBH Status. 149 | */ 150 | USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, 151 | uint8_t *buff, 152 | uint16_t length, 153 | uint8_t pipe_num) 154 | { 155 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 156 | pipe_num, /* Pipe index */ 157 | 1U, /* Direction : IN */ 158 | USBH_EP_CONTROL, /* EP type */ 159 | USBH_PID_DATA, /* Type Data */ 160 | buff, /* data buffer */ 161 | length, /* data length */ 162 | 0U); 163 | return USBH_OK; 164 | 165 | } 166 | 167 | 168 | /** 169 | * @brief USBH_BulkSendData 170 | * Sends the Bulk Packet to the device 171 | * @param phost: Host Handle 172 | * @param buff: Buffer pointer from which the Data will be sent to Device 173 | * @param length: Length of the data to be sent 174 | * @param pipe_num: Pipe Number 175 | * @retval USBH Status 176 | */ 177 | USBH_StatusTypeDef USBH_BulkSendData(USBH_HandleTypeDef *phost, 178 | uint8_t *buff, 179 | uint16_t length, 180 | uint8_t pipe_num, 181 | uint8_t do_ping) 182 | { 183 | if (phost->device.speed != USBH_SPEED_HIGH) 184 | { 185 | do_ping = 0U; 186 | } 187 | 188 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 189 | pipe_num, /* Pipe index */ 190 | 0U, /* Direction : IN */ 191 | USBH_EP_BULK, /* EP type */ 192 | USBH_PID_DATA, /* Type Data */ 193 | buff, /* data buffer */ 194 | length, /* data length */ 195 | do_ping); /* do ping (HS Only)*/ 196 | return USBH_OK; 197 | } 198 | 199 | 200 | /** 201 | * @brief USBH_BulkReceiveData 202 | * Receives IN bulk packet from device 203 | * @param phost: Host Handle 204 | * @param buff: Buffer pointer in which the received data packet to be copied 205 | * @param length: Length of the data to be received 206 | * @param pipe_num: Pipe Number 207 | * @retval USBH Status. 208 | */ 209 | USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, 210 | uint8_t *buff, 211 | uint16_t length, 212 | uint8_t pipe_num) 213 | { 214 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 215 | pipe_num, /* Pipe index */ 216 | 1U, /* Direction : IN */ 217 | USBH_EP_BULK, /* EP type */ 218 | USBH_PID_DATA, /* Type Data */ 219 | buff, /* data buffer */ 220 | length, /* data length */ 221 | 0U); 222 | return USBH_OK; 223 | } 224 | 225 | 226 | /** 227 | * @brief USBH_InterruptReceiveData 228 | * Receives the Device Response to the Interrupt IN token 229 | * @param phost: Host Handle 230 | * @param buff: Buffer pointer in which the response needs to be copied 231 | * @param length: Length of the data to be received 232 | * @param pipe_num: Pipe Number 233 | * @retval USBH Status. 234 | */ 235 | USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, 236 | uint8_t *buff, 237 | uint8_t length, 238 | uint8_t pipe_num) 239 | { 240 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 241 | pipe_num, /* Pipe index */ 242 | 1U, /* Direction : IN */ 243 | USBH_EP_INTERRUPT, /* EP type */ 244 | USBH_PID_DATA, /* Type Data */ 245 | buff, /* data buffer */ 246 | (uint16_t)length, /* data length */ 247 | 0U); 248 | 249 | return USBH_OK; 250 | } 251 | 252 | /** 253 | * @brief USBH_InterruptSendData 254 | * Sends the data on Interrupt OUT Endpoint 255 | * @param phost: Host Handle 256 | * @param buff: Buffer pointer from where the data needs to be copied 257 | * @param length: Length of the data to be sent 258 | * @param pipe_num: Pipe Number 259 | * @retval USBH Status. 260 | */ 261 | USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, 262 | uint8_t *buff, 263 | uint8_t length, 264 | uint8_t pipe_num) 265 | { 266 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 267 | pipe_num, /* Pipe index */ 268 | 0U, /* Direction : OUT */ 269 | USBH_EP_INTERRUPT, /* EP type */ 270 | USBH_PID_DATA, /* Type Data */ 271 | buff, /* data buffer */ 272 | (uint16_t)length, /* data length */ 273 | 0U); 274 | 275 | return USBH_OK; 276 | } 277 | 278 | /** 279 | * @brief USBH_IsocReceiveData 280 | * Receives the Device Response to the Isochronous IN token 281 | * @param phost: Host Handle 282 | * @param buff: Buffer pointer in which the response needs to be copied 283 | * @param length: Length of the data to be received 284 | * @param pipe_num: Pipe Number 285 | * @retval USBH Status. 286 | */ 287 | USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, 288 | uint8_t *buff, 289 | uint32_t length, 290 | uint8_t pipe_num) 291 | { 292 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 293 | pipe_num, /* Pipe index */ 294 | 1U, /* Direction : IN */ 295 | USBH_EP_ISO, /* EP type */ 296 | USBH_PID_DATA, /* Type Data */ 297 | buff, /* data buffer */ 298 | (uint16_t)length, /* data length */ 299 | 0U); 300 | 301 | 302 | return USBH_OK; 303 | } 304 | 305 | /** 306 | * @brief USBH_IsocSendData 307 | * Sends the data on Isochronous OUT Endpoint 308 | * @param phost: Host Handle 309 | * @param buff: Buffer pointer from where the data needs to be copied 310 | * @param length: Length of the data to be sent 311 | * @param pipe_num: Pipe Number 312 | * @retval USBH Status. 313 | */ 314 | USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost, 315 | uint8_t *buff, 316 | uint32_t length, 317 | uint8_t pipe_num) 318 | { 319 | (void)USBH_LL_SubmitURB(phost, /* Driver handle */ 320 | pipe_num, /* Pipe index */ 321 | 0U, /* Direction : OUT */ 322 | USBH_EP_ISO, /* EP type */ 323 | USBH_PID_DATA, /* Type Data */ 324 | buff, /* data buffer */ 325 | (uint16_t)length, /* data length */ 326 | 0U); 327 | 328 | return USBH_OK; 329 | } 330 | /** 331 | * @} 332 | */ 333 | 334 | /** 335 | * @} 336 | */ 337 | 338 | /** 339 | * @} 340 | */ 341 | 342 | /** 343 | * @} 344 | */ 345 | 346 | 347 | 348 | -------------------------------------------------------------------------------- /Core/Src/usbh_pipes.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbh_pipes.c 4 | * @author MCD Application Team 5 | * @brief This file implements functions for opening and closing Pipes 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "usbh_pipes.h" 21 | 22 | /** @addtogroup USBH_LIB 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup USBH_LIB_CORE 27 | * @{ 28 | */ 29 | 30 | /** @defgroup USBH_PIPES 31 | * @brief This file includes opening and closing Pipes 32 | * @{ 33 | */ 34 | 35 | /** @defgroup USBH_PIPES_Private_Defines 36 | * @{ 37 | */ 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup USBH_PIPES_Private_TypesDefinitions 43 | * @{ 44 | */ 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup USBH_PIPES_Private_Macros 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBH_PIPES_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup USBH_PIPES_Private_Functions 68 | * @{ 69 | */ 70 | static uint16_t USBH_GetFreePipe(USBH_HandleTypeDef *phost); 71 | 72 | 73 | /** 74 | * @brief USBH_Open_Pipe 75 | * Open a pipe 76 | * @param phost: Host Handle 77 | * @param pipe_num: Pipe Number 78 | * @param dev_address: USB Device address allocated to attached device 79 | * @param speed : USB device speed (Full/Low) 80 | * @param ep_type: end point type (Bulk/int/ctl) 81 | * @param mps: max pkt size 82 | * @retval USBH Status 83 | */ 84 | USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost, uint8_t pipe_num, 85 | uint8_t epnum, uint8_t dev_address, 86 | uint8_t speed, uint8_t ep_type, uint16_t mps) 87 | { 88 | (void)USBH_LL_OpenPipe(phost, pipe_num, epnum, dev_address, speed, ep_type, mps); 89 | 90 | return USBH_OK; 91 | } 92 | 93 | #if defined (USBH_IN_NAK_PROCESS) && (USBH_IN_NAK_PROCESS == 1U) 94 | /** 95 | * @brief USBH_ActivatePipe 96 | * Activate a pipe 97 | * @param phost: Host Handle 98 | * @param pipe_num: Pipe Number 99 | * @retval USBH Status 100 | */ 101 | USBH_StatusTypeDef USBH_ActivatePipe(USBH_HandleTypeDef *phost, uint8_t pipe_num) 102 | { 103 | USBH_LL_ActivatePipe(phost, pipe_num); 104 | 105 | return USBH_OK; 106 | } 107 | #endif /* defined (USBH_IN_NAK_PROCESS) && (USBH_IN_NAK_PROCESS == 1U) */ 108 | 109 | /** 110 | * @brief USBH_ClosePipe 111 | * Close a pipe 112 | * @param phost: Host Handle 113 | * @param pipe_num: Pipe Number 114 | * @retval USBH Status 115 | */ 116 | USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe_num) 117 | { 118 | (void)USBH_LL_ClosePipe(phost, pipe_num); 119 | 120 | return USBH_OK; 121 | } 122 | 123 | 124 | /** 125 | * @brief USBH_Alloc_Pipe 126 | * Allocate a new Pipe 127 | * @param phost: Host Handle 128 | * @param ep_addr: End point for which the Pipe to be allocated 129 | * @retval Pipe number 130 | */ 131 | uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost, uint8_t ep_addr) 132 | { 133 | uint16_t pipe; 134 | 135 | pipe = USBH_GetFreePipe(phost); 136 | 137 | if (pipe != 0xFFFFU) 138 | { 139 | phost->Pipes[pipe & 0xFU] = (uint32_t)(0x8000U | ep_addr); 140 | } 141 | 142 | return (uint8_t)pipe; 143 | } 144 | 145 | 146 | /** 147 | * @brief USBH_Free_Pipe 148 | * Free the USB Pipe 149 | * @param phost: Host Handle 150 | * @param idx: Pipe number to be freed 151 | * @retval USBH Status 152 | */ 153 | USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost, uint8_t idx) 154 | { 155 | if (idx < USBH_MAX_PIPES_NBR) 156 | { 157 | phost->Pipes[idx] &= 0x7FFFU; 158 | } 159 | 160 | return USBH_OK; 161 | } 162 | 163 | 164 | /** 165 | * @brief USBH_GetFreePipe 166 | * @param phost: Host Handle 167 | * Get a free Pipe number for allocation to a device endpoint 168 | * @retval idx: Free Pipe number 169 | */ 170 | static uint16_t USBH_GetFreePipe(USBH_HandleTypeDef *phost) 171 | { 172 | uint8_t idx = 0U; 173 | 174 | for (idx = 0U; idx < USBH_MAX_PIPES_NBR; idx++) 175 | { 176 | if ((phost->Pipes[idx] & 0x8000U) == 0U) 177 | { 178 | return (uint16_t)idx; 179 | } 180 | } 181 | 182 | return 0xFFFFU; 183 | } 184 | /** 185 | * @} 186 | */ 187 | 188 | /** 189 | * @} 190 | */ 191 | 192 | /** 193 | * @} 194 | */ 195 | 196 | /** 197 | * @} 198 | */ 199 | 200 | 201 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | SLA0044 Rev5/February 2018 2 | 3 | ## Software license agreement 4 | 5 | ### __ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT__ 6 | 7 | BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE 8 | OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS 9 | INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES 10 | (STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON 11 | BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES 12 | TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. 13 | 14 | Under STMicroelectronics’ intellectual property rights, the redistribution, 15 | reproduction and use in source and binary forms of the software or any part 16 | thereof, with or without modification, are permitted provided that the following 17 | conditions are met: 18 | 19 | 1. Redistribution of source code (modified or not) must retain any copyright 20 | notice, this list of conditions and the disclaimer set forth below as items 10 21 | and 11. 22 | 23 | 2. Redistributions in binary form, except as embedded into microcontroller or 24 | microprocessor device manufactured by or for STMicroelectronics or a software 25 | update for such device, must reproduce any copyright notice provided with the 26 | binary code, this list of conditions, and the disclaimer set forth below as 27 | items 10 and 11, in documentation and/or other materials provided with the 28 | distribution. 29 | 30 | 3. Neither the name of STMicroelectronics nor the names of other contributors to 31 | this software may be used to endorse or promote products derived from this 32 | software or part thereof without specific written permission. 33 | 34 | 4. This software or any part thereof, including modifications and/or derivative 35 | works of this software, must be used and execute solely and exclusively on or in 36 | combination with a microcontroller or microprocessor device manufactured by or 37 | for STMicroelectronics. 38 | 39 | 5. No use, reproduction or redistribution of this software partially or totally 40 | may be done in any manner that would subject this software to any Open Source 41 | Terms. “Open Source Terms” shall mean any open source license which requires as 42 | part of distribution of software that the source code of such software is 43 | distributed therewith or otherwise made available, or open source license that 44 | substantially complies with the Open Source definition specified at 45 | www.opensource.org and any other comparable open source license such as for 46 | example GNU General Public License (GPL), Eclipse Public License (EPL), Apache 47 | Software License, BSD license or MIT license. 48 | 49 | 6. STMicroelectronics has no obligation to provide any maintenance, support or 50 | updates for the software. 51 | 52 | 7. The software is and will remain the exclusive property of STMicroelectronics 53 | and its licensors. The recipient will not take any action that jeopardizes 54 | STMicroelectronics and its licensors' proprietary rights or acquire any rights 55 | in the software, except the limited rights specified hereunder. 56 | 57 | 8. The recipient shall comply with all applicable laws and regulations affecting 58 | the use of the software or any part thereof including any applicable export 59 | control law or regulation. 60 | 61 | 9. Redistribution and use of this software or any part thereof other than as 62 | permitted under this license is void and will automatically terminate your 63 | rights under this license. 64 | 65 | 10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND 66 | ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 67 | IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 68 | NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE 69 | DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL 70 | STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 71 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 72 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 73 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 74 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 75 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 76 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 77 | 78 | 11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER 79 | EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY 80 | RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Middleware USB Host MCU Component 2 | 3 | ![latest tag](https://img.shields.io/github/v/tag/STMicroelectronics/stm32_mw_usb_host.svg?color=brightgreen) 4 | 5 | ## Overview 6 | 7 | **STM32Cube** is an STMicroelectronics original initiative to ease developers' life by reducing efforts, time and cost. 8 | 9 | **STM32Cube** covers the overall STM32 products portfolio. It includes a comprehensive embedded software platform delivered for each STM32 series. 10 | * The CMSIS modules (core and device) corresponding to the ARM(tm) core implemented in this STM32 product. 11 | * The STM32 HAL-LL drivers, an abstraction layer offering a set of APIs ensuring maximized portability across the STM32 portfolio. 12 | * The BSP drivers of each evaluation, demonstration or nucleo board provided for this STM32 series. 13 | * A consistent set of middleware libraries such as RTOS, USB, FatFS, graphics, touch sensing library... 14 | * A full set of software projects (basic examples, applications, and demonstrations) for each board provided for this STM32 series. 15 | 16 | Two models of publication are proposed for the STM32Cube embedded software: 17 | * The monolithic **MCU Package**: all STM32Cube software modules of one STM32 series are present (Drivers, Middleware, Projects, Utilities) in the repository (usual name **STM32Cubexx**, xx corresponding to the STM32 series). 18 | * The **MCU component**: each STM32Cube software module being part of the STM32Cube MCU Package, is delivered as an individual repository, allowing the user to select and get only the required software functions. 19 | 20 | ## Description 21 | 22 | This **stm32_mw_usb_host** MCU component repository is one element **common to all** STM32Cube MCU embedded software packages, providing the **USB Host MCU Middleware** part. 23 | 24 | It represents ST offer to ensure the support of USB Host role on STM32 MCUs. 25 | It includes two main modules: 26 | * **Core** module for the USB host standard peripheral control APIs. It includes the files ensuring USB 2.0 standard code implementation for an USB host. 27 | These files’ APIs will be called within every USB Host application regardless the desired functionality. 28 | * **Class** module for the commonly supported classes APIs. it includes the files including different USB host classes. All STM32 USB classes are implemented according to the USB 2.0 and every class’s specifications. These files’ APIs will be called within USB Host applications according to the desired functionality. 29 | 30 | ## Release note 31 | 32 | Details about the content of this release are available in the release note [here](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/stm32_mw_usb_host/blob/master/Release_Notes.html). 33 | 34 | ## Troubleshooting 35 | 36 | Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) guide. -------------------------------------------------------------------------------- /_htmresc/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STMicroelectronics/stm32-mw-usb-host/9d46e44c858a77bf126920b7bcc258d59afa89b1/_htmresc/favicon.png -------------------------------------------------------------------------------- /_htmresc/st_logo_2020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STMicroelectronics/stm32-mw-usb-host/9d46e44c858a77bf126920b7bcc258d59afa89b1/_htmresc/st_logo_2020.png --------------------------------------------------------------------------------