前段時間公司開發(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,
上一篇:利用樹莓派打造STM32無線在線調(diào)試器!
下一篇:stm32在linux編譯,遠程調(diào)試
- 熱門資源推薦
- 熱門放大器推薦
設計資源 培訓 開發(fā)板 精華推薦
- iTOP-i.MX6開發(fā)板設備數(shù)驅(qū)動Menuconfig的用法
- 迅為IMX6ULL開發(fā)板Qt for Android搭建開發(fā)環(huán)境
- 迅為i.MX8M mini開發(fā)板Windots QT系統(tǒng)開發(fā)環(huán)境搭建
- 迅為IMX8MM開發(fā)板Yocto系統(tǒng)使用Gstarwmra(一)
- 迅為IMX8M mini開發(fā)板Linix系統(tǒng)修改默認屏幕
- iTOP-4412開發(fā)板支持4G以上文件系統(tǒng)擴展
- 迅為IMX8MM開發(fā)板Yocto系統(tǒng)設置開機自啟動
- 迅為IMX6Q開發(fā)板 Buildroot文件系統(tǒng)mqtt測試
- 迅為IMX8MM開發(fā)板Linux系統(tǒng)修改默認屏幕
- 采用 ICE5AR4770BZS 空調(diào) 15W 輔助 SMPS
- DK-MAXII-1270N,MAX II 開發(fā)板,包含在 MAX II 開發(fā)套件中
- 使用 NXP Semiconductors 的 PCF2129A 的參考設計
- 使用 ROHM Semiconductor 的 BD90GA5WEFJ 的參考設計
- DC2104A,LT8312EMS 演示板,90VAC = VIN = 265VAC,VOUT = 400Vdc,0.375A
- 使用 Analog Devices 的 ADP2165 的參考設計
- DPP904R000,MEAS Pi Weather Shield 評估板,基于 HTU21D 濕度傳感器、MS5637 壓力傳感器、TSYS01 溫度傳感器和 TSD305-1C55 熱電堆傳感器
- STM32DebugCard
- TG-5021CG_CC112x,用于 CC1120、CC1200 和 CC1121 系列低功耗射頻無線應用的外部振蕩電路
- 【創(chuàng)意PCB】立方燈
- 電力電容器在工業(yè)中的應用案例
- 伺服電機編碼器的作用及工作原理·低壓伺服電機驅(qū)動方案開發(fā)
- 安科瑞信號隔離柵在自控系統(tǒng)中應用
- 為了用好氮化鎵,TI 在集成化與工程化上正在持續(xù)攻堅
- 數(shù)據(jù)中心電源保護革命:eFuse 如何應對兆瓦級挑戰(zhàn)
- 蔡司攜多功能智能玻璃技術(shù)亮相2025上海國際車展
- 歐盟“AI大陸”戰(zhàn)略下,如何布局AI工廠與數(shù)據(jù)空間?
- UALink規(guī)范發(fā)布:挑戰(zhàn)英偉達AI統(tǒng)治的開始
- 韓國研究團隊開發(fā)出新混合陽極材料 推動鋰離子電池技術(shù)進步
- 傳統(tǒng)鋰電、半固態(tài)、固態(tài)電池終極對決