@ -264,6 +264,14 @@ static void raw_hid_task(void)
* Console
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifdef CONSOLE_ENABLE
static bool console_flush = false ;
# define CONSOLE_FLUSH_SET(b) do { \
ATOMIC_BLOCK ( ATOMIC_RESTORESTATE ) { \
console_flush = b ; \
} \
} while ( 0 )
static void Console_Task ( void )
{
/* Device must be connected and configured for the task to run */
@ -272,49 +280,62 @@ static void Console_Task(void)
uint8_t ep = Endpoint_GetCurrentEndpoint ( ) ;
#if 0
// TODO: impl receivechar()/recvchar()
Endpoint_SelectEndpoint ( CONSOLE_OUT_EPNUM ) ;
# ifdef CONSOLE_IN_ENABLE
/* Create a temporary buffer to hold the read in report from the host */
uint8_t ConsoleData [ CONSOLE_EPSIZE ] ;
bool data_read = false ;
/* Check to see if a packet has been sent from the host */
if ( Endpoint_IsOUTReceived ( ) )
{
/* Check to see if the packet contains data */
if ( Endpoint_IsReadWriteAllowed ( ) )
{
/* Create a temporary buffer to hold the read in report from the host */
uint8_t ConsoleData [ CONSOLE_EPSIZE ] ;
// TODO: impl receivechar()/recvchar()
Endpoint_SelectEndpoint ( CONSOLE_OUT_EPNUM ) ;
/* Read Console Report Data */
Endpoint_Read_Stream_LE ( & ConsoleData , sizeof ( ConsoleData ) , NULL ) ;
/* Check to see if a packet has been sent from the host */
if ( Endpoint_IsOUTReceived ( ) )
{
/* Check to see if the packet contains data */
if ( Endpoint_IsReadWriteAllowed ( ) )
{
/* Read Console Report Data */
Endpoint_Read_Stream_LE ( & ConsoleData , sizeof ( ConsoleData ) , NULL ) ;
data_read = true ;
}
/* Finalize the stream transfer to send the last packet */
Endpoint_ClearOUT ( ) ;
if ( data_read ) {
/* Process Console Report Data */
//ProcessConsoleHIDReport(ConsoleData);
}
process_console_data_quantum ( ConsoleData , sizeof ( ConsoleData ) ) ;
}
/* Finalize the stream transfer to send the last packet */
Endpoint_ClearOUT ( ) ;
}
# endif
}
/* IN packet */
Endpoint_SelectEndpoint ( CONSOLE_IN_EPNUM ) ;
if ( ! Endpoint_IsEnabled ( ) | | ! Endpoint_IsConfigured ( ) ) {
Endpoint_SelectEndpoint ( ep ) ;
return ;
}
# endif
if ( console_flush ) {
/* IN packet */
Endpoint_SelectEndpoint ( CONSOLE_IN_EPNUM ) ;
if ( ! Endpoint_IsEnabled ( ) | | ! Endpoint_IsConfigured ( ) ) {
Endpoint_SelectEndpoint ( ep ) ;
return ;
}
// fill empty bank
while ( Endpoint_IsReadWriteAllowed ( ) )
Endpoint_Write_8 ( 0 ) ;
// fill empty bank
while ( Endpoint_IsReadWriteAllowed ( ) )
Endpoint_Write_8 ( 0 ) ;
// flash senchar packet
if ( Endpoint_IsINReady ( ) ) {
Endpoint_ClearIN ( ) ;
// flash senchar packet
if ( Endpoint_IsINReady ( ) ) {
Endpoint_ClearIN ( ) ;
}
// CONSOLE_FLUSH_SET(false);
console_flush = false ;
}
Endpoint_SelectEndpoint ( ep ) ;
}
# endif
@ -380,13 +401,8 @@ void EVENT_USB_Device_WakeUp()
# ifdef CONSOLE_ENABLE
static bool console_flush = false ;
# define CONSOLE_FLUSH_SET(b) do { \
ATOMIC_BLOCK ( ATOMIC_RESTORESTATE ) { \
console_flush = b ; \
} \
} while ( 0 )
// #ifdef CONSOLE_ENABLE
#if 0
// called every 1ms
void EVENT_USB_Device_StartOfFrame ( void )
@ -395,9 +411,9 @@ void EVENT_USB_Device_StartOfFrame(void)
if ( + + count % 50 ) return ;
count = 0 ;
if ( ! console_flush ) return ;
//if (!console_flush) return;
Console_Task ( ) ;
console_flush = false ;
//console_flush = false;
}
# endif
@ -440,10 +456,10 @@ void EVENT_USB_Device_ConfigurationChanged(void)
/* Setup Console HID Report Endpoints */
ConfigSuccess & = ENDPOINT_CONFIG ( CONSOLE_IN_EPNUM , EP_TYPE_INTERRUPT , ENDPOINT_DIR_IN ,
CONSOLE_EPSIZE , ENDPOINT_BANK_SINGLE ) ;
#if 0
# ifdef CONSOLE_IN_ENABLE
ConfigSuccess & = ENDPOINT_CONFIG ( CONSOLE_OUT_EPNUM , EP_TYPE_INTERRUPT , ENDPOINT_DIR_OUT ,
CONSOLE_EPSIZE , ENDPOINT_BANK_SINGLE ) ;
# endif
# endif
# endif
# ifdef NKRO_ENABLE
@ -1101,7 +1117,7 @@ static void setup_usb(void)
USB_Init ( ) ;
// for Console_Task
USB_Device_EnableSOFEvents ( ) ;
//USB_Device_EnableSOFEvents();
print_set_sendchar ( sendchar ) ;
}
@ -1216,6 +1232,10 @@ int main(void)
raw_hid_task ( ) ;
# endif
# ifdef CONSOLE_ENABLE
Console_Task ( ) ;
# endif
# if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask ( ) ;
# endif