Commits

Andrew Cooper committed a4ed77d

Adjust formatting

  • Participants
  • Parent commits cfb7e34

Comments (0)

Files changed (31)

arch/at90usb128/lib_board/stk_525/stk_525.c

  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____  I N C L U D E S ___________________________________________________
+//_____  I N C L U D E S _______________________________________________________
 
 #include "config.h"
 #include "stk_525.h"
 #ifdef USE_ADC
 #include "lib_mcu/adc/adc_drv.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 
 //_____ P R I V A T E    D E C L A R A T I O N _____________________________
 
 
-//_____ D E F I N I T I O N ________________________________________________
+//_____ D E F I N I T I O N ____________________________________________________
 
 /**
  * The following table give the correspondance between the ADC code and the temperature

arch/at90usb128/lib_board/stk_525/stk_525.h

 #ifndef STK_525_H
 #define STK_525_H
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 #include "config.h"
 
 #if (TARGET_BOARD==STK525)
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 /**
  * @defgroup STK525_module STK525

arch/at90usb128/lib_board/usb_key/usb_key.c

  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____  I N C L U D E S ___________________________________________________
+//_____  I N C L U D E S _______________________________________________________
 
 #include "config.h"
 #include "usb_key.h"
 #ifdef USE_ADC
 #include "lib_mcu/adc/adc_drv.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 
 //_____ P R I V A T E    D E C L A R A T I O N _____________________________
 
 
-//_____ D E F I N I T I O N ________________________________________________
+//_____ D E F I N I T I O N ____________________________________________________
 
 /**
  * The following table give the correspondance between the ADC code and the temperature
 	0x64,0x61,0x5E,0x5B,0x58,0x55,0x53,0x50,0x4E,0x4C,0x49,0x47,0x45,0x43,
 	0x41,0x3F,0x3D,0x3C,0x3A,0x38};
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
 #ifdef __ICCAVR__
 #pragma diag_suppress=Pa082

arch/at90usb128/lib_board/usb_key/usb_key.h

 #ifndef USB_KEY_H
 #define USB_KEY_H
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 #include "config.h"
 #if (TARGET_BOARD==USBKEY)
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 
 /**

arch/at90usb128/lib_mcu/flash/flash_drv.h

 #ifndef FLASH_DRV_H
 #define FLASH_DRV_H
 
-//_____ I N C L U D E S ______________________________________________________
+//_____ I N C L U D E S __________________________________________________________
 
 #include "config.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 /**
  * @name These macros allow to read a specific device ID of the product.

arch/at90usb128/lib_mcu/pll/pll_drv.h

 #ifndef PLL_DRV_H
 #define PLL_DRV_H
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 /**
  * @defgroup PLL PLL driver
  * PLL Module
  * @{
  */
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 /**
  * @defgroup PLL_macros PLL Macros

arch/at90usb128/lib_mcu/power/power_drv.c

  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 #include "config.h"
 #include "power_drv.h"
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
 
+//TODO Delete
 /**
  * @brief This function write the CPU prescaler register to a define value
  *

arch/at90usb128/lib_mcu/power/power_drv.h

  * @{
  */
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 #define Setup_idle_mode()                       (SMCR=0,SMCR |= (1<<SE))
 #define Setup_power_down_mode()                 (SMCR=0,SMCR |= (1<<SE)+(1<<SM1))
 #define Set_power_down_mode()      set_power_down_mode()
 #define Set_idle_mode()            set_idle_mode()
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
 void set_idle_mode( void );
 void set_power_down_mode( void );

arch/at90usb128/lib_mcu/usart/usart.c

 static volatile unsigned char USART_TxHead;
 static volatile unsigned char USART_TxTail;
 
-/* Initialize USART */
+/**
+ *  Initialize USART
+ */
 void USART0_Init( unsigned int baudrate )
-	{
-	unsigned char x;
+{
+    unsigned char x;
 
-	/* Set the baud rate */
-	UBRR1H = ( unsigned char )( baudrate >> 8 );
-	UBRR1L = ( unsigned char )baudrate;
+    /* Set the baud rate */
+    UBRR1H = ( unsigned char )( baudrate >> 8 );
+    UBRR1L = ( unsigned char )baudrate;
 
-	/* Enable UART receiver and transmitter */
-	UCSR1B = ( ( 1 << RXCIE1 ) | ( 1 << RXEN1 ) | ( 1 << TXEN1 ) );
+    /* Enable UART receiver and transmitter */
+    UCSR1B = ( ( 1 << RXCIE1 ) | ( 1 << RXEN1 ) | ( 1 << TXEN1 ) );
 
-	/* Set frame format: 8 data 2stop */
-	UCSR1C = ( 1 << USBS1 ) | ( 1 << UCSZ11 ) | ( 1 << UCSZ10 ); //For devices with Extended IO
-	//UCSR0C = (1<<URSEL)|(1<<USBS0)|(1<<UCSZ01)|(1<<UCSZ00);   //For devices without Extended IO
+    /* Set frame format: 8 data 2stop */
+    UCSR1C = ( 1 << USBS1 ) | ( 1 << UCSZ11 ) | ( 1 << UCSZ10 ); //For devices with Extended IO
+    //UCSR0C = (1<<URSEL)|(1<<USBS0)|(1<<UCSZ01)|(1<<UCSZ00);   //For devices without Extended IO
 
-	/* Flush receive buffer */
-	x = 0;
+    /* Flush receive buffer */
+    x = 0;
 
-	USART_RxTail = x;
-	USART_RxHead = x;
-	USART_TxTail = x;
-	USART_TxHead = x;
-	}
+    USART_RxTail = x;
+    USART_RxHead = x;
+    USART_TxTail = x;
+    USART_TxHead = x;
+}
 
-/* Interrupt handlers */
+/**
+ * Interrupt handler called when USART1 receives a byte
+ */
 ISR(USART1_RX_vect)
-	{
-	unsigned char rxdata;
-	unsigned char tmphead;
+{
+    unsigned char rxdata;
+    unsigned char tmphead;
 
-	/* Read the received data */
-	rxdata = UDR1;
-	/* Calculate buffer index */
-	tmphead = ( USART_RxHead + 1 ) & USART_RX_BUFFER_MASK;
-	USART_RxHead = tmphead; /* Store new index */
+    /* Read the received data */
+    rxdata = UDR1;
+    /* Calculate buffer index */
+    tmphead = ( USART_RxHead + 1 ) & USART_RX_BUFFER_MASK;
+    USART_RxHead = tmphead; /* Store new index */
 
-	if( tmphead == USART_RxTail )
-		{
-		/* ERROR! Receive buffer overflow */
-		}
+    if( tmphead == USART_RxTail )
+    {
+        /* ERROR! Receive buffer overflow */
+    }
 
-	USART_RxBuf[tmphead] = rxdata; /* Store received data in buffer */
-	}
+    USART_RxBuf[tmphead] = rxdata; /* Store received data in buffer */
+}
 
+/**
+ * Interrupt handler called when USART1 is ready to send
+ */
 ISR(USART1_TX_vect)
-	{
-	unsigned char tmptail;
+{
+    unsigned char tmptail;
 
-	/* Check if all data is transmitted */
-	if( USART_TxHead != USART_TxTail )
-		{
-		/* Calculate buffer index */
-		tmptail = ( USART_TxTail + 1 ) & USART_TX_BUFFER_MASK;
-		USART_TxTail = tmptail; /* Store new index */
+    /* Check if all data is transmitted */
+    if( USART_TxHead != USART_TxTail )
+    {
+        /* Calculate buffer index */
+        tmptail = ( USART_TxTail + 1 ) & USART_TX_BUFFER_MASK;
+        USART_TxTail = tmptail; /* Store new index */
 
-		UDR1 = USART_TxBuf[tmptail]; /* Start transmition */
-		}
-	else
-		{
-		UCSR1B &= ~ ( 1 << UDRIE1 ); /* Disable UDRE interrupt */
-		}
-	}
+        UDR1 = USART_TxBuf[tmptail]; /* Start transmition */
+    }
+    else
+    {
+        UCSR1B &= ~( 1 << UDRIE1 ); /* Disable UDRE interrupt */
+    }
+}
 
-/* Read and write functions */
+/**
+ * Read a byte from the data buffer. Blocks if no bytes are available.
+ * @return next received byte
+ */
 unsigned char USART0_Receive( void )
-	{
-	unsigned char tmptail;
+{
+    unsigned char tmptail;
 
-	while( USART_RxHead == USART_RxTail )
-		/* Wait for incomming data */
-		;
-	tmptail = ( USART_RxTail + 1 ) & USART_RX_BUFFER_MASK;/* Calculate buffer index */
+    while( USART_RxHead == USART_RxTail )
+        /* Wait for incomming data */
+        ;
+    tmptail = ( USART_RxTail + 1 ) & USART_RX_BUFFER_MASK;/* Calculate buffer index */
 
-	USART_RxTail = tmptail; /* Store new index */
+    USART_RxTail = tmptail; /* Store new index */
 
-	return USART_RxBuf[tmptail]; /* Return data */
-	}
+    return USART_RxBuf[tmptail]; /* Return data */
+}
 
+/**
+ * Add a byte to the data buffer to be transmitted. Blocks if no space is available.
+ * @param txdata
+ */
 void USART0_Transmit( unsigned char txdata )
-	{
-	unsigned char tmphead;
-	/* Calculate buffer index */
-	tmphead = ( USART_TxHead + 1 ) & USART_TX_BUFFER_MASK; /* Wait for free space in buffer */
-	while( tmphead == USART_TxTail )
-		;
+{
+    unsigned char tmphead;
+    /* Calculate buffer index */
+    tmphead = ( USART_TxHead + 1 ) & USART_TX_BUFFER_MASK; /* Wait for free space in buffer */
+    while( tmphead == USART_TxTail )
+        ;
 
-	USART_TxBuf[tmphead] = txdata; /* Store data in buffer */
-	USART_TxHead = tmphead; /* Store new index */
+    USART_TxBuf[tmphead] = txdata; /* Store data in buffer */
+    USART_TxHead = tmphead; /* Store new index */
 
-	UCSR1B |= ( 1 << UDRIE1 ); /* Enable UDRE interrupt */
-	}
+    UCSR1B |= ( 1 << UDRIE1 ); /* Enable UDRE interrupt */
+}
 
+/**
+ *
+ * @return
+ */
 unsigned char DataInReceiveBuffer( void )
-	{
-	return ( USART_RxHead != USART_RxTail ); /* Return 0 (FALSE) if the receive buffer is empty */
-	}
+{
+    return ( USART_RxHead != USART_RxTail ); /* Return 0 (false) if the receive buffer is empty */
+}

arch/at90usb128/lib_mcu/usart/usart.h

  *
  */
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
+/**
+ * Initialize USART0 hardware, buffers and interrupt handlers.
+ *
+ * @param baudrate target bit clock for USART, already in proper format for UBRR
+ */
 void USART0_Init( unsigned int baudrate );
 
-unsigned char USART0_Receive( void );
+/**
+ * Copy any received frames into data.
+ *
+ * @param data buffer for received frames
+ * @param size of data buffer
+ * @return number of frames copied
+ */
+int USART0_Receive( unsigned char * data, int size );
 
-void USART0_Transmit( unsigned char data );
+/**
+ * Copy frames to transmit queue.
+ *
+ * @param data buffer for outgoing data
+ * @param size of data buffer
+ * @return number of frames copied; may be less than size if queue becomes full
+ */
+int USART0_Transmit( unsigned char const * data, int size );

arch/at90usb128/lib_mcu/usb/usb_drv.c

  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 #include <stdbool.h>
 #include "config.h"
 #include "conf_usb.h"
 #include "usb_drv.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
 #if (USB_DEVICE_FEATURE==false && USB_HOST_FEATURE==false)
 #error at least one of  USB_DEVICE_FEATURE or USB_HOST_FEATURE should be unabled

arch/at90usb128/lib_mcu/usb/usb_drv.h

 #ifndef _USB_DRV_H_
 #define _USB_DRV_H_
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 
 typedef enum endpoint_parameter
  * @{
  */
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 #define MAX_EP_NB             7
 
 
 ///@}
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
 uint8_t usb_config_ep( uint8_t, uint8_t );
 uint8_t usb_select_enpoint_interrupt( void );

arch/at90usb128/modules/usb/device_chap9/usb_device_task.c

  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-//_____  I N C L U D E S ___________________________________________________
+//_____  I N C L U D E S _______________________________________________________
 #include <stdbool.h>
 #include <avr/interrupt.h>
 #include "config.h"
 #if ((TARGET_BOARD==SPIDER) && (USB_OTG_FEATURE==true))
 #include "lib_board/lcd/lcd_drv.h"
 #endif
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 //_____ D E F I N I T I O N S ______________________________________________
 /**
  * Public : (bool) usb_connected

arch/at90usb128/modules/usb/device_chap9/usb_device_task.h

  * @{
  */
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 
 //_____ D E C L A R A T I O N S ____________________________________________

arch/at90usb128/modules/usb/device_chap9/usb_standard_descriptors.h

 #ifndef _USB_STANDARD_DESCRIPTORS_H_
 #define _USB_STANDARD_DESCRIPTORS_H_
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 /// USB Request
 typedef struct

arch/at90usb128/modules/usb/device_chap9/usb_standard_request.c

  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 #include "config.h"
 #include "conf_usb.h"
 static uint8_t bin_to_ascii (uint8_t b);
 #endif
 
-//_____ D E F I N I T I O N ________________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
 static bool usb_get_descriptor( void );
 static void usb_set_address( void );
 uint8_t f_get_serial_string=false;
 #endif
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E F I N I T I O N ____________________________________________________
 
 #ifdef __GNUC__                          // AVRGCC does not support point to PGM space
 PGM_VOID_P pbuffer;

arch/at90usb128/modules/usb/device_chap9/usb_standard_request.h

 #ifndef _USB_STANDARD_REQUEST_H_
 #define _USB_STANDARD_REQUEST_H_
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 #include "modules/usb/usb_task.h"
 #include "usb_descriptors.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 //_____ S T A N D A R D    D E F I N I T I O N S ___________________________
 
 #define OTG_A_HNP_SUPPORT       4
 #define OTG_A_ALT_HNP_SUPPORT   5
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
 /**
  * Returns true when device connected and correctly enumerated with an host.

arch/at90usb128/modules/usb/usb_commun.h

 #ifndef _USB_COMMUN_H_
 #define _USB_COMMUN_H_
 
+//_____ C O N S T A N T S ______________________________________________________
+
 ///@name Vendor Identifiant according by USB org to ATMEL
 #define  VID_ATMEL                              0x03EB
 

arch/at90usb128/modules/usb/usb_task.c

  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____  I N C L U D E S ___________________________________________________
+//_____  I N C L U D E S _______________________________________________________
 #include <stdbool.h>
 #include <avr/interrupt.h>
 

arch/at90usb128/modules/usb/usb_task.h

  * @{
  */
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 /**
  * @defgroup usb_software_evts USB software Events Management

arch/common/lib_mcu/wdt/wdt_drv.h

 #ifndef _WDT_DRV_H_
 #define _WDT_DRV_H_
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 #include <avr/io.h>
 #include <avr/wdt.h>

arch/common/modules/scheduler/scheduler.c

  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 #define _SCHEDULER_C_
 #include "config.h"                         // system definition
 #include "conf/conf_scheduler.h"            // Configuration for the scheduler
 #include "scheduler.h"                      // scheduler definition
 
-//_____ M A C R O S ________________________________________________________
-//_____ D E F I N I T I O N ________________________________________________
+//_____ M A C R O S ____________________________________________________________
+//_____ D E F I N I T I O N ____________________________________________________
 #if SCHEDULER_TYPE != SCHEDULER_FREE
  * When SCHEDULER_TYPE != SCHEDULER_FREE, this flag control task calls.
 bit scheduler_tick_flag;
 unsigned char token;
 #endif
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 /**
  * @brief Scheduler initialization
  *

arch/common/modules/scheduler/scheduler.h

 #ifndef _SCHEDULER_H_
 #define _SCHEDULER_H_
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 #ifdef KEIL
 #include <intrins.h>
 #define Wait_semaphore(a) while(!_testbit_(a))
 #define Wait_semaphore(a) while(!(a)) (a) = false
 #endif
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 /**
  * Definition of Task ID. This ID is used to properly send the event to a
  * specific task.
 extern void Scheduler_task_11 (void);
 #endif
 
-//_____ D E F I N I T I O N ________________________________________________
+//_____ D E F I N I T I O N ____________________________________________________
 #if SCHEDULER_TYPE != SCHEDULER_FREE
 extern bit scheduler_tick_flag;
 #endif
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____  I N C L U D E S ___________________________________________________
+//_____  I N C L U D E S _______________________________________________________
 
 #include "config.h"
 #include "conf_usb.h"
 //_____ M A C R O S ____________________________________________________________
 
 
-//_____ V A R I A B L E S __________________________________________________
+//_____ V A R I A B L E S ______________________________________________________
 
 volatile uint8_t cpt_sof = 0;
 extern uint8_t jump_bootloader;
 
 struct hid_report report;
 
-//_____ P R O C E D U R E S ________________________________________________
+//_____ D E F I N I T I O N S __________________________________________________
 
 void hid_report_out( void );
 void hid_report_in( void );
  * @brief Initialize the target board resources.
  */
 void hid_task_init( void )
-	{
-	Leds_init();
-	Joy_init();
-	}
+{
+    Leds_init();
+    Joy_init();
+}
 
 /**
  * @brief Entry point of the HID generic communication task
  * This function manages IN/OUT report management.
  */
 void hid_task( void )
-	{
-	if( ! Is_device_enumerated() ) // Check USB HID is enumerated
-		return;
+{
+    if( !Is_device_enumerated() ) // Check USB HID is enumerated
+        return;
 
-	hid_report_out();
-	hid_report_in();
-	}
+    hid_report_out();
+    hid_report_in();
+}
 
 /**
  * @brief Get data report from Host
  */
 void hid_report_out( void )
-	{
-	Usb_select_endpoint(EP_HID_OUT);
-	if( Is_usb_receive_out() )
-		{
-		Usb_ack_receive_out();
-		}
+{
+    Usb_select_endpoint(EP_HID_OUT);
+    if( Is_usb_receive_out() )
+    {
+        Usb_ack_receive_out();
+    }
 
-	// Check if we received DFU mode command from host
-//	if( jump_bootloader )
-//		{
-//		uint32_t volatile tempo;
-//		Leds_off();
-//		Usb_detach(); // Detach actual generic HID application
-//		for( tempo = 0; tempo < 70000; tempo++ )
-//			; // Wait some time before
-//		start_boot(); // Jumping to booltoader
-//		}
-	}
+    // Check if we received DFU mode command from host
+    //	if( jump_bootloader )
+    //		{
+    //		uint32_t volatile tempo;
+    //		Leds_off();
+    //		Usb_detach(); // Detach actual generic HID application
+    //		for( tempo = 0; tempo < 70000; tempo++ )
+    //			; // Wait some time before
+    //		start_boot(); // Jumping to booltoader
+    //		}
+}
 
 /**
  * @brief Send data report to Host
  */
 void hid_report_in( void )
-	{
-	uint8_t *report_p = (uint8_t*)&report;
-	int i;
+{
+    uint8_t *report_p = ( uint8_t* ) &report;
+    int i;
 
-	Usb_select_endpoint(EP_HID_IN);
-	if( ! Is_usb_write_enabled() )
-		return; // Not ready to send report
+    Usb_select_endpoint(EP_HID_IN);
+    if( !Is_usb_write_enabled() )
+        return; // Not ready to send report
 
-	for( i = 0; i < sizeof(report); ++i)
-		{
+    for( i = 0; i < sizeof( report ); ++i )
+    {
 
-		}
-	// Send report
-	Usb_write_byte(g_last_joy); // Joystick
-	Usb_write_byte(GPIOR1); // Dummy (not used)
-	Usb_write_byte(GPIOR1); // Dummy (not used)
-	Usb_write_byte(GPIOR1); // Dummy (not used)
-	Usb_write_byte(GPIOR1); // Dummy (not used)
-	Usb_write_byte(GPIOR1); // Dummy (not used)
-	Usb_write_byte(GPIOR1); // Dummy (not used)
-	Usb_write_byte(GPIOR1); // Dummy (not used)
+    }
+    // Send report
+    Usb_write_byte(g_last_joy); // Joystick
+    Usb_write_byte(GPIOR1); // Dummy (not used)
+    Usb_write_byte(GPIOR1); // Dummy (not used)
+    Usb_write_byte(GPIOR1); // Dummy (not used)
+    Usb_write_byte(GPIOR1); // Dummy (not used)
+    Usb_write_byte(GPIOR1); // Dummy (not used)
+    Usb_write_byte(GPIOR1); // Dummy (not used)
+    Usb_write_byte(GPIOR1); // Dummy (not used)
 
-	Usb_ack_in_ready(); // Send data over the USB
-	}
+    Usb_ack_in_ready(); // Send data over the USB
+}
 
 /**
  * @brief  Increments the cpt_sof counter
  * Useful to manage time delays.
  */
 void sof_action()
-	{
-	cpt_sof++ ;
-	}
+{
+    cpt_sof++ ;
+}
 //_____ T Y P E S __________________________________________________________
 
 struct hid_report
-	{
-	/*
-	 * Inputs, 1bit * 13
-	 * Usage: Generic Desktop / Gamepad / Button
-	 */
-	uint8_t		b1:1;
-	uint8_t		b2:1;
-	uint8_t		b3:1;
-	uint8_t		b4:1;
-	uint8_t		b5:1;
-	uint8_t		b6:1;
-	uint8_t		b7:1;
-	uint8_t		b8:1;
-	uint8_t		b9:1;
-	uint8_t		b10:1;
-	uint8_t		b11:1;
-	uint8_t		b12:1;
-	uint8_t		b13:1;
+{
+    /*
+     * Inputs, 1bit * 13
+     * Usage: Generic Desktop / Gamepad / Button
+     */
+    uint8_t b1 :1;
+    uint8_t b2 :1;
+    uint8_t b3 :1;
+    uint8_t b4 :1;
+    uint8_t b5 :1;
+    uint8_t b6 :1;
+    uint8_t b7 :1;
+    uint8_t b8 :1;
+    uint8_t b9 :1;
+    uint8_t b10 :1;
+    uint8_t b11 :1;
+    uint8_t b12 :1;
+    uint8_t b13 :1;
 
-	/*
-	 * Padding, 1bit * 3
-	 */
-	uint8_t		pad1:3;
+    /*
+     * Padding, 1bit * 3
+     */
+    uint8_t pad1 :3;
 
-	/*
-	 * Inputs: 4bit * 1
-	 * Usage: Generic Desktop / Gamepad
-	 * Logical: 0..7
-	 * Physical: 0..315
-	 */
-	/// hatswitch
-	uint8_t		hat:4;
+    /*
+     * Inputs: 4bit * 1
+     * Usage: Generic Desktop / Gamepad
+     * Logical: 0..7
+     * Physical: 0..315
+     */
+    /// hatswitch
+    uint8_t hat :4;
 
-	/*
-	 * Padding 4bit * 1
-	 */
-	uint8_t		pad2:4;
+    /*
+     * Padding 4bit * 1
+     */
+    uint8_t pad2 :4;
 
-	/*
-	 * Inputs: 8bit * 4
-	 * Usage: Generic Desktop / Gamepad
-	 * Logical: 0..255
-	 * Physical: 0..255
-	 */
-	/// X axis
-	uint8_t		x;
-	/// Y axis
-	uint8_t		y;
-	/// Z axis
-	uint8_t		z;
-	/// Rz axis
-	uint8_t		Rz;
+    /*
+     * Inputs: 8bit * 4
+     * Usage: Generic Desktop / Gamepad
+     * Logical: 0..255
+     * Physical: 0..255
+     */
+    /// X axis
+    uint8_t x;
+    /// Y axis
+    uint8_t y;
+    /// Z axis
+    uint8_t z;
+    /// Rz axis
+    uint8_t Rz;
 
-	/*
-	 * Inputs: 8bit * 12
-	 * Usage: Generic Desktop / 65280 (Vendor)
-	 */
-	/// Usage 0x20
-	uint8_t		iVendorX20;
-	/// Usage 0x21
-	uint8_t		iVendorX21;
-	/// Usage 0x22
-	uint8_t		iVendorX22;
-	/// Usage 0x23
-	uint8_t		iVendorX23;
-	/// Usage 0x24
-	uint8_t		iVendorX24;
-	/// Usage 0x25
-	uint8_t		iVendorX25;
-	/// Usage 0x26
-	uint8_t		iVendorX26;
-	/// Usage 0x27
-	uint8_t		iVendorX27;
-	/// Usage 0x28
-	uint8_t		iVendorX28;
-	/// Usage 0x29
-	uint8_t		iVendorX29;
-	/// Usage 0x2A
-	uint8_t		iVendorX2A;
-	/// Usage 0x2B
-	uint8_t		iVendorX2B;
+    /*
+     * Inputs: 8bit * 12
+     * Usage: Generic Desktop / 65280 (Vendor)
+     */
+    /// Usage 0x20
+    uint8_t iVendorX20;
+    /// Usage 0x21
+    uint8_t iVendorX21;
+    /// Usage 0x22
+    uint8_t iVendorX22;
+    /// Usage 0x23
+    uint8_t iVendorX23;
+    /// Usage 0x24
+    uint8_t iVendorX24;
+    /// Usage 0x25
+    uint8_t iVendorX25;
+    /// Usage 0x26
+    uint8_t iVendorX26;
+    /// Usage 0x27
+    uint8_t iVendorX27;
+    /// Usage 0x28
+    uint8_t iVendorX28;
+    /// Usage 0x29
+    uint8_t iVendorX29;
+    /// Usage 0x2A
+    uint8_t iVendorX2A;
+    /// Usage 0x2B
+    uint8_t iVendorX2B;
 
-	/*
-	 * Features: 8bit * 8
-	 * Usage: Generic Desktop / 65280 (Vendor)
-	 */
-	/// Usage 0x2621
-	uint8_t		iFeatureD2621_1;
-	uint8_t		iFeatureD2621_2;
-	uint8_t		iFeatureD2621_3;
-	uint8_t		iFeatureD2621_4;
-	uint8_t		iFeatureD2621_5;
-	uint8_t		iFeatureD2621_6;
-	uint8_t		iFeatureD2621_7;
-	uint8_t		iFeatureD2621_8;
+    /*
+     * Features: 8bit * 8
+     * Usage: Generic Desktop / 65280 (Vendor)
+     */
+    /// Usage 0x2621
+    uint8_t iFeatureD2621_1;
+    uint8_t iFeatureD2621_2;
+    uint8_t iFeatureD2621_3;
+    uint8_t iFeatureD2621_4;
+    uint8_t iFeatureD2621_5;
+    uint8_t iFeatureD2621_6;
+    uint8_t iFeatureD2621_7;
+    uint8_t iFeatureD2621_8;
 
-	/*
-	 * Outputs: 8bit * 8
-	 * Usage: Generic Desktop / 65280 (Vendor)
-	 */
-	/// Usage 0x2621
-	uint8_t		iOutputD2621_1;
-	uint8_t		iOutputD2621_2;
-	uint8_t		iOutputD2621_3;
-	uint8_t		iOutputD2621_4;
-	uint8_t		iOutputD2621_5;
-	uint8_t		iOutputD2621_6;
-	uint8_t		iOutputD2621_7;
-	uint8_t		iOutputD2621_8;
+    /*
+     * Outputs: 8bit * 8
+     * Usage: Generic Desktop / 65280 (Vendor)
+     */
+    /// Usage 0x2621
+    uint8_t iOutputD2621_1;
+    uint8_t iOutputD2621_2;
+    uint8_t iOutputD2621_3;
+    uint8_t iOutputD2621_4;
+    uint8_t iOutputD2621_5;
+    uint8_t iOutputD2621_6;
+    uint8_t iOutputD2621_7;
+    uint8_t iOutputD2621_8;
 
-	/*
-	 * Inputs: 16bit * 4
-	 * Usage: Generic Destop / 65280 (Vendor)
-	 * Logical: 0..1023
-	 * Physical: 0..1023
-	 */
-	/// Usage 0x2C
-	uint16_t		iInputX2C;
-	/// Usage 0x2D
-	uint16_t		iInputX2D;
-	/// Usage 0x2E
-	uint16_t		iInputX2E;
-	/// Usage 0x2F
-	uint16_t		iInputx2F;
-	};
-
-
+    /*
+     * Inputs: 16bit * 4
+     * Usage: Generic Destop / 65280 (Vendor)
+     * Logical: 0..1023
+     * Physical: 0..1023
+     */
+    /// Usage 0x2C
+    uint16_t iInputX2C;
+    /// Usage 0x2D
+    uint16_t iInputX2D;
+    /// Usage 0x2E
+    uint16_t iInputX2E;
+    /// Usage 0x2F
+    uint16_t iInputx2F;
+};
 
 #endif /* _HID_TASK_H_ */
 
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-//_____  I N C L U D E S ___________________________________________________
+//_____  I N C L U D E S _______________________________________________________
 
 #include "config.h"
 #include "modules/scheduler/scheduler.h"
 
 //_____ D E F I N I T I O N S ______________________________________________
 
-int main(void)
-    {
+int main( void )
+{
     start_boot_if_required();
     wdtdrv_disable();
     Clear_prescaler();
     scheduler();
     return 0;
-    }
+}
 
 /**
  * @name Procedure to speed up the startup code
 ///@{
 // Locate low level init function before RAM init (init3 section)
 // and remove std prologue/epilogue
-char __low_level_init(void) __attribute__ ((section (".init3"),naked));
+char __low_level_init( void ) __attribute__ ((section (".init3"),naked));
 
 #ifdef __cplusplus
 extern "C"
-    {
+{
 #endif
 char __low_level_init()
-    {
+{
     Clear_prescaler();
     return 1;
-    }
+}
 #ifdef __cplusplus
 }
 #endif
 /* Copyright (c) 2010 Andrew Cooper. All rights reserved.
  */
 
-//_____  I N C L U D E S ___________________________________________________
+//_____  I N C L U D E S _______________________________________________________
 
 #include <stdbool.h>
 #include <avr/interrupt.h>
 //_____ M A C R O S ____________________________________________________________
 
 
-//_____ V A R I A B L E S __________________________________________________
+//_____ V A R I A B L E S ______________________________________________________
 
 
 static uint8_t rx_buffer[USART_RX_BUFFER_SIZE];
 static int tx_head;
 static int tx_tail;
 
-//_____ P R O C E D U R E S ________________________________________________
+//_____ D E F I N I T I O N S __________________________________________________
 
 
 /**
  */
 void uart_task_init( void )
 {
-/** Initialize buffer variables                                              **/
-rx_head = 0;
-rx_overflow = false;
-rx_tail = 0;
-tx_head = 0;
-tx_tail = 0;
+    /** Initialize buffer variables                                          **/
+    rx_head = 0;
+    rx_overflow = false;
+    rx_tail = 0;
+    tx_head = 0;
+    tx_tail = 0;
 
 }
 

usb_descriptors.c

 //_____ D E F I N I T I O N ____________________________________________________
 // usb_user_device_descriptor
 PROGMEM S_usb_device_descriptor usb_dev_desc =
-	{
-	sizeof( usb_dev_desc ),
-	DESCRIPTOR_DEVICE,
-	USB_SPECIFICATION,
-	DEVICE_CLASS,
-	DEVICE_SUB_CLASS,
-	DEVICE_PROTOCOL,
-	EP_CONTROL_LENGTH,
-	VENDOR_ID,
-	PRODUCT_ID,
-	RELEASE_NUMBER,
-	MAN_INDEX,
-	PROD_INDEX,
-	SN_INDEX,
-	NB_CONFIGURATION
-	};
+    {
+    sizeof( usb_dev_desc ),
+    DESCRIPTOR_DEVICE,
+    USB_SPECIFICATION,
+    DEVICE_CLASS,
+    DEVICE_SUB_CLASS,
+    DEVICE_PROTOCOL,
+    EP_CONTROL_LENGTH,
+    VENDOR_ID,
+    PRODUCT_ID,
+    RELEASE_NUMBER,
+    MAN_INDEX,
+    PROD_INDEX,
+    SN_INDEX,
+    NB_CONFIGURATION
+    };
 // usb_user_configuration_descriptor FS
 PROGMEM S_usb_user_configuration_descriptor usb_conf_desc =
-	{
-	.cfg =
-		{
-		.bLength = sizeof(S_usb_configuration_descriptor),
-		.bDescriptorType = DESCRIPTOR_CONFIGURATION,
-		.wTotalLength = sizeof(S_usb_configuration_descriptor)
-                      + sizeof(S_usb_interface_descriptor)
-                      + sizeof(S_usb_hid_descriptor)
-                      + sizeof(S_usb_endpoint_descriptor)
-                      + sizeof(S_usb_endpoint_descriptor),
-		.bNumInterfaces = NB_INTERFACE,
-		.bConfigurationValue = CONF_NB,
-		.iConfiguration = CONF_INDEX,
-		.bmAttributes = CONF_ATTRIBUTES,
-		.MaxPower = MAX_POWER
-		},
-	.ifc =
-		{
-		.bLength = sizeof(S_usb_interface_descriptor),
-		.bDescriptorType = DESCRIPTOR_INTERFACE,
-		.bInterfaceNumber = INTERFACE_NB,
-		.bAlternateSetting = ALTERNATE,
-		.bNumEndpoints = NB_ENDPOINT,
-		.bInterfaceClass = INTERFACE_CLASS,
-		.bInterfaceSubClass = INTERFACE_SUB_CLASS,
-		.bInterfaceProtocol = INTERFACE_PROTOCOL,
-		.iInterface = INTERFACE_INDEX
-		},
-	.hid =
-		{
-		.bLength = sizeof(S_usb_hid_descriptor),
-		.bDescriptorType = DESCRIPTOR_HID,
-		.bcdHIDVer = HID_BCD,
-		.bCountryCode = HID_NO_COUNTRY_CODE,
-		.bNumDescriptors = HID_CLASS_DESC_NB_DEFAULT,
-		.bRDescriptorType = DESCRIPTOR_REPORT,
-		.wDescriptorLength = sizeof(S_usb_hid_report_descriptor)
-		},
-	.ep1 =
-		{
-		.bLength = sizeof(S_usb_endpoint_descriptor),
-		.bDescriptorType = DESCRIPTOR_ENDPOINT,
-		.bEndpointAddress = ENDPOINT_NB_1,
-		.bmAttributes = EP_ATTRIBUTES_1,
-		.wMaxPacketSize = EP_SIZE_1,
-		.bInterval = EP_INTERVAL_1
-		},
-	.ep2 =
-		{
-		.bLength = sizeof(S_usb_endpoint_descriptor),
-		.bDescriptorType = DESCRIPTOR_ENDPOINT,
-		.bEndpointAddress = ENDPOINT_NB_2,
-		.bmAttributes = EP_ATTRIBUTES_2,
-		.wMaxPacketSize = EP_SIZE_2,
-		.bInterval = EP_INTERVAL_2
-		}
-	};
+    {
+    .cfg =
+    {
+        .bLength = sizeof(S_usb_configuration_descriptor),
+        .bDescriptorType = DESCRIPTOR_CONFIGURATION,
+        .wTotalLength = sizeof(S_usb_configuration_descriptor)
+        + sizeof(S_usb_interface_descriptor)
+        + sizeof(S_usb_hid_descriptor)
+        + sizeof(S_usb_endpoint_descriptor)
+        + sizeof(S_usb_endpoint_descriptor),
+        .bNumInterfaces = NB_INTERFACE,
+        .bConfigurationValue = CONF_NB,
+        .iConfiguration = CONF_INDEX,
+        .bmAttributes = CONF_ATTRIBUTES,
+        .MaxPower = MAX_POWER
+    },
+    .ifc =
+    {
+        .bLength = sizeof(S_usb_interface_descriptor),
+        .bDescriptorType = DESCRIPTOR_INTERFACE,
+        .bInterfaceNumber = INTERFACE_NB,
+        .bAlternateSetting = ALTERNATE,
+        .bNumEndpoints = NB_ENDPOINT,
+        .bInterfaceClass = INTERFACE_CLASS,
+        .bInterfaceSubClass = INTERFACE_SUB_CLASS,
+        .bInterfaceProtocol = INTERFACE_PROTOCOL,
+        .iInterface = INTERFACE_INDEX
+    },
+    .hid =
+    {
+        .bLength = sizeof(S_usb_hid_descriptor),
+        .bDescriptorType = DESCRIPTOR_HID,
+        .bcdHIDVer = HID_BCD,
+        .bCountryCode = HID_NO_COUNTRY_CODE,
+        .bNumDescriptors = HID_CLASS_DESC_NB_DEFAULT,
+        .bRDescriptorType = DESCRIPTOR_REPORT,
+        .wDescriptorLength = sizeof(S_usb_hid_report_descriptor)
+    },
+    .ep1 =
+    {
+        .bLength = sizeof(S_usb_endpoint_descriptor),
+        .bDescriptorType = DESCRIPTOR_ENDPOINT,
+        .bEndpointAddress = ENDPOINT_NB_1,
+        .bmAttributes = EP_ATTRIBUTES_1,
+        .wMaxPacketSize = EP_SIZE_1,
+        .bInterval = EP_INTERVAL_1
+    },
+    .ep2 =
+    {
+        .bLength = sizeof(S_usb_endpoint_descriptor),
+        .bDescriptorType = DESCRIPTOR_ENDPOINT,
+        .bEndpointAddress = ENDPOINT_NB_2,
+        .bmAttributes = EP_ATTRIBUTES_2,
+        .wMaxPacketSize = EP_SIZE_2,
+        .bInterval = EP_INTERVAL_2
+    }
+    };
 // usb_user_manufacturer_string_descriptor
 PROGMEM S_usb_manufacturer_string_descriptor usb_user_manufacturer_string_descriptor =
-	{
-	.bLength = sizeof( usb_user_manufacturer_string_descriptor ),
-	.bDescriptorType = DESCRIPTOR_STRING,
-	.wString = USB_MANUFACTURER_NAME
-	};
+    {
+    .bLength = sizeof( usb_user_manufacturer_string_descriptor ),
+    .bDescriptorType = DESCRIPTOR_STRING,
+    .wString = USB_MANUFACTURER_NAME
+    };
 // usb_user_product_string_descriptor
 PROGMEM S_usb_product_string_descriptor usb_user_product_string_descriptor =
-	{
-	.bLength = sizeof( usb_user_product_string_descriptor ),
-	.bDescriptorType = DESCRIPTOR_STRING,
-	.wString = USB_PRODUCT_NAME
-	};
+    {
+    .bLength = sizeof( usb_user_product_string_descriptor ),
+    .bDescriptorType = DESCRIPTOR_STRING,
+    .wString = USB_PRODUCT_NAME
+    };
 // usb_user_serial_number
 #if (USB_DEVICE_SN_USE==true)
 PROGMEM S_usb_serial_number usb_user_serial_number =
-	{
+{
 #if (USE_DEVICE_SN_UNIQUE==true)
-	sizeof(usb_user_serial_number)+4*SN_LENGTH,
-	DESCRIPTOR_STRING
+    sizeof(usb_user_serial_number)+4*SN_LENGTH,
+    DESCRIPTOR_STRING
 #else
-	sizeof(usb_user_serial_number),
-	DESCRIPTOR_STRING,
-	USB_SERIAL_NUMBER
+    sizeof(usb_user_serial_number),
+    DESCRIPTOR_STRING,
+    USB_SERIAL_NUMBER
 #endif
-	};
+};
 #endif
 
 // usb_user_language_id
 
 PROGMEM S_usb_language_id usb_user_language_id =
-	{
-	.bLength = sizeof( usb_user_language_id ),
-	.bDescriptorType = DESCRIPTOR_STRING,
-	.wLangId = LANGUAGE_ID
-	};
+    {
+    .bLength = sizeof( usb_user_language_id ),
+    .bDescriptorType = DESCRIPTOR_STRING,
+    .wLangId = LANGUAGE_ID
+    };
 PROGMEM S_usb_hid_report_descriptor usb_hid_report_descriptor =
-	{
-	.report =
-		{
-		REPORT_ITEM_SHORT1( GLOBAL_USAGE_PAGE, USAGE_PAGE_GENERIC_DESKTOP ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_GAMEPAD ),
-		REPORT_ITEM_SHORT1( MAIN_COLLECTION, COLLECTION_APPLICATION ),
-		REPORT_ITEM_SHORT1( GLOBAL_LOGICAL_MIN, 0 ),
-		REPORT_ITEM_SHORT1( GLOBAL_LOGICAL_MAX, 1 ),
-		REPORT_ITEM_SHORT1( GLOBAL_PHYSICAL_MIN, 0 ),
-		REPORT_ITEM_SHORT1( GLOBAL_PHYSICAL_MAX, 1 ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_SIZE, 1 ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 13 ),
-		REPORT_ITEM_SHORT1( GLOBAL_USAGE_PAGE, USAGE_PAGE_BUTTON ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE_MIN, 1 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE_MAX, 13 ),
-		REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
-			INPUT_VARIABLE |
-			INPUT_ABSOLUTE |
-			INPUT_NO_WRAP |
-			INPUT_LINEAR |
-			INPUT_PREFERRED_STATE |
-			INPUT_NO_NULL_POSITION |
-			INPUT_BITFIELD ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 3 ),
-		REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_CONSTANT |
-			INPUT_ARRAY |
-			INPUT_ABSOLUTE ),
-		REPORT_ITEM_SHORT1( GLOBAL_USAGE_PAGE, USAGE_PAGE_GENERIC_DESKTOP ),
-		REPORT_ITEM_SHORT1( GLOBAL_LOGICAL_MAX, 7 ),
-		REPORT_ITEM_SHORT2( GLOBAL_PHYSICAL_MAX, 315 ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_SIZE, 4 ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 1 ),
-		REPORT_ITEM_SHORT1( GLOBAL_UNIT, 20 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_HATSWITCH ),
-		REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
-			INPUT_VARIABLE |
-			INPUT_ABSOLUTE |
-			INPUT_NO_WRAP |
-			INPUT_LINEAR |
-			INPUT_PREFERRED_STATE |
-			INPUT_NULL_STATE |
-			INPUT_BITFIELD ),
-		REPORT_ITEM_SHORT1( GLOBAL_UNIT, 0 ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 1 ),
-		REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_CONSTANT |
-			INPUT_ARRAY |
-			INPUT_ABSOLUTE ),
-		REPORT_ITEM_SHORT2( GLOBAL_LOGICAL_MAX, 255 ),
-		REPORT_ITEM_SHORT2( GLOBAL_PHYSICAL_MAX, 255 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_X ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_Y ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_Z ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_RZ ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_SIZE, 8 ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 4 ),
-		REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
-			INPUT_VARIABLE |
-			INPUT_ABSOLUTE |
-			INPUT_NO_WRAP |
-			INPUT_LINEAR |
-			INPUT_PREFERRED_STATE |
-			INPUT_NO_NULL_POSITION |
-			INPUT_BITFIELD ),
-		REPORT_ITEM_SHORT2( GLOBAL_USAGE_PAGE, 65280 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x20 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x21 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x22 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x23 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x24 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x25 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x26 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x27 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x28 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x29 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2a ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2b ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 12 ),
-		REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
-			INPUT_VARIABLE |
-			INPUT_ABSOLUTE |
-			INPUT_NO_WRAP |
-			INPUT_LINEAR |
-			INPUT_PREFERRED_STATE |
-			INPUT_NO_NULL_POSITION |
-			INPUT_BITFIELD ),
-		REPORT_ITEM_SHORT2( LOCAL_USAGE, 0x2621 ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 8 ),
-		REPORT_ITEM_SHORT1( MAIN_FEATURE, FEATURE_DATA |
-			FEATURE_VARIABLE |
-			FEATURE_ABSOLUTE |
-			FEATURE_NO_WRAP |
-			FEATURE_LINEAR |
-			FEATURE_PREFERRED_STATE |
-			FEATURE_NO_NULL_POSITION |
-			FEATURE_NONVOLATILE |
-			FEATURE_BITFIELD ),
-		REPORT_ITEM_SHORT2( LOCAL_USAGE, 0x2621 ),
-		REPORT_ITEM_SHORT1( MAIN_OUTPUT, OUTPUT_DATA |
-			OUTPUT_VARIABLE |
-			OUTPUT_ABSOLUTE |
-			OUTPUT_NO_WRAP |
-			OUTPUT_LINEAR |
-			OUTPUT_PREFERRED_STATE |
-			OUTPUT_NO_NULL_POSITION |
-			OUTPUT_NONVOLATILE |
-			OUTPUT_BITFIELD ),
-		REPORT_ITEM_SHORT2( GLOBAL_LOGICAL_MAX, 1023 ),
-		REPORT_ITEM_SHORT2( GLOBAL_PHYSICAL_MAX, 1023 ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2c ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2d ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2e ),
-		REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2f ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_SIZE, 16 ),
-		REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 4 ),
-		REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
-			INPUT_VARIABLE |
-			INPUT_ABSOLUTE |
-			INPUT_NO_WRAP |
-			INPUT_LINEAR |
-			INPUT_PREFERRED_STATE |
-			INPUT_NO_NULL_POSITION |
-			INPUT_BITFIELD ),
-		REPORT_ITEM_SHORT0( MAIN_ENDCOLLECTION )
-		}
-	};
+    {
+    .report =
+    {
+        REPORT_ITEM_SHORT1( GLOBAL_USAGE_PAGE, USAGE_PAGE_GENERIC_DESKTOP ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_GAMEPAD ),
+        REPORT_ITEM_SHORT1( MAIN_COLLECTION, COLLECTION_APPLICATION ),
+        REPORT_ITEM_SHORT1( GLOBAL_LOGICAL_MIN, 0 ),
+        REPORT_ITEM_SHORT1( GLOBAL_LOGICAL_MAX, 1 ),
+        REPORT_ITEM_SHORT1( GLOBAL_PHYSICAL_MIN, 0 ),
+        REPORT_ITEM_SHORT1( GLOBAL_PHYSICAL_MAX, 1 ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_SIZE, 1 ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 13 ),
+        REPORT_ITEM_SHORT1( GLOBAL_USAGE_PAGE, USAGE_PAGE_BUTTON ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE_MIN, 1 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE_MAX, 13 ),
+        REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
+            INPUT_VARIABLE |
+            INPUT_ABSOLUTE |
+            INPUT_NO_WRAP |
+            INPUT_LINEAR |
+            INPUT_PREFERRED_STATE |
+            INPUT_NO_NULL_POSITION |
+            INPUT_BITFIELD ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 3 ),
+        REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_CONSTANT |
+            INPUT_ARRAY |
+            INPUT_ABSOLUTE ),
+        REPORT_ITEM_SHORT1( GLOBAL_USAGE_PAGE, USAGE_PAGE_GENERIC_DESKTOP ),
+        REPORT_ITEM_SHORT1( GLOBAL_LOGICAL_MAX, 7 ),
+        REPORT_ITEM_SHORT2( GLOBAL_PHYSICAL_MAX, 315 ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_SIZE, 4 ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 1 ),
+        REPORT_ITEM_SHORT1( GLOBAL_UNIT, 20 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_HATSWITCH ),
+        REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
+            INPUT_VARIABLE |
+            INPUT_ABSOLUTE |
+            INPUT_NO_WRAP |
+            INPUT_LINEAR |
+            INPUT_PREFERRED_STATE |
+            INPUT_NULL_STATE |
+            INPUT_BITFIELD ),
+        REPORT_ITEM_SHORT1( GLOBAL_UNIT, 0 ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 1 ),
+        REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_CONSTANT |
+            INPUT_ARRAY |
+            INPUT_ABSOLUTE ),
+        REPORT_ITEM_SHORT2( GLOBAL_LOGICAL_MAX, 255 ),
+        REPORT_ITEM_SHORT2( GLOBAL_PHYSICAL_MAX, 255 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_X ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_Y ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_Z ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, GENERIC_DESKTOP_RZ ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_SIZE, 8 ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 4 ),
+        REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
+            INPUT_VARIABLE |
+            INPUT_ABSOLUTE |
+            INPUT_NO_WRAP |
+            INPUT_LINEAR |
+            INPUT_PREFERRED_STATE |
+            INPUT_NO_NULL_POSITION |
+            INPUT_BITFIELD ),
+        REPORT_ITEM_SHORT2( GLOBAL_USAGE_PAGE, 65280 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x20 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x21 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x22 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x23 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x24 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x25 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x26 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x27 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x28 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x29 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2a ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2b ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 12 ),
+        REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
+            INPUT_VARIABLE |
+            INPUT_ABSOLUTE |
+            INPUT_NO_WRAP |
+            INPUT_LINEAR |
+            INPUT_PREFERRED_STATE |
+            INPUT_NO_NULL_POSITION |
+            INPUT_BITFIELD ),
+        REPORT_ITEM_SHORT2( LOCAL_USAGE, 0x2621 ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 8 ),
+        REPORT_ITEM_SHORT1( MAIN_FEATURE, FEATURE_DATA |
+            FEATURE_VARIABLE |
+            FEATURE_ABSOLUTE |
+            FEATURE_NO_WRAP |
+            FEATURE_LINEAR |
+            FEATURE_PREFERRED_STATE |
+            FEATURE_NO_NULL_POSITION |
+            FEATURE_NONVOLATILE |
+            FEATURE_BITFIELD ),
+        REPORT_ITEM_SHORT2( LOCAL_USAGE, 0x2621 ),
+        REPORT_ITEM_SHORT1( MAIN_OUTPUT, OUTPUT_DATA |
+            OUTPUT_VARIABLE |
+            OUTPUT_ABSOLUTE |
+            OUTPUT_NO_WRAP |
+            OUTPUT_LINEAR |
+            OUTPUT_PREFERRED_STATE |
+            OUTPUT_NO_NULL_POSITION |
+            OUTPUT_NONVOLATILE |
+            OUTPUT_BITFIELD ),
+        REPORT_ITEM_SHORT2( GLOBAL_LOGICAL_MAX, 1023 ),
+        REPORT_ITEM_SHORT2( GLOBAL_PHYSICAL_MAX, 1023 ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2c ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2d ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2e ),
+        REPORT_ITEM_SHORT1( LOCAL_USAGE, 0x2f ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_SIZE, 16 ),
+        REPORT_ITEM_SHORT1( GLOBAL_REPORT_COUNT, 4 ),
+        REPORT_ITEM_SHORT1( MAIN_INPUT, INPUT_DATA |
+            INPUT_VARIABLE |
+            INPUT_ABSOLUTE |
+            INPUT_NO_WRAP |
+            INPUT_LINEAR |
+            INPUT_PREFERRED_STATE |
+            INPUT_NO_NULL_POSITION |
+            INPUT_BITFIELD ),
+        REPORT_ITEM_SHORT0( MAIN_ENDCOLLECTION )
+    }
+    };
 

usb_descriptors.h

 #define EP_ATTRIBUTES_1     0x03          // BULK = 0x02, INTERUPT = 0x03
 #define EP_SIZE_1           64
 #define EP_INTERVAL_1       10 //interrupt pooling from host
-
 // USB Endpoint 2 descriptor FS
 #define ENDPOINT_NB_2       (EP_HID_OUT)
 #define EP_ATTRIBUTES_2     0x03          // BULK = 0x02, INTERUPT = 0x03
 
 /// manufacturer string
 typedef struct
-	{
-		/// size of this descriptor in bytes
-		uint8_t bLength;
-		/// STRING descriptor type
-		uint8_t bDescriptorType;
-		/// unicode characters
-		uint16_t wString[USB_MN_LENGTH];
-	} S_usb_manufacturer_string_descriptor;
+{
+    /// size of this descriptor in bytes
+    uint8_t bLength;
+    /// STRING descriptor type
+    uint8_t bDescriptorType;
+    /// unicode characters
+    uint16_t wString[USB_MN_LENGTH];
+} S_usb_manufacturer_string_descriptor;
 
 //_____ U S B   P R O D U C T   D E S C R I P T O R _________________________
 
 
 /// product string
 typedef struct
-	{
-		/// size of this descriptor in bytes
-		uint8_t bLength;
-		/// STRING descriptor type
-		uint8_t bDescriptorType;
-		/// unicode characters
-		uint16_t wString[USB_PN_LENGTH];
-	} S_usb_product_string_descriptor;
+{
+    /// size of this descriptor in bytes
+    uint8_t bLength;
+    /// STRING descriptor type
+    uint8_t bDescriptorType;
+    /// unicode characters
+    uint16_t wString[USB_PN_LENGTH];
+} S_usb_product_string_descriptor;
 
 //_____ U S B   S E R I A L   N U M B E R   D E S C R I P T O R _____________
 
 #if (USB_DEVICE_SN_USE==true)
 /// device serial number
 typedef struct
-	{
-	/// size of this descriptor in bytes
-	uint8_t bLength;
-	/// STRING descriptor type
-	uint8_t bDescriptorType;
+{
+    /// size of this descriptor in bytes
+    uint8_t bLength;
+    /// STRING descriptor type
+    uint8_t bDescriptorType;
 #if (USE_DEVICE_SN_UNIQUE==true)
 
 #else
-	/// unicode characters
-	uint16_t wString[USB_SN_LENGTH];
+/// unicode characters
+uint16_t wString[USB_SN_LENGTH];
 #endif
-	}S_usb_serial_number;
+} S_usb_serial_number;
 #endif
 
 /*_____ U S B   H I D   D E S C R I P T O R __________________________________*/
 
 /// USB configuration descriptor
 typedef struct
-	{
-		S_usb_configuration_descriptor cfg;
-		S_usb_interface_descriptor ifc;
-		S_usb_hid_descriptor hid;
-		S_usb_endpoint_descriptor ep1;
-		S_usb_endpoint_descriptor ep2;
-	} S_usb_user_configuration_descriptor;
+{
+    S_usb_configuration_descriptor cfg;
+    S_usb_interface_descriptor ifc;
+    S_usb_hid_descriptor hid;
+    S_usb_endpoint_descriptor ep1;
+    S_usb_endpoint_descriptor ep2;
+} S_usb_user_configuration_descriptor;
 
 #endif
 

usb_specific_request.c

  * @return false, if the request is'nt know (STALL handshake is managed by the main standard request function).
  */
 bool usb_user_read_request( uint8_t type, uint8_t request )
-    {
+{
     uint8_t wValue_msb;
     uint8_t wValue_lsb;
 
 
     // Specific request from Class HID
     if( USB_SETUP_GET_STAND_INTERFACE == type )
-        {
+    {
         switch( request )
             {
         case SETUP_GET_DESCRIPTOR :
                 }
             break;
             }
-        }
+    }
     if( USB_SETUP_SET_CLASS_INTER == type )
-        {
+    {
         switch( request )
             {
         case SETUP_HID_SET_REPORT :
             // TODO
             break;
             }
-        }
+    }
     if( USB_SETUP_GET_CLASS_INTER == type )
-        {
+    {
         switch( request )
             {
         case SETUP_HID_GET_REPORT :
             // TODO
             break;
             }
-        }
+    }
     return false; // No supported request
-    }
+}
 
 /**
  * @brief Configure the endpoints
  * @param conf_nb configuration number choosed by USB host
  */
 void usb_user_endpoint_init( uint8_t conf_nb )
-    {
+{
     usb_configure_endpoint( EP_HID_IN,
         TYPE_INTERRUPT,
         DIRECTION_IN,
         SIZE_8,
         ONE_BANK,
         NYET_ENABLED);
-    }
+}
 
 /**
  * @brief Return the interface alternate setting
  * @return alternate setting configurated
  */
 uint8_t usb_user_interface_get( uint16_t wInterface )
-    {
+{
     return 0; // Only one alternate setting possible for all interface
-    }
+}
 
 /**
  * @brief Select (and resets) the interface alternate setting
  * @param alternate_setting  alternate setting selected
  */
 void usb_user_interface_reset( uint16_t wInterface, uint8_t alternate_setting )
-    {
+{
     // default setting selected = reset data toggle
     if( INTERFACE_NB == wInterface )
-        {
+    {
         // Interface HID
         Usb_select_endpoint(EP_HID_IN);
         Usb_disable_stall_handshake();
         Usb_disable_stall_handshake();
         Usb_reset_endpoint(EP_HID_OUT);
         Usb_reset_data_toggle();
-        }
     }
+}
 
 /**
  * @brief Fill the global descriptor
  * @return false, if the global descriptor no filled
  */
 bool usb_user_get_descriptor( uint8_t type, uint8_t string )
-    {
+{
     switch( type )
         {
     case DESCRIPTOR_STRING :
             {
         case LANG_ID :
             data_to_transfer = sizeof( usb_user_language_id );
-            pbuffer = & ( usb_user_language_id.bLength );
+            pbuffer = &( usb_user_language_id.bLength );
             return true;
             break;
 
         case MAN_INDEX :
             data_to_transfer = sizeof( usb_user_manufacturer_string_descriptor );
-            pbuffer = & ( usb_user_manufacturer_string_descriptor.bLength );
+            pbuffer = &( usb_user_manufacturer_string_descriptor.bLength );
             return true;
             break;
 
         case PROD_INDEX :
             data_to_transfer = sizeof( usb_user_product_string_descriptor );
-            pbuffer = & ( usb_user_product_string_descriptor.bLength );
+            pbuffer = &( usb_user_product_string_descriptor.bLength );
             return true;
             break;
 
         break;
         }
     return false;
-    }
+}
 
 /**
  * @brief Manage HID get report request.
  */
 void hid_get_report_descriptor( void )
-    {
+{
     uint16_t wLength;
     uint8_t nb_byte;
     bool zlp = false;
     BYTEn( wInterface, 1 ) = Usb_read_byte();
 
     data_to_transfer = sizeof( usb_hid_report_descriptor );
-    pbuffer = & ( usb_hid_report_descriptor.report[0] );
+    pbuffer = &( usb_hid_report_descriptor.report[0] );
 
     BYTEn( wLength, 0 ) = Usb_read_byte();
     BYTEn( wLength, 1 ) = Usb_read_byte();
     Usb_ack_receive_setup();
 
     if( wLength > data_to_transfer )
+    {
+        if( ( data_to_transfer % EP_CONTROL_LENGTH ) == 0 )
         {
-        if( ( data_to_transfer % EP_CONTROL_LENGTH ) == 0 )
-            {
             zlp = true;
-            }
+        }
         else
-            {
+        {
             zlp = false;
-            }
         }
+    }
     else
-        {
+    {
         data_to_transfer = ( uint8_t )wLength; // send only requested number of data
-        }
+    }
 
-    while( ( data_to_transfer != 0 ) && ( ! Is_usb_receive_out() ) )
-        {
-        while( ! Is_usb_read_control_enabled() )
+    while( ( data_to_transfer != 0 ) && ( !Is_usb_receive_out() ) )
+    {
+        while( !Is_usb_read_control_enabled() )
             ;
 
         nb_byte = 0;
         while( data_to_transfer != 0 ) // Send data until necessary
+        {
+            if( nb_byte++ == EP_CONTROL_LENGTH ) // Check endpoint 0 size
             {
-            if( nb_byte++ == EP_CONTROL_LENGTH ) // Check endpoint 0 size
-                {
                 break;
-                }
+            }
             //warning with AVRGCC assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory
             Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));
             data_to_transfer-- ;
-            }
+        }
         Usb_send_control_in();
-        }
+    }
 
     if( Is_usb_receive_out() )
-        {
+    {
         // abort from Host
         Usb_ack_receive_out();
         return;
-        }
+    }
     if( zlp == true )
-        {
-        while( ! Is_usb_read_control_enabled() )
+    {
+        while( !Is_usb_read_control_enabled() )
             ;
         Usb_send_control_in();
-        }
+    }
 
-    while( ! Is_usb_receive_out() )
+    while( !Is_usb_receive_out() )
         ;
     Usb_ack_receive_out();
-    }
+}
 
 /**
  * @brief Manage HID set report request.
  */
 void usb_hid_set_report_ouput( void )
-    {
+{
     Usb_ack_receive_setup();
     Usb_send_control_in();
 
-    while( ! Is_usb_receive_out() )
+    while( !Is_usb_receive_out() )
         ;
     Usb_ack_receive_out();
     Usb_send_control_in();
-    }
+}
 
 /**
  * @brief Manages HID set idle request.
  * 			else only applies to the Report ID
  */
 void usb_hid_set_idle( uint8_t u8_report_id, uint8_t u8_duration )
-    {
+{
     uint16_t wInterface;
 
     // Get interface number to put in idle mode
     g_u8_report_rate = u8_duration;
 
     Usb_send_control_in();
-    while( ! Is_usb_in_ready() )
+    while( !Is_usb_in_ready() )
         ;
-    }
+}
 
 /**
  * @brief Manage HID get idle request.
  * 			else only applies to the Report ID
  */
 void usb_hid_get_idle( uint8_t u8_report_id )
-    {
+{
     uint16_t wLength;
     uint16_t wInterface;
 
     Usb_ack_receive_setup();
 
     if( wLength != 0 )
-        {
+    {
         Usb_write_byte(g_u8_report_rate);
         Usb_send_control_in();
-        }
+    }
 
-    while( ! Is_usb_receive_out