娇小w搡bbbb搡bbb,《第一次の人妻》,中国成熟妇女毛茸茸,边啃奶头边躁狠狠躁视频免费观看

stm32 usb和安卓手機的通訊過程

發(fā)布者:感恩的7號最新更新時間:2020-03-25 來源: eefocus關(guān)鍵字:stm32  usb  安卓手機  通訊過程 手機看文章 掃描二維碼
隨時隨地手機看文章

前段時間公司開發(fā)了一個安卓外設,主要是用某寶淘來的demo 在stm32F103的usb功能來和安卓設備的usb來通訊


敘述之前先來一個整體的框圖吧:

在這里插入圖片描述

需要準備的設備有:


①.安卓手機或者安卓pad,(手機必須支持otg功能,否則就得用host功能了)

②.otg轉(zhuǎn)接線或者轉(zhuǎn)接頭

③.安卓數(shù)據(jù)線(一定要是能通訊數(shù)據(jù)的線纜,有些山寨的這個線只有2根線,沒有數(shù)據(jù)線)

④.帶有usb功能的單片機(這個usb需要能支持用戶自行定義)


接下來就開始搗鼓stm32單片機程序了,下面是usb功能的代碼

usb功能看了一下主要是借助hid的標準協(xié)議上衍生而來的一個usb標準設備


/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************

* File Name          : usb_desc.c

* Author             : MCD Application Team

* Version            : V3.2.1

* Date               : 07/05/2010

* Description        : Descriptors for Mass Storage Device

********************************************************************************

* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS

* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.

* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,

* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE

* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING

* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.

*******************************************************************************/


/* Includes ------------------------------------------------------------------*/

#include "usb_desc.h"

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Extern variables ----------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/


/* USB Standard Device Descriptor */


const u8 CustomHID_DeviceDescriptor[CUSTOMHID_SIZ_DEVICE_DESC] =

  {

    0x12,                       /*bLength */

    USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/

    0x00,0x02,                  /*bcdUSB */

    0x00,                       /*bDeviceClass*/

    0x00,                       /*bDeviceSubClass*/

    0x00,                       /*bDeviceProtocol*/

    0x08,                       /*bMaxPacketSize40*/

    0x71,0x04,                  /*idVendor (0x0471)*/

    0x08,0x24,                  /*idProduct = 0x2408*/

    0x00,0x02,                  /*bcdDevice rel. 2.00*/

    1,                          /*Index of string descriptor describing manufacturer */

    2,                          /*Index of string descriptor describing product*/

    3,                          /*Index of string descriptor describing the device serial number */

    0x01                        /*bNumConfigurations*/

  }

  ; /* CustomHID_DeviceDescriptor */



/* USB Configuration Descriptor */

/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */

const u8 CustomHID_ConfigDescriptor[ENEPOINT_NUM*7+18] =

  {

    0x09, /* bLength: Configuation Descriptor size */

    USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */

    ENEPOINT_NUM*7+18,    /*CUSTOMHID_SIZ_CONFIG_DESC, wTotalLength: Bytes returned */

    0x00,

    0x01,         /* bNumInterfaces: 1 interface */

    0x01,         /* bConfigurationValue: Configuration value */

    0x00,         /* iConfiguration: Index of string descriptor describing

                                 the configuration*/

    0xC0,         /* bmAttributes: Bus powered */

    0x32,         /* MaxPower 100 mA: this current is used for detecting Vbus */


    /************** Descriptor of Custom HID interface ****************/

    /* 09 */

    0x09,         /* bLength: Interface Descriptor size */

    USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */

    0x00,         /* bInterfaceNumber: Number of Interface */

    0x00,         /* bAlternateSetting: Alternate setting */

    ENEPOINT_NUM,         /* bNumEndpoints */

    0x00,         /* bInterfaceClass: HID=0X03,其他選0 */

    0x00,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */

    0x00,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */

    0,            /* iInterface: Index of string descriptor */

    /********************以下只對HID的描述符  Descriptor of Custom HID HID ********************/

    /* 18 */

  //  0x09,         /* bLength: HID Descriptor size */

  //  HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */

  //  0x10,         /* bcdHID: HID Class Spec release number */

  //  0x01,

  //  0x00,         /* bCountryCode: Hardware target country */

  //  0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */

  //  0x22,         /* bDescriptorType */

  //  CUSTOMHID_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor */

  //  0x00,

  

  

  /******************** Descriptor of Custom endpoints ******************/

   

    0x07, /* bLength: Endpoint Descriptor size */

    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

/* Endpoint descriptor type */

    0x01, /* bEndpointAddress: */

/* Endpoint Address (OUT) */

    USB_ENDPOINT_TYPE_BULK,/* bmAttributes: Interrupt endpoint */

    0x10,0x00, /* wMaxPacketSize: 32 Bytes max  */

    0x20, /* bInterval: Polling Interval (20 ms) */

    

   /* 27 */  

    0x07,          /* bLength: Endpoint Descriptor size */

    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

    0x81,          /* bEndpointAddress: Endpoint Address (IN) */

  USB_ENDPOINT_TYPE_BULK,          /* bmAttributes: Interrupt endpoint */

    0x10, 0x00,         /* wMaxPacketSize: 32 Bytes max */

    0x20,          /* bInterval: Polling Interval (32 ms) */

    /* 34 */

    

    0x07, /* bLength: Endpoint Descriptor size */

    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

/* Endpoint descriptor type */

    0x82, /* bEndpointAddress: */

/* Endpoint Address (OUT) */

    USB_ENDPOINT_TYPE_BULK,/* bmAttributes: Interrupt endpoint */

    0x40,0x00, /* wMaxPacketSize: 512 Bytes max  */

    0x20 /* bInterval: Polling Interval (20 ms) */   

  }

  ;


/* USB String Descriptors (optional) */

const u8 CustomHID_StringLangID[CUSTOMHID_SIZ_STRING_LANGID] =

  {

CUSTOMHID_SIZ_STRING_LANGID,

USB_STRING_DESCRIPTOR_TYPE,

0x09,

0x04

  }

  ; /* LangID = 0x0409: U.S. English */


const u8 CustomHID_StringVendor[CUSTOMHID_SIZ_STRING_VENDOR] =

  {

    CUSTOMHID_SIZ_STRING_VENDOR, /* Size of Vendor string */

    USB_STRING_DESCRIPTOR_TYPE,  /* bDescriptorType*/

    /* Manufacturer: "STMicroelectronics" */

'O', 0,

'T', 0,

'G', 0,

  };


const u8 CustomHID_StringProduct[CUSTOMHID_SIZ_STRING_PRODUCT] =

  {

    CUSTOMHID_SIZ_STRING_PRODUCT,          /* bLength */

    USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */

'S', 0,

'T', 0,

'M', 0,

'3', 0,

'2', 0,

'A',0,

'n',0,

'd',0,

'r',0,

'o',0,

'i',0,

'd',0,

' ',0,

'U',0,

'S',0,

'B',0,

' ',0,

'O', 0,

'T', 0,

'G', 0,

  };

u8 CustomHID_StringSerial[CUSTOMHID_SIZ_STRING_SERIAL] =

  {

    CUSTOMHID_SIZ_STRING_SERIAL,           /* bLength */

    USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */

'T', 0,

'a', 0,

'o', 0,

'b', 0,

'a', 0,

'o', 0,

'-', 0,

'B', 0,

'e', 0,

'i', 0,

'j', 0,

'i',0,

'n',0,

'g',0,

'Y',0,

[1] [2]
關(guān)鍵字:stm32  usb  安卓手機  通訊過程 引用地址:stm32 usb和安卓手機的通訊過程

上一篇:利用樹莓派打造STM32無線在線調(diào)試器!
下一篇:stm32在linux編譯,遠程調(diào)試

小廣播
設計資源 培訓 開發(fā)板 精華推薦

最新單片機文章

 
EEWorld訂閱號

 
EEWorld服務號

 
汽車開發(fā)圈

 
機器人開發(fā)圈

電子工程世界版權(quán)所有 京B2-20211791 京ICP備10001474號-1 電信業(yè)務審批[2006]字第258號函 京公網(wǎng)安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
主站蜘蛛池模板: 潞西市| 青田县| 阿鲁科尔沁旗| 原阳县| 环江| 巩留县| 屯门区| 石棉县| 城市| 宣威市| 儋州市| 新乐市| 富裕县| 双柏县| 福安市| 延安市| 石棉县| 凤庆县| 电白县| 纳雍县| 察隅县| 柳林县| 新巴尔虎左旗| 西和县| 大荔县| 镇康县| 恩施市| 托里县| 会理县| 仪征市| 湟中县| 清徐县| 阿合奇县| 漠河县| 泗洪县| 贡觉县| 余干县| 邵东县| 沙雅县| 陕西省| 突泉县|