📄 usb.c
字号:
case HID_DESCRIPTOR: break;
case REPORT_DESCRIPTOR: break;
case PHYSICAL_DESCRIPTOR: break;
default:
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取其它描述符..................描述符索引为:");
Print_Long(MSB(Control_Data.DeviceRequest.wValue));
Print_Msg("!\r\n");
#endif
} break;
}
if (Control_Data.wLength > Control_Data.wCount)
{
Control_Data.wLength = Control_Data.wCount;
}
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
return 0;
}
//===============================================================================//
//== 函 数 名:get_descriptor_interface
//== 功 能:得到描述符
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char get_descriptor_interface(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing get_descriptor_interface()!\r\n");
#endif
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取描述符(从接口)..............................\r\n");
#endif
switch(MSB(Control_Data.DeviceRequest.wValue))
{
case HID_DESCRIPTOR:
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取HID描述符................................\r\n");
#endif
Control_Data.wCount = sizeof(HID_DESCRIPTOR_STRUCT);
Control_Data.pData = (unsigned char*)(&con_int_endp_descriptor.hid_descriptor);
if (Control_Data.wLength < Control_Data.wCount)
{
Control_Data.wCount = Control_Data.wLength;
}
} break;
case REPORT_DESCRIPTOR:
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取报告描述符................................\r\n");
#endif
Control_Data.wCount = sizeof(DataReportDescriptor);
Control_Data.pData = (unsigned char *)(DataReportDescriptor);
if (Control_Data.wLength < Control_Data.wCount)
{
Control_Data.wCount = Control_Data.wLength;
}
} break;
case PHYSICAL_DESCRIPTOR:
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取物理描述符................................\r\n");
#endif
} break;
default:
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取其它描述符..................描述符索引为:");
Print_Long(MSB(Control_Data.DeviceRequest.wValue));
Print_Msg("!\r\n");
#endif
} break;
}
if (Control_Data.wLength > Control_Data.wCount)
{
Control_Data.wLength = Control_Data.wCount;
}
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
return 0;
}
//===============================================================================//
//== 函 数 名:set_descriptor
//== 功 能:设置描述符
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char set_descriptor(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 设置描述符................................\r\n");
#endif
return 0;
}
//===============================================================================//
//== 函 数 名:get_configuration
//== 功 能:得到配置
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char get_configuration(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing get_configuration()!\r\n");
#endif
usb_transmit_buf[0] = 1;
Control_Data.pData = usb_transmit_buf;
Control_Data.wLength = 1;
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
return 0;
}
//===============================================================================//
//== 函 数 名:set_configuration
//== 功 能:设置配置
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char set_configuration(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing set_configuration()!\r\n");
#endif
if (Control_Data.DeviceRequest.wValue == 0) //== 设备进入未配置状态
{
bEPPflags.bits.configuration = 0;
Control_Data.wLength = 0; //== 发送0字节长度数据到主机做回答
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
set_endpoint_disable();
}
else
{
if (Control_Data.DeviceRequest.wValue == 1) //== 配置设备
{
Control_Data.wLength = 0; //== 发送0字节长度数据到主机做回答
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
set_endpoint_disable();
set_endpoint_enable();
bEPPflags.bits.configuration = 1;
}
else
{
stall_ep0();
}
}
return 0;
}
//===============================================================================//
//== 函 数 名:get_interface
//== 功 能:得到接口
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char get_interface(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing get_interface()!\r\n");
#endif
usb_transmit_buf[0] = 0;
Control_Data.pData = usb_transmit_buf;
Control_Data.wLength = 1;
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
return 0;
}
//===============================================================================//
//== 函 数 名:set_interface
//== 功 能:设置接口
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char set_interface(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing set_interface()!\r\n");
#endif
if (Control_Data.DeviceRequest.wValue == 0 && Control_Data.DeviceRequest.wIndex == 0)
{
Control_Data.wLength = 0; //== 发送0字节长度数据到主机做回答
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
}
else
{
stall_ep0();
}
return 0;
}
//===============================================================================//
//== 函 数 名:get_report
//== 功 能:得到报告
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char get_report(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing get_report()!\r\n");
#endif
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取报告................................\r\n");
#endif
return 0;
}
//===============================================================================//
//== 函 数 名:set_report
//== 功 能:设置报告
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char set_report(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing set_report()!\r\n");
#endif
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 设置报告................................\r\n");
#endif
return 0;
}
//===============================================================================//
//== 函 数 名:set_report
//== 功 能:设置报告
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char get_idle(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing get_idle()!\r\n");
#endif
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取空闲................................\r\n");
#endif
Control_Data.pData = &hid_idle;
Control_Data.wLength = 1;
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
return 0;
}
//===============================================================================//
//== 函 数 名:set_idle
//== 功 能:设置报告
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char set_idle(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing set_idle()!\r\n");
#endif
hid_idle = Control_Data.DeviceRequest.wValue;
Control_Data.wLength = 0; //== 发送0字节长度数据到主机做回答
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
return 0;
}
//===============================================================================//
//== 函 数 名:get_protocol
//== 功 能:获得协议
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char get_protocol(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing get_protocol()!\r\n");
#endif
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg(" 获取协议................................\r\n");
#endif
Control_Data.pData = &hid_protocol;
Control_Data.wLength = 1;
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
return 0;
}
//===============================================================================//
//== 函 数 名:set_protocol
//== 功 能:设置协议
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:无
//== 返 回 值:0
//===============================================================================//
unsigned char set_protocol(void)
{
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing set_protocol()!\r\n");
#endif
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("设置协议................................\r\n");
#endif
hid_protocol = Control_Data.DeviceRequest.wValue;
Control_Data.wLength = 0; //== 发送0字节长度数据到主机做回答
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
return 0;
}
//===============================================================================//
//== 函 数 名:clear_feature
//== 功 能:清除特性
//== 说 明:
//== 时 间:2008.8.20 创建函数
//== 入口参数:receiver: 被清除的对象
//== 返 回 值:0
//===============================================================================//
unsigned char clear_feature(unsigned char receiver)
{
unsigned char endp;
#ifdef __DEBUG__ //== 打印调试信息
Print_Msg("Runing clear_feature()!\r\n");
#endif
switch (receiver)
{
case USB_RECIPIENT_DEVICE:
{
if (Control_Data.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP) //== 清除远程唤醒功能
{
bEPPflags.bits.remote_wakeup = 0;
Control_Data.wLength = 0; //== 发送0字节长度数据到主机做回答
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
}
} break;
case USB_RECIPIENT_INTERFACE:
{
if (Control_Data.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL)//== 清除端点stall
{
endp = (unsigned char)(Control_Data.DeviceRequest.wIndex & MAX_ENDPOINTS);
if (Control_Data.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
{
set_endpoint_status(endp*2 + 1, 0); //== clear TX stall for IN on EPn.
}
else
{
set_endpoint_status(endp*2, 0); //== clear RX stall for OUT on EPn.
}
Control_Data.wLength = 0; //== 发送0字节长度数据到主机做回答
Control_Data.wCount = 0;
bEPPflags.bits.control_state = USB_TRANSMIT; //== 设置为发送状态,等待in端点中断
}
else
{
stall_ep0();
}
} break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -