Quote
[...continues from previous post]
The following MS Word Macro will (mostly) extract function definitions from code
Paste the declarations in the space above where suggested
__
Sub ExtractFunctionDefinitions()
'
' Extract function definitions from C code
' Open all the relevant documents in word
' Once finished, copy the declarations to the appropriate location in your code
'
For Each currDoc In Documents
currDoc.Select
ActiveDocument.PageSetup.PageWidth = CentimetersToPoints(55)
Selection.HomeKey Unit:=wdStory
Selection.TypeText "/*** " & ActiveDocument.Name & " Declarations ***/"
Selection.TypeParagraph
While ActiveDocument.Range.End > Selection.End + 5
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
If InStr(Selection.Text, "::") > 0 Then
classDec = 1
Else
classDec = 0
End If
' Search the first 10 characters of each line for type markers
curStr = Left(Trim(Selection.Text), 6)
If InStr(curStr, "void") Or _
InStr(curStr, "int") Or _
InStr(curStr, "double") Or _
InStr(curStr, "bool") Or _
InStr(curStr, "long") Or _
InStr(curStr, "int8_t") Or _
InStr(curStr, "inline") Or _
InStr(curStr, "static") Then
' If it's not a comment
If Left(curStr, 2) <> "//" Then
' If the rightmost character (excluding return char) is not ';' then
curStr = Trim(Replace(Replace(Selection.Text, Chr(13), ""), Chr(10), ""))
If InStr(curStr, "(") > 0 And Right(curStr, 1) <> ";" Then
curStr = Replace(curStr, "()", "(void)") ' function declarations should have arguments as void if there are none
curStr = curStr & ";" & vbCrLf
If classDec = 1 Then
' Don't need to declare class functions
curStr = "//" & curStr
End If
Selection.TypeText curStr
' Selection.MoveRight Unit:=wdCharacter, Count:=1
Else
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Else
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Else
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Wend
Next
newDoc = Documents.Add(Template:="Normal", NewTemplate:=False, DocumentType:=0)
For Each currDoc In Documents
Debug.Print currDoc.Name
If currDoc.Name = newDoc Then
currDoc.PageSetup.PageWidth = CentimetersToPoints(55)
Else
currDoc.Select
Selection.WholeStory
Selection.Cut
Windows(newDoc).Activate
Selection.HomeKey Unit:=wdStory
If InStr(currDoc.Name, ".pde") = 0 Then Selection.TypeText "//"
Selection.TypeText "#include """ & currDoc.Name & """"
Selection.TypeParagraph
Selection.EndKey Unit:=wdStory
Selection.PasteAndFormat (wdPasteDefault)
currDoc.Close False
End If
Next
End Sub
--------------------------------------------------
/*** LUFA Under Eclipse ***/
The following are the adjustments to the properties to enable LUFA to build
with an automatic makefile under Eclipse
*** Create a new project on the workbench ***
RCPEW = right click in Project Explorer Window/New/Project
Select: C++ project
Select: AVR Cross Target Application
Give it a name: Template
Set your hardware (eg AT90USB1287 at 8000000Hz)
Click Finish
Copy the LUFA library directory into the project root directory.
Delete all .c files which are not used (see in the makefile for which these are)
Optional: Delete Doxygen.conf
[ProjectName].txt (used by Doxygen)
[ProjectName].aps (used by AVR Studio)
makefile
Now modify the project properties (RCPEW/Properties)
Set Configuration to [All Configurations]
/*** AVR / Target Hardware ***/
AT90USB1287
8000000
/*** C/C++ Build / Build Variables ***/
#MCU = at90usb1287
#BOARD = USBKEY
#F_CPU = 8000000
#F_CLOCK = 8000000
#FORMAT = ihex
#OBJSRC
/*** C/C++ Build / Settings / AVR Assembler / General / Other GCC Flags ***/
#-Wa,-adhlns=$(<
.S=./%.lst),-gstabs,--listing-cont-lines=100
/*** C/C++ Build / Settings / AVR Assembler / Debugging / Debug Info Format ***/
#dwarf-2
/*** C/C++ Build / Settings / AVR Compiler / Optomization / Optimization Level ***/
Os
/*** C/C++ Build / Settings / AVR Compiler / Language Standard ***/
-std=gnu99 // This is required for LUFA
/*** C/C++ Build / Settings / AVR C Compiler / Miscellaneous / Other Flags ***/
-DF_CLOCK=8000000UL -DBOARD=BOARD_USBKEY -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS -DUSB_DEVICE_ONLY -DFIXED_CONTROL_ENDPOINT_SIZE=8 -DUSE_SINGLE_DEVICE_CONFIGURATION -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -ffunction-sections -finline-limit=20 -Wall -Wstrict-prototypes -Wundef $(OBJSRC:%.c=$(OBJDIR)/%.o)
/*** C/C++ Build / Settings / AVR C++ Compiler / Miscellaneous / Other Flags ***/
-DF_CLOCK=8000000UL -DBOARD=BOARD_USBKEY -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS -DUSB_DEVICE_ONLY -DFIXED_CONTROL_ENDPOINT_SIZE=8 -DUSE_SINGLE_DEVICE_CONFIGURATION -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -ffunction-sections -finline-limit=20 -Wall -Wundef $(OBJSRC:%.c=$(OBJDIR)/%.o)
/*** C/C++ Build / Settings / AVR C Linker / General / Other Arguments ***/
-Wl,--relax -Wl,--gc-sections -lm
/*** C/C++ General / Paths and Symbols ***/
Add an include for the project root directory (so the LUFA includes will be recognised
The following MS Word Macro will (mostly) extract function definitions from code
Paste the declarations in the space above where suggested
__
Sub ExtractFunctionDefinitions()
'
' Extract function definitions from C code
' Open all the relevant documents in word
' Once finished, copy the declarations to the appropriate location in your code
'
For Each currDoc In Documents
currDoc.Select
ActiveDocument.PageSetup.PageWidth = CentimetersToPoints(55)
Selection.HomeKey Unit:=wdStory
Selection.TypeText "/*** " & ActiveDocument.Name & " Declarations ***/"
Selection.TypeParagraph
While ActiveDocument.Range.End > Selection.End + 5
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
If InStr(Selection.Text, "::") > 0 Then
classDec = 1
Else
classDec = 0
End If
' Search the first 10 characters of each line for type markers
curStr = Left(Trim(Selection.Text), 6)
If InStr(curStr, "void") Or _
InStr(curStr, "int") Or _
InStr(curStr, "double") Or _
InStr(curStr, "bool") Or _
InStr(curStr, "long") Or _
InStr(curStr, "int8_t") Or _
InStr(curStr, "inline") Or _
InStr(curStr, "static") Then
' If it's not a comment
If Left(curStr, 2) <> "//" Then
' If the rightmost character (excluding return char) is not ';' then
curStr = Trim(Replace(Replace(Selection.Text, Chr(13), ""), Chr(10), ""))
If InStr(curStr, "(") > 0 And Right(curStr, 1) <> ";" Then
curStr = Replace(curStr, "()", "(void)") ' function declarations should have arguments as void if there are none
curStr = curStr & ";" & vbCrLf
If classDec = 1 Then
' Don't need to declare class functions
curStr = "//" & curStr
End If
Selection.TypeText curStr
' Selection.MoveRight Unit:=wdCharacter, Count:=1
Else
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Else
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Else
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Wend
Next
newDoc = Documents.Add(Template:="Normal", NewTemplate:=False, DocumentType:=0)
For Each currDoc In Documents
Debug.Print currDoc.Name
If currDoc.Name = newDoc Then
currDoc.PageSetup.PageWidth = CentimetersToPoints(55)
Else
currDoc.Select
Selection.WholeStory
Selection.Cut
Windows(newDoc).Activate
Selection.HomeKey Unit:=wdStory
If InStr(currDoc.Name, ".pde") = 0 Then Selection.TypeText "//"
Selection.TypeText "#include """ & currDoc.Name & """"
Selection.TypeParagraph
Selection.EndKey Unit:=wdStory
Selection.PasteAndFormat (wdPasteDefault)
currDoc.Close False
End If
Next
End Sub
--------------------------------------------------
/*** LUFA Under Eclipse ***/
The following are the adjustments to the properties to enable LUFA to build
with an automatic makefile under Eclipse
*** Create a new project on the workbench ***
RCPEW = right click in Project Explorer Window/New/Project
Select: C++ project
Select: AVR Cross Target Application
Give it a name: Template
Set your hardware (eg AT90USB1287 at 8000000Hz)
Click Finish
Copy the LUFA library directory into the project root directory.
Delete all .c files which are not used (see in the makefile for which these are)
Optional: Delete Doxygen.conf
[ProjectName].txt (used by Doxygen)
[ProjectName].aps (used by AVR Studio)
makefile
Now modify the project properties (RCPEW/Properties)
Set Configuration to [All Configurations]
/*** AVR / Target Hardware ***/
AT90USB1287
8000000
/*** C/C++ Build / Build Variables ***/
#MCU = at90usb1287
#BOARD = USBKEY
#F_CPU = 8000000
#F_CLOCK = 8000000
#FORMAT = ihex
#OBJSRC
/*** C/C++ Build / Settings / AVR Assembler / General / Other GCC Flags ***/
#-Wa,-adhlns=$(<
.S=./%.lst),-gstabs,--listing-cont-lines=100/*** C/C++ Build / Settings / AVR Assembler / Debugging / Debug Info Format ***/
#dwarf-2
/*** C/C++ Build / Settings / AVR Compiler / Optomization / Optimization Level ***/
Os
/*** C/C++ Build / Settings / AVR Compiler / Language Standard ***/
-std=gnu99 // This is required for LUFA
/*** C/C++ Build / Settings / AVR C Compiler / Miscellaneous / Other Flags ***/
-DF_CLOCK=8000000UL -DBOARD=BOARD_USBKEY -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS -DUSB_DEVICE_ONLY -DFIXED_CONTROL_ENDPOINT_SIZE=8 -DUSE_SINGLE_DEVICE_CONFIGURATION -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -ffunction-sections -finline-limit=20 -Wall -Wstrict-prototypes -Wundef $(OBJSRC:%.c=$(OBJDIR)/%.o)
/*** C/C++ Build / Settings / AVR C++ Compiler / Miscellaneous / Other Flags ***/
-DF_CLOCK=8000000UL -DBOARD=BOARD_USBKEY -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS -DUSB_DEVICE_ONLY -DFIXED_CONTROL_ENDPOINT_SIZE=8 -DUSE_SINGLE_DEVICE_CONFIGURATION -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -ffunction-sections -finline-limit=20 -Wall -Wundef $(OBJSRC:%.c=$(OBJDIR)/%.o)
/*** C/C++ Build / Settings / AVR C Linker / General / Other Arguments ***/
-Wl,--relax -Wl,--gc-sections -lm
/*** C/C++ General / Paths and Symbols ***/
Add an include for the project root directory (so the LUFA includes will be recognised
