本帖最后由 EDA3rd 于 2017-8-15 00:19 编辑
结构体怎么能执行呢?
static USB_ClassInfo_HID_Host_t Keyboard_HID_Interface = {
.Config = {
.DataINPipeNumber = 1,
.DataINPipeDoubleBank = false,
.DataOUTPipeNumber = 2,
.DataOUTPipeDoubleBank = false,
.HIDInterfaceProtocol = HID_CSCP_KeyboardBootProtocol,
.PortNumber = 0,
},
};
static inline void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
static inline void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo)
{
(void)HIDInterfaceInfo;
}
int main(void)
{
SetupHardware();
DEBUGOUT("Keyboard Host Demo running.
");
for (;; ) {
KeyboardHost_Task();
HID_Host_USBTask(&Keyboard_HID_Interface);
USB_USBTask(Keyboard_HID_Interface.Config.PortNumber, USB_MODE_Host);
}
}
注意 HID_Host_USBTask(&Keyboard_HID_Interface); 这句代码,传递参数是结构体指针,执行 HID_Host_USBTask 就等于执行 (void) &Keyboard_HID_Interface; 不会跑飞吗?事实上板子运行没出现什么问题
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
(void)HIDInterfaceInf; 相当于
int a;
a;
实际上相当于NOP操作,既然是nop,自然就不会跑飞了,楼上说法确实也有道理,估计就是类似c++的虚函数,等用户去具体实现。
来了来了
[mw_shl_code=c,true] typedef struct
{
struct
{
uint8_t DataINPipeNumber; /**< Pipe number of the HID interface's IN data pipe. */
bool DataINPipeDoubleBank; /**< Indicates if the HID interface's IN data pipe should use double banking. */
uint8_t DataOUTPipeNumber; /**< Pipe number of the HID interface's OUT data pipe. */
bool DataOUTPipeDoubleBank; /**< Indicates if the HID interface's OUT data pipe should use double banking. */
uint8_t HIDInterfaceProtocol; /**< HID interface protocol value to match against if a specific
* boot subclass protocol is required, a protocol value from the
* @ref HID_Descriptor_ClassSubclassProtocol_t enum.
*/
#if !defined(HID_HOST_BOOT_PROTOCOL_ONLY)
HID_ReportInfo_t* HIDParserData; /**< HID parser data to store the parsed HID report data, when boot protocol
* is not used.
*
* @note When the c HID_HOST_BOOT_PROTOCOL_ONLY compile time token is defined,
* this method is unavailable.
*/
#endif
uint8_t PortNumber; /**< Port number that this interface is running.
*/
} Config; /**< Config data for the USB class interface within the device. All elements in this section
* <b>must</b> be set or the interface will fail to enumerate and operate correctly.
*/
struct
{
bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid
* after @ref HID_Host_ConfigurePipes() is called and the Host state machine is in the
* Configured state.
*/
uint8_t InterfaceNumber; /**< Interface index of the HID interface within the attached device. */
uint16_t DataINPipeSize; /**< Size in bytes of the HID interface's IN data pipe. */
uint16_t DataOUTPipeSize; /**< Size in bytes of the HID interface's OUT data pipe. */
bool SupportsBootProtocol; /**< Indicates if the current interface instance supports the HID Boot
* Protocol when enabled via @ref HID_Host_SetBootProtocol().
*/
bool DeviceUsesOUTPipe; /**< Indicates if the current interface instance uses a separate OUT data pipe for
* OUT reports, or if OUT reports are sent via the control pipe instead.
*/
bool UsingBootProtocol; /**< Indicates that the interface is currently initialized in Boot Protocol mode */
uint16_t HIDReportSize; /**< Size in bytes of the HID report descriptor in the device. */
uint8_t LargestReportSize; /**< Largest report the device will send, in bytes. */
} State; /**< State data for the USB class interface within the device. All elements in this section
* <b>may</b> be set to initial values, but may also be ignored to default to sane values when
* the interface is enumerated.
*/
} USB_ClassInfo_HID_Host_t;[/mw_shl_code]
代码来自LPCOpen中 2.10 中的usbhost_keyboard.uvproj 例程
[url=http://www.nxp.com/products/developer-resources/software-development-tools/software-tools/lpcopen-libraries-and-examples/lpcopen-software-development-platform-lpc17xxPCOPEN-SOFTWARE-FOR-LPC17XX]http://www.nxp.com/downloads/en/software/lpcopen_2_10_keil_iar_ea_devkit_1788.zip[/url]
int main(void)
{
char *pp = NULL; //这里添加
SetupHardware();
DEBUGOUT("Keyboard Host Demo running. ");
for (;; ) {
KeyboardHost_Task();
//HID_Host_USBTask(&Keyboard_HID_Interface);
(void)pp; //这里添加
USB_USBTask(Keyboard_HID_Interface.Config.PortNumber, USB_MODE_Host);
}
}
1、无论屏蔽或不屏蔽HID_Host_USBTask(&Keyboard_HID_Interface);和 (void)pp; 编译后代码量均没有变化。
2、说明这内联函数HID_Host_USBTask(&Keyboard_HID_Interface);当前是无意义的。估计是提供一个接口,让用户添加。
3、我是菜鸟,仅是为了求知。呈送拙见!
一周热门 更多>