mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-06-27 19:42:04 +00:00
Clean up XPLAINBridge code.
This commit is contained in:
parent
2b51944a4b
commit
c77b30e9e6
@ -37,6 +37,7 @@
|
|||||||
#define _USBDEVICEMODE_H_
|
#define _USBDEVICEMODE_H_
|
||||||
|
|
||||||
/* Includes: */
|
/* Includes: */
|
||||||
|
#include <LUFA/Drivers/USB/USB.h>
|
||||||
#include <LUFA/Drivers/USB/Class/MassStorage.h>
|
#include <LUFA/Drivers/USB/Class/MassStorage.h>
|
||||||
|
|
||||||
#include "Webserver.h"
|
#include "Webserver.h"
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#define _USBHOSTMODE_H_
|
#define _USBHOSTMODE_H_
|
||||||
|
|
||||||
/* Includes: */
|
/* Includes: */
|
||||||
|
#include <LUFA/Drivers/USB/USB.h>
|
||||||
#include <LUFA/Drivers/USB/Class/RNDIS.h>
|
#include <LUFA/Drivers/USB/Class/RNDIS.h>
|
||||||
|
|
||||||
#include "Webserver.h"
|
#include "Webserver.h"
|
||||||
|
@ -35,12 +35,12 @@
|
|||||||
volatile uint8_t srx_done, stx_count;
|
volatile uint8_t srx_done, stx_count;
|
||||||
volatile uint8_t srx_data, srx_mask, srx_tmp, stx_data;
|
volatile uint8_t srx_data, srx_mask, srx_tmp, stx_data;
|
||||||
|
|
||||||
unsigned char SoftUART_IsReady(void)
|
uint8_t SoftUART_IsReady(void)
|
||||||
{
|
{
|
||||||
return !(stx_count);
|
return !(stx_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char SoftUART_TxByte(unsigned char c)
|
uint8_t SoftUART_TxByte(uint8_t c)
|
||||||
{
|
{
|
||||||
while (stx_count);
|
while (stx_count);
|
||||||
|
|
||||||
@ -50,12 +50,12 @@ unsigned char SoftUART_TxByte(unsigned char c)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char SoftUART_IsReceived(void)
|
uint8_t SoftUART_IsReceived(void)
|
||||||
{
|
{
|
||||||
return srx_done;
|
return srx_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char SoftUART_RxByte(void)
|
uint8_t SoftUART_RxByte(void)
|
||||||
{
|
{
|
||||||
while (!(srx_done));
|
while (!(srx_done));
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@
|
|||||||
#define STXDDR DDRD
|
#define STXDDR DDRD
|
||||||
|
|
||||||
/* Function Prototypes: */
|
/* Function Prototypes: */
|
||||||
unsigned char SoftUART_IsReady(void);
|
uint8_t SoftUART_IsReady(void);
|
||||||
unsigned char SoftUART_TxByte(unsigned char c);
|
uint8_t SoftUART_TxByte(uint8_t c);
|
||||||
unsigned char SoftUART_IsReceived(void);
|
uint8_t SoftUART_IsReceived(void);
|
||||||
unsigned char SoftUART_RxByte(void);
|
uint8_t SoftUART_RxByte(void);
|
||||||
void SoftUART_Init(void);
|
void SoftUART_Init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -80,22 +80,25 @@ int main(void)
|
|||||||
Buffer_Initialize(&USBtoUART_Buffer);
|
Buffer_Initialize(&USBtoUART_Buffer);
|
||||||
Buffer_Initialize(&UARTtoUSB_Buffer);
|
Buffer_Initialize(&UARTtoUSB_Buffer);
|
||||||
|
|
||||||
|
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (USB_DeviceState == DEVICE_STATE_Configured)
|
if (CurrentFirmwareMode == MODE_USART_BRIDGE)
|
||||||
{
|
USARTBridge_Task();
|
||||||
if (CurrentFirmwareMode == MODE_USART_BRIDGE)
|
else
|
||||||
USARTBridge_Task();
|
AVRISP_Task();
|
||||||
else
|
|
||||||
AVRISP_Task();
|
|
||||||
}
|
|
||||||
|
|
||||||
USB_USBTask();
|
USB_USBTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVRISP_Task(void)
|
void AVRISP_Task(void)
|
||||||
{
|
{
|
||||||
|
/* Must be in the configured state for the AVRISP code to process data */
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||||
|
return;
|
||||||
|
|
||||||
Endpoint_SelectEndpoint(AVRISP_DATA_EPNUM);
|
Endpoint_SelectEndpoint(AVRISP_DATA_EPNUM);
|
||||||
|
|
||||||
/* Check to see if a V2 Protocol command has been received */
|
/* Check to see if a V2 Protocol command has been received */
|
||||||
@ -112,6 +115,10 @@ void AVRISP_Task(void)
|
|||||||
|
|
||||||
void USARTBridge_Task(void)
|
void USARTBridge_Task(void)
|
||||||
{
|
{
|
||||||
|
/* Must be in the configured state for the USART Bridge code to process data */
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Read bytes from the USB OUT endpoint into the UART transmit buffer */
|
/* Read bytes from the USB OUT endpoint into the UART transmit buffer */
|
||||||
for (uint8_t DataBytesRem = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); DataBytesRem != 0; DataBytesRem--)
|
for (uint8_t DataBytesRem = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); DataBytesRem != 0; DataBytesRem--)
|
||||||
{
|
{
|
||||||
@ -130,8 +137,8 @@ void USARTBridge_Task(void)
|
|||||||
SoftUART_TxByte(Buffer_GetElement(&USBtoUART_Buffer));
|
SoftUART_TxByte(Buffer_GetElement(&USBtoUART_Buffer));
|
||||||
|
|
||||||
/* Load bytes from the UART into the UART receive buffer */
|
/* Load bytes from the UART into the UART receive buffer */
|
||||||
if(SoftUART_IsReceived())
|
if (SoftUART_IsReceived())
|
||||||
Buffer_StoreElement(&UARTtoUSB_Buffer, SoftUART_RxByte());
|
Buffer_StoreElement(&UARTtoUSB_Buffer, SoftUART_RxByte());
|
||||||
|
|
||||||
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
|
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
|
||||||
}
|
}
|
||||||
@ -169,6 +176,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
|
|||||||
{
|
{
|
||||||
bool EndpointConfigSuccess;
|
bool EndpointConfigSuccess;
|
||||||
|
|
||||||
|
/* Configure the device endpoints according to the selected mode */
|
||||||
if (CurrentFirmwareMode == MODE_USART_BRIDGE)
|
if (CurrentFirmwareMode == MODE_USART_BRIDGE)
|
||||||
{
|
{
|
||||||
EndpointConfigSuccess = CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
|
EndpointConfigSuccess = CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
|
||||||
@ -193,6 +201,18 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||||||
CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
|
CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Event handler for the library USB Connection event. */
|
||||||
|
void EVENT_USB_Device_Connect(void)
|
||||||
|
{
|
||||||
|
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Event handler for the library USB Disconnection event. */
|
||||||
|
void EVENT_USB_Device_Disconnect(void)
|
||||||
|
{
|
||||||
|
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||||||
|
}
|
||||||
|
|
||||||
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
|
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
|
||||||
* documentation) by the application code so that the address and size of a requested descriptor can be given
|
* documentation) by the application code so that the address and size of a requested descriptor can be given
|
||||||
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
|
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
|
||||||
@ -201,6 +221,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||||||
*/
|
*/
|
||||||
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)
|
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)
|
||||||
{
|
{
|
||||||
|
/* Return the correct descriptors based on the selected mode */
|
||||||
if (CurrentFirmwareMode == MODE_USART_BRIDGE)
|
if (CurrentFirmwareMode == MODE_USART_BRIDGE)
|
||||||
return USART_GetDescriptor(wValue, wIndex, DescriptorAddress);
|
return USART_GetDescriptor(wValue, wIndex, DescriptorAddress);
|
||||||
else
|
else
|
||||||
|
@ -85,8 +85,8 @@
|
|||||||
|
|
||||||
void EVENT_USB_Device_ConfigurationChanged(void);
|
void EVENT_USB_Device_ConfigurationChanged(void);
|
||||||
void EVENT_USB_Device_UnhandledControlRequest(void);
|
void EVENT_USB_Device_UnhandledControlRequest(void);
|
||||||
|
void EVENT_USB_Device_Connect(void);
|
||||||
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo);
|
void EVENT_USB_Device_Disconnect(void);
|
||||||
|
|
||||||
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress);
|
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user