Commits

Andrew Cooper committed ced37f2

update tasks

Comments (0)

Files changed (13)

 <option id="de.innot.avreclipse.compiler.option.optimize.1166383761" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize"/>
 <option id="de.innot.avreclipse.compiler.option.incpath.1701094562" name="Include Paths (-I)" superClass="de.innot.avreclipse.compiler.option.incpath" valueType="includePath">
 <listOptionValue builtIn="false" value="&quot;${workspace_loc:/cacomantis}&quot;"/>
-<listOptionValue builtIn="false" value="&quot;${workspace_loc:/cacomantis/at90usb128}&quot;"/>
-<listOptionValue builtIn="false" value="&quot;${workspace_loc:/cacomantis/common}&quot;"/>
 <listOptionValue builtIn="false" value="&quot;${workspace_loc:/cacomantis/conf}&quot;"/>
+<listOptionValue builtIn="false" value="&quot;${workspace_loc:/cacomantis/arch/at90usb128}&quot;"/>
+<listOptionValue builtIn="false" value="&quot;${workspace_loc:/cacomantis/arch/common}&quot;"/>
+<listOptionValue builtIn="false" value="&quot;${workspace_loc:/cacomantis/kernel/include}&quot;"/>
 </option>
 <inputType id="de.innot.avreclipse.compiler.winavr.input.1894123255" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
 </tool>
-##############################################################################
-# Generic Makefile for following parts AT90USBx ATMegaxUx
-###############################################################################
+################################################################################
+# Project Makefile for Cacomantis (Rock Band Robot) 
+################################################################################
 
+################################################################################
+# Project Variables 
+################################################################################
+
+# Project name
+PROJECT = cacomantis
+
+# CPU architecture
+MCU = at90usb1287
+
+# Build Directory
 OUTPUT = build
 
-# General Flags
-TARGET = $(PROJECT).elf
+# Include Directories
+INCLUDES =  -I"."\
+			-I"conf"\
+			-I"arch/at90usb128"\
+			-I"arch/common"\
+
+# Source files
+CSRCS = \
+    main.c\
+    hid_task.c\
+    uart_task.c\
+    usb_descriptors.c\
+    usb_specific_request.c\
+    arch/at90usb128/lib_board/usb_key/usb_key.c\
+    arch/at90usb128/lib_mcu/usb/usb_drv.c\
+    arch/at90usb128/lib_mcu/util/start_boot.c\
+    arch/at90usb128/modules/usb/device_chap9/usb_device_task.c\
+    arch/at90usb128/modules/usb/device_chap9/usb_standard_request.c\
+    arch/at90usb128/modules/usb/usb_task.c\
+    arch/common/lib_mcu/wdt/wdt_drv.c\
+    arch/common/modules/scheduler/scheduler.c\
+
+#    arch/at90usb128/lib_mcu/usart/usart.c\
+
+# Assembler source files
+ASSRCS = \
+
+################################################################################
+# Compile Variables 
+################################################################################
+
+# Compiler
 CC = avr-gcc
-MAKECFG   = config.mk
 
 # Options common to compile, link and assembly rules
-COMMON = -mmcu=$(MCU)
+COMMON = -mmcu=$(MCU) -MD -MP -MF $(OUTPUT)/$(*).d
 
 # Compile options common for all C compilation units.
 CFLAGS = $(COMMON)
 CFLAGS += -std=c99 -Wall -gdwarf-2 -Os -fsigned-char -ffunction-sections
-CFLAGS += -MD -MP -MF $(OUTPUT)/dep/$(@F).d 
 
 # Assembly specific flags
 ASMFLAGS = $(COMMON)
 HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
 HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0
 
-# Include Directories
-INCLUDES = -I"." -I"conf" -I"at90usb128" -I"common" 
+################################################################################
+# Derived Variables 
+################################################################################
 
-# Include Source files list and part informations
-include $(MAKECFG)
+# Target name
+TARGET = $(PROJECT).elf
 
-# Create objects files list with sources files
-OBJECTS  = $(CSRCS:.c=.o) $(ASSRCS:.s=.o)
+# Object files in build directory
+OBJECTS := $(CSRCS:.c=.o) $(ASSRCS:.s=.o)
+OBJECTS := $(addprefix $(OUTPUT)/,$(OBJECTS))
 
+# Dependency files in build directory
+DEPS = $(OBJECTS:.o=.d)
 
-## Build
+# Tell make where to look for files
+VPATH = $(OUTPUT)
+
+################################################################################
+# Rules 
+################################################################################
+
+# Default Rule
 .PHONY: all
 all: $(TARGET) $(PROJECT).hex size
 
-## Clean target
+# Cleanup build products
 .PHONY: clean
 clean:
 	@echo "Clean project"
-	-rm -rf $(OUTPUT)/dep/* $(OBJECTS) $(PROJECT).elf $(PROJECT).hex $(PROJECT).eep $(PROJECT).map
+	-rm -rf $(OUTPUT) $(PROJECT).elf $(PROJECT).hex $(PROJECT).eep $(PROJECT).map
 
-## Rebuild the project.
+# Rebuild the project
 .PHONY: rebuild
 rebuild: clean all
 
-## Prerequisites
--include $(OUTPUT)/dep/*
+# Include Compiler-generated Prerequisites
+-include $(DEPS)
 
-## Compile
-
-.PHONY: objfiles
-objfiles: $(OBJECTS)
-
-# create object files from C source files.
-%.o: %.c
+# Compile: create object files from C source files.
+$(OUTPUT)/%.o: %.c
 	@echo 'Building file: $<'
-	@$(shell mkdir $(OUTPUT) 2>/dev/null)
-	@$(shell mkdir $(OUTPUT)/dep 2>/dev/null)
-	@$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $(@)
+	@mkdir -p $(dir $@) 2>/dev/null
+	$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $(@)
 	
 # Preprocess & assemble: create object files from assembler source files.
-%.o: %.s
+$(OUTPUT)/%.o: %.s
 	@echo 'Building file: $<'
-	@$(shell mkdir $(OUTPUT) 2>/dev/null)
-	@$(shell mkdir $(OUTPUT)/dep 2>/dev/null)
+	@mkdir -p $(dir $@) 2>/dev/null
 	@$(CC) $(INCLUDES) $(ASMFLAGS) -c $< -o $(@)
 
-
-## Link
+# Link: bring object files together into a final executable
 $(TARGET): $(OBJECTS)
 	@echo "Linking"
 	@$(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
 
+# Hexify: convert executable into Intel-Hex format
 %.hex: $(TARGET)
 	@echo "Create hex file"
 	@avr-objcopy -O ihex $(HEX_FLASH_FLAGS)  $< $@
 
+# EEPify: convert executable into EEP format
 %.eep: $(TARGET)
 	@echo "Create eep file"
 	@avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@  || exit 0
 
+# LSSify: convert executable into LSS format
 %.lss: $(TARGET)
 	@echo "Create lss file"
 	@avr-objdump -h -S $< > $@
 
+# Size: Tell memory usage of the executable
 size: ${TARGET}
 	@avr-size -C --mcu=${MCU} ${TARGET}
 
  */
 
 /**
- * @brief ENABLE to activate the host software library support
+ * @brief true to activate the host software library support
  *
- * Possible values ENABLE or DISABLE
+ * Possible values true or false
  */
-#define USB_HOST_FEATURE            DISABLED
+#define USB_HOST_FEATURE            false
 
 /**
- * @brief ENABLE to activate the device software library support
+ * @brief true to activate the device software library support
  *
- * Possible values ENABLE or DISABLE
+ * Possible values true or false
  */
-#define USB_DEVICE_FEATURE          ENABLED
+#define USB_DEVICE_FEATURE          true
 
 ///@}
 
  * the internal USB pads regulatr can be disabled.
  */
 #ifndef USE_USB_PADS_REGULATOR
-#define USE_USB_PADS_REGULATOR   ENABLE      // Possible values ENABLE or DISABLE
+#define USE_USB_PADS_REGULATOR   true      // Possible values true or false
 #endif
 ///@}
 
-#if defined(USB_HOST_FEATURE) && USB_HOST_FEATURE == ENABLED
+#if defined(USB_HOST_FEATURE) && USB_HOST_FEATURE == true
 // _________________ HOST MODE CONFIGURATION ____________________________
 //
 /**
  * When enabled, if the device PID/VID does not belongs  to the supported list,
  * the host controller library will not go to deeper configuration, but to error state.
  */
-#define HOST_STRICT_VID_PID_TABLE      DISABLE
+#define HOST_STRICT_VID_PID_TABLE      false
 
 /**
  * Try to configure the host pipe according to the device descriptors received
  */
-#define HOST_AUTO_CFG_ENDPOINT         ENABLE
+#define HOST_AUTO_CFG_ENDPOINT         true
 
 /**
  * Host start of frame interrupt always enable
  */
-#define HOST_CONTINUOUS_SOF_INTERRUPT  DISABLE
+#define HOST_CONTINUOUS_SOF_INTERRUPT  false
 
 /**
  * When Host error state detected, goto unattached state
  */
-#define HOST_ERROR_RESTART             ENABLE
+#define HOST_ERROR_RESTART             true
 
 /**
  * Force WDT reset upon ID pin change
  */
-#define ID_PIN_CHANGE_GENERATE_RESET   DISABLE
+#define ID_PIN_CHANGE_GENERATE_RESET   false
 
 /**
  * NAK handshake in 1/4sec (250ms) before timeout
  */
 #define NAK_TIMEOUT_DELAY              1
 
-#if (HOST_AUTO_CFG_ENDPOINT==FALSE)
+#if (HOST_AUTO_CFG_ENDPOINT==false)
 /**
  * If no auto configuration of EP, map here user function
  */
 #define Host_device_error_action()
 ///@}
 
-extern void host_suspend_action(void);
+extern void host_suspend_action( void );
 ///@}
-#endif /* USB_HOST_FEATURE == ENABLED */
+#endif /* USB_HOST_FEATURE == true */
 
 // _________________ DEVICE MODE CONFIGURATION __________________________
 
  * @{
  */
 
-#define USB_DEVICE_SN_USE          DISABLE            // DISABLE
-#define USE_DEVICE_SN_UNIQUE       DISABLE            // ignore if USB_DEVICE_SN_USE = DISABLE
-#define Usb_unicode(a)         ((U16)(a))
+#define USB_DEVICE_SN_USE          false            // false
+#define USE_DEVICE_SN_UNIQUE       false            // ignore if USB_DEVICE_SN_USE = false
+#define Usb_unicode(a)         ((uint16_t)(a))
 
 #define EP_HID_IN             1
 #define EP_HID_OUT            2
 
-#define USB_REMOTE_WAKEUP_FEATURE   DISABLE
+#define USB_REMOTE_WAKEUP_FEATURE   false
 
 /**
  * @defgroup device_cst_actions USB device custom actions
 #define Usb_set_configuration_action()
 ///@}
 
-extern void sof_action(void);
+extern void sof_action( void );
 ///@}
 
 ///@}
 #ifndef _CONFIG_H_
 #define _CONFIG_H_
 
-// Compiler switch (do not change these settings)
-#include "lib_mcu/compiler.h"             // Compiler definitions
-#ifdef __GNUC__
+//_____ I N C L U D E S ________________________________________________________
+
 #include <avr/io.h>                    // Use AVR-GCC library
-#elif __ICCAVR__
-#define ENABLE_BIT_DEFINITIONS
-#include <ioavr.h>                     // Use IAR-AVR library
-#else
-#error Current COMPILER not supported
-#endif
+
+//_____ C O N S T A N T S ______________________________________________________
 
 /**
  * @defgroup global_config Application configuration
 /// AVCC As reference voltage (See adc_drv.h)
 #define ADC_INTERNAL_VREF  2
 
+//------------------------------------------------------------------------------
+// F r e e R T O S    T a s k    C o n f i g u r a t i o n
+//------------------------------------------------------------------------------
+
+#define kUART_TASK_PRIORITY             ( 1 )
+#define kUSB_TASK_PRIORITY              ( 1 )
+#define kHID_TASK_PRIORITY              ( 1 )
+
 /// @}
 
 #endif // _CONFIG_H_
 # be useful for C code in case the coding convention dictates that all compound 
 # types are typedef'ed and only the typedef is referenced, never the tag name.
 
-TYPEDEF_HIDES_STRUCT   = NO
+TYPEDEF_HIDES_STRUCT   = YES
 
 # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to 
 # determine which symbols to keep in memory and which to flush to disk. 
 # then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy 
 # in the documentation. The default is NO.
 
-SHOW_DIRECTORIES       = NO
+SHOW_DIRECTORIES       = YES
 
 # Set the SHOW_FILES tag to NO to disable the generation of the Files page. 
 # This will remove the Files entry from the Quick Index and from the 
 # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
 
 FILE_PATTERNS          = *.h \
-                         *.c \
-                         *.txt
+                         *.c
 
 # The RECURSIVE tag can be used to turn specify whether or not subdirectories 
 # should be searched for input files as well. Possible values are YES and NO. 
 # JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox 
 # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
 
-HTML_DYNAMIC_SECTIONS  = NO
+HTML_DYNAMIC_SECTIONS  = YES
 
 # If the GENERATE_DOCSET tag is set to YES, additional index files 
 # will be generated that can be used as input for Apple's Xcode 3 
 # fallback. It is recommended to install and use dot, since it yields more 
 # powerful graphs.
 
-CLASS_DIAGRAMS         = YES
+CLASS_DIAGRAMS         = NO
 
 # You can define message sequence charts within doxygen comments using the \msc 
 # command. Doxygen will then run the mscgen tool (see 
 # collaboration diagrams in a style similar to the OMG's Unified Modeling 
 # Language.
 
-UML_LOOK               = NO
+UML_LOOK               = YES
 
 # If set to YES, the inheritance and collaboration graphs will show the 
 # relations between templates and their instances.
 # enabling this option may lead to badly anti-aliased labels on the edges of 
 # a graph (i.e. they become hard to read).
 
-DOT_TRANSPARENT        = NO
+DOT_TRANSPARENT        = YES
 
 # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output 
 # files in one run (i.e. multiple -o and -T options on the command line). This 
 # makes dot run faster, but since only newer versions of dot (>1.8.10) 
 # support this, this feature is disabled by default.
 
-DOT_MULTI_TARGETS      = NO
+DOT_MULTI_TARGETS      = YES
 
 # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will 
 # generate a legend page explaining the meaning of the various boxes and 
 #include "usb_specific_request.h"
 #include "lib_mcu/util/start_boot.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 
 //_____ V A R I A B L E S __________________________________________________
 
-volatile U8 cpt_sof = 0;
-extern U8 jump_bootloader;
-U8 g_last_joy = 0;
+volatile uint8_t cpt_sof = 0;
+extern uint8_t jump_bootloader;
+uint8_t g_last_joy = 0;
 
 struct hid_report report;
 
 	// Check if we received DFU mode command from host
 //	if( jump_bootloader )
 //		{
-//		U32 volatile tempo;
+//		uint32_t volatile tempo;
 //		Leds_off();
 //		Usb_detach(); // Detach actual generic HID application
 //		for( tempo = 0; tempo < 70000; tempo++ )
  */
 void hid_report_in( void )
 	{
-	U8 *report_p = (U8*)&report;
+	uint8_t *report_p = (uint8_t*)&report;
 	int i;
 
 	Usb_select_endpoint(EP_HID_IN);
 #ifndef _HID_TASK_H_
 #define _HID_TASK_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 ____________________________________________________________
 
 
 //_____ T Y P E S __________________________________________________________
 	 * Inputs, 1bit * 13
 	 * Usage: Generic Desktop / Gamepad / Button
 	 */
-	U8		b1:1;
-	U8		b2:1;
-	U8		b3:1;
-	U8		b4:1;
-	U8		b5:1;
-	U8		b6:1;
-	U8		b7:1;
-	U8		b8:1;
-	U8		b9:1;
-	U8		b10:1;
-	U8		b11:1;
-	U8		b12:1;
-	U8		b13:1;
+	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
 	 */
-	U8		pad1:3;
+	uint8_t		pad1:3;
 
 	/*
 	 * Inputs: 4bit * 1
 	 * Physical: 0..315
 	 */
 	/// hatswitch
-	U8		hat:4;
+	uint8_t		hat:4;
 
 	/*
 	 * Padding 4bit * 1
 	 */
-	U8		pad2:4;
+	uint8_t		pad2:4;
 
 	/*
 	 * Inputs: 8bit * 4
 	 * Physical: 0..255
 	 */
 	/// X axis
-	U8		x;
+	uint8_t		x;
 	/// Y axis
-	U8		y;
+	uint8_t		y;
 	/// Z axis
-	U8		z;
+	uint8_t		z;
 	/// Rz axis
-	U8		Rz;
+	uint8_t		Rz;
 
 	/*
 	 * Inputs: 8bit * 12
 	 * Usage: Generic Desktop / 65280 (Vendor)
 	 */
 	/// Usage 0x20
-	U8		iVendorX20;
+	uint8_t		iVendorX20;
 	/// Usage 0x21
-	U8		iVendorX21;
+	uint8_t		iVendorX21;
 	/// Usage 0x22
-	U8		iVendorX22;
+	uint8_t		iVendorX22;
 	/// Usage 0x23
-	U8		iVendorX23;
+	uint8_t		iVendorX23;
 	/// Usage 0x24
-	U8		iVendorX24;
+	uint8_t		iVendorX24;
 	/// Usage 0x25
-	U8		iVendorX25;
+	uint8_t		iVendorX25;
 	/// Usage 0x26
-	U8		iVendorX26;
+	uint8_t		iVendorX26;
 	/// Usage 0x27
-	U8		iVendorX27;
+	uint8_t		iVendorX27;
 	/// Usage 0x28
-	U8		iVendorX28;
+	uint8_t		iVendorX28;
 	/// Usage 0x29
-	U8		iVendorX29;
+	uint8_t		iVendorX29;
 	/// Usage 0x2A
-	U8		iVendorX2A;
+	uint8_t		iVendorX2A;
 	/// Usage 0x2B
-	U8		iVendorX2B;
+	uint8_t		iVendorX2B;
 
 	/*
 	 * Features: 8bit * 8
 	 * Usage: Generic Desktop / 65280 (Vendor)
 	 */
 	/// Usage 0x2621
-	U8		iFeatureD2621_1;
-	U8		iFeatureD2621_2;
-	U8		iFeatureD2621_3;
-	U8		iFeatureD2621_4;
-	U8		iFeatureD2621_5;
-	U8		iFeatureD2621_6;
-	U8		iFeatureD2621_7;
-	U8		iFeatureD2621_8;
+	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
-	U8		iOutputD2621_1;
-	U8		iOutputD2621_2;
-	U8		iOutputD2621_3;
-	U8		iOutputD2621_4;
-	U8		iOutputD2621_5;
-	U8		iOutputD2621_6;
-	U8		iOutputD2621_7;
-	U8		iOutputD2621_8;
+	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
 	 * Physical: 0..1023
 	 */
 	/// Usage 0x2C
-	U16		iInputX2C;
+	uint16_t		iInputX2C;
 	/// Usage 0x2D
-	U16		iInputX2D;
+	uint16_t		iInputX2D;
 	/// Usage 0x2E
-	U16		iInputX2E;
+	uint16_t		iInputX2E;
 	/// Usage 0x2F
-	U16		iInputx2F;
+	uint16_t		iInputx2F;
 	};
 
 
 #include "lib_mcu/power/power_drv.h"
 #include "lib_mcu/util/start_boot.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 //_____ D E F I N I T I O N S ______________________________________________
 
  * This one increment the CPU clock before RAM initialisation
  */
 ///@{
-#ifdef  __GNUC__
 // Locate low level init function before RAM init (init3 section)
 // and remove std prologue/epilogue
 char __low_level_init(void) __attribute__ ((section (".init3"),naked));
-#endif
 
 #ifdef __cplusplus
 extern "C"
 /**
  * @file
  *
- * @brief This file manages the generic HID IN/OUT task.
+ * @brief This file manages the uart task for communicating with a PC
+ * @author               Andrew Cooper
  *
- * - Compiler:           IAR EWAVR and GNU GCC for AVR
- * - Supported devices:  AT90USB1287, AT90USB1286, AT90USB647, AT90USB646
  *
- * @author               Andrew Cooper
  *
  */
 
 
 //_____  I N C L U D E S ___________________________________________________
 
+#include <stdbool.h>
+#include <avr/interrupt.h>
 #include "config.h"
-#include "at90usb128//lib_mcu/usart/usart.h"
+#include "lib_mcu/usart/usart.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 
 //_____ V A R I A B L E S __________________________________________________
 
 
+static uint8_t rx_buffer[USART_RX_BUFFER_SIZE];
+static int rx_head;
+static bool rx_overflow;
+static int rx_tail;
+
+static uint8_t tx_buffer[USART_TX_BUFFER_SIZE];
+static int tx_head;
+static int tx_tail;
+
 //_____ P R O C E D U R E S ________________________________________________
 
 
 /**
+ * @brief Interpret any received commands, send any pending responses
+ */
+void uart_task( void )
+{
+
+}
+
+/**
  * @brief Initialize the target USART module
  */
 void uart_task_init( void )
-	{
-	USART0_Init( USART_BAUDRATE );
-	}
+{
+/** Initialize buffer variables                                              **/
+rx_head = 0;
+rx_overflow = false;
+rx_tail = 0;
+tx_head = 0;
+tx_tail = 0;
 
+}
 
-/**
- * @brief Interpret any received commands, send any pending responses
- */
-void uart_task( void )
-	{
-
-	}
-

usb_descriptors.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 <avr/pgmspace.h>
 #include "config.h"
 #include "conf_usb.h"
 #include "lib_mcu/usb/usb_drv.h"
 #include "usb_descriptors.h"
 #include "modules/usb/device_chap9/usb_standard_request.h"
 #include "usb_specific_request.h"
-#if ((USB_DEVICE_SN_USE==ENABLE) && (USE_DEVICE_SN_UNIQUE==ENABLE))
+#if ((USB_DEVICE_SN_USE==true) && (USE_DEVICE_SN_UNIQUE==true))
 #include "lib_mcu/flash/flash_drv.h"
 #endif
-//_____ 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 ____________________________________________________
 // usb_user_device_descriptor
-code S_usb_device_descriptor usb_dev_desc =
+PROGMEM S_usb_device_descriptor usb_dev_desc =
 	{
 	sizeof( usb_dev_desc ),
 	DESCRIPTOR_DEVICE,
-	Usb_write_word_enum_struc(USB_SPECIFICATION),
+	USB_SPECIFICATION,
 	DEVICE_CLASS,
 	DEVICE_SUB_CLASS,
 	DEVICE_PROTOCOL,
 	EP_CONTROL_LENGTH,
-	Usb_write_word_enum_struc(VENDOR_ID),
-	Usb_write_word_enum_struc(PRODUCT_ID),
-	Usb_write_word_enum_struc(RELEASE_NUMBER),
+	VENDOR_ID,
+	PRODUCT_ID,
+	RELEASE_NUMBER,
 	MAN_INDEX,
 	PROD_INDEX,
 	SN_INDEX,
 	NB_CONFIGURATION
 	};
 // usb_user_configuration_descriptor FS
-code S_usb_user_configuration_descriptor usb_conf_desc =
+PROGMEM S_usb_user_configuration_descriptor usb_conf_desc =
 	{
 	.cfg =
 		{
 		.bLength = sizeof(S_usb_configuration_descriptor),
 		.bDescriptorType = DESCRIPTOR_CONFIGURATION,
-		.wTotalLength = Usb_write_word_enum_struc(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)),
+		.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,
 		.bCountryCode = HID_NO_COUNTRY_CODE,
 		.bNumDescriptors = HID_CLASS_DESC_NB_DEFAULT,
 		.bRDescriptorType = DESCRIPTOR_REPORT,
-		.wDescriptorLength = Usb_write_word_enum_struc(sizeof(S_usb_hid_report_descriptor))
+		.wDescriptorLength = sizeof(S_usb_hid_report_descriptor)
 		},
 	.ep1 =
 		{
 		.bDescriptorType = DESCRIPTOR_ENDPOINT,
 		.bEndpointAddress = ENDPOINT_NB_1,
 		.bmAttributes = EP_ATTRIBUTES_1,
-		.wMaxPacketSize = Usb_write_word_enum_struc(EP_SIZE_1),
+		.wMaxPacketSize = EP_SIZE_1,
 		.bInterval = EP_INTERVAL_1
 		},
 	.ep2 =
 		.bDescriptorType = DESCRIPTOR_ENDPOINT,
 		.bEndpointAddress = ENDPOINT_NB_2,
 		.bmAttributes = EP_ATTRIBUTES_2,
-		.wMaxPacketSize = Usb_write_word_enum_struc(EP_SIZE_2),
+		.wMaxPacketSize = EP_SIZE_2,
 		.bInterval = EP_INTERVAL_2
 		}
 	};
 // usb_user_manufacturer_string_descriptor
-code S_usb_manufacturer_string_descriptor 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
 	};
 // usb_user_product_string_descriptor
-code S_usb_product_string_descriptor 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
 	};
 // usb_user_serial_number
-#if (USB_DEVICE_SN_USE==ENABLE)
-code S_usb_serial_number usb_user_serial_number =
+#if (USB_DEVICE_SN_USE==true)
+PROGMEM S_usb_serial_number usb_user_serial_number =
 	{
-#if (USE_DEVICE_SN_UNIQUE==ENABLE)
+#if (USE_DEVICE_SN_UNIQUE==true)
 	sizeof(usb_user_serial_number)+4*SN_LENGTH,
 	DESCRIPTOR_STRING
 #else
 
 // usb_user_language_id
 
-code S_usb_language_id usb_user_language_id =
+PROGMEM S_usb_language_id usb_user_language_id =
 	{
 	.bLength = sizeof( usb_user_language_id ),
 	.bDescriptorType = DESCRIPTOR_STRING,
-	.wLangId = Usb_write_word_enum_struc(LANGUAGE_ID)
+	.wLangId = LANGUAGE_ID
 	};
-code S_usb_hid_report_descriptor usb_hid_report_descriptor =
+PROGMEM S_usb_hid_report_descriptor usb_hid_report_descriptor =
 	{
 	.report =
 		{

usb_descriptors.h

 #ifndef _USB_DESCRIPTORS_H_
 #define _USB_DESCRIPTORS_H_
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
 
 #include "config.h"
 #include "modules/usb/device_chap9/usb_standard_request.h"
 #include "modules/usb/device_chap9/usb_standard_descriptors.h"
 #include "conf_usb.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
 #define Usb_get_dev_desc_pointer()        (&(usb_dev_desc.bLength))
 #define Usb_get_dev_desc_length()         (sizeof (usb_dev_desc))
 #define RELEASE_NUMBER        0x0200
 #define MAN_INDEX             0x01
 #define PROD_INDEX            0x02
-#if (USB_DEVICE_SN_USE==ENABLE)
+#if (USB_DEVICE_SN_USE==true)
 #define SN_INDEX              0x03
 #else
 #define SN_INDEX              0x00  // No serial number field
 typedef struct
 	{
 		/// size of this descriptor in bytes
-		U8 bLength;
+		uint8_t bLength;
 		/// STRING descriptor type
-		U8 bDescriptorType;
+		uint8_t bDescriptorType;
 		/// unicode characters
-		U16 wString[USB_MN_LENGTH];
+		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 _________________________
 typedef struct
 	{
 		/// size of this descriptor in bytes
-		U8 bLength;
+		uint8_t bLength;
 		/// STRING descriptor type
-		U8 bDescriptorType;
+		uint8_t bDescriptorType;
 		/// unicode characters
-		U16 wString[USB_PN_LENGTH];
+		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==ENABLE)
+#if (USB_DEVICE_SN_USE==true)
 /// device serial number
 typedef struct
 	{
 	/// size of this descriptor in bytes
-	U8 bLength;
+	uint8_t bLength;
 	/// STRING descriptor type
-	U8 bDescriptorType;
-#if (USE_DEVICE_SN_UNIQUE==ENABLE)
+	uint8_t bDescriptorType;
+#if (USE_DEVICE_SN_UNIQUE==true)
 
 #else
 	/// unicode characters
-	U16 wString[USB_SN_LENGTH];
+	uint16_t wString[USB_SN_LENGTH];
 #endif
 	}S_usb_serial_number;
 #endif

usb_specific_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"
 #include "usb_descriptors.h"
 #include "modules/usb/device_chap9/usb_standard_request.h"
 #include "usb_specific_request.h"
-#if ((USB_DEVICE_SN_USE==ENABLE) && (USE_DEVICE_SN_UNIQUE==ENABLE))
+#if ((USB_DEVICE_SN_USE==true) && (USE_DEVICE_SN_UNIQUE==true))
 #include "lib_mcu/flash/flash_drv.h"
 #endif
 
-//_____ D E F I N I T I O N ________________________________________________
+//_____ D E F I N I T I O N ____________________________________________________
 
-#ifdef __GNUC__
 extern PGM_VOID_P pbuffer;
-#else
-extern U8 code *pbuffer;
-#endif
-extern U8 data_to_transfer;
-extern code S_usb_hid_report_descriptor usb_hid_report_descriptor;
-U8 jump_bootloader = 0;
+extern uint8_t data_to_transfer;
+extern PROGMEM S_usb_hid_report_descriptor usb_hid_report_descriptor;
+uint8_t jump_bootloader = 0;
 
-U8 g_u8_report_rate = 0;
+uint8_t g_u8_report_rate = 0;
 
-//_____ D E C L A R A T I O N ______________________________________________
+//_____ D E C L A R A T I O N __________________________________________________
 
 void hid_get_report_descriptor( void );
 void usb_hid_set_report_ouput( void );
-void usb_hid_set_idle( U8 u8_report_id, U8 u8_duration );
-void usb_hid_get_idle( U8 u8_report_id );
+void usb_hid_set_idle( uint8_t u8_report_id, uint8_t u8_duration );
+void usb_hid_get_idle( uint8_t u8_report_id );
 void hid_get_hid_descriptor( void );
 void usb_hid_set_report_feature( void );
 
  * @param type      corresponding at bmRequestType (see USB specification)
  * @param request   corresponding at bRequest (see USB specification)
  *
- * @return TRUE,  when the request is processed
- * @return FALSE, if the request is'nt know (STALL handshake is managed by the main standard request function).
+ * @return true,  when the request is processed
+ * @return false, if the request is'nt know (STALL handshake is managed by the main standard request function).
  */
-Bool usb_user_read_request( U8 type, U8 request )
-	{
-	U8 wValue_msb;
-	U8 wValue_lsb;
+bool usb_user_read_request( uint8_t type, uint8_t request )
+    {
+    uint8_t wValue_msb;
+    uint8_t wValue_lsb;
 
-	// Read wValue
-	wValue_lsb = Usb_read_byte();
-	wValue_msb = Usb_read_byte();
+    // Read wValue
+    wValue_lsb = Usb_read_byte();
+    wValue_msb = Usb_read_byte();
 
-	// Specific request from Class HID
-	if( USB_SETUP_GET_STAND_INTERFACE == type )
-		{
-		switch( request )
-			{
-		case SETUP_GET_DESCRIPTOR :
-			switch( wValue_msb )
-				// Descriptor ID
-				{
-			case DESCRIPTOR_HID :
-				hid_get_hid_descriptor();
-				return TRUE;
-				break;
+    // Specific request from Class HID
+    if( USB_SETUP_GET_STAND_INTERFACE == type )
+        {
+        switch( request )
+            {
+        case SETUP_GET_DESCRIPTOR :
+            switch( wValue_msb )
+                // Descriptor ID
+                {
+            case DESCRIPTOR_HID :
+                hid_get_hid_descriptor();
+                return true;
+                break;
 
-			case DESCRIPTOR_REPORT :
-				hid_get_report_descriptor();
-				return TRUE;
+            case DESCRIPTOR_REPORT :
+                hid_get_report_descriptor();
+                return true;
 
-			case DESCRIPTOR_PHYSICAL :
-				// TODO
-				break;
-				}
-			break;
-			}
-		}
-	if( USB_SETUP_SET_CLASS_INTER == type )
-		{
-		switch( request )
-			{
-		case SETUP_HID_SET_REPORT :
-			// The MSB wValue field specifies the Report Type
-			// The LSB wValue field specifies the Report ID
-			switch( wValue_msb )
-				{
-			case REPORT_TYPE_INPUT :
-				// TODO
-				break;
+            case DESCRIPTOR_PHYSICAL :
+                // TODO
+                break;
+                }
+            break;
+            }
+        }
+    if( USB_SETUP_SET_CLASS_INTER == type )
+        {
+        switch( request )
+            {
+        case SETUP_HID_SET_REPORT :
+            // The MSB wValue field specifies the Report Type
+            // The LSB wValue field specifies the Report ID
+            switch( wValue_msb )
+                {
+            case REPORT_TYPE_INPUT :
+                // TODO
+                break;
 
-			case REPORT_TYPE_OUTPUT :
-				usb_hid_set_report_ouput();
-				return TRUE;
-				break;
+            case REPORT_TYPE_OUTPUT :
+                usb_hid_set_report_ouput();
+                return true;
+                break;
 
-			case REPORT_TYPE_FEATURE :
-				usb_hid_set_report_feature();
-				return TRUE;
-				break;
-				}
-			break;
+            case REPORT_TYPE_FEATURE :
+                usb_hid_set_report_feature();
+                return true;
+                break;
+                }
+            break;
 
-		case SETUP_HID_SET_IDLE :
-			usb_hid_set_idle( wValue_lsb, wValue_msb );
-			return TRUE;
+        case SETUP_HID_SET_IDLE :
+            usb_hid_set_idle( wValue_lsb, wValue_msb );
+            return true;
 
-		case SETUP_HID_SET_PROTOCOL :
-			// TODO
-			break;
-			}
-		}
-	if( USB_SETUP_GET_CLASS_INTER == type )
-		{
-		switch( request )
-			{
-		case SETUP_HID_GET_REPORT :
-			// TODO
-			break;
-		case SETUP_HID_GET_IDLE :
-			usb_hid_get_idle( wValue_lsb );
-			return TRUE;
-		case SETUP_HID_GET_PROTOCOL :
-			// TODO
-			break;
-			}
-		}
-	return FALSE; // No supported request
-	}
+        case SETUP_HID_SET_PROTOCOL :
+            // TODO
+            break;
+            }
+        }
+    if( USB_SETUP_GET_CLASS_INTER == type )
+        {
+        switch( request )
+            {
+        case SETUP_HID_GET_REPORT :
+            // TODO
+            break;
+        case SETUP_HID_GET_IDLE :
+            usb_hid_get_idle( wValue_lsb );
+            return true;
+        case SETUP_HID_GET_PROTOCOL :
+            // 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( U8 conf_nb )
-	{
-	usb_configure_endpoint( EP_HID_IN,
-		TYPE_INTERRUPT,
-		DIRECTION_IN,
-		SIZE_8,
-		ONE_BANK,
-		NYET_ENABLED);
+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);
 
-	usb_configure_endpoint( EP_HID_OUT,
-		TYPE_INTERRUPT,
-		DIRECTION_OUT,
-		SIZE_8,
-		ONE_BANK,
-		NYET_ENABLED);
-	}
+    usb_configure_endpoint( EP_HID_OUT,
+        TYPE_INTERRUPT,
+        DIRECTION_OUT,
+        SIZE_8,
+        ONE_BANK,
+        NYET_ENABLED);
+    }
 
 /**
  * @brief Return the interface alternate setting
  *
  * @return alternate setting configurated
  */
-U8 usb_user_interface_get( U16 wInterface )
-	{
-	return 0; // Only one alternate setting possible for all interface
-	}
+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 wInterface         Interface selected
  * @param alternate_setting  alternate setting selected
  */
-void usb_user_interface_reset( U16 wInterface, U8 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_reset_endpoint(EP_HID_IN);
-		Usb_reset_data_toggle();
-		Usb_select_endpoint(EP_HID_OUT);
-		Usb_disable_stall_handshake();
-		Usb_reset_endpoint(EP_HID_OUT);
-		Usb_reset_data_toggle();
-		}
-	}
+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_reset_endpoint(EP_HID_IN);
+        Usb_reset_data_toggle();
+        Usb_select_endpoint(EP_HID_OUT);
+        Usb_disable_stall_handshake();
+        Usb_reset_endpoint(EP_HID_OUT);
+        Usb_reset_data_toggle();
+        }
+    }
 
 /**
  * @brief Fill the global descriptor
  * @param type      corresponding at MSB of wValue (see USB specification)
  * @param string    corresponding at LSB of wValue (see USB specification)
  *
- * @return FALSE, if the global descriptor no filled
+ * @return false, if the global descriptor no filled
  */
-Bool usb_user_get_descriptor( U8 type, U8 string )
-	{
-	switch( type )
-		{
-	case DESCRIPTOR_STRING :
-		switch( string )
-			{
-		case LANG_ID :
-			data_to_transfer = sizeof( usb_user_language_id );
-			pbuffer = & ( usb_user_language_id.bLength );
-			return TRUE;
-			break;
+bool usb_user_get_descriptor( uint8_t type, uint8_t string )
+    {
+    switch( type )
+        {
+    case DESCRIPTOR_STRING :
+        switch( string )
+            {
+        case LANG_ID :
+            data_to_transfer = sizeof( usb_user_language_id );
+            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 );
-			return TRUE;
-			break;
+        case MAN_INDEX :
+            data_to_transfer = sizeof( usb_user_manufacturer_string_descriptor );
+            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 );
-			return TRUE;
-			break;
+        case PROD_INDEX :
+            data_to_transfer = sizeof( usb_user_product_string_descriptor );
+            pbuffer = & ( usb_user_product_string_descriptor.bLength );
+            return true;
+            break;
 
-#if (USB_DEVICE_SN_USE==ENABLE)
-			case SN_INDEX:
-			data_to_transfer = sizeof (usb_user_serial_number);
-			pbuffer = &(usb_user_serial_number.bLength);
-#if (USE_DEVICE_SN_UNIQUE==ENABLE)
-			f_get_serial_string=TRUE;
-			data_to_transfer += (SN_LENGTH*4);
+#if (USB_DEVICE_SN_USE==true)
+            case SN_INDEX:
+            data_to_transfer = sizeof (usb_user_serial_number);
+            pbuffer = &(usb_user_serial_number.bLength);
+#if (USE_DEVICE_SN_UNIQUE==true)
+            f_get_serial_string=true;
+            data_to_transfer += (SN_LENGTH*4);
 #endif
-			return TRUE;
-			break;
+            return true;
+            break;
 #endif
-			}
-		break;
-		}
-	return FALSE;
-	}
+            }
+        break;
+        }
+    return false;
+    }
 
 /**
  * @brief Manage HID get report request.
  */
 void hid_get_report_descriptor( void )
-	{
-	U16 wLength;
-	U8 nb_byte;
-	bit zlp = FALSE;
-	U16 wInterface;
+    {
+    uint16_t wLength;
+    uint8_t nb_byte;
+    bool zlp = false;
+    uint16_t wInterface;
 
-	LSB(wInterface) = Usb_read_byte();
-	MSB(wInterface) = Usb_read_byte();
+    BYTEn( wInterface, 0 ) = Usb_read_byte();
+    BYTEn( wInterface, 1 ) = Usb_read_byte();
 
-	data_to_transfer = sizeof( usb_hid_report_descriptor );
-	pbuffer = & ( usb_hid_report_descriptor.report[0] );
+    data_to_transfer = sizeof( usb_hid_report_descriptor );
+    pbuffer = & ( usb_hid_report_descriptor.report[0] );
 
-	LSB(wLength) = Usb_read_byte();
-	MSB(wLength) = Usb_read_byte();
-	Usb_ack_receive_setup();
+    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 )
-			{
-			zlp = TRUE;
-			}
-		else
-			{
-			zlp = FALSE;
-			}
-		}
-	else
-		{
-		data_to_transfer = ( U8 )wLength; // send only requested number of data
-		}
+    if( wLength > data_to_transfer )
+        {
+        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
-				{
-				break;
-				}
-#ifndef __GNUC__
-			Usb_write_byte(*pbuffer++);
-#else    // AVRGCC does not support point to PGM space
-			//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++));
-#endif
-			data_to_transfer-- ;
-			}
-		Usb_send_control_in();
-		}
+        nb_byte = 0;
+        while( data_to_transfer != 0 ) // Send data until necessary
+            {
+            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() )
-			;
-		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() )
+            ;
+        Usb_send_control_in();
+        }
 
-	while( ! Is_usb_receive_out() )
-		;
-	Usb_ack_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();
+    {
+    Usb_ack_receive_setup();
+    Usb_send_control_in();
 
-	while( ! Is_usb_receive_out() )
-		;
-	Usb_ack_receive_out();
-	Usb_send_control_in();
-	}
+    while( ! Is_usb_receive_out() )
+        ;
+    Usb_ack_receive_out();
+    Usb_send_control_in();
+    }
 
 /**
  * @brief Manages HID set idle request.
  * 			0 the idle rate applies to all input reports,
  * 			else only applies to the Report ID
  */
-void usb_hid_set_idle( U8 u8_report_id, U8 u8_duration )
-	{
-	U16 wInterface;
+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
-	LSB(wInterface) = Usb_read_byte();
-	MSB(wInterface) = Usb_read_byte();
-	Usb_ack_receive_setup();
+    // Get interface number to put in idle mode
+    BYTEn( wInterface, 0 ) = Usb_read_byte();
+    BYTEn( wInterface, 1 ) = Usb_read_byte();
+    Usb_ack_receive_setup();
 
-	g_u8_report_rate = u8_duration;
+    g_u8_report_rate = u8_duration;
 
-	Usb_send_control_in();
-	while( ! Is_usb_in_ready() )
-		;
-	}
+    Usb_send_control_in();
+    while( ! Is_usb_in_ready() )
+        ;
+    }
 
 /**
  * @brief Manage HID get idle request.
  * 			0 the idle rate applies to all input reports,
  * 			else only applies to the Report ID
  */
-void usb_hid_get_idle( U8 u8_report_id )
-	{
-	U16 wLength;
-	U16 wInterface;
+void usb_hid_get_idle( uint8_t u8_report_id )
+    {
+    uint16_t wLength;
+    uint16_t wInterface;
 
-	// Get interface number to put in idle mode
-	LSB(wInterface) = Usb_read_byte();
-	MSB(wInterface) = Usb_read_byte();
-	LSB(wLength) = Usb_read_byte();
-	MSB(wLength) = Usb_read_byte();
-	Usb_ack_receive_setup();
+    // Get interface number to put in idle mode
+    BYTEn( wInterface, 0 ) = Usb_read_byte();
+    BYTEn( wInterface, 1 ) = Usb_read_byte();
+    BYTEn( wLength, 0 ) = Usb_read_byte();
+    BYTEn( wLength, 1 ) = Usb_read_byte();
+    Usb_ack_receive_setup();
 
-	if( wLength != 0 )
-		{
-		Usb_write_byte(g_u8_report_rate);
-		Usb_send_control_in();
-		}
+    if( wLength != 0 )
+        {
+        Usb_write_byte(g_u8_report_rate);
+        Usb_send_control_in();
+        }
 
-	while( ! Is_usb_receive_out() )
-		;
-	Usb_ack_receive_out();
-	}
+    while( ! Is_usb_receive_out() )
+        ;
+    Usb_ack_receive_out();
+    }
 
 void usb_hid_set_report_feature( void )
-	{
+    {
 
-	Usb_ack_receive_setup();
-	Usb_send_control_in();
+    Usb_ack_receive_setup();
+    Usb_send_control_in();
 
-	while( ! Is_usb_receive_out() )
-		;
+    while( ! Is_usb_receive_out() )
+        ;
 
-	if( Usb_read_byte() == 0x55 )
-		if( Usb_read_byte() == 0xAA )
-			if( Usb_read_byte() == 0x55 )
-				if( Usb_read_byte() == 0xAA )
-					{
-					jump_bootloader = 1;
-					}
-	Usb_ack_receive_out();
-	Usb_send_control_in();
-	while( ! Is_usb_in_ready() )
-		;
-	}
+    if( Usb_read_byte() == 0x55 )
+        if( Usb_read_byte() == 0xAA )
+            if( Usb_read_byte() == 0x55 )
+                if( Usb_read_byte() == 0xAA )
+                    {
+                    jump_bootloader = 1;
+                    }
+    Usb_ack_receive_out();
+    Usb_send_control_in();
+    while( ! Is_usb_in_ready() )
+        ;
+    }
 
 /**
  * @brief Manage HID get hid descriptor request.
  */
 void hid_get_hid_descriptor( void )
-	{
-	U16 wLength;
-	U8 nb_byte;
-	bit zlp = FALSE;
-	U16 wInterface;
+    {
+    uint16_t wLength;
+    uint8_t nb_byte;
+    bool zlp = false;
+    uint16_t wInterface;
 
-	LSB(wInterface) = Usb_read_byte();
-	MSB(wInterface) = Usb_read_byte();
+    BYTEn( wInterface, 0 ) = Usb_read_byte();
+    BYTEn( wInterface, 1 ) = Usb_read_byte();
 
-	data_to_transfer = sizeof( usb_conf_desc.hid );
-	pbuffer = & ( usb_conf_desc.hid.bLength );
+    data_to_transfer = sizeof( usb_conf_desc.hid );
+    pbuffer = & ( usb_conf_desc.hid.bLength );
 
-	LSB(wLength) = Usb_read_byte();
-	MSB(wLength) = Usb_read_byte();
-	Usb_ack_receive_setup();
+    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 )
-			{
-			zlp = TRUE;
-			}
-		else
-			{
-			zlp = FALSE;
-			} // no need of zero length packet
-		}
-	else
-		{
-		data_to_transfer = ( U8 )wLength; // send only requested number of data
-		}
+    if( wLength > data_to_transfer )
+        {
+        if( ( data_to_transfer % EP_CONTROL_LENGTH ) == 0 )
+            {
+            zlp = true;
+            }
+        else
+            {
+            zlp = false;
+            } // no need of zero length packet
+        }
+    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
-				{
-				break;
-				}
-#ifndef __GNUC__
-			Usb_write_byte(*pbuffer++);
-#else    // AVRGCC does not support point to PGM space
-			//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++));
-#endif
-			data_to_transfer-- ;
-			}
-		Usb_send_control_in();
-		}
+        nb_byte = 0;
+        while( data_to_transfer != 0 ) // Send data until necessary
+            {
+            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() )
-			;
-		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() )
+            ;
+        Usb_send_control_in();
+        }
 
-	while( ! Is_usb_receive_out() )
-		;
-	Usb_ack_receive_out();
-	}
+    while( ! Is_usb_receive_out() )
+        ;
+    Usb_ack_receive_out();
+    }
 

usb_specific_request.h

 #ifndef _USB_SPECIFIC_REQUEST_H_
 #define _USB_SPECIFIC_REQUEST_H_
 
-//_____ I N C L U D E S ____________________________________________________
+//_____ I N C L U D E S ________________________________________________________
+
+#include <avr/pgmspace.h>
+#include <stdbool.h>
+
 
 #include "config.h"
 
-//_____ M A C R O S ________________________________________________________
+//_____ M A C R O S ____________________________________________________________
 
-extern code S_usb_device_descriptor usb_dev_desc;
-extern code S_usb_user_configuration_descriptor usb_conf_desc;
-extern code S_usb_manufacturer_string_descriptor
+extern PROGMEM S_usb_device_descriptor usb_dev_desc;
+extern PROGMEM S_usb_user_configuration_descriptor usb_conf_desc;
+extern PROGMEM S_usb_manufacturer_string_descriptor
 	usb_user_manufacturer_string_descriptor;
-extern code S_usb_product_string_descriptor usb_user_product_string_descriptor;
-#if (USB_DEVICE_SN_USE==ENABLE)
-extern code S_usb_serial_number usb_user_serial_number;
+extern PROGMEM S_usb_product_string_descriptor usb_user_product_string_descriptor;
+#if (USB_DEVICE_SN_USE==true)
+extern PROGMEM S_usb_serial_number usb_user_serial_number;
 #endif
-extern code S_usb_language_id usb_user_language_id;
+extern PROGMEM S_usb_language_id usb_user_language_id;
 
-//_____ D E F I N I T I O N ________________________________________________
+//_____ D E F I N I T I O N ____________________________________________________
 
-Bool usb_user_read_request(U8, U8);
-void usb_user_endpoint_init(U8);
-U8 usb_user_interface_get(U16 wInterface);
-void usb_user_interface_reset(U16 wInterface, U8 alternate_setting);
-Bool usb_user_get_descriptor(U8, U8);
+bool usb_user_read_request(uint8_t, uint8_t);
+void usb_user_endpoint_init(uint8_t);
+uint8_t usb_user_interface_get(uint16_t wInterface);
+void usb_user_interface_reset(uint16_t wInterface, uint8_t alternate_setting);
+bool usb_user_get_descriptor(uint8_t, uint8_t);
 
 /**
  * Usb HID Report Descriptor HID generic
  */
 typedef struct
     {
-	U8 report[SIZE_OF_REPORT];
+	uint8_t report[SIZE_OF_REPORT];
     } S_usb_hid_report_descriptor;
 
 #endif