diff --git a/internal/integrationtest/compile_4/compile_test.go b/internal/integrationtest/compile_4/compile_test.go new file mode 100644 index 00000000000..1c2b1401f4c --- /dev/null +++ b/internal/integrationtest/compile_4/compile_test.go @@ -0,0 +1,631 @@ +// This file is part of arduino-cli. +// +// Copyright 2023 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package compile_test + +import ( + "bytes" + "encoding/json" + "os/exec" + "strings" + "testing" + "text/template" + + "github.com/arduino/arduino-cli/arduino/builder/cpp" + "github.com/arduino/arduino-cli/internal/integrationtest" + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/require" + "golang.org/x/exp/slices" +) + +func TestCompileOfProblematicSketches(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + // Install Arduino AVR Boards + _, _, err := cli.Run("core", "install", "arduino:avr@1.8.6") + require.NoError(t, err) + _, _, err = cli.Run("core", "install", "arduino:sam@1.6.12") + require.NoError(t, err) + _, _, err = cli.Run("core", "install", "arduino:samd@1.8.13") + require.NoError(t, err) + + // Install REDBear Lad platform + _, _, err = cli.Run("config", "init") + require.NoError(t, err) + _, _, err = cli.Run("config", "add", "board_manager.additional_urls", "https://redbearlab.github.io/arduino/package_redbearlab_index.json") + require.NoError(t, err) + _, _, err = cli.Run("core", "update-index") + require.NoError(t, err) + _, _, err = cli.Run("core", "install", "RedBear:avr@1.0.0") + require.NoError(t, err) + + // XXX: This compiler gives an error "sorry - this program has been built without plugin support" + // for avr-gcc/4.8.1-arduino5/bin/avr-gcc-ar. Maybe it's a problem of the very old avr-gcc... + // Removing it will enforce the builder to use the more recent avr-gcc from arduino:avr platform. + require.NoError(t, cli.DataDir().Join("packages", "arduino", "tools", "avr-gcc", "4.8.1-arduino5").RemoveAll()) + + // Install Libraries required for tests + _, _, err = cli.Run("lib", "install", "Bridge@1.6.1") + require.NoError(t, err) + _, _, err = cli.Run("lib", "install", "CapacitiveSensor@0.5") + require.NoError(t, err) + + integrationtest.CLISubtests{ + {"SketchWithInlineFunction", testBuilderSketchWithInlineFunction}, + {"SketchWithConst", testBuilderSketchWithConst}, + {"SketchWithFunctionSignatureInsideIfdef", testBuilderSketchWithFunctionSignatureInsideIfdef}, + {"SketchWithOldLibrary", testBuilderSketchWithOldLibrary}, + {"SketchWithoutFunctions", testBuilderSketchWithoutFunctions}, + {"SketchWithConfig", testBuilderSketchWithConfig}, + {"SketchWithUsbcon", testBuilderSketchWithUsbcon}, + {"SketchWithTypename", testBuilderSketchWithTypename}, + {"SketchWithMacosxGarbage", tryBuildAvrLeonardo}, + {"SketchWithNamespace", testBuilderSketchWithNamespace}, + {"SketchWithDefaultArgs", testBuilderSketchWithDefaultArgs}, + {"SketchWithClass", testBuilderSketchWithClass}, + {"SketchWithBackupFiles", testBuilderSketchWithBackupFiles}, + {"SketchWithSubfolders", testBuilderSketchWithSubfolders}, + {"SketchWithTemplatesAndShift", testBuilderSketchWithTemplatesAndShift}, + {"SketchRequiringEOLProcessing", tryBuildAvrLeonardo}, + {"SketchWithIfDef", testBuilderSketchWithIfDef}, + {"SketchWithIfDef2", testBuilderSketchWithIfDef2}, + {"SketchWithIfDef3", testBuilderSketchWithIfDef3}, + {"BridgeExample", testBuilderBridgeExample}, + {"Baladuino", testBuilderBaladuino}, + {"SketchWithEscapedDoubleQuote", testBuilderSketchWithEscapedDoubleQuote}, + {"SketchWithIncludeBetweenMultilineComment", testBuilderSketchWithIncludeBetweenMultilineComment}, + {"SketchWithLineContinuations", testBuilderSketchWithLineContinuations}, + {"SketchWithStringWithComment", testBuilderSketchWithStringWithComment}, + {"SketchWithStruct", testBuilderSketchWithStruct}, + {"SketchNoFunctionsTwoFiles", testBuilderSketchNoFunctionsTwoFiles}, + {"SketchWithClassAndMethodSubstring", testBuilderSketchWithClassAndMethodSubstring}, + {"SketchThatChecksIfSPIHasTransactions", tryBuildAvrLeonardo}, + {"SketchWithDependendLibraries", tryBuildAvrLeonardo}, + {"SketchWithFunctionPointer", tryBuildAvrLeonardo}, + {"USBHostExample", testBuilderUSBHostExample}, + {"SketchWithConflictingLibraries", testBuilderSketchWithConflictingLibraries}, + }.Run(t, env, cli) +} + +func testBuilderSketchWithConfig(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Compile + out, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + buildPath := out.BuilderResult.BuildPath + require.NotNil(t, buildPath) + require.True(t, buildPath.Join("core", "HardwareSerial.cpp.o").Exist()) + require.True(t, buildPath.Join("sketch", "SketchWithConfig.ino.cpp.o").Exist()) + require.True(t, buildPath.Join("SketchWithConfig.ino.elf").Exist()) + require.True(t, buildPath.Join("SketchWithConfig.ino.hex").Exist()) + require.True(t, buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").Exist()) + + // Preprocessing + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithoutFunctions(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.Error(t, err) + _, err = tryBuild(t, env, cli, "RedBear:avr:blend") + require.Error(t, err) + + // Preprocess + sketchPath, preprocessedSketchData, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + preprocessedSketch := string(preprocessedSketchData) + quotedSketchMainFile := cpp.QuoteString(sketchPath.Join(sketchPath.Base() + ".ino").String()) + require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchMainFile+"\n") +} + +func testBuilderSketchWithBackupFiles(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + _, err = tryBuild(t, env, cli, "arduino:avr:uno") + require.NoError(t, err) +} + +func testBuilderSketchWithOldLibrary(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + _, err = tryBuild(t, env, cli, "arduino:avr:uno") + require.NoError(t, err) +} + +func testBuilderSketchWithSubfolders(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + out, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + importedLibraries := out.BuilderResult.UsedLibraries + slices.SortFunc(importedLibraries, func(x, y *builderLibrary) bool { return x.Name < y.Name }) + require.NoError(t, err) + require.Equal(t, 3, len(importedLibraries)) + require.Equal(t, "testlib1", importedLibraries[0].Name) + require.Equal(t, "testlib2", importedLibraries[1].Name) + require.Equal(t, "testlib3", importedLibraries[2].Name) + + _, err = tryBuild(t, env, cli, "arduino:avr:uno") + require.NoError(t, err) +} + +func testBuilderSketchWithClass(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + _, err = tryBuild(t, env, cli, "arduino:avr:uno") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:uno") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithTypename(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // XXX: Failing sketch, typename not supported. + // This test will be skipped until a better C++ parser is adopted + t.SkipNow() + + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithNamespace(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithDefaultArgs(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithInlineFunction(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithFunctionSignatureInsideIfdef(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithUsbcon(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithConst(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithTemplatesAndShift(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // XXX: Failing sketch, template with shift not supported. + // This test will be skipped until a better C++ parser is adopted + t.SkipNow() + + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithIfDef(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + output, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + require.Empty(t, output.BuilderResult.UsedLibraries) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithIfDef2(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + output, err := tryBuild(t, env, cli, "arduino:avr:yun") + require.NoError(t, err) + require.Empty(t, output.BuilderResult.UsedLibraries) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:yun") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderSketchWithIfDef3(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + // Build + output, err := tryBuild(t, env, cli, "arduino:sam:arduino_due_x_dbg") + require.NoError(t, err) + require.Empty(t, output.BuilderResult.UsedLibraries) + + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:sam:arduino_due_x_dbg") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) +} + +func testBuilderBridgeExample(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("BuildForAVR", func(t *testing.T) { + // Build + out, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + + buildPath := out.BuilderResult.BuildPath + require.True(t, buildPath.Join("core", "HardwareSerial.cpp.o").Exist()) + require.True(t, buildPath.Join("sketch", "BridgeExample.ino.cpp.o").Exist()) + require.True(t, buildPath.Join("BridgeExample.ino.elf").Exist()) + require.True(t, buildPath.Join("BridgeExample.ino.hex").Exist()) + require.True(t, buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").Exist()) + + // Build again... + out2, err2 := tryBuild(t, env, cli, "arduino:avr:leonardo", "no-clean") + require.NoError(t, err2) + buildPath2 := out2.BuilderResult.BuildPath + require.True(t, buildPath2.Join("core", "HardwareSerial.cpp.o").Exist()) + require.True(t, buildPath2.Join("sketch", "BridgeExample.ino.cpp.o").Exist()) + require.True(t, buildPath2.Join("BridgeExample.ino.elf").Exist()) + require.True(t, buildPath2.Join("BridgeExample.ino.hex").Exist()) + require.True(t, buildPath2.Join("libraries", "Bridge", "Mailbox.cpp.o").Exist()) + }) + + t.Run("BuildForSAM", func(t *testing.T) { + // Build again for SAM... + out, err := tryBuild(t, env, cli, "arduino:sam:arduino_due_x_dbg", "all-warnings") + require.NoError(t, err) + + buildPath := out.BuilderResult.BuildPath + require.True(t, buildPath.Join("core", "syscalls_sam3.c.o").Exist()) + require.True(t, buildPath.Join("core", "USB", "PluggableUSB.cpp.o").Exist()) + require.True(t, buildPath.Join("core", "avr", "dtostrf.c.d").Exist()) + require.True(t, buildPath.Join("sketch", "BridgeExample.ino.cpp.o").Exist()) + require.True(t, buildPath.Join("BridgeExample.ino.elf").Exist()) + require.True(t, buildPath.Join("BridgeExample.ino.bin").Exist()) + require.True(t, buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").Exist()) + + objdump := cli.DataDir().Join("packages", "arduino", "tools", "arm-none-eabi-gcc", "4.8.3-2014q1", "bin", "arm-none-eabi-objdump") + cmd := exec.Command( + objdump.String(), + "-f", buildPath.Join("core", "core.a").String()) + bytes, err := cmd.CombinedOutput() + require.NoError(t, err) + require.NotContains(t, string(bytes), "variant.cpp.o") + }) + + t.Run("BuildForRedBearAVR", func(t *testing.T) { + // Build again for RedBearLab... + out, err := tryBuild(t, env, cli, "RedBear:avr:blend", "verbose") + require.NoError(t, err) + buildPath := out.BuilderResult.BuildPath + require.True(t, buildPath.Join("core", "HardwareSerial.cpp.o").Exist()) + require.True(t, buildPath.Join("sketch", "BridgeExample.ino.cpp.o").Exist()) + require.True(t, buildPath.Join("BridgeExample.ino.elf").Exist()) + require.True(t, buildPath.Join("BridgeExample.ino.hex").Exist()) + require.True(t, buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").Exist()) + }) + + t.Run("BuildPathMustNotContainsUnusedPreviouslyCompiledLibrary", func(t *testing.T) { + out, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + buildPath := out.BuilderResult.BuildPath + + // Simulate a library use in libraries build path + require.NoError(t, buildPath.Join("libraries", "SPI").MkdirAll()) + + // Build again... + _, err = tryBuild(t, env, cli, "arduino:avr:leonardo", "no-clean") + require.NoError(t, err) + + require.False(t, buildPath.Join("libraries", "SPI").Exist()) + require.True(t, buildPath.Join("libraries", "Bridge").Exist()) + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderBaladuino(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + t.Skip("The sketch is missing required libraries to build") + + // Build + output, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + require.Empty(t, output.BuilderResult.UsedLibraries) + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderSketchWithEscapedDoubleQuote(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderSketchWithIncludeBetweenMultilineComment(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderSketchWithLineContinuations(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderSketchWithStringWithComment(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderSketchWithStruct(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderSketchNoFunctionsTwoFiles(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // Build + out, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.Error(t, err) + require.Contains(t, out.CompilerErr, "undefined reference to `loop'") + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderSketchWithClassAndMethodSubstring(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // Build + _, err := tryBuild(t, env, cli, "arduino:avr:uno") + require.NoError(t, err) + }) + + t.Run("Preprocess", func(t *testing.T) { + // Preprocess + sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:uno") + require.NoError(t, err) + comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch) + }) +} + +func testBuilderUSBHostExample(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // Build + out, err := tryBuild(t, env, cli, "arduino:samd:arduino_zero_native") + require.NoError(t, err) + + libs := out.BuilderResult.UsedLibraries + require.Len(t, libs, 1) + require.Equal(t, "USBHost", libs[0].Name) + usbHostLibDir, err := paths.New("testdata", "libraries", "USBHost", "src").Abs() + require.NoError(t, err) + require.True(t, libs[0].SourceDir.EquivalentTo(usbHostLibDir)) + }) +} + +func testBuilderSketchWithConflictingLibraries(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + t.Run("Build", func(t *testing.T) { + // This library has a conflicting IRremote.h + _, _, err := cli.Run("lib", "install", "Robot IR Remote@1.0.2") + require.NoError(t, err) + + // Build + out, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) + libs := out.BuilderResult.UsedLibraries + slices.SortFunc(libs, func(x, y *builderLibrary) bool { return x.Name < y.Name }) + require.Len(t, libs, 2) + require.Equal(t, "Bridge", libs[0].Name) + require.Equal(t, "IRremote", libs[1].Name) + }) +} + +func tryBuildAvrLeonardo(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") + require.NoError(t, err) +} + +type builderOutput struct { + CompilerOut string `json:"compiler_out"` + CompilerErr string `json:"compiler_err"` + BuilderResult struct { + BuildPath *paths.Path `json:"build_path"` + UsedLibraries []*builderLibrary `json:"used_libraries"` + } `json:"builder_result"` +} + +type builderLibrary struct { + Name string `json:"Name"` + InstallDir *paths.Path `json:"install_dir"` + SourceDir *paths.Path `json:"source_dir"` +} + +func tryBuild(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI, fqbn string, options ...string) (*builderOutput, error) { + subTestName := strings.Split(t.Name(), "/")[1] + sketchPath, err := paths.New("testdata", subTestName).Abs() + require.NoError(t, err) + libsPath, err := paths.New("testdata", "libraries").Abs() + require.NoError(t, err) + args := []string{ + "compile", + "-b", fqbn, + "--libraries", libsPath.String(), + "--format", "json", + sketchPath.String()} + if !slices.Contains(options, "no-clean") { + args = append(args, "--clean") + } + if slices.Contains(options, "all-warnings") { + args = append(args, "--warnings", "all") + } + if slices.Contains(options, "verbose") { + args = append(args, "-v") + } + jsonOut, _, err := cli.Run(args...) + var out builderOutput + require.NoError(t, json.Unmarshal(jsonOut, &out)) + return &out, err +} + +func tryPreprocess(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI, fqbn string) (*paths.Path, []byte, error) { + subTestName := strings.Split(t.Name(), "/")[1] + sketchPath, err := paths.New("testdata", subTestName).Abs() + require.NoError(t, err) + libsPath, err := paths.New("testdata", "libraries").Abs() + require.NoError(t, err) + out, _, err := cli.Run("compile", "-b", fqbn, "--preprocess", "--libraries", libsPath.String(), sketchPath.String()) + return sketchPath, out, err +} + +func comparePreprocessGoldenFile(t *testing.T, sketchDir *paths.Path, preprocessedSketchData []byte) { + preprocessedSketch := string(preprocessedSketchData) + + sketchName := sketchDir.Base() + sketchMainFile := sketchDir.Join(sketchName + ".ino") + sketchTemplate := sketchDir.Join(sketchName + ".preprocessed.txt") + + funcsMap := template.FuncMap{ + "QuoteCppString": func(p *paths.Path) string { return cpp.QuoteString(p.String()) }, + } + tpl, err := template.New(sketchTemplate.Base()). + Funcs(funcsMap). + ParseFiles(sketchTemplate.String()) + require.NoError(t, err) + + data := make(map[string]interface{}) + data["sketchMainFile"] = sketchMainFile + data["sketchDir"] = sketchDir + var buf bytes.Buffer + err = tpl.Execute(&buf, data) + require.NoError(t, err) + + require.Equal(t, buf.String(), strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) +} diff --git a/legacy/builder/test/Baladuino/Baladuino.ino b/internal/integrationtest/compile_4/testdata/Baladuino/Baladuino.ino similarity index 100% rename from legacy/builder/test/Baladuino/Baladuino.ino rename to internal/integrationtest/compile_4/testdata/Baladuino/Baladuino.ino diff --git a/legacy/builder/test/Baladuino/Baladuino.preprocessed.txt b/internal/integrationtest/compile_4/testdata/Baladuino/Baladuino.preprocessed.txt similarity index 98% rename from legacy/builder/test/Baladuino/Baladuino.preprocessed.txt rename to internal/integrationtest/compile_4/testdata/Baladuino/Baladuino.preprocessed.txt index 8636e91422f..048b66e9af7 100644 --- a/legacy/builder/test/Baladuino/Baladuino.preprocessed.txt +++ b/internal/integrationtest/compile_4/testdata/Baladuino/Baladuino.preprocessed.txt @@ -1,5 +1,5 @@ #include -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} /* * The code is released under the GNU General Public License. * Developed by Kristian Lauszus, TKJ Electronics 2013 @@ -87,11 +87,11 @@ WII Wii(&Btd); // The Wii library can communicate with Wiimotes and the Nunchuck // This can also be done using the Android or Processing application #endif -#line 88 {{QuoteCppString .sketch.MainFile}} +#line 88 {{QuoteCppString .sketchMainFile}} void setup(); -#line 204 {{QuoteCppString .sketch.MainFile}} +#line 204 {{QuoteCppString .sketchMainFile}} void loop(); -#line 88 {{QuoteCppString .sketch.MainFile}} +#line 88 {{QuoteCppString .sketchMainFile}} void setup() { /* Initialize UART */ Serial.begin(115200); diff --git a/internal/integrationtest/compile_4/testdata/BridgeExample/BridgeExample.ino b/internal/integrationtest/compile_4/testdata/BridgeExample/BridgeExample.ino new file mode 100644 index 00000000000..c6c7be3af23 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/BridgeExample/BridgeExample.ino @@ -0,0 +1,185 @@ +/* + Arduino Yún Bridge example + + This example for the Arduino Yún shows how to use the + Bridge library to access the digital and analog pins + on the board through REST calls. It demonstrates how + you can create your own API when using REST style + calls through the browser. + + Possible commands created in this shetch: + + "/arduino/digital/13" -> digitalRead(13) + "/arduino/digital/13/1" -> digitalWrite(13, HIGH) + "/arduino/analog/2/123" -> analogWrite(2, 123) + "/arduino/analog/2" -> analogRead(2) + "/arduino/mode/13/input" -> pinMode(13, INPUT) + "/arduino/mode/13/output" -> pinMode(13, OUTPUT) + + This example code is part of the public domain + + http://www.arduino.cc/en/Tutorial/Bridge + +*/ + +#include +#include +#include + +// Listen to the default port 5555, the Yún webserver +// will forward there all the HTTP requests you send +BridgeServer server; + +void setup() { + // Bridge startup + pinMode(13, OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); + digitalWrite(13, HIGH); + + // Listen for incoming connection only from localhost + // (no one from the external network could connect) + server.listenOnLocalhost(); + server.begin(); +} + +void loop() { + // Get clients coming from server + BridgeClient client = server.accept(); + + // There is a new client? + if (client) { + // Process request + process(client); + + // Close connection and free resources. + client.stop(); + } + + delay(50); // Poll every 50ms +} + +void process(BridgeClient client) { + // read the command + String command = client.readStringUntil('/'); + + // is "digital" command? + if (command == "digital") { + digitalCommand(client); + } + + // is "analog" command? + if (command == "analog") { + analogCommand(client); + } + + // is "mode" command? + if (command == "mode") { + modeCommand(client); + } +} + +void digitalCommand(BridgeClient client) { + int pin, value; + + // Read pin number + pin = client.parseInt(); + + // If the next character is a '/' it means we have an URL + // with a value like: "/digital/13/1" + if (client.read() == '/') { + value = client.parseInt(); + digitalWrite(pin, value); + } else { + value = digitalRead(pin); + } + + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" set to ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "D"; + key += pin; + Bridge.put(key, String(value)); +} + +void analogCommand(BridgeClient client) { + int pin, value; + + // Read pin number + pin = client.parseInt(); + + // If the next character is a '/' it means we have an URL + // with a value like: "/analog/5/120" + if (client.read() == '/') { + // Read value and execute command + value = client.parseInt(); + analogWrite(pin, value); + + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" set to analog ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "D"; + key += pin; + Bridge.put(key, String(value)); + } else { + // Read analog pin + value = analogRead(pin); + + // Send feedback to client + client.print(F("Pin A")); + client.print(pin); + client.print(F(" reads analog ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "A"; + key += pin; + Bridge.put(key, String(value)); + } +} + +void modeCommand(BridgeClient client) { + int pin; + + // Read pin number + pin = client.parseInt(); + + // If the next character is not a '/' we have a malformed URL + if (client.read() != '/') { + client.println(F("error")); + return; + } + + String mode = client.readStringUntil('\r'); + + if (mode == "input") { + pinMode(pin, INPUT); + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" configured as INPUT!")); + return; + } + + if (mode == "output") { + pinMode(pin, OUTPUT); + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" configured as OUTPUT!")); + return; + } + + client.print(F("error: invalid mode ")); + client.print(mode); +} + + diff --git a/internal/integrationtest/compile_4/testdata/BridgeExample/BridgeExample.preprocessed.txt b/internal/integrationtest/compile_4/testdata/BridgeExample/BridgeExample.preprocessed.txt new file mode 100644 index 00000000000..af7738c21e4 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/BridgeExample/BridgeExample.preprocessed.txt @@ -0,0 +1,201 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +/* + Arduino Yún Bridge example + + This example for the Arduino Yún shows how to use the + Bridge library to access the digital and analog pins + on the board through REST calls. It demonstrates how + you can create your own API when using REST style + calls through the browser. + + Possible commands created in this shetch: + + "/arduino/digital/13" -> digitalRead(13) + "/arduino/digital/13/1" -> digitalWrite(13, HIGH) + "/arduino/analog/2/123" -> analogWrite(2, 123) + "/arduino/analog/2" -> analogRead(2) + "/arduino/mode/13/input" -> pinMode(13, INPUT) + "/arduino/mode/13/output" -> pinMode(13, OUTPUT) + + This example code is part of the public domain + + http://www.arduino.cc/en/Tutorial/Bridge + +*/ + +#include +#include +#include + +// Listen to the default port 5555, the Yún webserver +// will forward there all the HTTP requests you send +BridgeServer server; + +#line 33 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 46 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 62 {{QuoteCppString .sketchMainFile}} +void process(BridgeClient client); +#line 82 {{QuoteCppString .sketchMainFile}} +void digitalCommand(BridgeClient client); +#line 109 {{QuoteCppString .sketchMainFile}} +void analogCommand(BridgeClient client); +#line 149 {{QuoteCppString .sketchMainFile}} +void modeCommand(BridgeClient client); +#line 33 {{QuoteCppString .sketchMainFile}} +void setup() { + // Bridge startup + pinMode(13, OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); + digitalWrite(13, HIGH); + + // Listen for incoming connection only from localhost + // (no one from the external network could connect) + server.listenOnLocalhost(); + server.begin(); +} + +void loop() { + // Get clients coming from server + BridgeClient client = server.accept(); + + // There is a new client? + if (client) { + // Process request + process(client); + + // Close connection and free resources. + client.stop(); + } + + delay(50); // Poll every 50ms +} + +void process(BridgeClient client) { + // read the command + String command = client.readStringUntil('/'); + + // is "digital" command? + if (command == "digital") { + digitalCommand(client); + } + + // is "analog" command? + if (command == "analog") { + analogCommand(client); + } + + // is "mode" command? + if (command == "mode") { + modeCommand(client); + } +} + +void digitalCommand(BridgeClient client) { + int pin, value; + + // Read pin number + pin = client.parseInt(); + + // If the next character is a '/' it means we have an URL + // with a value like: "/digital/13/1" + if (client.read() == '/') { + value = client.parseInt(); + digitalWrite(pin, value); + } else { + value = digitalRead(pin); + } + + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" set to ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "D"; + key += pin; + Bridge.put(key, String(value)); +} + +void analogCommand(BridgeClient client) { + int pin, value; + + // Read pin number + pin = client.parseInt(); + + // If the next character is a '/' it means we have an URL + // with a value like: "/analog/5/120" + if (client.read() == '/') { + // Read value and execute command + value = client.parseInt(); + analogWrite(pin, value); + + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" set to analog ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "D"; + key += pin; + Bridge.put(key, String(value)); + } else { + // Read analog pin + value = analogRead(pin); + + // Send feedback to client + client.print(F("Pin A")); + client.print(pin); + client.print(F(" reads analog ")); + client.println(value); + + // Update datastore key with the current pin value + String key = "A"; + key += pin; + Bridge.put(key, String(value)); + } +} + +void modeCommand(BridgeClient client) { + int pin; + + // Read pin number + pin = client.parseInt(); + + // If the next character is not a '/' we have a malformed URL + if (client.read() != '/') { + client.println(F("error")); + return; + } + + String mode = client.readStringUntil('\r'); + + if (mode == "input") { + pinMode(pin, INPUT); + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" configured as INPUT!")); + return; + } + + if (mode == "output") { + pinMode(pin, OUTPUT); + // Send feedback to client + client.print(F("Pin D")); + client.print(pin); + client.print(F(" configured as OUTPUT!")); + return; + } + + client.print(F("error: invalid mode ")); + client.print(mode); +} + + + diff --git a/legacy/builder/test/sketch_no_functions/sketch_no_functions.ino b/internal/integrationtest/compile_4/testdata/SketchNoFunctionsTwoFiles/SketchNoFunctionsTwoFiles.ino similarity index 100% rename from legacy/builder/test/sketch_no_functions/sketch_no_functions.ino rename to internal/integrationtest/compile_4/testdata/SketchNoFunctionsTwoFiles/SketchNoFunctionsTwoFiles.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchNoFunctionsTwoFiles/SketchNoFunctionsTwoFiles.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchNoFunctionsTwoFiles/SketchNoFunctionsTwoFiles.preprocessed.txt new file mode 100644 index 00000000000..d90053a8799 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchNoFunctionsTwoFiles/SketchNoFunctionsTwoFiles.preprocessed.txt @@ -0,0 +1,16 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +/* + +Test sketch + + + +*/ + + +#line 1 {{QuoteCppString ( .sketchDir.Join "partb.ino" ) }} +#include + +int a = 0; +int b = 0; diff --git a/legacy/builder/test/sketch_no_functions_two_files/partb.ino b/internal/integrationtest/compile_4/testdata/SketchNoFunctionsTwoFiles/partb.ino similarity index 100% rename from legacy/builder/test/sketch_no_functions_two_files/partb.ino rename to internal/integrationtest/compile_4/testdata/SketchNoFunctionsTwoFiles/partb.ino diff --git a/legacy/builder/test/eol_processing/eol_processing.ino b/internal/integrationtest/compile_4/testdata/SketchRequiringEOLProcessing/SketchRequiringEOLProcessing.ino similarity index 100% rename from legacy/builder/test/eol_processing/eol_processing.ino rename to internal/integrationtest/compile_4/testdata/SketchRequiringEOLProcessing/SketchRequiringEOLProcessing.ino diff --git a/legacy/builder/test/sketch_that_checks_if_SPI_has_transactions/sketch_that_checks_if_SPI_has_transactions.ino b/internal/integrationtest/compile_4/testdata/SketchThatChecksIfSPIHasTransactions/SketchThatChecksIfSPIHasTransactions.ino similarity index 100% rename from legacy/builder/test/sketch_that_checks_if_SPI_has_transactions/sketch_that_checks_if_SPI_has_transactions.ino rename to internal/integrationtest/compile_4/testdata/SketchThatChecksIfSPIHasTransactions/SketchThatChecksIfSPIHasTransactions.ino diff --git a/legacy/builder/test/sketch_with_backup_files/sketch_with_backup_files.ino b/internal/integrationtest/compile_4/testdata/SketchWithBackupFiles/SketchWithBackupFiles.ino similarity index 100% rename from legacy/builder/test/sketch_with_backup_files/sketch_with_backup_files.ino rename to internal/integrationtest/compile_4/testdata/SketchWithBackupFiles/SketchWithBackupFiles.ino diff --git a/legacy/builder/test/sketch_with_backup_files/backup/sketch_with_backup_files.ino b/internal/integrationtest/compile_4/testdata/SketchWithBackupFiles/backup/SketchWithBackupFiles.ino similarity index 100% rename from legacy/builder/test/sketch_with_backup_files/backup/sketch_with_backup_files.ino rename to internal/integrationtest/compile_4/testdata/SketchWithBackupFiles/backup/SketchWithBackupFiles.ino diff --git a/legacy/builder/test/sketch_with_class/sketch_with_class.ino b/internal/integrationtest/compile_4/testdata/SketchWithClass/SketchWithClass.ino similarity index 100% rename from legacy/builder/test/sketch_with_class/sketch_with_class.ino rename to internal/integrationtest/compile_4/testdata/SketchWithClass/SketchWithClass.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithClass/SketchWithClass.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithClass/SketchWithClass.preprocessed.txt new file mode 100644 index 00000000000..5b7d102643c --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithClass/SketchWithClass.preprocessed.txt @@ -0,0 +1,26 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +class Rectangle { + int width, height; + public: + void set_values (int,int); + int area() {return width*height;} +}; + +void Rectangle::set_values (int x, int y) { + width = x; + height = y; +} + +#line 13 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 17 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 13 {{QuoteCppString .sketchMainFile}} +void setup() { + +} + +void loop() { + +} diff --git a/legacy/builder/test/sketch_with_class_and_method_substring/sketch_with_class_and_method_substring.ino b/internal/integrationtest/compile_4/testdata/SketchWithClassAndMethodSubstring/SketchWithClassAndMethodSubstring.ino similarity index 68% rename from legacy/builder/test/sketch_with_class_and_method_substring/sketch_with_class_and_method_substring.ino rename to internal/integrationtest/compile_4/testdata/SketchWithClassAndMethodSubstring/SketchWithClassAndMethodSubstring.ino index d933816a800..ce055e83044 100644 --- a/legacy/builder/test/sketch_with_class_and_method_substring/sketch_with_class_and_method_substring.ino +++ b/internal/integrationtest/compile_4/testdata/SketchWithClassAndMethodSubstring/SketchWithClassAndMethodSubstring.ino @@ -1,13 +1,14 @@ class Foo { +public: int blooper(int x) { return x+1; } }; Foo foo; void setup() { - foo.setup(); + foo.blooper(1); } void loop() { - foo.loop(); + foo.blooper(2); } diff --git a/internal/integrationtest/compile_4/testdata/SketchWithClassAndMethodSubstring/SketchWithClassAndMethodSubstring.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithClassAndMethodSubstring/SketchWithClassAndMethodSubstring.preprocessed.txt new file mode 100644 index 00000000000..ce5b8b79fb1 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithClassAndMethodSubstring/SketchWithClassAndMethodSubstring.preprocessed.txt @@ -0,0 +1,22 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +class Foo { +public: +int blooper(int x) { return x+1; } +}; + +Foo foo; + +#line 8 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 12 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 8 {{QuoteCppString .sketchMainFile}} +void setup() { + foo.blooper(1); +} + +void loop() { + foo.blooper(2); +} + diff --git a/legacy/builder/test/sketch_with_config/sketch_with_config.ino b/internal/integrationtest/compile_4/testdata/SketchWithConfig/SketchWithConfig.ino similarity index 100% rename from legacy/builder/test/sketch_with_config/sketch_with_config.ino rename to internal/integrationtest/compile_4/testdata/SketchWithConfig/SketchWithConfig.ino diff --git a/legacy/builder/test/sketch_with_config/sketch_with_config.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithConfig/SketchWithConfig.preprocessed.txt similarity index 53% rename from legacy/builder/test/sketch_with_config/sketch_with_config.preprocessed.txt rename to internal/integrationtest/compile_4/testdata/SketchWithConfig/SketchWithConfig.preprocessed.txt index e633c616300..e1bf315a04e 100644 --- a/legacy/builder/test/sketch_with_config/sketch_with_config.preprocessed.txt +++ b/internal/integrationtest/compile_4/testdata/SketchWithConfig/SketchWithConfig.preprocessed.txt @@ -1,5 +1,5 @@ #include -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} #include "config.h" #ifdef DEBUG @@ -12,11 +12,11 @@ #include -#line 13 {{QuoteCppString .sketch.MainFile}} +#line 13 {{QuoteCppString .sketchMainFile}} void setup(); -#line 17 {{QuoteCppString .sketch.MainFile}} +#line 17 {{QuoteCppString .sketchMainFile}} void loop(); -#line 13 {{QuoteCppString .sketch.MainFile}} +#line 13 {{QuoteCppString .sketchMainFile}} void setup() { } diff --git a/legacy/builder/test/sketch_with_config/config.h b/internal/integrationtest/compile_4/testdata/SketchWithConfig/config.h similarity index 100% rename from legacy/builder/test/sketch_with_config/config.h rename to internal/integrationtest/compile_4/testdata/SketchWithConfig/config.h diff --git a/legacy/builder/test/sketch_with_config/src/includes/de bug.cpp b/internal/integrationtest/compile_4/testdata/SketchWithConfig/src/includes/de bug.cpp similarity index 100% rename from legacy/builder/test/sketch_with_config/src/includes/de bug.cpp rename to internal/integrationtest/compile_4/testdata/SketchWithConfig/src/includes/de bug.cpp diff --git a/legacy/builder/test/sketch_with_config/src/includes/de bug.h b/internal/integrationtest/compile_4/testdata/SketchWithConfig/src/includes/de bug.h similarity index 100% rename from legacy/builder/test/sketch_with_config/src/includes/de bug.h rename to internal/integrationtest/compile_4/testdata/SketchWithConfig/src/includes/de bug.h diff --git a/legacy/builder/test/sketch9/sketch9.ino b/internal/integrationtest/compile_4/testdata/SketchWithConflictingLibraries/SketchWithConflictingLibraries.ino similarity index 84% rename from legacy/builder/test/sketch9/sketch9.ino rename to internal/integrationtest/compile_4/testdata/SketchWithConflictingLibraries/SketchWithConflictingLibraries.ino index 105b1014b73..cf22dfedaea 100644 --- a/legacy/builder/test/sketch9/sketch9.ino +++ b/internal/integrationtest/compile_4/testdata/SketchWithConflictingLibraries/SketchWithConflictingLibraries.ino @@ -3,4 +3,4 @@ #include void setup() {} -void loop() {} \ No newline at end of file +void loop() {} diff --git a/legacy/builder/test/sketch_with_const/sketch_with_const.ino b/internal/integrationtest/compile_4/testdata/SketchWithConst/SketchWithConst.ino similarity index 100% rename from legacy/builder/test/sketch_with_const/sketch_with_const.ino rename to internal/integrationtest/compile_4/testdata/SketchWithConst/SketchWithConst.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithConst/SketchWithConst.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithConst/SketchWithConst.preprocessed.txt new file mode 100644 index 00000000000..988fe42c407 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithConst/SketchWithConst.preprocessed.txt @@ -0,0 +1,26 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 2 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 4 {{QuoteCppString .sketchMainFile}} +const __FlashStringHelper* test(); +#line 6 {{QuoteCppString .sketchMainFile}} +const int test3(); +#line 8 {{QuoteCppString .sketchMainFile}} +volatile __FlashStringHelper* test2(); +#line 10 {{QuoteCppString .sketchMainFile}} +volatile int test4(); +#line 1 {{QuoteCppString .sketchMainFile}} +void setup() {} +void loop() {} + +const __FlashStringHelper* test() {} + +const int test3() {} + +volatile __FlashStringHelper* test2() {} + +volatile int test4() {} + diff --git a/legacy/builder/test/sketch_with_default_args/sketch_with_default_args.ino b/internal/integrationtest/compile_4/testdata/SketchWithDefaultArgs/SketchWithDefaultArgs.ino similarity index 100% rename from legacy/builder/test/sketch_with_default_args/sketch_with_default_args.ino rename to internal/integrationtest/compile_4/testdata/SketchWithDefaultArgs/SketchWithDefaultArgs.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithDefaultArgs/SketchWithDefaultArgs.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithDefaultArgs/SketchWithDefaultArgs.preprocessed.txt new file mode 100644 index 00000000000..9a4f827cc12 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithDefaultArgs/SketchWithDefaultArgs.preprocessed.txt @@ -0,0 +1,15 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +#line 4 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 7 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 1 {{QuoteCppString .sketchMainFile}} +void test(int x = 1) { +} + +void setup() { +} + +void loop() { +} diff --git a/internal/integrationtest/compile_4/testdata/SketchWithDependendLibraries/SketchWithDependendLibraries.ino b/internal/integrationtest/compile_4/testdata/SketchWithDependendLibraries/SketchWithDependendLibraries.ino new file mode 100644 index 00000000000..1183d9b748e --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithDependendLibraries/SketchWithDependendLibraries.ino @@ -0,0 +1,4 @@ +#include + +void setup() {} +void loop() {} diff --git a/legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.ino b/internal/integrationtest/compile_4/testdata/SketchWithEscapedDoubleQuote/SketchWithEscapedDoubleQuote.ino similarity index 100% rename from legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.ino rename to internal/integrationtest/compile_4/testdata/SketchWithEscapedDoubleQuote/SketchWithEscapedDoubleQuote.ino diff --git a/legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithEscapedDoubleQuote/SketchWithEscapedDoubleQuote.preprocessed.txt similarity index 92% rename from legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.preprocessed.txt rename to internal/integrationtest/compile_4/testdata/SketchWithEscapedDoubleQuote/SketchWithEscapedDoubleQuote.preprocessed.txt index e6363b45861..6a0676d1146 100644 --- a/legacy/builder/test/CharWithEscapedDoubleQuote/CharWithEscapedDoubleQuote.preprocessed.txt +++ b/internal/integrationtest/compile_4/testdata/SketchWithEscapedDoubleQuote/SketchWithEscapedDoubleQuote.preprocessed.txt @@ -1,5 +1,5 @@ #include -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} #include // required to send and receive AT commands from the GPRS Shield #include // required for I2C communication with the RTC @@ -38,49 +38,49 @@ Code Exclusively for GPRS shield: // Default set of instructions for GPRS Shield power control // -#line 39 {{QuoteCppString .sketch.MainFile}} +#line 39 {{QuoteCppString .sketchMainFile}} void setPowerStateTo( int newState ); -#line 64 {{QuoteCppString .sketch.MainFile}} +#line 64 {{QuoteCppString .sketchMainFile}} int getPowerState(); -#line 75 {{QuoteCppString .sketch.MainFile}} +#line 75 {{QuoteCppString .sketchMainFile}} void powerUpOrDown(); -#line 90 {{QuoteCppString .sketch.MainFile}} +#line 90 {{QuoteCppString .sketchMainFile}} void clearBufferArray(); -#line 96 {{QuoteCppString .sketch.MainFile}} +#line 96 {{QuoteCppString .sketchMainFile}} void makeMissedCall( char num[] ); -#line 111 {{QuoteCppString .sketch.MainFile}} +#line 111 {{QuoteCppString .sketchMainFile}} void sendTextMessage( char number[], char messg[] ); -#line 129 {{QuoteCppString .sketch.MainFile}} +#line 129 {{QuoteCppString .sketchMainFile}} void analise(byte incoming[], int length); -#line 179 {{QuoteCppString .sketch.MainFile}} +#line 179 {{QuoteCppString .sketchMainFile}} byte decToBcd( byte b ); -#line 184 {{QuoteCppString .sketch.MainFile}} +#line 184 {{QuoteCppString .sketchMainFile}} boolean getBit( byte addr, int pos ); -#line 190 {{QuoteCppString .sketch.MainFile}} +#line 190 {{QuoteCppString .sketchMainFile}} void setBit( byte addr, int pos, boolean newBit ); -#line 204 {{QuoteCppString .sketch.MainFile}} +#line 204 {{QuoteCppString .sketchMainFile}} byte getByte( byte addr ); -#line 213 {{QuoteCppString .sketch.MainFile}} +#line 213 {{QuoteCppString .sketchMainFile}} boolean getBytes( byte addr, int amount ); -#line 230 {{QuoteCppString .sketch.MainFile}} +#line 230 {{QuoteCppString .sketchMainFile}} void setByte( byte addr, byte newByte ); -#line 235 {{QuoteCppString .sketch.MainFile}} +#line 235 {{QuoteCppString .sketchMainFile}} void setBytes( byte addr, byte newBytes[], int amount ); -#line 244 {{QuoteCppString .sketch.MainFile}} +#line 244 {{QuoteCppString .sketchMainFile}} void getTime(); -#line 260 {{QuoteCppString .sketch.MainFile}} +#line 260 {{QuoteCppString .sketchMainFile}} void setTime( byte newTime[ 7 ] ); -#line 267 {{QuoteCppString .sketch.MainFile}} +#line 267 {{QuoteCppString .sketchMainFile}} void getRTCTemperature(); -#line 277 {{QuoteCppString .sketch.MainFile}} +#line 277 {{QuoteCppString .sketchMainFile}} void gprsListen(); -#line 294 {{QuoteCppString .sketch.MainFile}} +#line 294 {{QuoteCppString .sketchMainFile}} void printTime(); -#line 317 {{QuoteCppString .sketch.MainFile}} +#line 317 {{QuoteCppString .sketchMainFile}} void setup(); -#line 334 {{QuoteCppString .sketch.MainFile}} +#line 334 {{QuoteCppString .sketchMainFile}} void loop(); -#line 39 {{QuoteCppString .sketch.MainFile}} +#line 39 {{QuoteCppString .sketchMainFile}} void setPowerStateTo( int newState ) { if( newState != 1 && newState != 0 ) { // tests for an invalid state. In this case no change is made to powerstate diff --git a/legacy/builder/test/sketch_with_function_pointer/CallbackBug.h b/internal/integrationtest/compile_4/testdata/SketchWithFunctionPointer/CallbackBug.h similarity index 100% rename from legacy/builder/test/sketch_with_function_pointer/CallbackBug.h rename to internal/integrationtest/compile_4/testdata/SketchWithFunctionPointer/CallbackBug.h diff --git a/legacy/builder/test/sketch_with_function_pointer/sketch_with_function_pointer.ino b/internal/integrationtest/compile_4/testdata/SketchWithFunctionPointer/SketchWithFunctionPointer.ino similarity index 100% rename from legacy/builder/test/sketch_with_function_pointer/sketch_with_function_pointer.ino rename to internal/integrationtest/compile_4/testdata/SketchWithFunctionPointer/SketchWithFunctionPointer.ino diff --git a/legacy/builder/test/sketch_with_function_signature_inside_ifdef/sketch_with_function_signature_inside_ifdef.ino b/internal/integrationtest/compile_4/testdata/SketchWithFunctionSignatureInsideIfdef/SketchWithFunctionSignatureInsideIfdef.ino similarity index 100% rename from legacy/builder/test/sketch_with_function_signature_inside_ifdef/sketch_with_function_signature_inside_ifdef.ino rename to internal/integrationtest/compile_4/testdata/SketchWithFunctionSignatureInsideIfdef/SketchWithFunctionSignatureInsideIfdef.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithFunctionSignatureInsideIfdef/SketchWithFunctionSignatureInsideIfdef.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithFunctionSignatureInsideIfdef/SketchWithFunctionSignatureInsideIfdef.preprocessed.txt new file mode 100644 index 00000000000..fb05ef65dd6 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithFunctionSignatureInsideIfdef/SketchWithFunctionSignatureInsideIfdef.preprocessed.txt @@ -0,0 +1,30 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 3 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 15 {{QuoteCppString .sketchMainFile}} +int8_t adalight(); +#line 1 {{QuoteCppString .sketchMainFile}} +void setup() {} + +void loop() { + // Visualize leds via Adalight + int8_t newData = adalight(); + +} + + +//#define ADALIGHT_USE_TEMPLATE + +#ifdef ADALIGHT_USE_TEMPLATE +int16_t adalight() +#else +int8_t adalight() +#endif +{ + // Flag if the leds got a new frame that should be updated + return 0; +} + diff --git a/legacy/builder/test/SketchWithIfDef/SketchWithIfDef.ino b/internal/integrationtest/compile_4/testdata/SketchWithIfDef/SketchWithIfDef.ino similarity index 100% rename from legacy/builder/test/SketchWithIfDef/SketchWithIfDef.ino rename to internal/integrationtest/compile_4/testdata/SketchWithIfDef/SketchWithIfDef.ino diff --git a/legacy/builder/test/SketchWithIfDef/SketchWithIfDef.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithIfDef/SketchWithIfDef.preprocessed.txt similarity index 67% rename from legacy/builder/test/SketchWithIfDef/SketchWithIfDef.preprocessed.txt rename to internal/integrationtest/compile_4/testdata/SketchWithIfDef/SketchWithIfDef.preprocessed.txt index 4faa5fe83e3..ae2fd48d4db 100644 --- a/legacy/builder/test/SketchWithIfDef/SketchWithIfDef.preprocessed.txt +++ b/internal/integrationtest/compile_4/testdata/SketchWithIfDef/SketchWithIfDef.preprocessed.txt @@ -1,5 +1,5 @@ #include -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} #define DEBUG 1 #define DISABLED 0 @@ -15,17 +15,17 @@ typedef int MyType; #include "empty_2.h" -#line 16 {{QuoteCppString .sketch.MainFile}} +#line 16 {{QuoteCppString .sketchMainFile}} void setup(); -#line 21 {{QuoteCppString .sketch.MainFile}} +#line 21 {{QuoteCppString .sketchMainFile}} void loop(); -#line 33 {{QuoteCppString .sketch.MainFile}} +#line 33 {{QuoteCppString .sketchMainFile}} void debug(); -#line 44 {{QuoteCppString .sketch.MainFile}} +#line 44 {{QuoteCppString .sketchMainFile}} void disabledIsDefined(); -#line 48 {{QuoteCppString .sketch.MainFile}} +#line 48 {{QuoteCppString .sketchMainFile}} int useMyType(MyType type); -#line 16 {{QuoteCppString .sketch.MainFile}} +#line 16 {{QuoteCppString .sketchMainFile}} void setup() { // put your setup code here, to run once: diff --git a/legacy/builder/test/SketchWithIfDef/SketchWithIfDef.resolved.directives.txt b/internal/integrationtest/compile_4/testdata/SketchWithIfDef/SketchWithIfDef.resolved.directives.txt similarity index 100% rename from legacy/builder/test/SketchWithIfDef/SketchWithIfDef.resolved.directives.txt rename to internal/integrationtest/compile_4/testdata/SketchWithIfDef/SketchWithIfDef.resolved.directives.txt diff --git a/legacy/builder/test/SketchWithIfDef/empty_1.h b/internal/integrationtest/compile_4/testdata/SketchWithIfDef/empty_1.h similarity index 100% rename from legacy/builder/test/SketchWithIfDef/empty_1.h rename to internal/integrationtest/compile_4/testdata/SketchWithIfDef/empty_1.h diff --git a/legacy/builder/test/SketchWithIfDef/empty_2.h b/internal/integrationtest/compile_4/testdata/SketchWithIfDef/empty_2.h similarity index 100% rename from legacy/builder/test/SketchWithIfDef/empty_2.h rename to internal/integrationtest/compile_4/testdata/SketchWithIfDef/empty_2.h diff --git a/legacy/builder/test/sketch_with_ifdef/sketch_with_ifdef.ino b/internal/integrationtest/compile_4/testdata/SketchWithIfDef2/SketchWithIfDef2.ino similarity index 100% rename from legacy/builder/test/sketch_with_ifdef/sketch_with_ifdef.ino rename to internal/integrationtest/compile_4/testdata/SketchWithIfDef2/SketchWithIfDef2.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithIfDef2/SketchWithIfDef2.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithIfDef2/SketchWithIfDef2.preprocessed.txt new file mode 100644 index 00000000000..788ad96d272 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithIfDef2/SketchWithIfDef2.preprocessed.txt @@ -0,0 +1,28 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +#if __SAM3X8E__ +void ifBranch() { +} +#else +#line 5 {{QuoteCppString .sketchMainFile}} +void elseBranch(); +#line 9 {{QuoteCppString .sketchMainFile}} +void f1(); +#line 10 {{QuoteCppString .sketchMainFile}} +void f2(); +#line 12 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 14 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 5 {{QuoteCppString .sketchMainFile}} +void elseBranch() { +} +#endif + +void f1(){ f2(); } +void f2(){;} + +void setup() { +} +void loop() { +} diff --git a/internal/integrationtest/compile_4/testdata/SketchWithIfDef3/SketchWithIfDef3.ino b/internal/integrationtest/compile_4/testdata/SketchWithIfDef3/SketchWithIfDef3.ino new file mode 100644 index 00000000000..3d3e2f49ca5 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithIfDef3/SketchWithIfDef3.ino @@ -0,0 +1,15 @@ +#if __SAM3X8E__ +void ifBranch() { +} +#else +void elseBranch() { +} +#endif + +void f1(){ f2(); } +void f2(){;} + +void setup() { +} +void loop() { +} \ No newline at end of file diff --git a/internal/integrationtest/compile_4/testdata/SketchWithIfDef3/SketchWithIfDef3.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithIfDef3/SketchWithIfDef3.preprocessed.txt new file mode 100644 index 00000000000..1b2b05c65d4 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithIfDef3/SketchWithIfDef3.preprocessed.txt @@ -0,0 +1,28 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +#if __SAM3X8E__ +#line 2 {{QuoteCppString .sketchMainFile}} +void ifBranch(); +#line 9 {{QuoteCppString .sketchMainFile}} +void f1(); +#line 10 {{QuoteCppString .sketchMainFile}} +void f2(); +#line 12 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 14 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 2 {{QuoteCppString .sketchMainFile}} +void ifBranch() { +} +#else +void elseBranch() { +} +#endif + +void f1(){ f2(); } +void f2(){;} + +void setup() { +} +void loop() { +} diff --git a/legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.ino b/internal/integrationtest/compile_4/testdata/SketchWithIncludeBetweenMultilineComment/SketchWithIncludeBetweenMultilineComment.ino similarity index 100% rename from legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.ino rename to internal/integrationtest/compile_4/testdata/SketchWithIncludeBetweenMultilineComment/SketchWithIncludeBetweenMultilineComment.ino diff --git a/legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithIncludeBetweenMultilineComment/SketchWithIncludeBetweenMultilineComment.preprocessed.txt similarity index 62% rename from legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.preprocessed.txt rename to internal/integrationtest/compile_4/testdata/SketchWithIncludeBetweenMultilineComment/SketchWithIncludeBetweenMultilineComment.preprocessed.txt index a4890529793..209788e5a8a 100644 --- a/legacy/builder/test/IncludeBetweenMultilineComment/IncludeBetweenMultilineComment.preprocessed.txt +++ b/internal/integrationtest/compile_4/testdata/SketchWithIncludeBetweenMultilineComment/SketchWithIncludeBetweenMultilineComment.preprocessed.txt @@ -1,15 +1,15 @@ #include -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} #include /* #include */ CapacitiveSensor cs_13_8 = CapacitiveSensor(13,8); -#line 6 {{QuoteCppString .sketch.MainFile}} +#line 6 {{QuoteCppString .sketchMainFile}} void setup(); -#line 10 {{QuoteCppString .sketch.MainFile}} +#line 10 {{QuoteCppString .sketchMainFile}} void loop(); -#line 6 {{QuoteCppString .sketch.MainFile}} +#line 6 {{QuoteCppString .sketchMainFile}} void setup() { Serial.begin(9600); diff --git a/legacy/builder/test/sketch_with_inline_function/sketch_with_inline_function.ino b/internal/integrationtest/compile_4/testdata/SketchWithInlineFunction/SketchWithInlineFunction.ino similarity index 100% rename from legacy/builder/test/sketch_with_inline_function/sketch_with_inline_function.ino rename to internal/integrationtest/compile_4/testdata/SketchWithInlineFunction/SketchWithInlineFunction.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithInlineFunction/SketchWithInlineFunction.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithInlineFunction/SketchWithInlineFunction.preprocessed.txt new file mode 100644 index 00000000000..462cf889077 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithInlineFunction/SketchWithInlineFunction.preprocessed.txt @@ -0,0 +1,28 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 2 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 4 {{QuoteCppString .sketchMainFile}} +short unsigned int testInt(); +#line 8 {{QuoteCppString .sketchMainFile}} +static int8_t testInline(); +#line 12 {{QuoteCppString .sketchMainFile}} +uint8_t testAttribute(); +#line 1 {{QuoteCppString .sketchMainFile}} +void setup() {} +void loop() {} + +short unsigned int testInt(){ + +} + +static inline int8_t testInline(){ + +} + +__attribute__((always_inline)) uint8_t testAttribute() { + +} + diff --git a/legacy/builder/test/LineContinuations/LineContinuations.ino b/internal/integrationtest/compile_4/testdata/SketchWithLineContinuations/SketchWithLineContinuations.ino similarity index 100% rename from legacy/builder/test/LineContinuations/LineContinuations.ino rename to internal/integrationtest/compile_4/testdata/SketchWithLineContinuations/SketchWithLineContinuations.ino diff --git a/legacy/builder/test/LineContinuations/LineContinuations.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithLineContinuations/SketchWithLineContinuations.preprocessed.txt similarity index 90% rename from legacy/builder/test/LineContinuations/LineContinuations.preprocessed.txt rename to internal/integrationtest/compile_4/testdata/SketchWithLineContinuations/SketchWithLineContinuations.preprocessed.txt index 6338d8366f3..04dd08c00fe 100644 --- a/legacy/builder/test/LineContinuations/LineContinuations.preprocessed.txt +++ b/internal/integrationtest/compile_4/testdata/SketchWithLineContinuations/SketchWithLineContinuations.preprocessed.txt @@ -1,16 +1,16 @@ #include -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} const char *foo = "\ hello \ world\n"; //" delete this comment line and the IDE parser will crash -#line 7 {{QuoteCppString .sketch.MainFile}} +#line 7 {{QuoteCppString .sketchMainFile}} void setup(); -#line 11 {{QuoteCppString .sketch.MainFile}} +#line 11 {{QuoteCppString .sketchMainFile}} void loop(); -#line 7 {{QuoteCppString .sketch.MainFile}} +#line 7 {{QuoteCppString .sketchMainFile}} void setup() { } diff --git a/legacy/builder/test/sketch_with_macosx_garbage/.#sketch.ino b/internal/integrationtest/compile_4/testdata/SketchWithMacosxGarbage/.#sketch.ino similarity index 100% rename from legacy/builder/test/sketch_with_macosx_garbage/.#sketch.ino rename to internal/integrationtest/compile_4/testdata/SketchWithMacosxGarbage/.#sketch.ino diff --git a/legacy/builder/test/sketch_with_macosx_garbage/sketch_with_macosx_garbage.ino b/internal/integrationtest/compile_4/testdata/SketchWithMacosxGarbage/SketchWithMacosxGarbage.ino similarity index 100% rename from legacy/builder/test/sketch_with_macosx_garbage/sketch_with_macosx_garbage.ino rename to internal/integrationtest/compile_4/testdata/SketchWithMacosxGarbage/SketchWithMacosxGarbage.ino diff --git a/legacy/builder/test/sketch_with_namespace/sketch_with_namespace.ino b/internal/integrationtest/compile_4/testdata/SketchWithNamespace/SketchWithNamespace.ino similarity index 100% rename from legacy/builder/test/sketch_with_namespace/sketch_with_namespace.ino rename to internal/integrationtest/compile_4/testdata/SketchWithNamespace/SketchWithNamespace.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithNamespace/SketchWithNamespace.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithNamespace/SketchWithNamespace.preprocessed.txt new file mode 100644 index 00000000000..80c5b9aea61 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithNamespace/SketchWithNamespace.preprocessed.txt @@ -0,0 +1,16 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +namespace Test { + int value() { + return 42; + } + int ciao = 24; +} +#line 7 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 8 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 7 {{QuoteCppString .sketchMainFile}} +void setup() {} +void loop() {} + diff --git a/legacy/builder/test/sketch_with_old_lib/sketch_with_old_lib.ino b/internal/integrationtest/compile_4/testdata/SketchWithOldLibrary/SketchWithOldLibrary.ino similarity index 100% rename from legacy/builder/test/sketch_with_old_lib/sketch_with_old_lib.ino rename to internal/integrationtest/compile_4/testdata/SketchWithOldLibrary/SketchWithOldLibrary.ino diff --git a/legacy/builder/test/StringWithComment/StringWithComment.ino b/internal/integrationtest/compile_4/testdata/SketchWithStringWithComment/SketchWithStringWithComment.ino similarity index 100% rename from legacy/builder/test/StringWithComment/StringWithComment.ino rename to internal/integrationtest/compile_4/testdata/SketchWithStringWithComment/SketchWithStringWithComment.ino diff --git a/legacy/builder/test/StringWithComment/StringWithComment.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithStringWithComment/SketchWithStringWithComment.preprocessed.txt similarity index 67% rename from legacy/builder/test/StringWithComment/StringWithComment.preprocessed.txt rename to internal/integrationtest/compile_4/testdata/SketchWithStringWithComment/SketchWithStringWithComment.preprocessed.txt index 23677ef8ec8..6766b81ff08 100644 --- a/legacy/builder/test/StringWithComment/StringWithComment.preprocessed.txt +++ b/internal/integrationtest/compile_4/testdata/SketchWithStringWithComment/SketchWithStringWithComment.preprocessed.txt @@ -1,10 +1,10 @@ #include -#line 1 {{QuoteCppString .sketch.MainFile}} -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} void setup(); -#line 10 {{QuoteCppString .sketch.MainFile}} +#line 10 {{QuoteCppString .sketchMainFile}} void loop(); -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} void setup() { // put your setup code here, to run once: // "comment with a double quote diff --git a/legacy/builder/test/SketchWithStruct/SketchWithStruct.ino b/internal/integrationtest/compile_4/testdata/SketchWithStruct/SketchWithStruct.ino similarity index 100% rename from legacy/builder/test/SketchWithStruct/SketchWithStruct.ino rename to internal/integrationtest/compile_4/testdata/SketchWithStruct/SketchWithStruct.ino diff --git a/legacy/builder/test/SketchWithStruct/SketchWithStruct.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithStruct/SketchWithStruct.preprocessed.txt similarity index 52% rename from legacy/builder/test/SketchWithStruct/SketchWithStruct.preprocessed.txt rename to internal/integrationtest/compile_4/testdata/SketchWithStruct/SketchWithStruct.preprocessed.txt index 4dd1ae448a5..19201541a6b 100644 --- a/legacy/builder/test/SketchWithStruct/SketchWithStruct.preprocessed.txt +++ b/internal/integrationtest/compile_4/testdata/SketchWithStruct/SketchWithStruct.preprocessed.txt @@ -1,5 +1,5 @@ #include -#line 1 {{QuoteCppString .sketch.MainFile}} +#line 1 {{QuoteCppString .sketchMainFile}} /* START CODE */ struct A_NEW_TYPE { @@ -8,13 +8,13 @@ struct A_NEW_TYPE { int c; } foo; -#line 9 {{QuoteCppString .sketch.MainFile}} +#line 9 {{QuoteCppString .sketchMainFile}} void setup(); -#line 13 {{QuoteCppString .sketch.MainFile}} +#line 13 {{QuoteCppString .sketchMainFile}} void loop(); -#line 17 {{QuoteCppString .sketch.MainFile}} -void dostuff (A_NEW_TYPE * bar); -#line 9 {{QuoteCppString .sketch.MainFile}} +#line 17 {{QuoteCppString .sketchMainFile}} +void dostuff(A_NEW_TYPE * bar); +#line 9 {{QuoteCppString .sketchMainFile}} void setup() { } diff --git a/legacy/builder/test/sketch_with_subfolders/sketch_with_subfolders.ino b/internal/integrationtest/compile_4/testdata/SketchWithSubfolders/SketchWithSubfolders.ino similarity index 100% rename from legacy/builder/test/sketch_with_subfolders/sketch_with_subfolders.ino rename to internal/integrationtest/compile_4/testdata/SketchWithSubfolders/SketchWithSubfolders.ino diff --git a/legacy/builder/test/sketch_with_subfolders/src/subfolder/dont_load_me.ino b/internal/integrationtest/compile_4/testdata/SketchWithSubfolders/src/subfolder/dont_load_me.ino similarity index 100% rename from legacy/builder/test/sketch_with_subfolders/src/subfolder/dont_load_me.ino rename to internal/integrationtest/compile_4/testdata/SketchWithSubfolders/src/subfolder/dont_load_me.ino diff --git a/legacy/builder/test/sketch_with_subfolders/src/subfolder/other.cpp b/internal/integrationtest/compile_4/testdata/SketchWithSubfolders/src/subfolder/other.cpp similarity index 100% rename from legacy/builder/test/sketch_with_subfolders/src/subfolder/other.cpp rename to internal/integrationtest/compile_4/testdata/SketchWithSubfolders/src/subfolder/other.cpp diff --git a/legacy/builder/test/sketch_with_subfolders/src/subfolder/other.h b/internal/integrationtest/compile_4/testdata/SketchWithSubfolders/src/subfolder/other.h similarity index 100% rename from legacy/builder/test/sketch_with_subfolders/src/subfolder/other.h rename to internal/integrationtest/compile_4/testdata/SketchWithSubfolders/src/subfolder/other.h diff --git a/legacy/builder/test/sketch_with_subfolders/subfolder/dont_load_me.cpp b/internal/integrationtest/compile_4/testdata/SketchWithSubfolders/subfolder/dont_load_me.cpp similarity index 100% rename from legacy/builder/test/sketch_with_subfolders/subfolder/dont_load_me.cpp rename to internal/integrationtest/compile_4/testdata/SketchWithSubfolders/subfolder/dont_load_me.cpp diff --git a/legacy/builder/test/sketch_with_subfolders/subfolder/dont_load_me.ino b/internal/integrationtest/compile_4/testdata/SketchWithSubfolders/subfolder/dont_load_me.ino similarity index 100% rename from legacy/builder/test/sketch_with_subfolders/subfolder/dont_load_me.ino rename to internal/integrationtest/compile_4/testdata/SketchWithSubfolders/subfolder/dont_load_me.ino diff --git a/legacy/builder/test/sketch_with_subfolders/subfolder/other.h b/internal/integrationtest/compile_4/testdata/SketchWithSubfolders/subfolder/other.h similarity index 100% rename from legacy/builder/test/sketch_with_subfolders/subfolder/other.h rename to internal/integrationtest/compile_4/testdata/SketchWithSubfolders/subfolder/other.h diff --git a/legacy/builder/test/sketch_with_templates_and_shift/sketch_with_templates_and_shift.ino b/internal/integrationtest/compile_4/testdata/SketchWithTemplatesAndShift/SketchWithTemplatesAndShift.ino similarity index 100% rename from legacy/builder/test/sketch_with_templates_and_shift/sketch_with_templates_and_shift.ino rename to internal/integrationtest/compile_4/testdata/SketchWithTemplatesAndShift/SketchWithTemplatesAndShift.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithTemplatesAndShift/SketchWithTemplatesAndShift.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithTemplatesAndShift/SketchWithTemplatesAndShift.preprocessed.txt new file mode 100644 index 00000000000..4c7bb18de00 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithTemplatesAndShift/SketchWithTemplatesAndShift.preprocessed.txt @@ -0,0 +1,27 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +template<> class FastPin<0> : public _ARMPIN<0, 10, 1 << 10, 0> {};; + +template<> class FastPin<0> : public _ARMPIN<0, 10, 1 < 10, 0> {};; + +template class OtherType> class NestedTemplateClass +{ + OtherType f; +}; + +#line 10 {{QuoteCppString .sketchMainFile}} +void printGyro(); +#line 18 {{QuoteCppString .sketchMainFile}} +template func( c< 1< & aParam) ; +#line 10 {{QuoteCppString .sketchMainFile}} +void printGyro() +{ +} + +template class c {}; +c< 8 > bVar; +c< 1<<8 > aVar; + +template func( c< 1< & aParam) { +} + diff --git a/legacy/builder/test/sketch_with_typename/sketch_with_typename.ino b/internal/integrationtest/compile_4/testdata/SketchWithTypename/SketchWithTypename.ino similarity index 100% rename from legacy/builder/test/sketch_with_typename/sketch_with_typename.ino rename to internal/integrationtest/compile_4/testdata/SketchWithTypename/SketchWithTypename.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithTypename/SketchWithTypename.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithTypename/SketchWithTypename.preprocessed.txt new file mode 100644 index 00000000000..d9249812c41 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithTypename/SketchWithTypename.preprocessed.txt @@ -0,0 +1,24 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +template< typename T > + struct Foo{ + typedef T Bar; +}; + +#line 6 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 10 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 12 +Foo::Bar func(); +#line 6 {{QuoteCppString .sketchMainFile}} +void setup() { + func(); +} + +void loop() {} + +typename Foo::Bar func(){ + +} + diff --git a/legacy/builder/test/sketch_with_usbcon/sketch_with_usbcon.ino b/internal/integrationtest/compile_4/testdata/SketchWithUsbcon/SketchWithUsbcon.ino similarity index 100% rename from legacy/builder/test/sketch_with_usbcon/sketch_with_usbcon.ino rename to internal/integrationtest/compile_4/testdata/SketchWithUsbcon/SketchWithUsbcon.ino diff --git a/internal/integrationtest/compile_4/testdata/SketchWithUsbcon/SketchWithUsbcon.preprocessed.txt b/internal/integrationtest/compile_4/testdata/SketchWithUsbcon/SketchWithUsbcon.preprocessed.txt new file mode 100644 index 00000000000..355d86f5b74 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/SketchWithUsbcon/SketchWithUsbcon.preprocessed.txt @@ -0,0 +1,27 @@ +#include +#line 1 {{QuoteCppString .sketchMainFile}} +#if !defined(USBCON) +#error "Where's my USBCON?" +#endif +#if defined(USBCON) +#line 5 {{QuoteCppString .sketchMainFile}} +void ciao(); +#line 10 {{QuoteCppString .sketchMainFile}} +void setup(); +#line 15 {{QuoteCppString .sketchMainFile}} +void loop(); +#line 5 {{QuoteCppString .sketchMainFile}} +void ciao() { + +} +#endif + +void setup() { + // put your setup code here, to run once: + +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/legacy/builder/test/sketch_no_functions_two_files/sketch_no_functions_two_files.ino b/internal/integrationtest/compile_4/testdata/SketchWithoutFunctions/SketchWithoutFunctions.ino similarity index 100% rename from legacy/builder/test/sketch_no_functions_two_files/sketch_no_functions_two_files.ino rename to internal/integrationtest/compile_4/testdata/SketchWithoutFunctions/SketchWithoutFunctions.ino diff --git a/legacy/builder/test/sketch_usbhost/sketch_usbhost.ino b/internal/integrationtest/compile_4/testdata/USBHostExample/USBHostExample.ino similarity index 100% rename from legacy/builder/test/sketch_usbhost/sketch_usbhost.ino rename to internal/integrationtest/compile_4/testdata/USBHostExample/USBHostExample.ino diff --git a/legacy/builder/test/dependent_libraries/library4/library4.h b/internal/integrationtest/compile_4/testdata/libraries/Balanduino/Balanduino.h similarity index 100% rename from legacy/builder/test/dependent_libraries/library4/library4.h rename to internal/integrationtest/compile_4/testdata/libraries/Balanduino/Balanduino.h diff --git a/internal/integrationtest/compile_4/testdata/libraries/Balanduino/Kalman.h b/internal/integrationtest/compile_4/testdata/libraries/Balanduino/Kalman.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/Balanduino/PS3BT.h b/internal/integrationtest/compile_4/testdata/libraries/Balanduino/PS3BT.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/Balanduino/SPP.h b/internal/integrationtest/compile_4/testdata/libraries/Balanduino/SPP.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/Balanduino/Wii.h b/internal/integrationtest/compile_4/testdata/libraries/Balanduino/Wii.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/Balanduino/XBOXRECV.h b/internal/integrationtest/compile_4/testdata/libraries/Balanduino/XBOXRECV.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/Balanduino/adk.h b/internal/integrationtest/compile_4/testdata/libraries/Balanduino/adk.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/Balanduino/usbhub.h b/internal/integrationtest/compile_4/testdata/libraries/Balanduino/usbhub.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/IRremote/IRremote.h b/internal/integrationtest/compile_4/testdata/libraries/IRremote/IRremote.h new file mode 100644 index 00000000000..5497fbd7255 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/IRremote/IRremote.h @@ -0,0 +1 @@ +#warning IRRemote included! \ No newline at end of file diff --git a/internal/integrationtest/compile_4/testdata/libraries/IRremote/IRremoteInt.h b/internal/integrationtest/compile_4/testdata/libraries/IRremote/IRremoteInt.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/ShouldNotRecurseWithOldLibs.cpp b/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/ShouldNotRecurseWithOldLibs.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/ShouldNotRecurseWithOldLibs.h b/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/ShouldNotRecurseWithOldLibs.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/doc/error.cpp b/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/doc/error.cpp new file mode 100644 index 00000000000..28fe130ceb5 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/doc/error.cpp @@ -0,0 +1 @@ + #error "This file is never supposed to be compiled" diff --git a/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/utility/utils.cpp b/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/utility/utils.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/utility/utils.h b/internal/integrationtest/compile_4/testdata/libraries/ShouldNotRecurseWithOldLibs/utility/utils.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino new file mode 100644 index 00000000000..ea7509cbce8 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino @@ -0,0 +1,75 @@ +/* + Copyright (c) 2012 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#define ARDUINO_MAIN +//#include "variant.h" +#include "Arduino.h" +#include +#include + + +USBHost usb; +ADK adk(&usb,"Arduino SA", + "Arduino_Terminal", + "Arduino Terminal for Android", + "1.0", + "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk", + "1"); + +void setup(void) +{ + SERIAL_PORT_MONITOR.begin( 115200 ); + while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("\r\nADK demo start"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay(20); +} + +#define RCVSIZE 128 + +void loop(void) +{ + uint8_t buf[RCVSIZE]; + uint32_t nbread = 0; + char helloworld[] = "Hello World!\r\n"; + + usb.Task(); + + if( adk.isReady() == false ) { + return; + } + /* Write hello string to ADK */ + adk.SndData(strlen(helloworld), (uint8_t *)helloworld); + + delay(1000); + + /* Read data from ADK and print to UART */ + adk.RcvData((uint8_t *)&nbread, buf); + if (nbread > 0) + { + SERIAL_PORT_MONITOR.print("RCV: "); + for (uint32_t i = 0; i < nbread; ++i) + { + SERIAL_PORT_MONITOR.print((char)buf[i]); + } + SERIAL_PORT_MONITOR.print("\r\n"); + } +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/KeyboardController/KeyboardController.ino b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/KeyboardController/KeyboardController.ino new file mode 100644 index 00000000000..f1b6463a400 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/KeyboardController/KeyboardController.ino @@ -0,0 +1,89 @@ +/* + Keyboard Controller Example + + Shows the output of a USB Keyboard connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + https://www.arduino.cc/en/Tutorial/KeyboardController + + This sample code is part of the public domain. + */ + +// Require keyboard control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach keyboard controller to USB +KeyboardController keyboard(usb); + +void printKey(); + +// This function intercepts key press +void keyPressed() { + SERIAL_PORT_MONITOR.print("Pressed: "); + printKey(); +} + +// This function intercepts key release +void keyReleased() { + SERIAL_PORT_MONITOR.print("Released: "); + printKey(); +} + +void printKey() { + // getOemKey() returns the OEM-code associated with the key + SERIAL_PORT_MONITOR.print(" key:"); + SERIAL_PORT_MONITOR.print(keyboard.getOemKey()); + + // getModifiers() returns a bits field with the modifiers-keys + int mod = keyboard.getModifiers(); + SERIAL_PORT_MONITOR.print(" mod:"); + SERIAL_PORT_MONITOR.print(mod); + + SERIAL_PORT_MONITOR.print(" => "); + + if (mod & LeftCtrl) + SERIAL_PORT_MONITOR.print("L-Ctrl "); + if (mod & LeftShift) + SERIAL_PORT_MONITOR.print("L-Shift "); + if (mod & Alt) + SERIAL_PORT_MONITOR.print("Alt "); + if (mod & LeftCmd) + SERIAL_PORT_MONITOR.print("L-Cmd "); + if (mod & RightCtrl) + SERIAL_PORT_MONITOR.print("R-Ctrl "); + if (mod & RightShift) + SERIAL_PORT_MONITOR.print("R-Shift "); + if (mod & AltGr) + SERIAL_PORT_MONITOR.print("AltGr "); + if (mod & RightCmd) + SERIAL_PORT_MONITOR.print("R-Cmd "); + + // getKey() returns the ASCII translation of OEM key + // combined with modifiers. + SERIAL_PORT_MONITOR.write(keyboard.getKey()); + SERIAL_PORT_MONITOR.println(); +} + +void setup() +{ + SERIAL_PORT_MONITOR.begin( 115200 ); + while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Keyboard Controller Program started"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay( 20 ); +} + +void loop() +{ + // Process USB tasks + usb.Task(); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/MouseController/MouseController.ino b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/MouseController/MouseController.ino new file mode 100644 index 00000000000..fd02d3e3abd --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/MouseController/MouseController.ino @@ -0,0 +1,97 @@ +/* + Mouse Controller Example + + Shows the output of a USB Mouse connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + https://www.arduino.cc/en/Tutorial/MouseController + + This sample code is part of the public domain. + */ + +// Require mouse control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach mouse controller to USB +MouseController mouse(usb); + +// variables for mouse button states +bool leftButton = false; +bool middleButton = false; +bool rightButton = false; + +// This function intercepts mouse movements +void mouseMoved() { + SERIAL_PORT_MONITOR.print("Move: "); + SERIAL_PORT_MONITOR.print(mouse.getXChange()); + SERIAL_PORT_MONITOR.print(", "); + SERIAL_PORT_MONITOR.println(mouse.getYChange()); +} + +// This function intercepts mouse movements while a button is pressed +void mouseDragged() { + SERIAL_PORT_MONITOR.print("DRAG: "); + SERIAL_PORT_MONITOR.print(mouse.getXChange()); + SERIAL_PORT_MONITOR.print(", "); + SERIAL_PORT_MONITOR.println(mouse.getYChange()); +} + +// This function intercepts mouse button press +void mousePressed() { + SERIAL_PORT_MONITOR.print("Pressed: "); + if (mouse.getButton(LEFT_BUTTON)) { + SERIAL_PORT_MONITOR.print("L"); + leftButton = true; + } + if (mouse.getButton(MIDDLE_BUTTON)) { + SERIAL_PORT_MONITOR.print("M"); + middleButton = true; + } + if (mouse.getButton(RIGHT_BUTTON)) { + SERIAL_PORT_MONITOR.print("R"); + rightButton = true; + } + SERIAL_PORT_MONITOR.println(); +} + +// This function intercepts mouse button release +void mouseReleased() { + SERIAL_PORT_MONITOR.print("Released: "); + if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) { + SERIAL_PORT_MONITOR.print("L"); + leftButton = false; + } + if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) { + SERIAL_PORT_MONITOR.print("M"); + middleButton = false; + } + if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) { + SERIAL_PORT_MONITOR.print("R"); + rightButton = false; + } + SERIAL_PORT_MONITOR.println(); +} + +void setup() +{ + SERIAL_PORT_MONITOR.begin( 115200 ); + while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Mouse Controller Program started"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay( 20 ); +} + +void loop() +{ + // Process USB tasks + usb.Task(); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/USB_desc/USB_desc.ino b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/USB_desc/USB_desc.ino new file mode 100644 index 00000000000..de9ab09f478 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/USB_desc/USB_desc.ino @@ -0,0 +1,389 @@ + + +#include "Arduino.h" +#include +#include "pgmstrings.h" +// Satisfy IDE, which only needs to see the include statment in the ino. +#ifdef dobogusinclude +#include +#endif + +USBHost usb; +//USBHub Hub1(&Usb); +//USBHub Hub2(&Usb); +//USBHub Hub3(&Usb); +//USBHub Hub4(&Usb); +//USBHub Hub5(&Usb); +//USBHub Hub6(&Usb); +//USBHub Hub7(&Usb); + +uint32_t next_time; + +void print_hex(int v, int num_places); +void printintfdescr( uint8_t* descr_ptr ); +byte getconfdescr( byte addr, byte conf ); +void printconfdescr( uint8_t* descr_ptr ); +void printunkdescr( uint8_t* descr_ptr ); +void printepdescr( uint8_t* descr_ptr ); +void printProgStr(const prog_char str[]); +void printHIDdescr( uint8_t* descr_ptr ); + +void PrintAllAddresses(UsbDeviceDefinition *pdev) +{ + UsbDeviceAddress adr; + adr.devAddress = pdev->address.devAddress; + SERIAL_PORT_MONITOR.print("\r\nAddr:"); + SERIAL_PORT_MONITOR.print(adr.devAddress, HEX); + SERIAL_PORT_MONITOR.print("("); + SERIAL_PORT_MONITOR.print(adr.bmHub, HEX); + SERIAL_PORT_MONITOR.print("."); + SERIAL_PORT_MONITOR.print(adr.bmParent, HEX); + SERIAL_PORT_MONITOR.print("."); + SERIAL_PORT_MONITOR.print(adr.bmAddress, HEX); + SERIAL_PORT_MONITOR.println(")"); +} + +void PrintAddress(uint8_t addr) +{ + UsbDeviceAddress adr; + adr.devAddress = addr; + SERIAL_PORT_MONITOR.print("\r\nADDR:\t"); + SERIAL_PORT_MONITOR.println(adr.devAddress,HEX); + SERIAL_PORT_MONITOR.print("DEV:\t"); + SERIAL_PORT_MONITOR.println(adr.bmAddress,HEX); + SERIAL_PORT_MONITOR.print("PRNT:\t"); + SERIAL_PORT_MONITOR.println(adr.bmParent,HEX); + SERIAL_PORT_MONITOR.print("HUB:\t"); + SERIAL_PORT_MONITOR.println(adr.bmHub,HEX); +} + +void setup() +{ + SERIAL_PORT_MONITOR.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Start USB Desc"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay( 20 ); + + next_time = millis() + 10000; +} + +byte getdevdescr( byte addr, byte &num_conf ); + +void PrintDescriptors(uint8_t addr) +{ + uint8_t rcode = 0; + byte num_conf = 0; + + rcode = getdevdescr( (byte)addr, num_conf ); + if( rcode ) + { + printProgStr(Gen_Error_str); + print_hex( rcode, 8 ); + } + SERIAL_PORT_MONITOR.print("\r\n"); + + for (int i=0; iaddress.devAddress, 8); + SERIAL_PORT_MONITOR.println("\r\n--"); + PrintDescriptors( pdev->address.devAddress ); +} + +void loop() +{ + usb.Task(); + + if( usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + //if (millis() >= next_time) + { + usb.ForEachUsbDevice(&PrintAllDescriptors); + usb.ForEachUsbDevice(&PrintAllAddresses); + + while( 1 ); //stop + } + } +} + +byte getdevdescr( byte addr, byte &num_conf ) +{ + USB_DEVICE_DESCRIPTOR buf; + byte rcode; + rcode = usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); + if( rcode ) { + return( rcode ); + } + printProgStr(Dev_Header_str); + printProgStr(Dev_Length_str); + print_hex( buf.bLength, 8 ); + printProgStr(Dev_Type_str); + print_hex( buf.bDescriptorType, 8 ); + printProgStr(Dev_Version_str); + print_hex( buf.bcdUSB, 16 ); + printProgStr(Dev_Class_str); + print_hex( buf.bDeviceClass, 8 ); + printProgStr(Dev_Subclass_str); + print_hex( buf.bDeviceSubClass, 8 ); + printProgStr(Dev_Protocol_str); + print_hex( buf.bDeviceProtocol, 8 ); + printProgStr(Dev_Pktsize_str); + print_hex( buf.bMaxPacketSize0, 8 ); + printProgStr(Dev_Vendor_str); + print_hex( buf.idVendor, 16 ); + printProgStr(Dev_Product_str); + print_hex( buf.idProduct, 16 ); + printProgStr(Dev_Revision_str); + print_hex( buf.bcdDevice, 16 ); + printProgStr(Dev_Mfg_str); + print_hex( buf.iManufacturer, 8 ); + printProgStr(Dev_Prod_str); + print_hex( buf.iProduct, 8 ); + printProgStr(Dev_Serial_str); + print_hex( buf.iSerialNumber, 8 ); + printProgStr(Dev_Nconf_str); + print_hex( buf.bNumConfigurations, 8 ); + num_conf = buf.bNumConfigurations; + return( 0 ); +} + +void printhubdescr(uint8_t *descrptr, uint8_t addr) +{ + HubDescriptor *pHub = (HubDescriptor*) descrptr; + uint8_t len = *((uint8_t*)descrptr); + + printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n")); + printProgStr(PSTR("bDescLength:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bDescLength, HEX); + + printProgStr(PSTR("bDescriptorType:\t")); + SERIAL_PORT_MONITOR.println(pHub->bDescriptorType, HEX); + + printProgStr(PSTR("bNbrPorts:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bNbrPorts, HEX); + + printProgStr(PSTR("LogPwrSwitchMode:\t")); + SERIAL_PORT_MONITOR.println(pHub->LogPwrSwitchMode, BIN); + + printProgStr(PSTR("CompoundDevice:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->CompoundDevice, BIN); + + printProgStr(PSTR("OverCurrentProtectMode:\t")); + SERIAL_PORT_MONITOR.println(pHub->OverCurrentProtectMode, BIN); + + printProgStr(PSTR("TTThinkTime:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->TTThinkTime, BIN); + + printProgStr(PSTR("PortIndicatorsSupported:")); + SERIAL_PORT_MONITOR.println(pHub->PortIndicatorsSupported, BIN); + + printProgStr(PSTR("Reserved:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->Reserved, HEX); + + printProgStr(PSTR("bPwrOn2PwrGood:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bPwrOn2PwrGood, HEX); + + printProgStr(PSTR("bHubContrCurrent:\t")); + SERIAL_PORT_MONITOR.println(pHub->bHubContrCurrent, HEX); + + for (uint8_t i=7; ibNbrPorts; i++) + // PrintHubPortStatus(&Usb, addr, i, 1); +} + +byte getconfdescr( byte addr, byte conf ) +{ + uint8_t buf[ BUFSIZE ]; + uint8_t* buf_ptr = buf; + byte rcode; + byte descr_length; + byte descr_type; + uint16_t total_length; + rcode = usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length + LOBYTE( total_length ) = buf[ 2 ]; + HIBYTE( total_length ) = buf[ 3 ]; + if( total_length > sizeof(buf)) { //check if total length is larger than buffer + printProgStr(Conf_Trunc_str); + total_length = sizeof(buf); + } + rcode = usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor + while( buf_ptr < buf + total_length ) { //parsing descriptors + descr_length = *( buf_ptr ); + descr_type = *( buf_ptr + 1 ); + switch( descr_type ) { + case( USB_DESCRIPTOR_CONFIGURATION ): + printconfdescr( buf_ptr ); + break; + case( USB_DESCRIPTOR_INTERFACE ): + printintfdescr( buf_ptr ); + break; + case( USB_DESCRIPTOR_ENDPOINT ): + printepdescr( buf_ptr ); + break; + case 0x21: // HID Descriptor + printHIDdescr( buf_ptr ); + break; + case 0x29: + printhubdescr( buf_ptr, addr ); + break; + default: + printunkdescr( buf_ptr ); + break; + }//switch( descr_type + buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer + }//while( buf_ptr <=... + return( 0 ); +} +/* prints hex numbers with leading zeroes */ +// copyright, Peter H Anderson, Baltimore, MD, Nov, '07 +// source: http://www.phanderson.com/arduino/arduino_display.html +void print_hex(int v, int num_places) +{ + int mask=0, n, num_nibbles, digit; + + for (n=1; n<=num_places; n++) { + mask = (mask << 1) | 0x0001; + } + v = v & mask; // truncate v to specified number of places + + num_nibbles = num_places / 4; + if ((num_places % 4) != 0) { + ++num_nibbles; + } + do { + digit = ((v >> (num_nibbles-1) * 4)) & 0x0f; + SERIAL_PORT_MONITOR.print(digit, HEX); + } + while(--num_nibbles); +} +/* function to print configuration descriptor */ +void printconfdescr( uint8_t* descr_ptr ) +{ + USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr; + printProgStr(Conf_Header_str); + printProgStr(Conf_Totlen_str); + print_hex( conf_ptr->wTotalLength, 16 ); + printProgStr(Conf_Nint_str); + print_hex( conf_ptr->bNumInterfaces, 8 ); + printProgStr(Conf_Value_str); + print_hex( conf_ptr->bConfigurationValue, 8 ); + printProgStr(Conf_String_str); + print_hex( conf_ptr->iConfiguration, 8 ); + printProgStr(Conf_Attr_str); + print_hex( conf_ptr->bmAttributes, 8 ); + printProgStr(Conf_Pwr_str); + print_hex( conf_ptr->bMaxPower, 8 ); + return; +} +/* function to print interface descriptor */ +void printintfdescr( uint8_t* descr_ptr ) +{ + USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr; + printProgStr(Int_Header_str); + printProgStr(Int_Number_str); + print_hex( intf_ptr->bInterfaceNumber, 8 ); + printProgStr(Int_Alt_str); + print_hex( intf_ptr->bAlternateSetting, 8 ); + printProgStr(Int_Endpoints_str); + print_hex( intf_ptr->bNumEndpoints, 8 ); + printProgStr(Int_Class_str); + print_hex( intf_ptr->bInterfaceClass, 8 ); + printProgStr(Int_Subclass_str); + print_hex( intf_ptr->bInterfaceSubClass, 8 ); + printProgStr(Int_Protocol_str); + print_hex( intf_ptr->bInterfaceProtocol, 8 ); + printProgStr(Int_String_str); + print_hex( intf_ptr->iInterface, 8 ); + return; +} + +/* function to print HID descriptor */ +void printHIDdescr( uint8_t* descr_ptr ) +{ + USB_HID_DESCRIPTOR* ep_ptr = ( USB_HID_DESCRIPTOR* )descr_ptr; + + printProgStr(PSTR("\r\n\r\nHID Descriptor:\r\n")); + printProgStr(PSTR("HID Class Release:\t")); + print_hex( ep_ptr->bcdHID, 16 ); + printProgStr(PSTR("\r\nCountry Code:\t\t")); + print_hex( ep_ptr->bCountryCode, 8 ); + printProgStr(PSTR("\r\nNumb Class Descriptor:\t")); + print_hex( ep_ptr->bNumDescriptors, 8 ); + printProgStr(PSTR("\r\nDescriptor Type:\t")); + if( ep_ptr->bDescrType == 0x22 ) + printProgStr(PSTR("REPORT DESCRIPTOR")); + else + print_hex( ep_ptr->bDescrType, 8 ); + printProgStr(PSTR("\r\nCSize Report Descr:\t")); + print_hex( ep_ptr->wDescriptorLength, 16 ); +} + +/* function to print endpoint descriptor */ +void printepdescr( uint8_t* descr_ptr ) +{ + uint8_t transfer_type; + + USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr; + printProgStr(End_Header_str); + printProgStr(End_Address_str); + if( 0x80 & ep_ptr->bEndpointAddress ) printProgStr(PSTR("IN\t\t")); + else printProgStr(PSTR("OUT\t\t")); + print_hex( (ep_ptr->bEndpointAddress & 0xF), 8 ); + printProgStr(End_Attr_str); + transfer_type = ep_ptr->bmAttributes & bmUSB_TRANSFER_TYPE; + if( transfer_type == USB_TRANSFER_TYPE_INTERRUPT ) printProgStr(PSTR("INTERRUPT\t")); + else if( transfer_type == USB_TRANSFER_TYPE_BULK ) printProgStr(PSTR("BULK\t")); + else if( transfer_type == USB_TRANSFER_TYPE_ISOCHRONOUS ) printProgStr(PSTR("ISO\t")); + print_hex( ep_ptr->bmAttributes, 8 ); + printProgStr(End_Pktsize_str); + print_hex( ep_ptr->wMaxPacketSize, 16 ); + printProgStr(End_Interval_str); + print_hex( ep_ptr->bInterval, 8 ); + + return; +} +/*function to print unknown descriptor */ +void printunkdescr( uint8_t* descr_ptr ) +{ + byte length = *descr_ptr; + byte i; + printProgStr(Unk_Header_str); + printProgStr(Unk_Length_str); + print_hex( *descr_ptr, 8 ); + printProgStr(Unk_Type_str); + print_hex( *(descr_ptr + 1 ), 8 ); + printProgStr(Unk_Contents_str); + descr_ptr += 2; + for( i = 0; i < length; i++ ) { + print_hex( *descr_ptr, 8 ); + descr_ptr++; + } +} + + +/* Print a string from Program Memory directly to save RAM */ +void printProgStr(const prog_char str[]) +{ + char c; + if(!str) return; + while((c = pgm_read_byte(str++))) + SERIAL_PORT_MONITOR.print(c); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/USB_desc/pgmstrings.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/USB_desc/pgmstrings.h new file mode 100644 index 00000000000..bdb0077eccf --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/examples/USB_desc/pgmstrings.h @@ -0,0 +1,52 @@ +#if !defined(__PGMSTRINGS_H__) +#define __PGMSTRINGS_H__ + +#define LOBYTE(x) ((char*)(&(x)))[0] +#define HIBYTE(x) ((char*)(&(x)))[1] +#define BUFSIZE 256 //buffer size + + +/* Print strings in Program Memory */ +const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; +const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; +const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; +const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; +const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; +const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; +const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; +const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; +const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; +const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; +const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; +const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; +const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; +const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; +const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; +const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; +const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; +const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; +const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; +const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; +const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; +const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; +const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; +const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; +const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; +const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; +const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; +const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; +const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; +const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; +const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; +const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; +const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; +const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; +const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; +const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; +const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; +const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; +const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; +const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; +const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; + +#endif // __PGMSTRINGS_H__ \ No newline at end of file diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/keywords.txt b/internal/integrationtest/compile_4/testdata/libraries/USBHost/keywords.txt new file mode 100644 index 00000000000..dded4dcf729 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/keywords.txt @@ -0,0 +1,35 @@ +####################################### +# Syntax Coloring Map For USBHost +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +MouseController KEYWORD1 +USBHost KEYWORD1 +KeyboardController KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +Task KEYWORD2 +mouseMoved KEYWORD2 +mouseDragged KEYWORD2 +mousePressed KEYWORD2 +mouseReleased KEYWORD2 +getXChange KEYWORD2 +getYChange KEYWORD2 +getButton KEYWORD2 +keyPressed KEYWORD2 +keyReleased KEYWORD2 +getModifiers KEYWORD2 +getKey KEYWORD2 +getOemKey KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/library.properties b/internal/integrationtest/compile_4/testdata/libraries/USBHost/library.properties new file mode 100644 index 00000000000..c1db890dc62 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/library.properties @@ -0,0 +1,9 @@ +name=USBHost +version=1.0 +author=Arduino +maintainer=Arduino +sentence=Allows the communication with USB peripherals like mice, keyboards, and thumbdrives. For Arduino MKR1000 and Zero. +paragraph=The USBHost library allows the board to appear as a USB host, enabling it to communicate with peripherals like USB mice and keyboards. USBHost does not support devices that are connected through USB hubs. This includes some keyboards that have an internal hub. +category=Other +url=https://www.arduino.cc/en/Reference/USBHost +architectures=samd diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/KeyboardController.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/KeyboardController.cpp new file mode 100644 index 00000000000..70c769f64e0 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/KeyboardController.cpp @@ -0,0 +1,40 @@ +/* + Copyright (c) 2012 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +extern "C" { +void __keyboardControllerEmptyCallback() { } +} + +void keyPressed() __attribute__ ((weak, alias("__keyboardControllerEmptyCallback"))); +void keyReleased() __attribute__ ((weak, alias("__keyboardControllerEmptyCallback"))); + +void KeyboardController::OnKeyDown(uint8_t _mod, uint8_t _oemKey) { + modifiers = _mod; + keyOem = _oemKey; + key = OemToAscii(_mod, _oemKey); + keyPressed(); +} + +void KeyboardController::OnKeyUp(uint8_t _mod, uint8_t _oemKey) { + modifiers = _mod; + keyOem = _oemKey; + key = OemToAscii(_mod, _oemKey); + keyReleased(); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/KeyboardController.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/KeyboardController.h new file mode 100644 index 00000000000..e1b891bff8a --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/KeyboardController.h @@ -0,0 +1,54 @@ +/* + Copyright (c) 2012 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef KEYBOARD_CONTROLLER_H +#define KEYBOARD_CONTROLLER_H + +#include + +enum KeyboardModifiers { + LeftCtrl = 1, + LeftShift = 2, + Alt = 4, + LeftCmd = 8, + RightCtrl = 16, + RightShift = 32, + AltGr = 64, + RightCmd = 128 +}; + +class KeyboardController : public KeyboardReportParser { +public: + KeyboardController(USBHost &usb) : hostKeyboard(&usb), key(0), keyOem(0), modifiers(0) { + hostKeyboard.SetReportParser(0, this); + }; + + uint8_t getKey() { return key; }; + uint8_t getModifiers() { return modifiers; }; + uint8_t getOemKey() { return keyOem; }; + +protected: + virtual void OnKeyDown(uint8_t mod, uint8_t key); + virtual void OnKeyUp(uint8_t mod, uint8_t key); + +private: + HIDBoot hostKeyboard; + uint8_t key, keyOem, modifiers; +}; + +#endif diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/MouseController.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/MouseController.cpp new file mode 100644 index 00000000000..0912a03742d --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/MouseController.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2015 Arduino LLC. All right reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +extern "C" { +void __mouseControllerEmptyCallback() { } +} + +void mouseClicked() __attribute__ ((weak, alias("__mouseControllerEmptyCallback"))); +void mouseDragged() __attribute__ ((weak, alias("__mouseControllerEmptyCallback"))); +void mouseMoved() __attribute__ ((weak, alias("__mouseControllerEmptyCallback"))); +void mousePressed() __attribute__ ((weak, alias("__mouseControllerEmptyCallback"))); +void mouseReleased() __attribute__ ((weak, alias("__mouseControllerEmptyCallback"))); + +int MouseController::getXChange() { + int r = dx; + dx = 0; + return r; +} + +int MouseController::getYChange() { + int r = dy; + dy = 0; + return r; +} + +void MouseController::OnMouseMove(MOUSEINFO *mi) { + dx += mi->dX; + dy += mi->dY; + if (buttons != 0) + mouseDragged(); + else + mouseMoved(); +} + +void MouseController::OnLeftButtonUp(MOUSEINFO * /* mi */) { + buttons &= ~LEFT_BUTTON; + mouseReleased(); + mouseClicked(); +} + +void MouseController::OnLeftButtonDown(MOUSEINFO * /* mi */) { + buttons |= LEFT_BUTTON; + mousePressed(); +} + +void MouseController::OnMiddleButtonUp(MOUSEINFO * /* mi */) { + buttons &= ~MIDDLE_BUTTON; + mouseReleased(); + mouseClicked(); +} + +void MouseController::OnMiddleButtonDown(MOUSEINFO * /* mi */) { + buttons |= MIDDLE_BUTTON; + mousePressed(); +} + +void MouseController::OnRightButtonUp(MOUSEINFO * /* mi */) { + buttons &= ~RIGHT_BUTTON; + mouseReleased(); + mouseClicked(); +} + +void MouseController::OnRightButtonDown(MOUSEINFO * /* mi */) { + buttons |= RIGHT_BUTTON; + mousePressed(); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/MouseController.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/MouseController.h new file mode 100644 index 00000000000..4c8c65e9ce9 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/MouseController.h @@ -0,0 +1,57 @@ +/* + Copyright (c) 2012 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef MOUSE_CONTROLLER_H +#define MOUSE_CONTROLLER_H + +#include + +enum MouseButton { + LEFT_BUTTON = 0x01, + MIDDLE_BUTTON = 0x02, + RIGHT_BUTTON = 0x04 +}; + +class MouseController : public MouseReportParser +{ +public: + MouseController(USBHost &usb) : hostMouse(&usb), dx(0), dy(0), buttons(0) { + hostMouse.SetReportParser(0, this); + }; + + bool getButton(MouseButton button) { return (buttons & button) == button; }; + int getXChange(); + int getYChange(); + // int getWheelChange(); // Not implemented + +protected: + virtual void OnMouseMove(MOUSEINFO *mi); + virtual void OnLeftButtonUp(MOUSEINFO *mi); + virtual void OnLeftButtonDown(MOUSEINFO *mi); + virtual void OnMiddleButtonUp(MOUSEINFO *mi); + virtual void OnMiddleButtonDown(MOUSEINFO *mi); + virtual void OnRightButtonUp(MOUSEINFO *mi); + virtual void OnRightButtonDown(MOUSEINFO *mi); + +private: + HIDBoot hostMouse; + int dx, dy; + int buttons; +}; + +#endif diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/Usb.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/Usb.cpp new file mode 100644 index 00000000000..3b3b8b1c6c5 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/Usb.cpp @@ -0,0 +1,872 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +/* USB functions */ + +#include +#include "Arduino.h" +#include "Usb.h" + + +//#ifdef ARDUINO_SAMD_ZERO + +static uint32_t usb_error = 0; +static uint32_t usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; + +/* constructor */ +USBHost::USBHost() : bmHubPre(0) { + // Set up state machine + usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; //set up state machine +} + +/* Initialize data structures */ +uint32_t USBHost::Init() { + //devConfigIndex = 0; + // Init host stack + bmHubPre = 0; + UHD_Init(); + return 0; +} + +uint32_t USBHost::getUsbTaskState(void) { + return (usb_task_state); +} + +void USBHost::setUsbTaskState(uint32_t state) { + usb_task_state = state; +} + +uint32_t USBHost::getUsbErrorCode(void) { + return (usb_error); +} + +EpInfo* USBHost::getEpInfoEntry(uint32_t addr, uint32_t ep) { + UsbDeviceDefinition *p = addrPool.GetUsbDevicePtr(addr); + + if(!p || !p->epinfo) + return NULL; + + EpInfo *pep = p->epinfo; + + for (uint32_t i = 0; i < p->epcount; i++) { + if(pep->epAddr == ep) + return pep; + + pep++; + } + return NULL; +} + +/* set device table entry */ + +/* each device is different and has different number of endpoints. This function plugs endpoint record structure, defined in application, to devtable */ +uint32_t USBHost::setEpInfoEntry(uint32_t addr, uint32_t epcount, EpInfo* eprecord_ptr) { + if (!eprecord_ptr) + return USB_ERROR_INVALID_ARGUMENT; + + UsbDeviceDefinition *p = addrPool.GetUsbDevicePtr(addr); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + p->address.devAddress = addr; + p->epinfo = eprecord_ptr; + p->epcount = epcount; + + return 0; +} + +uint32_t USBHost::SetPipeAddress(uint32_t addr, uint32_t ep, EpInfo **ppep, uint32_t &nak_limit) { + UsbDeviceDefinition *p = addrPool.GetUsbDevicePtr(addr); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + if(!p->epinfo) + return USB_ERROR_EPINFO_IS_NULL; + + *ppep = getEpInfoEntry(addr, ep); + + if(!*ppep) + return USB_ERROR_EP_NOT_FOUND_IN_TBL; + + nak_limit = (0x0001UL << (((*ppep)->bmNakPower > USB_NAK_MAX_POWER ) ? USB_NAK_MAX_POWER : (*ppep)->bmNakPower)); + nak_limit--; + TRACE_USBHOST(printf(" => SetPipeAddress deviceEP=%lu configued as hostPIPE=%lu sending to address=%lu\r\n", ep, (*ppep)->epAddr, addr);) + /* + USBTRACE2("\r\nAddress: ", addr); + USBTRACE2(" EP: ", ep); + USBTRACE2(" NAK Power: ",(*ppep)->bmNakPower); + USBTRACE2(" NAK Limit: ", nak_limit); + USBTRACE("\r\n"); + */ + + // CTRL_PIPE.PDADDR: usb_pipe_table[pipe_num].HostDescBank[0].CTRL_PIPE.bit.PDADDR = addr + uhd_configure_address((*ppep)->epAddr, addr); // Set peripheral address + + return 0; +} + +/* Control transfer. Sets address, endpoint, fills control packet with necessary data, dispatches control packet, and initiates bulk IN transfer, */ +/* depending on request. Actual requests are defined as inlines */ +/* return codes: */ +/* 00 = success */ +/* 01-0f = non-zero HRSLT */ +uint32_t USBHost::ctrlReq(uint32_t addr, uint32_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, + uint16_t wInd, uint16_t total, uint32_t nbytes, uint8_t* dataptr, USBReadParser *p) { + + uint32_t direction = 0; // Request direction, IN or OUT + uint32_t rcode; + SETUP_PKT setup_pkt; + + EpInfo *pep = NULL; + uint32_t nak_limit = 0; + + TRACE_USBHOST(printf(" => ctrlReq\r\n");) + + rcode = SetPipeAddress(addr, ep, &pep, nak_limit); + if(rcode) + return rcode; + + // Allocate Pipe0 with default 64 bytes size if not already initialized + rcode = UHD_Pipe0_Alloc(0, 64); + if (rcode) + { + TRACE_USBHOST(printf("/!\\ USBHost::ctrlReq : EP0 allocation error: %lu\r\n", rcode);) + //USBTRACE2("\n\rUSBHost::ctrlReq : EP0 allocation error: ", rcode"); + return rcode; + } + + // Determine request direction + direction = ((bmReqType & 0x80 ) > 0); + + /* fill in setup packet */ + setup_pkt.ReqType_u.bmRequestType = bmReqType; + setup_pkt.bRequest = bRequest; + setup_pkt.wVal_u.wValueLo = wValLo; + setup_pkt.wVal_u.wValueHi = wValHi; + setup_pkt.wIndex = wInd; + setup_pkt.wLength = total; + + UHD_Pipe_Write(pep->epAddr, sizeof(setup_pkt), (uint8_t *)&setup_pkt); //transfer to setup packet FIFO + + rcode = dispatchPkt(tokSETUP, ep, nak_limit); // Dispatch packet + + if (rcode) //return HRSLT if not zero + return ( rcode); + + if (dataptr != NULL) //data stage, if present + { + if (direction) // IN transfer + { + uint32_t left = total; + TRACE_USBHOST(printf(" => ctrlData IN\r\n");) + + pep->bmRcvToggle = 1; //bmRCVTOG1; + + // Bytes read into buffer + uint32_t read = nbytes; + + rcode = InTransfer(pep, nak_limit, (uint8_t*)&read, dataptr); + + if((rcode&USB_ERROR_DATATOGGLE) == USB_ERROR_DATATOGGLE) { + // yes, we flip it wrong here so that next time it is actually correct! + //pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; + pep->bmRcvToggle = USB_HOST_DTGL(pep->epAddr); + //continue; + } + + if(rcode) { + //USBTRACE2("\n\rUSBHost::ctrlReq : in transfer: ", rcode"); + return rcode; + } + // Invoke callback function if inTransfer completed successfully and callback function pointer is specified + if(!rcode && p) + ((USBReadParser*)p)->Parse(read, dataptr, total - left); + } + else // OUT transfer + { + pep->bmSndToggle = 1; //bmSNDTOG1; + rcode = OutTransfer(pep, nak_limit, nbytes, dataptr); + } + if(rcode) //return error + return (rcode); + } + + // Status stage + UHD_Pipe_CountZero(pep->epAddr); + USB->HOST.HostPipe[pep->epAddr].PSTATUSSET.reg = USB_HOST_PSTATUSSET_DTGL; + return dispatchPkt((direction) ? tokOUTHS : tokINHS, pep->epAddr, nak_limit); //GET if direction +} + +/* IN transfer to arbitrary endpoint. Assumes PERADDR is set. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */ +/* Keep sending INs and writes data to memory area pointed by 'data' */ + +/* rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error, + fe USB xfer timeout */ +uint32_t USBHost::inTransfer(uint32_t addr, uint32_t ep, uint8_t *nbytesptr, uint8_t* data) { + EpInfo *pep = NULL; + uint32_t nak_limit = 0; + + uint32_t rcode = SetPipeAddress(addr, ep, &pep, nak_limit); + + if(rcode) { + USBTRACE3("(USB::InTransfer) SetAddress Failed ", rcode, 0x81); + USBTRACE3("(USB::InTransfer) addr requested ", addr, 0x81); + USBTRACE3("(USB::InTransfer) ep requested ", ep, 0x81); + return rcode; + } + return InTransfer(pep, nak_limit, nbytesptr, data); +} + +uint32_t USBHost::InTransfer(EpInfo *pep, uint32_t nak_limit, uint8_t *nbytesptr, uint8_t* data) { + uint32_t rcode = 0; + uint32_t pktsize = 0; + + uint32_t nbytes = *nbytesptr; + uint32_t maxpktsize = pep->maxPktSize; + + *nbytesptr = 0; + //set toggle value + if(pep->bmRcvToggle) + USB->HOST.HostPipe[pep->epAddr].PSTATUSSET.reg = USB_HOST_PSTATUSSET_DTGL; + else + USB->HOST.HostPipe[pep->epAddr].PSTATUSCLR.reg = USB_HOST_PSTATUSCLR_DTGL; + + usb_pipe_table[pep->epAddr].HostDescBank[0].ADDR.reg = (uint32_t)data; + + // use a 'break' to exit this loop + while (1) { + /* get pipe config from setting register */ + usb_pipe_table[pep->epAddr].HostDescBank[0].ADDR.reg += pktsize; + + rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS. + if(rcode == USB_ERROR_DATATOGGLE) { + // yes, we flip it wrong here so that next time it is actually correct! + //pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; + pep->bmRcvToggle = USB_HOST_DTGL(pep->epAddr); + //set toggle value + if(pep->bmRcvToggle) + USB->HOST.HostPipe[pep->epAddr].PSTATUSSET.reg = USB_HOST_PSTATUSSET_DTGL; + else + USB->HOST.HostPipe[pep->epAddr].PSTATUSCLR.reg = USB_HOST_PSTATUSCLR_DTGL; + continue; + } + if(rcode) { + uhd_freeze_pipe(pep->epAddr); + //printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode); + return(rcode);// break; //should be 0, indicating ACK. Else return error code. + } + /* check for RCVDAVIRQ and generate error if not present */ + /* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */ + + pktsize = uhd_byte_count(pep->epAddr); // Number of received bytes + + USB->HOST.HostPipe[pep->epAddr].PSTATUSCLR.reg = USB_HOST_PSTATUSCLR_BK0RDY; + + //printf("Got %i bytes \r\n", pktsize); + // This would be OK, but... + //assert(pktsize <= nbytes); + if(pktsize > nbytes) { + // This can happen. Use of assert on Arduino locks up the Arduino. + // So I will trim the value, and hope for the best. + //printf(">>>>>>>> Problem! Wanted %i bytes but got %i.\r\n", nbytes, pktsize); + pktsize = nbytes; + } + + int16_t mem_left = (int16_t)nbytes - *((int16_t*)nbytesptr); + + if(mem_left < 0) + mem_left = 0; + + //data = bytesRd(rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data); + + //regWr(rHIRQ, bmRCVDAVIRQ); // Clear the IRQ & free the buffer + *nbytesptr += pktsize;// add this packet's byte count to total transfer length + + /* The transfer is complete under two conditions: */ + /* 1. The device sent a short packet (L.T. maxPacketSize) */ + /* 2. 'nbytes' have been transferred. */ + if((pktsize < maxpktsize) || (*nbytesptr >= nbytes)) // have we transferred 'nbytes' bytes? + { + // Save toggle value + pep->bmRcvToggle = USB_HOST_DTGL(pep->epAddr); + //printf("\r\n"); + rcode = 0; + break; + } // if + } //while( 1 ) + uhd_freeze_pipe(pep->epAddr); + return ( rcode); +} + +/* OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */ +/* Handles NAK bug per Maxim Application Note 4000 for single buffer transfer */ + +/* rcode 0 if no errors. rcode 01-0f is relayed from HRSL */ +uint32_t USBHost::outTransfer(uint32_t addr, uint32_t ep, uint32_t nbytes, uint8_t* data) { + EpInfo *pep = NULL; + uint32_t nak_limit = 0; + + uint32_t rcode = SetPipeAddress(addr, ep, &pep, nak_limit); + + if(rcode) + return rcode; + + return OutTransfer(pep, nak_limit, nbytes, data); +} + +uint32_t USBHost::OutTransfer(EpInfo *pep, uint32_t nak_limit, uint32_t nbytes, uint8_t *data) { + uint32_t rcode = 0, retry_count; + uint8_t *data_p = data; //local copy of the data pointer + uint32_t bytes_tosend, nak_count; + uint32_t bytes_left = nbytes; + uint8_t buf[64]; + uint8_t i; + + uint32_t maxpktsize = pep->maxPktSize; + + if(maxpktsize < 1 || maxpktsize > 64) + return USB_ERROR_INVALID_MAX_PKT_SIZE; + + for( i=0; ibmSndToggle) + USB->HOST.HostPipe[pep->epAddr].PSTATUSSET.reg = USB_HOST_PSTATUSSET_DTGL; + else + USB->HOST.HostPipe[pep->epAddr].PSTATUSCLR.reg = USB_HOST_PSTATUSCLR_DTGL; + + while(bytes_left) { + retry_count = 0; + nak_count = 0; + bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left; + UHD_Pipe_Write(pep->epAddr, bytes_tosend, buf); //filling output FIFO + + //set number of bytes + //dispatch packet + //wait for the completion IRQ + //clear IRQ + + rcode = dispatchPkt(tokOUT, pep->epAddr, nak_limit); + if (rcode) + { + switch(rcode) { + case USB_ERRORFLOW: + nak_count++; + if(nak_limit && (nak_count == nak_limit)) + goto breakout; + return ( rcode); + break; + case USB_ERRORTIMEOUT: + retry_count++; + if(retry_count == USB_RETRY_LIMIT) + goto breakout; + return ( rcode); + break; + case USB_ERROR_DATATOGGLE: + // yes, we flip it wrong here so that next time it is actually correct! + pep->bmSndToggle = USB_HOST_DTGL(pep->epAddr); + //set toggle value + if(pep->bmSndToggle) + USB->HOST.HostPipe[pep->epAddr].PSTATUSSET.reg = USB_HOST_PSTATUSSET_DTGL; + else + USB->HOST.HostPipe[pep->epAddr].PSTATUSCLR.reg = USB_HOST_PSTATUSCLR_DTGL; + break; + default: + goto breakout; + }//switch( rcode + } + + bytes_left -= bytes_tosend; + data_p += bytes_tosend; + }//while( bytes_left... +breakout: + + pep->bmSndToggle = USB_HOST_DTGL(pep->epAddr); + return ( rcode); //should be 0 in all cases +} + +/* dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty */ +/* If NAK, tries to re-send up to nak_limit times */ +/* If nak_limit == 0, do not count NAKs, exit after timeout */ +/* If bus timeout, re-sends up to USB_RETRY_LIMIT times */ + +/* return codes 0x00-0x0f are HRSLT( 0x00 being success ), 0xff means timeout */ +uint32_t USBHost::dispatchPkt(uint32_t token, uint32_t epAddr, uint32_t nak_limit) { + uint32_t timeout = millis() + USB_XFER_TIMEOUT; + uint32_t nak_count = 0, retry_count=0; + uint32_t rcode = USB_ERROR_TRANSFER_TIMEOUT; + + TRACE_USBHOST(printf(" => dispatchPkt token=%lu pipe=%lu nak_limit=%lu\r\n", token, epAddr, nak_limit);) + + UHD_Pipe_Send(epAddr, token); //launch the transfer + + // Check timeout but don't hold timeout if VBUS is lost + while ((timeout > millis()) && (UHD_GetVBUSState() == UHD_STATE_CONNECTED)) + { + // Wait for transfer completion + if (UHD_Pipe_Is_Transfer_Complete(epAddr, token)) + { + return 0; + } + + //case hrNAK: + if((USB->HOST.HostPipe[epAddr].PINTFLAG.reg & USB_HOST_PINTFLAG_TRFAIL) ) { + USB->HOST.HostPipe[epAddr].PINTFLAG.reg = USB_HOST_PINTFLAG_TRFAIL; + nak_count++; + if(nak_limit && (nak_count == nak_limit)) { + rcode = USB_ERRORFLOW; + return (rcode); + } + } + + //case hrNAK: + if( (usb_pipe_table[epAddr].HostDescBank[0].STATUS_BK.reg & USB_ERRORFLOW ) ) { + nak_count++; + if(nak_limit && (nak_count == nak_limit)) { + rcode = USB_ERRORFLOW; + return (rcode); + } + } + + //case hrTIMEOUT: + if(usb_pipe_table[epAddr].HostDescBank[0].STATUS_PIPE.reg & USB_ERRORTIMEOUT) { + retry_count++; + if(retry_count == USB_RETRY_LIMIT) { + rcode = USB_ERRORTIMEOUT; + return (rcode); + } + } + + if( (usb_pipe_table[epAddr].HostDescBank[0].STATUS_PIPE.reg & USB_ERROR_DATATOGGLE ) ) { + rcode = USB_ERROR_DATATOGGLE; + return (rcode); + } + } + + return rcode; +} + +/* USB main task. Performs enumeration/cleanup */ +void USBHost::Task(void) //USB state machine +{ + uint32_t rcode = 0; + volatile uint32_t tmpdata = 0; + static uint32_t delay = 0; + //USB_DEVICE_DESCRIPTOR buf; + uint32_t lowspeed = 0; + + // Update USB task state on Vbus change + tmpdata = UHD_GetVBUSState(); + + /* modify USB task state if Vbus changed */ + switch (tmpdata) + { + case UHD_STATE_ERROR: //illegal state + usb_task_state = USB_DETACHED_SUBSTATE_ILLEGAL; + lowspeed = 0; + break; + + case UHD_STATE_DISCONNECTED: // Disconnected state + if ((usb_task_state & USB_STATE_MASK) != USB_STATE_DETACHED) + usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; + lowspeed = 0; + break; + + case UHD_STATE_CONNECTED: // Attached state + if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) { + delay = millis() + USB_SETTLE_DELAY; + usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE; + } + break; + }// switch( tmpdata + + // Poll connected devices (if required) + for (uint32_t i = 0; i < USB_NUMDEVICES; ++i) + if (devConfig[i]) + rcode = devConfig[i]->Poll(); + + // Perform USB enumeration stage and clean up + switch (usb_task_state) { + case USB_DETACHED_SUBSTATE_INITIALIZE: + TRACE_USBHOST(printf(" + USB_DETACHED_SUBSTATE_INITIALIZE\r\n");) + + // Init USB stack and driver + UHD_Init(); + + // Free all USB resources + for (uint32_t i = 0; i < USB_NUMDEVICES; ++i) + if (devConfig[i]) + rcode = devConfig[i]->Release(); + + usb_task_state = USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE; + break; + case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: //just sit here + // Nothing to do + break; + case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here + // Nothing to do + break; + case USB_ATTACHED_SUBSTATE_SETTLE: // Settle time for just attached device + if((long)(millis() - delay) >= 0L) + usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE; + break; + case USB_ATTACHED_SUBSTATE_RESET_DEVICE: + TRACE_USBHOST(printf(" + USB_ATTACHED_SUBSTATE_RESET_DEVICE\r\n");) + UHD_BusReset(); //issue bus reset + usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE; + break; + case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE: + if (Is_uhd_reset_sent()) + { + TRACE_USBHOST(printf(" + USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE\r\n");) + + // Clear Bus Reset flag + uhd_ack_reset_sent(); + + // Enable Start Of Frame generation + uhd_enable_sof(); + + usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF; + + // Wait 20ms after Bus Reset (USB spec) + delay = millis() + 20; + } + break; + case USB_ATTACHED_SUBSTATE_WAIT_SOF: + // Wait for SOF received first + if (Is_uhd_sof()) + { + if (delay < millis()) + { + TRACE_USBHOST(printf(" + USB_ATTACHED_SUBSTATE_WAIT_SOF\r\n");) + + // 20ms waiting elapsed + usb_task_state = USB_STATE_CONFIGURING; + } + } + break; + case USB_STATE_CONFIGURING: + TRACE_USBHOST(printf(" + USB_STATE_CONFIGURING\r\n");) + rcode = Configuring(0, 0, lowspeed); + + if (rcode) { + TRACE_USBHOST(printf("/!\\ USBHost::Task : USB_STATE_CONFIGURING failed with code: %lu\r\n", rcode);) + if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE) { + usb_error = rcode; + usb_task_state = USB_STATE_ERROR; + } + } + else { + usb_task_state = USB_STATE_RUNNING; + TRACE_USBHOST(printf(" + USB_STATE_RUNNING\r\n");) + } + break; + case USB_STATE_RUNNING: + break; + case USB_STATE_ERROR: + break; + } // switch( usb_task_state ) +} + +uint32_t USBHost::DefaultAddressing(uint32_t parent, uint32_t port, uint32_t lowspeed) { + //uint8_t buf[12]; + uint32_t rcode = 0; + UsbDeviceDefinition *p0 = NULL, *p = NULL; + + // Get pointer to pseudo device with address 0 assigned + p0 = addrPool.GetUsbDevicePtr(0); + + if(!p0) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + if(!p0->epinfo) + return USB_ERROR_EPINFO_IS_NULL; + + p0->lowspeed = (lowspeed) ? 1 : 0; + + // Allocate new address according to device class + uint32_t bAddress = addrPool.AllocAddress(parent, 0, port); + + if(!bAddress) + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + + p = addrPool.GetUsbDevicePtr(bAddress); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + p->lowspeed = lowspeed; + + // Assign new address to the device + rcode = setAddr(0, 0, bAddress); + + if(rcode) { + TRACE_USBHOST(printf("/!\\ USBHost::DefaultAddressing : Set address failed with code: %lu\r\n", rcode);) + addrPool.FreeAddress(bAddress); + bAddress = 0; + return rcode; + } + return 0; +} + +uint32_t USBHost::AttemptConfig(uint32_t driver, uint32_t parent, uint32_t port, uint32_t lowspeed) { + //printf("AttemptConfig: parent = %i, port = %i\r\n", parent, port); + uint8_t retries = 0; + +again: + uint8_t rcode = devConfig[driver]->ConfigureDevice(parent, port, lowspeed); + if(rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) { + if(parent == 0) { + // Send a bus reset on the root interface. + //regWr(rHCTL, bmBUSRST); //issue bus reset + UHD_BusReset(); + delay(102); // delay 102ms, compensate for clock inaccuracy. + } else { + // reset parent port + devConfig[parent]->ResetHubPort(port); + } + } else if(rcode != 0x00/*hrJERR*/ && retries < 3) { // Some devices returns this when plugged in - trying to initialize the device again usually works + delay(100); + retries++; + goto again; + } else if(rcode) + return rcode; + + rcode = devConfig[driver]->Init(parent, port, lowspeed); + if(rcode != 0x00/*hrJERR*/ && retries < 3) { // Some devices returns this when plugged in - trying to initialize the device again usually works + delay(100); + retries++; + goto again; + } + if(rcode) { + // Issue a bus reset, because the device may be in a limbo state + if(parent == 0) { + // Send a bus reset on the root interface. + //regWr(rHCTL, bmBUSRST); //issue bus reset + UHD_BusReset(); + delay(102); // delay 102ms, compensate for clock inaccuracy. + } else { + // reset parent port + devConfig[parent]->ResetHubPort(port); + } + } + return rcode; +} + +/* + * This is broken. We need to enumerate differently. + * It causes major problems with several devices if detected in an unexpected order. + * + * + * Oleg - I wouldn't do anything before the newly connected device is considered sane. + * i.e.(delays are not indicated for brevity): + * 1. reset + * 2. GetDevDescr(); + * 3a. If ACK, continue with allocating address, addressing, etc. + * 3b. Else reset again, count resets, stop at some number (5?). + * 4. When max.number of resets is reached, toggle power/fail + * If desired, this could be modified by performing two resets with GetDevDescr() in the middle - however, from my experience, if a device answers to GDD() + * it doesn't need to be reset again + * New steps proposal: + * 1: get address pool instance. exit on fail + * 2: pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf). exit on fail. + * 3: bus reset, 100ms delay + * 4: set address + * 5: pUsb->setEpInfoEntry(bAddress, 1, epInfo), exit on fail + * 6: while (configurations) { + * for(each configuration) { + * for (each driver) { + * 6a: Ask device if it likes configuration. Returns 0 on OK. + * If successful, the driver configured device. + * The driver now owns the endpoints, and takes over managing them. + * The following will need codes: + * Everything went well, instance consumed, exit with success. + * Instance already in use, ignore it, try next driver. + * Not a supported device, ignore it, try next driver. + * Not a supported configuration for this device, ignore it, try next driver. + * Could not configure device, fatal, exit with fail. + * } + * } + * } + * 7: for(each driver) { + * 7a: Ask device if it knows this VID/PID. Acts exactly like 6a, but using VID/PID + * 8: if we get here, no driver likes the device plugged in, so exit failure. + * + */ +uint32_t USBHost::Configuring(uint32_t parent, uint32_t port, uint32_t lowspeed) { + //uint32_t bAddress = 0; + //printf("Configuring: parent = %i, port = %i\r\n", parent, port); + uint32_t devConfigIndex; + uint32_t rcode = 0; + uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; + USB_DEVICE_DESCRIPTOR *udd = reinterpret_cast(buf); + UsbDeviceDefinition *p = NULL; + EpInfo *oldep_ptr = NULL; + EpInfo epInfo; + + epInfo.epAddr = 0; + epInfo.maxPktSize = 8; + epInfo.bmSndToggle = 0; + epInfo.bmRcvToggle = 0; + epInfo.bmNakPower = USB_NAK_MAX_POWER; + + //delay(2000); + AddressPool &addrPool = GetAddressPool(); + // Get pointer to pseudo device with address 0 assigned + p = addrPool.GetUsbDevicePtr(0); + if(!p) { + //printf("Configuring error: USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL\r\n"); + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + } + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + + // Temporary assign new pointer to epInfo to p->epinfo in order to + // avoid toggle inconsistence + + p->epinfo = &epInfo; + + p->lowspeed = lowspeed; + // Get device descriptor + rcode = getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); + // The first GetDescriptor give us the endpoint 0 max packet size. + epInfo.maxPktSize = buf[7]; + // Restore p->epinfo + p->epinfo = oldep_ptr; + + if(rcode) { + //printf("Configuring error: Can't get USB_DEVICE_DESCRIPTOR\r\n"); + return rcode; + } + + // to-do? + // Allocate new address according to device class + //bAddress = addrPool.AllocAddress(parent, false, port); + + //if (!bAddress) + // return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + uint16_t vid = udd->idVendor; + uint16_t pid = udd->idProduct; + uint8_t klass = udd->bDeviceClass; + + // Attempt to configure if VID/PID or device class matches with a driver + for(devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) { + if(!devConfig[devConfigIndex]) continue; // no driver + if(devConfig[devConfigIndex]->GetAddress()) continue; // consumed + if(devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass)) { + rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed); + if(rcode != USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED) + break; + } + } + + if(devConfigIndex < USB_NUMDEVICES) { + return rcode; + } + + + // blindly attempt to configure + for(devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) { + if(!devConfig[devConfigIndex]) continue; + if(devConfig[devConfigIndex]->GetAddress()) continue; // consumed + if(devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass)) continue; // If this is true it means it must have returned USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED above + rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed); + + //printf("ERROR ENUMERATING %2.2x\r\n", rcode); + if(!(rcode == USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED || rcode == USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE)) { + // in case of an error dev_index should be reset to 0 + // in order to start from the very beginning the + // next time the program gets here + //if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE) + // devConfigIndex = 0; + return rcode; + } + } + // if we get here that means that the device class is not supported by any of registered classes + rcode = DefaultAddressing(parent, port, lowspeed); + + return rcode; +} + +uint32_t USBHost::ReleaseDevice(uint32_t addr) { + if(!addr) + return 0; + + for(uint32_t i = 0; i < USB_NUMDEVICES; i++) { + if(!devConfig[i]) continue; + if(devConfig[i]->GetAddress() == addr) + return devConfig[i]->Release(); + } + return 0; +} + +//get device descriptor + +uint32_t USBHost::getDevDescr(uint32_t addr, uint32_t ep, uint32_t nbytes, uint8_t* dataptr) { + return (ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, nbytes, dataptr, 0)); +} +//get configuration descriptor + +uint32_t USBHost::getConfDescr(uint32_t addr, uint32_t ep, uint32_t nbytes, uint32_t conf, uint8_t* dataptr) { + return (ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, nbytes, dataptr, 0)); +} + +/* Requests Configuration Descriptor. Sends two Get Conf Descr requests. The first one gets the total length of all descriptors, then the second one requests this + total length. The length of the first request can be shorter ( 4 bytes ), however, there are devices which won't work unless this length is set to 9 */ +uint32_t USBHost::getConfDescr(uint32_t addr, uint32_t ep, uint32_t conf, USBReadParser *p) { + const uint32_t bufSize = 64; + uint8_t buf[bufSize]; + USB_CONFIGURATION_DESCRIPTOR *ucd = reinterpret_cast(buf); + + uint32_t ret = getConfDescr(addr, ep, 9, conf, buf); + + if(ret) + return ret; + + uint32_t total = ucd->wTotalLength; + + //USBTRACE2("\r\ntotal conf.size:", total); + + return (ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, total, bufSize, buf, p)); +} + +//get string descriptor + +uint32_t USBHost::getStrDescr(uint32_t addr, uint32_t ep, uint32_t nbytes, uint32_t index, uint32_t langid, uint8_t* dataptr) { + return (ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, nbytes, nbytes, dataptr, 0)); +} +//set address + +uint32_t USBHost::setAddr(uint32_t oldaddr, uint32_t ep, uint32_t newaddr) { + uint32_t rcode = ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL); + //delay(2); //per USB 2.0 sect.9.2.6.3 + delay(300); // Older spec says you should wait at least 200ms + return rcode; + //return ( ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL)); +} +//set configuration + +uint32_t USBHost::setConf(uint32_t addr, uint32_t ep, uint32_t conf_value) { + return ( ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL)); +} + +//#endif //ARDUINO_SAMD_ZERO diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/Usb.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/Usb.h new file mode 100644 index 00000000000..919b835232d --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/Usb.h @@ -0,0 +1,46 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +/* USB functions */ + +#ifndef USB_H_INCLUDED +#define USB_H_INCLUDED +#define _usb_h_ + +#include + +//#include "Arduino.h" +#include "macros.h" +// None of these should ever be included by a driver, or a user's sketch. + +#include "variant.h" +#define USB_HOST_SERIAL SERIAL_PORT_MONITOR +#include "Print.h" +#include "printhex.h" +#include "message.h" +#include "hexdump.h" +#include "sink_parser.h" + +#include "address.h" + +#include "usb_ch9.h" +//#include "usbhost.h" +#include "UsbCore.h" +#include "parsetools.h" + +#include "confdescparser.h" + +#endif /* USB_H_INCLUDED */ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/UsbCore.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/UsbCore.h new file mode 100644 index 00000000000..f5368cec2a6 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/UsbCore.h @@ -0,0 +1,292 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#if !defined(_usb_h_) || defined(USBCORE_H) +#error "Never include UsbCore.h directly; include Usb.h instead" +#else +#define USBCORE_H + +// Not used anymore? If anyone uses this, please let us know so that this may be +// moved to the proper place, settings.h. +//#define USB_METHODS_INLINE + +/* shield pins. First parameter - SS pin, second parameter - INT pin */ +#ifdef BOARD_BLACK_WIDDOW +typedef MAX3421e MAX3421E; // Black Widow +#elif defined(CORE_TEENSY) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)) +#if EXT_RAM +typedef MAX3421e MAX3421E; // Teensy++ 2.0 with XMEM2 +#else +typedef MAX3421e MAX3421E; // Teensy++ 1.0 and 2.0 +#endif +#elif defined(BOARD_MEGA_ADK) +typedef MAX3421e MAX3421E; // Arduino Mega ADK +#elif defined(ARDUINO_AVR_BALANDUINO) +typedef MAX3421e MAX3421E; // Balanduino +#else +//typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.) or Teensy 2.0 and 3.0 +#endif + +/* Common setup data constant combinations */ +#define bmREQ_GET_DESCR USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_DEVICE //get descriptor request type +#define bmREQ_SET USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_DEVICE //set request type for all but 'set feature' and 'set interface' +#define bmREQ_CL_GET_INTF USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE //get interface request type + +// D7 data transfer direction (0 - host-to-device, 1 - device-to-host) +// D6-5 Type (0- standard, 1 - class, 2 - vendor, 3 - reserved) +// D4-0 Recipient (0 - device, 1 - interface, 2 - endpoint, 3 - other, 4..31 - reserved) + +// USB Device Classes +#define USB_CLASS_USE_CLASS_INFO 0x00 // Use Class Info in the Interface Descriptors +#define USB_CLASS_AUDIO 0x01 // Audio +#define USB_CLASS_COM_AND_CDC_CTRL 0x02 // Communications and CDC Control +#define USB_CLASS_HID 0x03 // HID +#define USB_CLASS_PHYSICAL 0x05 // Physical +#define USB_CLASS_IMAGE 0x06 // Image +#define USB_CLASS_PRINTER 0x07 // Printer +#define USB_CLASS_MASS_STORAGE 0x08 // Mass Storage +#define USB_CLASS_HUB 0x09 // Hub +#define USB_CLASS_CDC_DATA 0x0a // CDC-Data +#define USB_CLASS_SMART_CARD 0x0b // Smart-Card +#define USB_CLASS_CONTENT_SECURITY 0x0d // Content Security +#define USB_CLASS_VIDEO 0x0e // Video +#define USB_CLASS_PERSONAL_HEALTH 0x0f // Personal Healthcare +#define USB_CLASS_DIAGNOSTIC_DEVICE 0xdc // Diagnostic Device +#define USB_CLASS_WIRELESS_CTRL 0xe0 // Wireless Controller +#define USB_CLASS_MISC 0xef // Miscellaneous +#define USB_CLASS_APP_SPECIFIC 0xfe // Application Specific +#define USB_CLASS_VENDOR_SPECIFIC 0xff // Vendor Specific + +// Additional Error Codes +#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED 0xD1 +#define USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE 0xD2 +#define USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS 0xD3 +#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL 0xD4 +#define USB_ERROR_HUB_ADDRESS_OVERFLOW 0xD5 +#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL 0xD6 +#define USB_ERROR_EPINFO_IS_NULL 0xD7 +#define USB_ERROR_INVALID_ARGUMENT 0xD8 +#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE 0xD9 +#define USB_ERROR_INVALID_MAX_PKT_SIZE 0xDA +#define USB_ERROR_EP_NOT_FOUND_IN_TBL 0xDB +#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET 0xE0 +#define USB_ERROR_FailGetDevDescr 0xE1 +#define USB_ERROR_FailSetDevTblEntry 0xE2 +#define USB_ERROR_FailGetConfDescr 0xE3 +#define USB_ERROR_TRANSFER_TIMEOUT 0xFF + +#define USB_XFER_TIMEOUT 10000 //30000 // (5000) USB transfer timeout in milliseconds, per section 9.2.6.1 of USB 2.0 spec +//#define USB_NAK_LIMIT 32000 //NAK limit for a transfer. 0 means NAKs are not counted +#define USB_RETRY_LIMIT 3 // 3 retry limit for a transfer +#define USB_SETTLE_DELAY 200 //settle delay in milliseconds + +#define USB_NUMDEVICES 16 //number of USB devices +//#define HUB_MAX_HUBS 7 // maximum number of hubs that can be attached to the host controller +#define HUB_PORT_RESET_DELAY 20 // hub port reset delay 10 ms recomended, can be up to 20 ms + +/* USB state machine states */ +#define USB_STATE_MASK 0xf0 + +#define USB_STATE_DETACHED 0x10 +#define USB_DETACHED_SUBSTATE_INITIALIZE 0x11 +#define USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE 0x12 +#define USB_DETACHED_SUBSTATE_ILLEGAL 0x13 +#define USB_ATTACHED_SUBSTATE_SETTLE 0x20 +#define USB_ATTACHED_SUBSTATE_RESET_DEVICE 0x30 +#define USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE 0x40 +#define USB_ATTACHED_SUBSTATE_WAIT_SOF 0x50 +#define USB_ATTACHED_SUBSTATE_WAIT_RESET 0x51 +#define USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE 0x60 +#define USB_STATE_ADDRESSING 0x70 +#define USB_STATE_CONFIGURING 0x80 +#define USB_STATE_RUNNING 0x90 +#define USB_STATE_ERROR 0xa0 + +class USBDeviceConfig { +public: + + virtual uint32_t Init(uint32_t /* parent */, uint32_t /* port */, uint32_t /* lowspeed */) { + return 0; + } + + virtual uint32_t ConfigureDevice(uint32_t /* parent */, uint32_t /* port */, uint32_t /* lowspeed */) { + return 0; + } + + virtual uint32_t Release() { + return 0; + } + + virtual uint32_t Poll() { + return 0; + } + + virtual uint32_t GetAddress() { + return 0; + } + + virtual void ResetHubPort(uint32_t /* port */) { + return; + } // Note used for hubs only! + + virtual uint32_t VIDPIDOK(uint32_t /* vid */, uint32_t /* pid */) { + return false; + } + + virtual uint32_t DEVCLASSOK(uint32_t /* klass */) { + return false; + } +}; + +/* USB Setup Packet Structure */ +typedef struct { + + union { // offset description + uint8_t bmRequestType; // 0 Bit-map of request type + + struct { + uint8_t recipient : 5; // Recipient of the request + uint8_t type : 2; // Type of request + uint8_t direction : 1; // Direction of data X-fer + }; + } ReqType_u; + uint8_t bRequest; // 1 Request + + union { + uint16_t wValue; // 2 Depends on bRequest + + struct { + uint8_t wValueLo; + uint8_t wValueHi; + }; + } wVal_u; + uint16_t wIndex; // 4 Depends on bRequest + uint16_t wLength; // 6 Depends on bRequest +} SETUP_PKT, *PSETUP_PKT; + + + +// Base class for incoming data parser + +class USBReadParser { +public: + virtual void Parse(const uint32_t len, const uint8_t *pbuf, const uint32_t &offset) = 0; +}; + +class USBHost { + AddressPoolImpl addrPool; + USBDeviceConfig* devConfig[USB_NUMDEVICES]; + uint8_t bmHubPre; + +public: + USBHost(void); + + void SetHubPreMask() { + //bmHubPre |= bmHUBPRE; + }; + + void ResetHubPreMask() { + //bmHubPre &= (~bmHUBPRE); + }; + + AddressPool& GetAddressPool() { + return (AddressPool&)addrPool; + }; + + uint32_t RegisterDeviceClass(USBDeviceConfig *pdev) { + for(uint8_t i = 0; i < USB_NUMDEVICES; i++) { + if(!devConfig[i]) { + devConfig[i] = pdev; + return 0; + } + } + return USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS; + }; + + void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) { + addrPool.ForEachUsbDevice(pfunc); + }; + uint32_t getUsbTaskState(void); + void setUsbTaskState(uint32_t state); + uint32_t getUsbErrorCode(void); + + EpInfo* getEpInfoEntry(uint32_t addr, uint32_t ep); + uint32_t setEpInfoEntry(uint32_t addr, uint32_t epcount, EpInfo* eprecord_ptr); + + /* Control requests */ + uint32_t getDevDescr(uint32_t addr, uint32_t ep, uint32_t nbytes, uint8_t* dataptr); + uint32_t getConfDescr(uint32_t addr, uint32_t ep, uint32_t nbytes, uint32_t conf, uint8_t* dataptr); + + uint32_t getConfDescr(uint32_t addr, uint32_t ep, uint32_t conf, USBReadParser *p); + + uint32_t getStrDescr(uint32_t addr, uint32_t ep, uint32_t nbytes, uint32_t index, uint32_t langid, uint8_t* dataptr); + uint32_t setAddr(uint32_t oldaddr, uint32_t ep, uint32_t newaddr); + uint32_t setConf(uint32_t addr, uint32_t ep, uint32_t conf_value); + /**/ + uint32_t ctrlData(uint32_t addr, uint32_t ep, uint32_t nbytes, uint8_t* dataptr, uint32_t direction); + uint32_t ctrlStatus(uint32_t ep, uint32_t direction, uint32_t nak_limit); + uint32_t inTransfer(uint32_t addr, uint32_t ep, uint8_t *nbytesptr, uint8_t* data); + uint32_t outTransfer(uint32_t addr, uint32_t ep, uint32_t nbytes, uint8_t* data); + uint32_t dispatchPkt(uint32_t token, uint32_t ep, uint32_t nak_limit); + + void Task(void); + + uint32_t DefaultAddressing(uint32_t parent, uint32_t port, uint32_t lowspeed); + uint32_t Configuring(uint32_t parent, uint32_t port, uint32_t lowspeed); + uint32_t ReleaseDevice(uint32_t addr); + + uint32_t ctrlReq(uint32_t addr, uint32_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, + uint16_t wInd, uint16_t total, uint32_t nbytes, uint8_t* dataptr, USBReadParser *p); + + uint32_t Init(); +private: + uint32_t SetPipeAddress(uint32_t addr, uint32_t ep, EpInfo **ppep, uint32_t &nak_limit); + uint32_t OutTransfer(EpInfo *pep, uint32_t nak_limit, uint32_t nbytes, uint8_t *data); + uint32_t InTransfer(EpInfo *pep, uint32_t nak_limit, uint8_t *nbytesptr, uint8_t *data); + uint32_t AttemptConfig(uint32_t driver, uint32_t parent, uint32_t port, uint32_t lowspeed); +}; + +#if 0 //defined(USB_METHODS_INLINE) +//get device descriptor + +inline uint8_t USBHost::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) { + return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, dataptr)); +} +//get configuration descriptor + +inline uint8_t USBHost::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) { + return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, dataptr)); +} +//get string descriptor + +inline uint8_t USBHost::getStrDescr(uint8_t addr, uint8_t ep, uint16_t nuint8_ts, uint8_t index, uint16_t langid, uint8_t* dataptr) { + return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, nuint8_ts, dataptr)); +} +//set address + +inline uint8_t USBHost::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) { + return ( ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, NULL)); +} +//set configuration + +inline uint8_t USBHost::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) { + return ( ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, NULL)); +} + +#endif // defined(USB_METHODS_INLINE) + +#endif /* USBCORE_H */ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/address.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/address.h new file mode 100644 index 00000000000..a96108224f8 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/address.h @@ -0,0 +1,280 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ + +#if !defined(_usb_h_) || defined(ADDRESS_H_INCLUDED) +#error "Never include address.h directly; include Usb.h instead" +#else +#define ADDRESS_H_INCLUDED + +#include +#include + +/* NAK powers. To save space in endpoint data structure, amount of retries before giving up and returning 0x4 is stored in */ +/* bmNakPower as a power of 2. The actual nak_limit is then calculated as nak_limit = ( 2^bmNakPower - 1) */ +#define USB_NAK_MAX_POWER 15 //NAK binary order maximum value +#define USB_NAK_DEFAULT 14 //default 32K-1 NAKs before giving up +#define USB_NAK_NOWAIT 1 //Single NAK stops transfer +#define USB_NAK_NONAK 0 //Do not count NAKs, stop retrying after USB Timeout + +struct EpInfo { + uint32_t epAddr; // Endpoint address + uint32_t maxPktSize; // Maximum packet size + union { + uint8_t epAttribs; + + struct { + uint8_t bmSndToggle : 1; // Send toggle, when zero bmSNDTOG0, bmSNDTOG1 otherwise + uint8_t bmRcvToggle : 1; // Send toggle, when zero bmRCVTOG0, bmRCVTOG1 otherwise + uint8_t bmNakPower : 6; // Binary order for NAK_LIMIT value + }; + }; +}; + +// 7 6 5 4 3 2 1 0 +// --------------------------------- +// | | H | P | P | P | A | A | A | +// --------------------------------- +// +// H - if 1 the address is a hub address +// P - parent hub address +// A - device address / port number in case of hub +// + +struct UsbDeviceAddress { + union { + struct { + uint32_t bmAddress : 3; // device address/port number + uint32_t bmParent : 3; // parent hub address + uint32_t bmHub : 1; // hub flag + uint32_t bmReserved : 25; // reserved, must be zerro + }; + uint32_t devAddress; + }; +}; + +#define bmUSB_DEV_ADDR_ADDRESS 0x07 +#define bmUSB_DEV_ADDR_PARENT 0x38 +#define bmUSB_DEV_ADDR_HUB 0x40 + +struct UsbDeviceDefinition { + EpInfo *epinfo; // endpoint info pointer + UsbDeviceAddress address; + uint32_t epcount; // number of endpoints + uint32_t lowspeed; // indicates if a device is the low speed one + // uint8_t devclass; // device class +}; + +class AddressPool { +public: + virtual UsbDeviceDefinition* GetUsbDevicePtr(uint32_t addr) = 0; + virtual uint32_t AllocAddress(uint32_t parent, uint32_t is_hub = 0, uint32_t port = 0) = 0; + virtual void FreeAddress(uint32_t addr) = 0; +}; + +typedef void (*UsbDeviceHandleFunc)(UsbDeviceDefinition *pdev); + +#define ADDR_ERROR_INVALID_INDEX 0xFF +#define ADDR_ERROR_INVALID_ADDRESS 0xFF + +template +class AddressPoolImpl : public AddressPool { + EpInfo dev0ep; //Endpoint data structure used during enumeration for uninitialized device + + uint32_t hubCounter; // hub counter is kept + // in order to avoid hub address duplication + + UsbDeviceDefinition thePool[MAX_DEVICES_ALLOWED]; + + // Initializes address pool entry + + void InitEntry(uint32_t index) { + thePool[index].address.devAddress = 0; + thePool[index].epcount = 1; + thePool[index].lowspeed = 0; + thePool[index].epinfo = &dev0ep; + }; + + // Returns thePool index for a given address + + uint32_t FindAddressIndex(uint32_t address = 0) { + for (uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++) { + if(thePool[i].address.devAddress == address) + return i; + } + return 0; + }; + + // Returns thePool child index for a given parent + + uint32_t FindChildIndex(UsbDeviceAddress addr, uint32_t start = 1) { + for (uint32_t i = (start < 1 || start >= MAX_DEVICES_ALLOWED) ? 1 : start; i < MAX_DEVICES_ALLOWED; i++) { + if(thePool[i].address.bmParent == addr.bmAddress) + return i; + } + return 0; + }; + + // Frees address entry specified by index parameter + + void FreeAddressByIndex(uint32_t index) { + // Zero field is reserved and should not be affected + if(index == 0) + return; + + UsbDeviceAddress uda = thePool[index].address; + // If a hub was switched off all port addresses should be freed + if(uda.bmHub == 1) { + for (uint32_t i = 1; (i = FindChildIndex(uda, i));) + FreeAddressByIndex(i); + + // If the hub had the last allocated address, hubCounter should be decremented + if(hubCounter == uda.bmAddress) + hubCounter--; + } + InitEntry(index); + } + + // Initializes the whole address pool at once + + void InitAllAddresses() { + for (uint32_t i = 1; i < MAX_DEVICES_ALLOWED; i++) + InitEntry(i); + + hubCounter = 0; + }; + +public: + + AddressPoolImpl() : hubCounter(0) { + // Zero address is reserved + InitEntry(0); + + thePool[0].address.devAddress = 0; + thePool[0].epinfo = &dev0ep; + dev0ep.epAddr = 0; + dev0ep.maxPktSize = 8; + dev0ep.epAttribs = 0; //set DATA0/1 toggles to 0 + dev0ep.bmNakPower = USB_NAK_MAX_POWER; + + InitAllAddresses(); + }; + + // Returns a pointer to a specified address entry + + virtual UsbDeviceDefinition* GetUsbDevicePtr(uint32_t addr) { + if(!addr) + return thePool; + + uint32_t index = FindAddressIndex(addr); + + return (!index) ? NULL : thePool + index; + }; + + // Performs an operation specified by pfunc for each addressed device + + void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) { + if(!pfunc) + return; + + for (uint32_t i = 1; i < MAX_DEVICES_ALLOWED; i++) + if(thePool[i].address.devAddress) + pfunc(thePool + i); + }; + + // Allocates new address + + virtual uint32_t AllocAddress(uint32_t parent, uint32_t is_hub = 0, uint32_t port = 0) { + /* if (parent != 0 && port == 0) + USB_HOST_SERIAL.println("PRT:0"); */ + UsbDeviceAddress _parent; + _parent.devAddress = parent; + if(_parent.bmReserved || port > 7) + //if(parent > 127 || port > 7) + return 0; + + if(is_hub && hubCounter == 7) + return 0; + + // finds first empty address entry starting from one + uint32_t index = FindAddressIndex(0); + + if(!index) // if empty entry is not found + return 0; + + if(_parent.devAddress == 0) { + if(is_hub) { + thePool[index].address.devAddress = 0x41; + hubCounter++; + } else + thePool[index].address.devAddress = 1; + + return thePool[index].address.devAddress; + } + + UsbDeviceAddress addr; + addr.devAddress = 0; // Ensure all bits are zero + addr.bmParent = _parent.bmAddress; + if(is_hub) { + addr.bmHub = 1; + addr.bmAddress = ++hubCounter; + } else { + addr.bmHub = 0; + addr.bmAddress = port; + } + thePool[index].address = addr; + /* + USB_HOST_SERIAL.print("Addr:"); + USB_HOST_SERIAL.print(addr.bmHub, HEX); + USB_HOST_SERIAL.print("."); + USB_HOST_SERIAL.print(addr.bmParent, HEX); + USB_HOST_SERIAL.print("."); + USB_HOST_SERIAL.println(addr.bmAddress, HEX); + */ + return thePool[index].address.devAddress; + }; + + // Empties pool entry + + virtual void FreeAddress(uint32_t addr) { + // if the root hub is disconnected all the addresses should be initialized + if(addr == 0x41) { + InitAllAddresses(); + return; + } + uint32_t index = FindAddressIndex(addr); + FreeAddressByIndex(index); + }; + + // Returns number of hubs attached + // It can be rather helpfull to find out if there are hubs attached than getting the exact number of hubs. + //uint32_t GetNumHubs() + //{ + // return hubCounter; + //}; + //uint32_t GetNumDevices() + //{ + // uint32_t counter = 0; + + // for (uint32_t i=1; iRegisterDeviceClass(this); //set devConfig[] entry + } +} + +uint32_t ADK::ConfigureDevice(uint32_t parent, uint32_t port, uint32_t lowspeed) { + return Init(parent, port, lowspeed); // Just call Init. Yes, really! +} + +/* Connection initialization of an Android phone */ +uint32_t ADK::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { + uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; + USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast(buf); + uint32_t rcode; + uint32_t num_of_conf; // number of configurations + UsbDeviceDefinition *p = NULL; + EpInfo *oldep_ptr = NULL; + + // get memory address of USB device address pool + AddressPool &addrPool = pUsb->GetAddressPool(); + + USBTRACE("\r\nADK Init"); + + // check if address has already been assigned to an instance + if(bAddress) { + USBTRACE("\r\nAddress in use"); + return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; + } + + // Get pointer to pseudo device with address 0 assigned + p = addrPool.GetUsbDevicePtr(0); + + if(!p) { + USBTRACE("\r\nAddress not found"); + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + } + + if(!p->epinfo) { + USBTRACE("epinfo is null\r\n"); + return USB_ERROR_EPINFO_IS_NULL; + } + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + + p->lowspeed = lowspeed; + + // Get device descriptor GET_DESCRIPTOR + rcode = pUsb->getDevDescr(0, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); + + // Restore p->epinfo + p->epinfo = oldep_ptr; + + if(rcode) { + USBTRACE("\r\nGetDevDesc1 Error "); + goto FailGetDevDescr; + } + + // Reset + UHD_BusReset(); + while( Is_uhd_starting_reset() ) {} + + // Allocate new address according to device class + bAddress = addrPool.AllocAddress(parent, false, port); + if (!bAddress) + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + + + // Extract Max Packet Size from device descriptor + epInfo[0].maxPktSize = udd->bMaxPacketSize0; + + // Assign new address to the device SET_ADDRESS + rcode = pUsb->setAddr(0, 0, bAddress); + if(rcode) { + USBTRACE("\r\nsetAddr Error "); + p->lowspeed = false; + addrPool.FreeAddress(bAddress); + bAddress = 0; + TRACE_USBHOST(printf("ADK::Init : setAddr failed with rcode %lu\r\n", rcode);) + return rcode; + }//if (rcode... + + USBTRACE2("\r\nAddr:", bAddress); + // Spec says you should wait at least 200ms. + //delay(300); + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + // Get device descriptor GET_DESCRIPTOR + rcode = pUsb->getDevDescr(bAddress, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); + // Restore p->epinfo + p->epinfo = oldep_ptr; + if (rcode) + { + USBTRACE("\r\nGetDevDesc2 Error "); + goto FailGetDevDescr; + } + + TRACE_USBHOST(printf("ADK::Init : device address is now %lu\r\n", bAddress);) + + p->lowspeed = false; + + //get pointer to assigned address record + p = addrPool.GetUsbDevicePtr(bAddress); + if(!p) { + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + } + + p->lowspeed = lowspeed; + + // Assign epInfo to epinfo pointer - only EP0 is known + rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); + if(rcode) { + goto FailSetDevTblEntry; + } + + //check if ADK device is already in accessory mode; if yes, configure and exit + if(udd->idVendor == ADK_VID && + (udd->idProduct == ADK_PID || udd->idProduct == ADB_PID)) { + USBTRACE("\r\nAcc.mode device detected"); + /* go through configurations, find first bulk-IN, bulk-OUT EP, fill epInfo and quit */ + num_of_conf = udd->bNumConfigurations; + + USBTRACE2("\r\nNC:",num_of_conf); + for (uint32_t i = 0; i < num_of_conf; i++) { + ConfigDescParser<0, 0, 0, 0> confDescrParser(this); + + delay(1); + rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); + +#if defined(XOOM) + //added by Jaylen Scott Vanorden + if(rcode) { + TRACE_USBHOST(printf("ADK::Init : Got 1st bad code for config: %lu\r\n", rcode);) + + // Try once more + rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); + } +#endif + if(rcode) { + goto FailGetConfDescr; + } + if(bNumEP > 2) { + break; + } + } // for (uint32_t i=0; isetEpInfoEntry(bAddress, 3, epInfo); + if(rcode) { + goto FailSetDevTblEntry; + } + } + + // Set Configuration Value + rcode = pUsb->setConf(bAddress, 0, bConfNum); + if(rcode) { + goto FailSetConfDescr; + } + /* print endpoint structure */ + + USBTRACE("\r\nEndpoint Structure:"); + USBTRACE("\r\nEP0:"); + USBTRACE2("\r\nAddr: ", epInfo[0].epAddr); + USBTRACE2("\r\nMax.pkt.size: ", epInfo[0].maxPktSize); + USBTRACE2("\r\nAttr: ", epInfo[0].epAttribs); + USBTRACE("\r\nEpout:"); + USBTRACE2("\r\nAddr: ", epInfo[epDataOutIndex].epAddr); + USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataOutIndex].maxPktSize); + USBTRACE2("\r\nAttr: ", epInfo[epDataOutIndex].epAttribs); + USBTRACE("\r\nEpin:"); + USBTRACE2("\r\nAddr: ", epInfo[epDataInIndex].epAddr); + USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataInIndex].maxPktSize); + USBTRACE2("\r\nAttr: ", epInfo[epDataInIndex].epAttribs); + + + USBTRACE("\r\nConfiguration successful"); + ready = true; + return 0; //successful configuration + }//if( buf->idVendor == ADK_VID... + + //probe device - get accessory protocol revision + { + uint32_t adkproto = 0; + delay(1); + //rcode = getProto((uint8_t*) & adkproto); // ADK_GETPROTO 0x33 + rcode = getProto((uint8_t*)buf); + +#if defined(XOOM) + //added by Jaylen Scott Vanorden + if(rcode) { + USBTRACE2("\r\nGot 1st bad code for proto: ", rcode); + // Try once more + rcode = getProto((uint8_t*) & adkproto); + } +#endif + if(rcode) { + goto FailGetProto; //init fails + } + adkproto = buf[0] | (buf[1]<<8); + USBTRACE2("\r\nADK protocol rev. ", adkproto); + } + + delay(100); + + //sending ID strings + // ADK_SENDSTR 0x34 + if( sendStr(ACCESSORY_STRING_MANUFACTURER, manufacturer) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_MANUFACTURER"); } + delay(10); + if( sendStr(ACCESSORY_STRING_MODEL, model) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_MODEL"); } + delay(10); + if( sendStr(ACCESSORY_STRING_DESCRIPTION, description) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_DESCRIPTION"); } + delay(10); + if( sendStr(ACCESSORY_STRING_VERSION, version) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_VERSION"); } + delay(10); + if( sendStr(ACCESSORY_STRING_URI, uri) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_URI"); } + delay(10); + if( sendStr(ACCESSORY_STRING_SERIAL, serial) ) { + USBTRACE("\r\nPb ACCESSORY_STRING_SERIAL"); } + + delay(100); + + USBTRACE("\r\nSwitch to accessory mode"); + //switch to accessory mode + //the Android phone will reset + rcode = switchAcc(); + if(rcode) { + goto FailSwAcc; //init fails + } + rcode = USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; + delay(100); // Give Android a chance to do its reset. This is a guess, and possibly could be lower. + goto SwAttempt; //switch to accessory mode attempted + + /* diagnostic messages */ +FailGetDevDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetDevDescr(rcode); + goto Fail; +#endif + +FailSetDevTblEntry: +#ifdef DEBUG_USB_HOST + NotifyFailSetDevTblEntry(rcode); + goto Fail; +#endif + +FailGetConfDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetConfDescr(rcode); + goto Fail; +#endif + +FailSetConfDescr: +#ifdef DEBUG_USB_HOST + NotifyFailSetConfDescr(rcode); + goto Fail; +#endif + +FailGetProto: +#ifdef DEBUG_USB_HOST + USBTRACE("\r\ngetProto:"); + goto Fail; +#endif + +FailSwAcc: +#ifdef DEBUG_USB_HOST + USBTRACE("\r\nswAcc:"); + goto Fail; +#endif + + //FailOnInit: + // USBTRACE("OnInit:"); + // goto Fail; + // +SwAttempt: +#ifdef DEBUG_USB_HOST + USBTRACE("\r\nAccessory mode switch attempt"); +Fail: +#endif + USBTRACE2("\r\nADK Init Failed, error code: ", rcode); + //NotifyFail(rcode); + Release(); + return rcode; +} + +/* Extracts bulk-IN and bulk-OUT endpoint information from config descriptor */ +void ADK::EndpointXtract(uint32_t conf, uint32_t /* iface */, uint32_t /* alt */, uint32_t /* proto */, const USB_ENDPOINT_DESCRIPTOR *pep) { + //ErrorMessage(PSTR("Conf.Val"), conf); + //ErrorMessage(PSTR("Iface Num"), iface); + //ErrorMessage(PSTR("Alt.Set"), alt); + + //added by Yuuichi Akagawa + if(bNumEP == 3) { + return; + } + + bConfNum = conf; + + if((pep->bmAttributes & 0x02) == 2) { + uint32_t index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex; + // Fill in the endpoint info structure + epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F); + epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize; + epInfo[index].bmSndToggle = 0; + epInfo[index].bmRcvToggle = 0; + + bNumEP++; + + //PrintEndpointDescriptor(pep); + } +} + +/* Performs a cleanup after failed Init() attempt */ +uint32_t ADK::Release() { + pUsb->GetAddressPool().FreeAddress(bAddress); + + bNumEP = 1; //must have to be reset to 1 + + bAddress = 0; + ready = false; + return 0; +} + +uint32_t ADK::RcvData(uint8_t *bytes_rcvd, uint8_t *dataptr) { + USBTRACE2("\r\nAddr: ", bAddress ); + USBTRACE2("\r\nEP: ",epInfo[epDataInIndex].epAddr); + return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); +} + +uint32_t ADK::SndData(uint32_t nbytes, uint8_t *dataptr) { + return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); +} + +void ADK::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { + Notify(PSTR("Endpoint descriptor:"), 0x80); + Notify(PSTR("\r\nLength:\t\t"), 0x80); + PrintHex (ep_ptr->bLength, 0x80); + Notify(PSTR("\r\nType:\t\t"), 0x80); + PrintHex (ep_ptr->bDescriptorType, 0x80); + Notify(PSTR("\r\nAddress:\t"), 0x80); + PrintHex (ep_ptr->bEndpointAddress, 0x80); + Notify(PSTR("\r\nAttributes:\t"), 0x80); + PrintHex (ep_ptr->bmAttributes, 0x80); + Notify(PSTR("\r\nMaxPktSize:\t"), 0x80); + PrintHex (ep_ptr->wMaxPacketSize, 0x80); + Notify(PSTR("\r\nPoll Intrv:\t"), 0x80); + PrintHex (ep_ptr->bInterval, 0x80); + Notify(PSTR("\r\n"), 0x80); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/adk.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/adk.h new file mode 100644 index 00000000000..ffd22cf3e1f --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/adk.h @@ -0,0 +1,148 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ + +/* Google ADK interface support header */ + +#ifndef ADK_H_INCLUDED +#define ADK_H_INCLUDED + +#include +#include "Usb.h" +#include "hid.h" +#include "Arduino.h" + +// #define ADK_VID 0x18D1 +// #define ADK_PID 0x2D00 +// #define ADB_PID 0x2D01 + +// JCB +#define ADK_VID 0x04E8 +#define ADK_PID 0x685C +#define ADB_PID 0x685D + +#define XOOM //enables repeating getProto() and getConf() attempts + //necessary for slow devices such as Motorola XOOM + //defined by default, can be commented out to save memory + +/* requests */ + +#define ADK_GETPROTO 51 //check USB accessory protocol version 0x33 +#define ADK_SENDSTR 52 //send identifying string 0x34 +#define ADK_ACCSTART 53 //start device in accessory mode 0x35 + +#define bmREQ_ADK_GET USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE +#define bmREQ_ADK_SEND USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE + +#define ACCESSORY_STRING_MANUFACTURER 0 +#define ACCESSORY_STRING_MODEL 1 +#define ACCESSORY_STRING_DESCRIPTION 2 +#define ACCESSORY_STRING_VERSION 3 +#define ACCESSORY_STRING_URI 4 +#define ACCESSORY_STRING_SERIAL 5 + +#define ADK_MAX_ENDPOINTS 3 //endpoint 0, bulk_IN, bulk_OUT + +class ADK; + +class ADK : public USBDeviceConfig, public UsbConfigXtracter { +private: + /* ID strings */ + const char* manufacturer; + const char* model; + const char* description; + const char* version; + const char* uri; + const char* serial; + + /* ADK proprietary requests */ + uint32_t getProto(uint8_t* adkproto); + uint32_t sendStr(uint32_t index, const char* str); + uint32_t switchAcc(void); + +protected: + static const uint32_t epDataInIndex; // DataIn endpoint index + static const uint32_t epDataOutIndex; // DataOUT endpoint index + + /* Mandatory members */ + USBHost *pUsb; + uint32_t bAddress; // Device USB address + uint32_t bConfNum; // configuration number + + uint32_t bNumEP; // total number of EP in the configuration + uint32_t ready; + + /* Endpoint data structure */ + EpInfo epInfo[ADK_MAX_ENDPOINTS]; + + void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); + +public: + ADK(USBHost *pUsb, const char* manufacturer, + const char* model, + const char* description, + const char* version, + const char* uri, + const char* serial); + + // Methods for receiving and sending data + uint32_t RcvData(uint8_t *nbytesptr, uint8_t *dataptr); + uint32_t SndData(uint32_t nbytes, uint8_t *dataptr); + + + // USBDeviceConfig implementation + virtual uint32_t ConfigureDevice(uint32_t parent, uint32_t port, uint32_t lowspeed); + virtual uint32_t Init(uint32_t parent, uint32_t port, uint32_t lowspeed); + virtual uint32_t Release(); + + virtual uint32_t Poll() { + return 0; + }; + + virtual uint32_t GetAddress() { + return bAddress; + }; + + virtual uint32_t isReady() { + return ready; + }; + + virtual uint32_t VIDPIDOK(uint32_t vid, uint32_t pid) { + return (vid == ADK_VID && (pid == ADK_PID || pid == ADB_PID)); + }; + + //UsbConfigXtracter implementation + virtual void EndpointXtract(uint32_t conf, uint32_t iface, uint32_t alt, uint32_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); +}; //class ADK : public USBDeviceConfig ... + +/* get ADK protocol version */ + +/* returns 2 bytes in *adkproto */ +inline uint32_t ADK::getProto(uint8_t* adkproto) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL)); +} + +/* send ADK string */ +inline uint32_t ADK::sendStr(uint32_t index, const char* str) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*)str, NULL)); +} + +/* switch to accessory mode */ +inline uint32_t ADK::switchAcc(void) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL)); +} + +#endif /* ADK_H_INCLUDED */ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/confdescparser.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/confdescparser.h new file mode 100644 index 00000000000..4b2b41b4f19 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/confdescparser.h @@ -0,0 +1,223 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ + +#if !defined(_usb_h_) || defined(__CONFDESCPARSER_H__) +#error "Never include confdescparser.h directly; include Usb.h instead" +#else + +#define __CONFDESCPARSER_H__ + +#include + +//#define TRACE_USBHOST(x) x +#define TRACE_USBHOST(x) + +class UsbConfigXtracter { +public: + //virtual void ConfigXtract(const USB_CONFIGURATION_DESCRIPTOR *conf) = 0; + //virtual void InterfaceXtract(uint32_t conf, const USB_INTERFACE_DESCRIPTOR *iface) = 0; + virtual void EndpointXtract(uint32_t conf, uint32_t iface, uint32_t alt, uint32_t proto, const USB_ENDPOINT_DESCRIPTOR *ep) = 0; +}; + +#define CP_MASK_COMPARE_CLASS 1 +#define CP_MASK_COMPARE_SUBCLASS 2 +#define CP_MASK_COMPARE_PROTOCOL 4 +#define CP_MASK_COMPARE_ALL 7 + +// Configuration Descriptor Parser Class Template + +template +class ConfigDescParser : public USBReadParser { + UsbConfigXtracter *theXtractor; + MultiValueBuffer theBuffer; + MultiByteValueParser valParser; + ByteSkipper theSkipper; + uint8_t varBuffer[16 /*sizeof(USB_CONFIGURATION_DESCRIPTOR)*/]; + + uint32_t stateParseDescr; // ParseDescriptor state + + uint32_t dscrLen; // Descriptor length + uint32_t dscrType; // Descriptor type + + bool isGoodInterface; // Apropriate interface flag + uint32_t confValue; // Configuration value + uint32_t protoValue; // Protocol value + uint32_t ifaceNumber; // Interface number + uint32_t ifaceAltSet; // Interface alternate settings + + bool UseOr; + bool ParseDescriptor(uint8_t **pp, uint32_t *pcntdn); + void PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc); + +public: + + void SetOR(void) { + UseOr = true; + } + ConfigDescParser(UsbConfigXtracter *xtractor); + virtual void Parse(const uint32_t len, const uint8_t *pbuf, const uint32_t &offset); +}; + +template +ConfigDescParser::ConfigDescParser(UsbConfigXtracter *xtractor) : + theXtractor(xtractor), + stateParseDescr(0), + dscrLen(0), + dscrType(0), +UseOr(false) { + theBuffer.pValue = varBuffer; + valParser.Initialize(&theBuffer); + theSkipper.Initialize(&theBuffer); +}; + +template +void ConfigDescParser::Parse(const uint32_t len, const uint8_t *pbuf, const uint32_t & /* offset */) { + uint32_t cntdn = len; + uint8_t *p = (uint8_t*)pbuf; + + while (cntdn) + if(!ParseDescriptor(&p, &cntdn)) + return; +} + +/* Parser for the configuration descriptor. Takes values for class, subclass, protocol fields in interface descriptor and + compare masks for them. When the match is found, calls EndpointXtract passing buffer containing endpoint descriptor */ +template +bool ConfigDescParser::ParseDescriptor(uint8_t **pp, uint32_t *pcntdn) { + USB_CONFIGURATION_DESCRIPTOR* ucd = reinterpret_cast(varBuffer); + USB_INTERFACE_DESCRIPTOR* uid = reinterpret_cast(varBuffer); + switch(stateParseDescr) { + case 0: + theBuffer.valueSize = 2; + valParser.Initialize(&theBuffer); + stateParseDescr = 1; + case 1: + if(!valParser.Parse(pp, pcntdn)) + return false; + dscrLen = *((uint8_t*)theBuffer.pValue); + dscrType = *((uint8_t*)theBuffer.pValue + 1); + stateParseDescr = 2; + case 2: + // This is a sort of hack. Assuming that two bytes are all ready in the buffer + // the pointer is positioned two bytes ahead in order for the rest of descriptor + // to be read right after the size and the type fields. + // This should be used carefully. varBuffer should be used directly to handle data + // in the buffer. + theBuffer.pValue = varBuffer + 2; + stateParseDescr = 3; + case 3: + switch(dscrType) { + case USB_DESCRIPTOR_INTERFACE: + isGoodInterface = false; + case USB_DESCRIPTOR_CONFIGURATION: + theBuffer.valueSize = sizeof (USB_CONFIGURATION_DESCRIPTOR) - 2; + break; + case USB_DESCRIPTOR_ENDPOINT: + theBuffer.valueSize = sizeof (USB_ENDPOINT_DESCRIPTOR) - 2; + break; + case HID_DESCRIPTOR_HID: + theBuffer.valueSize = dscrLen - 2; + break; + } + valParser.Initialize(&theBuffer); + stateParseDescr = 4; + case 4: + switch(dscrType) { + case USB_DESCRIPTOR_CONFIGURATION: + if(!valParser.Parse(pp, pcntdn)) + return false; + confValue = ucd->bConfigurationValue; + break; + case USB_DESCRIPTOR_INTERFACE: + if(!valParser.Parse(pp, pcntdn)) + return false; + if((MASK & CP_MASK_COMPARE_CLASS) && uid->bInterfaceClass != CLASS_ID) + break; + if((MASK & CP_MASK_COMPARE_SUBCLASS) && uid->bInterfaceSubClass != SUBCLASS_ID) + break; + if(UseOr) { + if((!((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol))) + break; + } else { + if((MASK & CP_MASK_COMPARE_PROTOCOL) && uid->bInterfaceProtocol != PROTOCOL_ID) + break; + } + isGoodInterface = true; + ifaceNumber = uid->bInterfaceNumber; + ifaceAltSet = uid->bAlternateSetting; + protoValue = uid->bInterfaceProtocol; + break; + case USB_DESCRIPTOR_ENDPOINT: + if(!valParser.Parse(pp, pcntdn)) + return false; + if(isGoodInterface) + if(theXtractor) + theXtractor->EndpointXtract(confValue, ifaceNumber, ifaceAltSet, protoValue, (USB_ENDPOINT_DESCRIPTOR*)varBuffer); + break; + //case HID_DESCRIPTOR_HID: + // if (!valParser.Parse(pp, pcntdn)) + // return false; + // PrintHidDescriptor((const USB_HID_DESCRIPTOR*)varBuffer); + // break; + default: + if(!theSkipper.Skip(pp, pcntdn, dscrLen - 2)) + return false; + } + theBuffer.pValue = varBuffer; + stateParseDescr = 0; + } + return true; +} + +template +void ConfigDescParser::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) { + Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80); + Notify(PSTR("bDescLength:\t\t"), 0x80); + PrintHex (pDesc->bLength, 0x80); + + Notify(PSTR("\r\nbDescriptorType:\t"), 0x80); + PrintHex (pDesc->bDescriptorType, 0x80); + + Notify(PSTR("\r\nbcdHID:\t\t\t"), 0x80); + PrintHex (pDesc->bcdHID, 0x80); + + Notify(PSTR("\r\nbCountryCode:\t\t"), 0x80); + PrintHex (pDesc->bCountryCode, 0x80); + + Notify(PSTR("\r\nbNumDescriptors:\t"), 0x80); + PrintHex (pDesc->bNumDescriptors, 0x80); + + //Notify(PSTR("\r\nbDescrType:\t\t")); + //PrintHex(pDesc->bDescrType); + // + //Notify(PSTR("\r\nwDescriptorLength:\t")); + //PrintHex(pDesc->wDescriptorLength); + + for (uint32_t i = 0; i < pDesc->bNumDescriptors; i++) { + HID_CLASS_DESCRIPTOR_LEN_AND_TYPE *pLT = (HID_CLASS_DESCRIPTOR_LEN_AND_TYPE*)&(pDesc->bDescrType); + + Notify(PSTR("\r\nbDescrType:\t\t"), 0x80); + PrintHex (pLT[i].bDescrType, 0x80); + + Notify(PSTR("\r\nwDescriptorLength:\t"), 0x80); + PrintHex (pLT[i].wDescriptorLength, 0x80); + } + Notify(PSTR("\r\n"), 0x80); +} + + +#endif // __CONFDESCPARSER_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hexdump.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hexdump.h new file mode 100644 index 00000000000..3818d850b71 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hexdump.h @@ -0,0 +1,61 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ +#if !defined(_usb_h_) || defined(__HEXDUMP_H__) +#error "Never include hexdump.h directly; include Usb.h instead" +#else +#define __HEXDUMP_H__ + +extern int UsbDEBUGlvl; + +template +class HexDumper : public BASE_CLASS { + uint8_t byteCount; + OFFSET_TYPE byteTotal; + +public: + + HexDumper() : byteCount(0), byteTotal(0) { + }; + + void Initialize() { + byteCount = 0; + byteTotal = 0; + }; + + virtual void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset); +}; + +template +void HexDumper::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset) { + if(UsbDEBUGlvl >= 0x80) { // Fully bypass this block of code if we do not debug. + for(LEN_TYPE j = 0; j < len; j++, byteCount++, byteTotal++) { + if(!byteCount) { + PrintHex (byteTotal, 0x80); + E_Notify(PSTR(": "), 0x80); + } + PrintHex (pbuf[j], 0x80); + E_Notify(PSTR(" "), 0x80); + + if(byteCount == 15) { + E_Notify(PSTR("\r\n"), 0x80); + byteCount = 0xFF; + } + } + } +} + +#endif // __HEXDUMP_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hid.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hid.cpp new file mode 100644 index 00000000000..40b08dd7e9b --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hid.cpp @@ -0,0 +1,112 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#include "hid.h" + +//get HID report descriptor + +/* WRONG! Endpoint is _ALWAYS_ ZERO for HID! We want the _INTERFACE_ value here! +uint32_t HID::GetReportDescr(uint32_t ep, USBReadParser *parser) { + const uint8_t constBufLen = 64; + uint8_t buf[constBufLen]; + + uint8_t rcode = pUsb->ctrlReq(bAddress, ep, bmREQ_HIDREPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00, + HID_DESCRIPTOR_REPORT, 0x0000, 128, constBufLen, buf, (USBReadParser*)parser); + + //return ((rcode != hrSTALL) ? rcode : 0); + return rcode; +} + */ +uint32_t HID::GetReportDescr(uint32_t wIndex, USBReadParser *parser) { + const uint8_t constBufLen = 128; + uint8_t buf[constBufLen]; + + uint8_t rcode = pUsb->ctrlReq(bAddress, 0x00, bmREQ_HIDREPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00, + HID_DESCRIPTOR_REPORT, wIndex, 128, constBufLen, buf, (USBReadParser*)parser); + + //return ((rcode != hrSTALL) ? rcode : 0); + return rcode; +} + +//uint32_t HID::getHidDescr( uint8_t ep, uint16_t nbytes, uint8_t* dataptr ) +//{ +// return( pUsb->ctrlReq( bAddress, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_HID, 0x0000, nbytes, dataptr )); +//} + +uint32_t HID::SetReport(uint32_t ep, uint32_t iface, uint32_t report_type, uint32_t report_id, uint32_t nbytes, uint8_t* dataptr) { + return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HIDOUT, HID_REQUEST_SET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL)); +} + +uint32_t HID::GetReport(uint32_t ep, uint32_t iface, uint32_t report_type, uint32_t report_id, uint32_t nbytes, uint8_t* dataptr) { + return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HIDIN, HID_REQUEST_GET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL)); +} + +uint32_t HID::GetIdle(uint32_t iface, uint32_t reportID, uint8_t* dataptr) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HIDIN, HID_REQUEST_GET_IDLE, reportID, 0, iface, 0x0001, 0x0001, dataptr, NULL)); +} + +uint32_t HID::SetIdle(uint32_t iface, uint32_t reportID, uint32_t duration) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HIDOUT, HID_REQUEST_SET_IDLE, reportID, duration, iface, 0x0000, 0x0000, NULL, NULL)); +} + +uint32_t HID::SetProtocol(uint32_t iface, uint32_t protocol) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HIDOUT, HID_REQUEST_SET_PROTOCOL, protocol, 0x00, iface, 0x0000, 0x0000, NULL, NULL)); +} + +uint32_t HID::GetProtocol(uint32_t iface, uint8_t* dataptr) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HIDIN, HID_REQUEST_GET_PROTOCOL, 0x00, 0x00, iface, 0x0001, 0x0001, dataptr, NULL)); +} + +void HID::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { + Notify(PSTR("Endpoint descriptor:"), 0x80); + Notify(PSTR("\r\nLength:\t\t"), 0x80); + D_PrintHex (ep_ptr->bLength, 0x80); + Notify(PSTR("\r\nType:\t\t"), 0x80); + D_PrintHex (ep_ptr->bDescriptorType, 0x80); + Notify(PSTR("\r\nAddress:\t"), 0x80); + D_PrintHex (ep_ptr->bEndpointAddress, 0x80); + Notify(PSTR("\r\nAttributes:\t"), 0x80); + D_PrintHex (ep_ptr->bmAttributes, 0x80); + Notify(PSTR("\r\nMaxPktSize:\t"), 0x80); + D_PrintHex (ep_ptr->wMaxPacketSize, 0x80); + Notify(PSTR("\r\nPoll Intrv:\t"), 0x80); + D_PrintHex (ep_ptr->bInterval, 0x80); +} + +void HID::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) { + Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80); + Notify(PSTR("bDescLength:\t\t"), 0x80); + D_PrintHex (pDesc->bLength, 0x80); + + Notify(PSTR("\r\nbDescriptorType:\t"), 0x80); + D_PrintHex (pDesc->bDescriptorType, 0x80); + + Notify(PSTR("\r\nbcdHID:\t\t\t"), 0x80); + D_PrintHex (pDesc->bcdHID, 0x80); + + Notify(PSTR("\r\nbCountryCode:\t\t"), 0x80); + D_PrintHex (pDesc->bCountryCode, 0x80); + + Notify(PSTR("\r\nbNumDescriptors:\t"), 0x80); + D_PrintHex (pDesc->bNumDescriptors, 0x80); + + Notify(PSTR("\r\nbDescrType:\t\t"), 0x80); + D_PrintHex (pDesc->bDescrType, 0x80); + + Notify(PSTR("\r\nwDescriptorLength:\t"), 0x80); + D_PrintHex (pDesc->wDescriptorLength, 0x80); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hid.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hid.h new file mode 100644 index 00000000000..ca697a56829 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hid.h @@ -0,0 +1,183 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#if !defined(__HID_H__) +#define __HID_H__ + +#include "Usb.h" +#include "hidusagestr.h" + +#define MAX_REPORT_PARSERS 2 +#define HID_MAX_HID_CLASS_DESCRIPTORS 5 + +#define DATA_SIZE_MASK 0x03 +#define TYPE_MASK 0x0C +#define TAG_MASK 0xF0 + +#define DATA_SIZE_0 0x00 +#define DATA_SIZE_1 0x01 +#define DATA_SIZE_2 0x02 +#define DATA_SIZE_4 0x03 + +#define TYPE_MAIN 0x00 +#define TYPE_GLOBAL 0x04 +#define TYPE_LOCAL 0x08 + +#define TAG_MAIN_INPUT 0x80 +#define TAG_MAIN_OUTPUT 0x90 +#define TAG_MAIN_COLLECTION 0xA0 +#define TAG_MAIN_FEATURE 0xB0 +#define TAG_MAIN_ENDCOLLECTION 0xC0 + +#define TAG_GLOBAL_USAGEPAGE 0x00 +#define TAG_GLOBAL_LOGICALMIN 0x10 +#define TAG_GLOBAL_LOGICALMAX 0x20 +#define TAG_GLOBAL_PHYSMIN 0x30 +#define TAG_GLOBAL_PHYSMAX 0x40 +#define TAG_GLOBAL_UNITEXP 0x50 +#define TAG_GLOBAL_UNIT 0x60 +#define TAG_GLOBAL_REPORTSIZE 0x70 +#define TAG_GLOBAL_REPORTID 0x80 +#define TAG_GLOBAL_REPORTCOUNT 0x90 +#define TAG_GLOBAL_PUSH 0xA0 +#define TAG_GLOBAL_POP 0xB0 + +#define TAG_LOCAL_USAGE 0x00 +#define TAG_LOCAL_USAGEMIN 0x10 +#define TAG_LOCAL_USAGEMAX 0x20 + +/* HID requests */ +#define bmREQ_HIDOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE +#define bmREQ_HIDIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE +#define bmREQ_HIDREPORT USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_INTERFACE + +/* HID constants. Not part of chapter 9 */ +/* Class-Specific Requests */ +#define HID_REQUEST_GET_REPORT 0x01 +#define HID_REQUEST_GET_IDLE 0x02 +#define HID_REQUEST_GET_PROTOCOL 0x03 +#define HID_REQUEST_SET_REPORT 0x09 +#define HID_REQUEST_SET_IDLE 0x0A +#define HID_REQUEST_SET_PROTOCOL 0x0B + +/* Class Descriptor Types */ +#define HID_DESCRIPTOR_HID 0x21 +#define HID_DESCRIPTOR_REPORT 0x22 +#define HID_DESRIPTOR_PHY 0x23 + +/* Protocol Selection */ +#define HID_BOOT_PROTOCOL 0x00 +#define HID_RPT_PROTOCOL 0x01 + +/* HID Interface Class Code */ +#define HID_INTF 0x03 + +/* HID Interface Class SubClass Codes */ +#define HID_BOOT_INTF_SUBCLASS 0x01 + +/* HID Interface Class Protocol Codes */ +#define HID_PROTOCOL_NONE 0x00 +#define HID_PROTOCOL_KEYBOARD 0x01 +#define HID_PROTOCOL_MOUSE 0x02 + +#define HID_ITEM_TYPE_MAIN 0 +#define HID_ITEM_TYPE_GLOBAL 1 +#define HID_ITEM_TYPE_LOCAL 2 +#define HID_ITEM_TYPE_RESERVED 3 + +#define HID_LONG_ITEM_PREFIX 0xfe // Long item prefix value + +#define bmHID_MAIN_ITEM_TAG 0xfc // Main item tag mask + +#define bmHID_MAIN_ITEM_INPUT 0x80 // Main item Input tag value +#define bmHID_MAIN_ITEM_OUTPUT 0x90 // Main item Output tag value +#define bmHID_MAIN_ITEM_FEATURE 0xb0 // Main item Feature tag value +#define bmHID_MAIN_ITEM_COLLECTION 0xa0 // Main item Collection tag value +#define bmHID_MAIN_ITEM_END_COLLECTION 0xce // Main item End Collection tag value + +#define HID_MAIN_ITEM_COLLECTION_PHYSICAL 0 +#define HID_MAIN_ITEM_COLLECTION_APPLICATION 1 +#define HID_MAIN_ITEM_COLLECTION_LOGICAL 2 +#define HID_MAIN_ITEM_COLLECTION_REPORT 3 +#define HID_MAIN_ITEM_COLLECTION_NAMED_ARRAY 4 +#define HID_MAIN_ITEM_COLLECTION_USAGE_SWITCH 5 +#define HID_MAIN_ITEM_COLLECTION_USAGE_MODIFIER 6 + +struct HidItemPrefix { + uint8_t bSize : 2; + uint8_t bType : 2; + uint8_t bTag : 4; +}; + +struct MainItemIOFeature { + uint8_t bmIsConstantOrData : 1; + uint8_t bmIsArrayOrVariable : 1; + uint8_t bmIsRelativeOrAbsolute : 1; + uint8_t bmIsWrapOrNoWrap : 1; + uint8_t bmIsNonLonearOrLinear : 1; + uint8_t bmIsNoPreferedOrPrefered : 1; + uint8_t bmIsNullOrNoNull : 1; + uint8_t bmIsVolatileOrNonVolatile : 1; +}; + +class HID; + +class HIDReportParser { +public: + virtual void Parse(HID *hid, uint32_t is_rpt_id, uint32_t len, uint8_t *buf)= 0; +}; + +class HID : public USBDeviceConfig, public UsbConfigXtracter { +protected: + USBHost *pUsb; // USB class instance pointer + uint32_t bAddress; // address + +protected: + static const uint32_t epInterruptInIndex = 1; // InterruptIN endpoint index + static const uint32_t epInterruptOutIndex = 2; // InterruptOUT endpoint index + + static const uint32_t maxHidInterfaces = 3; + static const uint32_t maxEpPerInterface = 2; + static const uint32_t totalEndpoints = (maxHidInterfaces * maxEpPerInterface + 1); + + void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); + void PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc); + + virtual HIDReportParser* GetReportParser(uint32_t id); + +public: + + HID(USBHost *pusb) : pUsb(pusb) { + }; + + const USBHost* GetUsb() { + return pUsb; + }; + virtual uint32_t SetReportParser(uint32_t id, HIDReportParser *prs); + + uint32_t SetProtocol(uint32_t iface, uint32_t protocol); + uint32_t GetProtocol(uint32_t iface, uint8_t* dataptr); + uint32_t GetIdle(uint32_t iface, uint32_t reportID, uint8_t* dataptr); + uint32_t SetIdle(uint32_t iface, uint32_t reportID, uint32_t duration); + + uint32_t GetReportDescr(uint32_t ep, USBReadParser *parser = NULL); + + uint32_t GetHidDescr(uint32_t ep, uint32_t nbytes, uint8_t* dataptr); + uint32_t GetReport(uint32_t ep, uint32_t iface, uint32_t report_type, uint32_t report_id, uint32_t nbytes, uint8_t* dataptr); + uint32_t SetReport(uint32_t ep, uint32_t iface, uint32_t report_type, uint32_t report_id, uint32_t nbytes, uint8_t* dataptr); +}; + +#endif // __HID_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidboot.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidboot.cpp new file mode 100644 index 00000000000..f477d2c7f88 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidboot.cpp @@ -0,0 +1,240 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#include "hidboot.h" + +void MouseReportParser::Parse(HID * /* hid */, uint32_t /* is_rpt_id */, uint32_t /* len */, uint8_t *buf) { + MOUSEINFO *pmi = (MOUSEINFO*)buf; + // Future: + // bool event; + +#if 0 + if (prevState.mouseInfo.bmLeftButton == 0 && pmi->bmLeftButton == 1) + OnLeftButtonDown(pmi); + + if (prevState.mouseInfo.bmLeftButton == 1 && pmi->bmLeftButton == 0) + OnLeftButtonUp(pmi); + + if (prevState.mouseInfo.bmRightButton == 0 && pmi->bmRightButton == 1) + OnRightButtonDown(pmi); + + if (prevState.mouseInfo.bmRightButton == 1 && pmi->bmRightButton == 0) + OnRightButtonUp(pmi); + + if (prevState.mouseInfo.bmMiddleButton == 0 && pmi->bmMiddleButton == 1) + OnMiddleButtonDown(pmi); + + if (prevState.mouseInfo.bmMiddleButton == 1 && pmi->bmMiddleButton == 0) + OnMiddleButtonUp(pmi); + + if (prevState.mouseInfo.dX != pmi->dX || prevState.mouseInfo.dY != pmi->dY) + OnMouseMove(pmi); + + if (len > sizeof (MOUSEINFO)) + for (uint32_t i = 0; ibmLeftButton ) { + if(pmi->bmLeftButton) { + OnLeftButtonDown(pmi); + } else { + OnLeftButtonUp(pmi); + } + // Future: + // event = true; + } + + if(prevState.mouseInfo.bmRightButton != pmi->bmRightButton) { + if(pmi->bmRightButton) { + OnRightButtonDown(pmi); + } else { + OnRightButtonUp(pmi); + } + // Future: + // event = true; + } + + if(prevState.mouseInfo.bmMiddleButton != pmi->bmMiddleButton) { + if(pmi->bmMiddleButton) { + OnMiddleButtonDown(pmi); + } else { + OnMiddleButtonUp(pmi); + } + // Future: + // event = true; + } + + // + // Scroll wheel(s), are not part of the spec, but we could support it. + // Logitech wireless keyboard and mouse combo reports scroll wheel in byte 4 + // We wouldn't even need to save this information. + //if(len > 3) { + //} + // + + // Mice only report motion when they actually move! + // Why not just pass the x/y values to simplify things?? + if(pmi->dX || pmi->dY) { + OnMouseMove(pmi); + // Future: + // event = true; + } + + // + // Future: + // Provide a callback that operates on the gathered events from above. + // + // if(event) OnMouse(); + // + + // Only the first byte matters (buttons). We do NOT need to save position info. + prevState.bInfo[0] = buf[0]; +#endif + +}; + +void KeyboardReportParser::Parse(HID *hid, uint32_t /* is_rpt_id */, uint32_t /* len */, uint8_t *buf) { + // On error - return + if (buf[2] == 1) + return; + + //KBDINFO *pki = (KBDINFO*)buf; + + // provide event for changed control key state + if (prevState.bInfo[0x00] != buf[0x00]) { + OnControlKeysChanged(prevState.bInfo[0x00], buf[0x00]); + } + + for (uint32_t i = 2; i < 8; i++) { + bool down = false; + bool up = false; + + for (uint8_t j = 2; j < 8; j++) { + if (buf[i] == prevState.bInfo[j] && buf[i] != 1) + down = true; + if (buf[j] == prevState.bInfo[i] && prevState.bInfo[i] != 1) + up = true; + } + if (!down) { + HandleLockingKeys(hid, buf[i]); + OnKeyDown(*buf, buf[i]); + } + if (!up) + OnKeyUp(prevState.bInfo[0], prevState.bInfo[i]); + } + for(uint32_t i = 0; i < 8; i++) + prevState.bInfo[i] = buf[i]; +}; + +uint8_t KeyboardReportParser::HandleLockingKeys(HID *hid, uint8_t key) { + uint8_t old_keys = kbdLockingKeys.bLeds; + + switch (key) { + case UHS_HID_BOOT_KEY_NUM_LOCK: + kbdLockingKeys.kbdLeds.bmNumLock = ~kbdLockingKeys.kbdLeds.bmNumLock; + break; + case UHS_HID_BOOT_KEY_CAPS_LOCK: + kbdLockingKeys.kbdLeds.bmCapsLock = ~kbdLockingKeys.kbdLeds.bmCapsLock; + break; + case UHS_HID_BOOT_KEY_SCROLL_LOCK: + kbdLockingKeys.kbdLeds.bmScrollLock = ~kbdLockingKeys.kbdLeds.bmScrollLock; + break; + } + + if (old_keys != kbdLockingKeys.bLeds && hid) + return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &kbdLockingKeys.bLeds)); + + return 0; +} + +const uint8_t KeyboardReportParser::numKeys[10] = { '!', '@', '#', '$', '%', '^', '&', '*', '(', ')'}; +const uint8_t KeyboardReportParser::symKeysUp[12] = { '_', '+', '{', '}', '|', '~', ':', '"', '~', '<', '>', '?'}; +const uint8_t KeyboardReportParser::symKeysLo[12] = { '-', '=', '[', ']', '\\', ' ', ';', '\'', '`', ',', '.', '/'}; +const uint8_t KeyboardReportParser::padKeys[5] = { '/', '*', '-', '+', 0x0d}; +#define VALUE_WITHIN(v,l,h) (((v)>=(l)) && ((v)<=(h))) +uint8_t KeyboardReportParser::OemToAscii(uint8_t mod, uint8_t key) { + uint8_t shift = (mod & 0x22); + uint8_t ctrl = (mod & 0x11); + + // [a-z] + if (VALUE_WITHIN(key, 0x04, 0x1d)) { + // [^a-^z] + if (ctrl) return (key - 3); + // Upper case letters + if ((kbdLockingKeys.kbdLeds.bmCapsLock == 0 && shift) || + (kbdLockingKeys.kbdLeds.bmCapsLock == 1 && shift == 0)) + return (key - 4 + 'A'); + + // Lower case letters + else + return (key - 4 + 'a'); + }// Numbers + else if (VALUE_WITHIN(key, 0x1e, 0x27)) { + if (ctrl && (key == 0x23)) return (0x1E); /* RS ^^ */ + if (shift) + return ((uint8_t)pgm_read_byte(&getNumKeys()[key - 0x1e])); + else + return ((key == UHS_HID_BOOT_KEY_ZERO) ? '0' : key - 0x1e + '1'); + }// Keypad Numbers + else if(VALUE_WITHIN(key, 0x59, 0x61)) { + if(kbdLockingKeys.kbdLeds.bmNumLock == 1) + return (key - 0x59 + '1'); + } else if(VALUE_WITHIN(key, 0x2d, 0x38)) { + if (ctrl) { + switch (key) { + case 0x2d: return (0x1f); /* US ^_ */ + case 0x2f: return (0x1b); /* ESC ^[ */ + case 0x30: return (0x1d); /* GS ^] */ + case 0x31: return (0x1c); /* FS ^\ */ + default: return (0x00); + } + } + return ((shift) ? (uint8_t)pgm_read_byte(&getSymKeysUp()[key - 0x2d]) : (uint8_t)pgm_read_byte(&getSymKeysLo()[key - 0x2d])); + } else if(VALUE_WITHIN(key, 0x54, 0x58)) + return (uint8_t)pgm_read_byte(&getPadKeys()[key - 0x54]); + else { + switch(key) { + case UHS_HID_BOOT_KEY_SPACE: return (0x20); + case UHS_HID_BOOT_KEY_ENTER: return (0x0d); + case UHS_HID_BOOT_KEY_ESCAPE: return (0x1b); + case UHS_HID_BOOT_KEY_DELETE: return (0x08); + case UHS_HID_BOOT_KEY_DELETE_FORWARD: return (0x7f); + case UHS_HID_BOOT_KEY_TAB: return (0x09); + case UHS_HID_BOOT_KEY_ZERO2: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '0': 0); + case UHS_HID_BOOT_KEY_PERIOD: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '.': 0); + } + } + return ( 0); +} + diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidboot.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidboot.h new file mode 100644 index 00000000000..50461296d62 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidboot.h @@ -0,0 +1,611 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ + +#ifndef HIDBOOT_H_INCLUDED +#define HIDBOOT_H_INCLUDED + +#include +#include "Usb.h" +#include "hid.h" +#include "Arduino.h" + +#define UHS_HID_BOOT_KEY_ZERO 0x27 +#define UHS_HID_BOOT_KEY_ENTER 0x28 +#define UHS_HID_BOOT_KEY_ESCAPE 0x29 +#define UHS_HID_BOOT_KEY_DELETE 0x2a // Backspace +#define UHS_HID_BOOT_KEY_DELETE_FORWARD 0x4C // Delete +#define UHS_HID_BOOT_KEY_TAB 0x2b +#define UHS_HID_BOOT_KEY_SPACE 0x2c +#define UHS_HID_BOOT_KEY_CAPS_LOCK 0x39 +#define UHS_HID_BOOT_KEY_SCROLL_LOCK 0x47 +#define UHS_HID_BOOT_KEY_NUM_LOCK 0x53 +#define UHS_HID_BOOT_KEY_ZERO2 0x62 +#define UHS_HID_BOOT_KEY_PERIOD 0x63 + +// Don't worry, GCC will optimize the result to a final value. +#define bitsEndpoints(p) ((((p) & HID_PROTOCOL_KEYBOARD)? 2 : 0) | (((p) & HID_PROTOCOL_MOUSE)? 1 : 0)) +#define totalEndpoints(p) ((bitsEndpoints(p) == 3) ? 3 : 2) +#define epMUL(p) ((((p) & HID_PROTOCOL_KEYBOARD)? 1 : 0) + (((p) & HID_PROTOCOL_MOUSE)? 1 : 0)) + +// Already defined in hid.h +// #define HID_MAX_HID_CLASS_DESCRIPTORS 5 + +struct MOUSEINFO { + + struct { + uint8_t bmLeftButton : 1; + uint8_t bmRightButton : 1; + uint8_t bmMiddleButton : 1; + uint8_t bmDummy : 5; + }; + int8_t dX; + int8_t dY; +}; + +class MouseReportParser : public HIDReportParser { + + union { + MOUSEINFO mouseInfo; + uint8_t bInfo[sizeof (MOUSEINFO)]; + } prevState; + +public: + virtual void Parse(HID *hid, uint32_t is_rpt_id, uint32_t len, uint8_t *buf); + +protected: + + virtual void OnMouseMove(MOUSEINFO *) { + }; + + virtual void OnLeftButtonUp(MOUSEINFO *) { + }; + + virtual void OnLeftButtonDown(MOUSEINFO *) { + }; + + virtual void OnRightButtonUp(MOUSEINFO *) { + }; + + virtual void OnRightButtonDown(MOUSEINFO *) { + }; + + virtual void OnMiddleButtonUp(MOUSEINFO *) { + }; + + virtual void OnMiddleButtonDown(MOUSEINFO *) { + }; +}; + +struct MODIFIERKEYS { + uint8_t bmLeftCtrl : 1; + uint8_t bmLeftShift : 1; + uint8_t bmLeftAlt : 1; + uint8_t bmLeftGUI : 1; + uint8_t bmRightCtrl : 1; + uint8_t bmRightShift : 1; + uint8_t bmRightAlt : 1; + uint8_t bmRightGUI : 1; +}; + +struct KBDINFO { + + struct { + uint8_t bmLeftCtrl : 1; + uint8_t bmLeftShift : 1; + uint8_t bmLeftAlt : 1; + uint8_t bmLeftGUI : 1; + uint8_t bmRightCtrl : 1; + uint8_t bmRightShift : 1; + uint8_t bmRightAlt : 1; + uint8_t bmRightGUI : 1; + }; + uint8_t bReserved; + uint8_t Keys[6]; +}; + +struct KBDLEDS { + uint8_t bmNumLock : 1; + uint8_t bmCapsLock : 1; + uint8_t bmScrollLock : 1; + uint8_t bmCompose : 1; + uint8_t bmKana : 1; + uint8_t bmReserved : 3; +}; + +class KeyboardReportParser : public HIDReportParser { + static const uint8_t numKeys[10]; + static const uint8_t symKeysUp[12]; + static const uint8_t symKeysLo[12]; + static const uint8_t padKeys[5]; + +protected: + + union { + KBDINFO kbdInfo; + uint8_t bInfo[sizeof (KBDINFO)]; + } prevState; + + union { + KBDLEDS kbdLeds; + uint8_t bLeds; + } kbdLockingKeys; + + uint8_t OemToAscii(uint8_t mod, uint8_t key); + +public: + + KeyboardReportParser() { + kbdLockingKeys.bLeds = 0; + }; + + virtual void Parse(HID *hid, uint32_t is_rpt_id, uint32_t len, uint8_t *buf); + +protected: + virtual uint8_t HandleLockingKeys(HID* hid, uint8_t key); + + virtual void OnControlKeysChanged(uint8_t /* before */, uint8_t /* after */) { + }; + + virtual void OnKeyDown(uint8_t /* mod */, uint8_t /* key */) { + }; + + virtual void OnKeyUp(uint8_t /* mod */, uint8_t /* key */) { + }; + + virtual const uint8_t *getNumKeys() { + return numKeys; + }; + + virtual const uint8_t *getSymKeysUp() { + return symKeysUp; + }; + + virtual const uint8_t *getSymKeysLo() { + return symKeysLo; + }; + + virtual const uint8_t *getPadKeys() { + return padKeys; + }; +}; + +template +class HIDBoot : public HID //public USBDeviceConfig, public UsbConfigXtracter +{ + EpInfo epInfo[totalEndpoints(BOOT_PROTOCOL)]; + HIDReportParser *pRptParser[epMUL(BOOT_PROTOCOL)]; + + uint32_t bConfNum; // configuration number + uint32_t bIfaceNum; // Interface Number + uint32_t bNumIface; // number of interfaces in the configuration + uint32_t bNumEP; // total number of EP in the configuration + + uint32_t qNextPollTime; // next poll time + uint32_t bPollEnable; // poll enable flag + uint32_t bInterval; // largest interval + + void Initialize(); + + virtual HIDReportParser* GetReportParser(uint32_t id) { + return pRptParser[id]; + }; + +public: + HIDBoot(USBHost *p); + + virtual uint32_t SetReportParser(uint32_t id, HIDReportParser *prs) { + pRptParser[id] = prs; + return true; + }; + + // USBDeviceConfig implementation + virtual uint32_t Init(uint32_t parent, uint32_t port, uint32_t lowspeed); + virtual uint32_t Release(); + virtual uint32_t Poll(); + + virtual uint32_t GetAddress() { + return bAddress; + }; + + // UsbConfigXtracter implementation + virtual void EndpointXtract(uint32_t conf, uint32_t iface, uint32_t alt, uint32_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); +}; + +template +HIDBoot::HIDBoot(USBHost *p) : + HID(p), + qNextPollTime(0), + bPollEnable(false) { + Initialize(); + + for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { + pRptParser[i] = NULL; + } + if(pUsb) + pUsb->RegisterDeviceClass(this); +} + +template +void HIDBoot::Initialize() { + for(int i = 0; i < totalEndpoints(BOOT_PROTOCOL); i++) { + epInfo[i].epAddr = 0; + epInfo[i].maxPktSize = (i) ? 0 : 8; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; + epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; + } + bNumEP = 1; + bNumIface = 0; + bConfNum = 0; +} + +template +uint32_t HIDBoot::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { + const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); + + uint8_t buf[constBufSize]; + uint32_t rcode; + UsbDeviceDefinition *p = NULL; + EpInfo *oldep_ptr = NULL; + uint32_t len = 0; + //uint16_t cd_len = 0; + + uint32_t num_of_conf; // number of configurations + //uint32_t num_of_intf; // number of interfaces + + // Get memory address of USB device address pool + AddressPool &addrPool = pUsb->GetAddressPool(); + + USBTRACE("BM Init\r\n"); + //USBTRACE2("totalEndpoints:", (uint8_t) (totalEndpoints(BOOT_PROTOCOL))); + //USBTRACE2("epMUL:", epMUL(BOOT_PROTOCOL)); + + // Check if address has already been assigned to an instance + if(bAddress) + return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; + + bInterval = 0; + // Get pointer to pseudo device with address 0 assigned + p = addrPool.GetUsbDevicePtr(0); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + if(!p->epinfo) { + USBTRACE("epinfo\r\n"); + return USB_ERROR_EPINFO_IS_NULL; + } + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + + p->lowspeed = lowspeed; + // Get device descriptor GET_DESCRIPTOR + rcode = pUsb->getDevDescr(0, 0, /*8*/sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); + + if(!rcode) + len = (buf[0] > constBufSize) ? constBufSize : buf[0]; + + if(rcode) { + // Restore p->epinfo + p->epinfo = oldep_ptr; + + goto FailGetDevDescr; + } + + + // Restore p->epinfo + p->epinfo = oldep_ptr; + + + // Allocate new address according to device class + bAddress = addrPool.AllocAddress(parent, false, port); + if(!bAddress) + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + + // Extract Max Packet Size from the device descriptor + epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; + + // Assign new address to the device SET_ADDRESS + + rcode = pUsb->setAddr(0, 0, bAddress); + if(rcode) { + p->lowspeed = false; + addrPool.FreeAddress(bAddress); + bAddress = 0; + USBTRACE2("setAddr:", rcode); + return rcode; + } + //delay(2); //per USB 2.0 sect.9.2.6.3 + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + // Get device descriptor GET_DESCRIPTOR + rcode = pUsb->getDevDescr(bAddress, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); + // Restore p->epinfo + p->epinfo = oldep_ptr; + if (rcode) + { + goto FailGetDevDescr; + } + + TRACE_USBHOST(printf("HIDBoot::Init : device address is now %lu\r\n", bAddress);) + + p->lowspeed = false; + + //get pointer to assigned address record + p = addrPool.GetUsbDevicePtr(bAddress); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + p->lowspeed = lowspeed; + + if(len) + rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf); + + if(rcode) + goto FailGetDevDescr; + + num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; + + USBTRACE2("NC:", num_of_conf); + + // GCC will optimize unused stuff away. + if((BOOT_PROTOCOL & (HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE)) == (HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE)) { + USBTRACE("HID_PROTOCOL_KEYBOARD AND MOUSE\r\n"); + ConfigDescParser< + USB_CLASS_HID, + HID_BOOT_INTF_SUBCLASS, + HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE, + CP_MASK_COMPARE_ALL > confDescrParser(this); + confDescrParser.SetOR(); // Use the OR variant. + for(uint32_t i = 0; i < num_of_conf; i++) { + pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); + if(bNumEP == (uint8_t)(totalEndpoints(BOOT_PROTOCOL))) + break; + } + } else { + // GCC will optimize unused stuff away. + if(BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD) { + USBTRACE("HID_PROTOCOL_KEYBOARD\r\n"); + for(uint32_t i = 0; i < num_of_conf; i++) { + ConfigDescParser< + USB_CLASS_HID, + HID_BOOT_INTF_SUBCLASS, + HID_PROTOCOL_KEYBOARD, + CP_MASK_COMPARE_ALL> confDescrParserA(this); + + pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA); + if(bNumEP == (uint8_t)(totalEndpoints(BOOT_PROTOCOL))) + break; + } + } + + // GCC will optimize unused stuff away. + if(BOOT_PROTOCOL & HID_PROTOCOL_MOUSE) { + USBTRACE("HID_PROTOCOL_MOUSE\r\n"); + for(uint32_t i = 0; i < num_of_conf; i++) { + ConfigDescParser< + USB_CLASS_HID, + HID_BOOT_INTF_SUBCLASS, + HID_PROTOCOL_MOUSE, + CP_MASK_COMPARE_ALL> confDescrParserB(this); + + pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB); + if(bNumEP == ((uint8_t)(totalEndpoints(BOOT_PROTOCOL)))) + break; + + } + } + } + USBTRACE2("bNumEP:", bNumEP); + + if(bNumEP != (uint8_t)(totalEndpoints(BOOT_PROTOCOL))) { + rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + goto Fail; + } + + // Assign epInfo to epinfo pointer + rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); + //USBTRACE2("setEpInfoEntry returned ", rcode); + USBTRACE2("Cnf:", bConfNum); + + delay(1000); + + // Set Configuration Value + rcode = pUsb->setConf(bAddress, 0, bConfNum); + + if(rcode) + goto FailSetConfDescr; + + delay(1000); + + USBTRACE2("bIfaceNum:", bIfaceNum); + USBTRACE2("bNumIface:", bNumIface); + + // Yes, mouse wants SetProtocol and SetIdle too! + for(uint32_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) { + USBTRACE2("\r\nInterface:", i); + rcode = SetProtocol(i, HID_BOOT_PROTOCOL); + if(rcode) goto FailSetProtocol; + USBTRACE2("PROTOCOL SET HID_BOOT rcode:", rcode); + rcode = SetIdle(i, 0, 0); + USBTRACE2("SET_IDLE rcode:", rcode); + // if(rcode) goto FailSetIdle; This can fail. + // Get the RPIPE and just throw it away. + SinkParser sink; + rcode = GetReportDescr(i, (USBReadParser *)&sink); + USBTRACE2("RPIPE rcode:", rcode); + } + + // Get RPIPE and throw it away. + + if(BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD) { + // Wake keyboard interface by twinkling up to 5 LEDs that are in the spec. + // kana, compose, scroll, caps, num + rcode = 0x20; // Reuse rcode. + while(rcode) { + rcode >>= 1; + // Ignore any error returned, we don't care if LED is not supported + SetReport(0, 0, 2, 0, 1, (uint8_t*)&rcode); // Eventually becomes zero (All off) + delay(25); + } + } + USBTRACE("BM configured\r\n"); + + bPollEnable = true; + return 0; + +FailGetDevDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetDevDescr(); + goto Fail; +#endif + + //FailSetDevTblEntry: + //#ifdef DEBUG_USB_HOST + // NotifyFailSetDevTblEntry(); + // goto Fail; + //#endif + + //FailGetConfDescr: + //#ifdef DEBUG_USB_HOST + // NotifyFailGetConfDescr(); + // goto Fail; + //#endif + +FailSetConfDescr: +#ifdef DEBUG_USB_HOST + NotifyFailSetConfDescr(); + goto Fail; +#endif + +FailSetProtocol: +#ifdef DEBUG_USB_HOST + USBTRACE("SetProto:"); + goto Fail; +#endif + + //FailSetIdle: + //#ifdef DEBUG_USB_HOST + // USBTRACE("SetIdle:"); + //#endif + +Fail: +#ifdef DEBUG_USB_HOST + NotifyFail(rcode); +#endif + Release(); + + return rcode; +} + +template +void HIDBoot::EndpointXtract(uint32_t conf, uint32_t iface, uint32_t /* alt */, uint32_t /* proto */, const USB_ENDPOINT_DESCRIPTOR *pep) { + // If the first configuration satisfies, the others are not considered. + //if(bNumEP > 1 && conf != bConfNum) + if(bNumEP == totalEndpoints(BOOT_PROTOCOL)) + return; + + bConfNum = conf; + bIfaceNum = iface; + + if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) { + if(pep->bInterval > bInterval) bInterval = pep->bInterval; + + // Fill in the endpoint info structure + epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); + epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; + epInfo[bNumEP].bmSndToggle = 0; + epInfo[bNumEP].bmRcvToggle = 0; + epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT; + bNumEP++; + + } +} + +template +uint32_t HIDBoot::Release() { + pUsb->GetAddressPool().FreeAddress(bAddress); + + bConfNum = 0; + bIfaceNum = 0; + bNumEP = 1; + bAddress = 0; + qNextPollTime = 0; + bPollEnable = false; + + return 0; +} + +template +uint32_t HIDBoot::Poll() { + uint32_t rcode = 0; + + if(bPollEnable && ((long)(millis() - qNextPollTime) >= 0L)) { + + // To-do: optimize manually, using the for loop only if needed. + for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { + const uint16_t const_buff_len = 16; + uint8_t buf[const_buff_len]; + + USBTRACE3("(hidboot.h) i=", i, 0x81); + USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 0x81); + USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81); + uint16_t read = (uint16_t)epInfo[epInterruptInIndex + i].maxPktSize; + UHD_Pipe_Alloc(bAddress, epInfo[epInterruptInIndex + i].epAddr, USB_HOST_PTYPE_BULK, USB_EP_DIR_IN, epInfo[epInterruptInIndex + i].maxPktSize, 0, USB_HOST_NB_BK_1); + rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex + i].epAddr, (uint8_t*)&read, buf); + // SOME buggy dongles report extra keys (like sleep) using a 2 byte packet on the wrong endpoint. + // Since keyboard and mice must report at least 3 bytes, we ignore the extra data. + if(!rcode && read > 2) { + if(pRptParser[i]) + pRptParser[i]->Parse((HID*)this, 0, (uint8_t)read, buf); +#ifdef DEBUG_USB_HOST + // We really don't care about errors and anomalies unless we are debugging. + } else { + if(rcode != USB_ERRORFLOW) { + USBTRACE3("(hidboot.h) Poll:", rcode, 0x81); + } + if(!rcode && read) { + USBTRACE3("(hidboot.h) Strange read count: ", read, 0x80); + USBTRACE3("(hidboot.h) Interface:", i, 0x80); + } + } + + if(!rcode && read && (UsbDEBUGlvl > 0x7f)) { + for(uint8_t i = 0; i < read; i++) { + PrintHex (buf[i], 0x80); + USBTRACE1(" ", 0x80); + } + if(read) + USBTRACE1("\r\n", 0x80); +#endif + } + + } + qNextPollTime = millis() + bInterval; + } + return rcode; +} + +#endif /* HIDBOOT_H_INCLUDED */ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidescriptorparser.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidescriptorparser.cpp new file mode 100644 index 00000000000..353874300d1 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidescriptorparser.cpp @@ -0,0 +1,1599 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#include "hidescriptorparser.h" + +const char * const ReportDescParserBase::usagePageTitles0[] PROGMEM = { + pstrUsagePageGenericDesktopControls, + pstrUsagePageSimulationControls, + pstrUsagePageVRControls, + pstrUsagePageSportControls, + pstrUsagePageGameControls, + pstrUsagePageGenericDeviceControls, + pstrUsagePageKeyboardKeypad, + pstrUsagePageLEDs, + pstrUsagePageButton, + pstrUsagePageOrdinal, + pstrUsagePageTelephone, + pstrUsagePageConsumer, + pstrUsagePageDigitizer, + pstrUsagePagePID, + pstrUsagePageUnicode +}; + +const char * const ReportDescParserBase::usagePageTitles1[] PROGMEM = { + pstrUsagePageBarCodeScanner, + pstrUsagePageScale, + pstrUsagePageMSRDevices, + pstrUsagePagePointOfSale, + pstrUsagePageCameraControl, + pstrUsagePageArcade +}; +const char * const ReportDescParserBase::genDesktopTitles0[] PROGMEM = { + pstrUsagePointer, + pstrUsageMouse, + pstrUsageJoystick, + pstrUsageGamePad, + pstrUsageKeyboard, + pstrUsageKeypad, + pstrUsageMultiAxisController, + pstrUsageTabletPCSystemControls + +}; +const char * const ReportDescParserBase::genDesktopTitles1[] PROGMEM = { + pstrUsageX, + pstrUsageY, + pstrUsageZ, + pstrUsageRx, + pstrUsageRy, + pstrUsageRz, + pstrUsageSlider, + pstrUsageDial, + pstrUsageWheel, + pstrUsageHatSwitch, + pstrUsageCountedBuffer, + pstrUsageByteCount, + pstrUsageMotionWakeup, + pstrUsageStart, + pstrUsageSelect, + pstrUsagePageReserved, + pstrUsageVx, + pstrUsageVy, + pstrUsageVz, + pstrUsageVbrx, + pstrUsageVbry, + pstrUsageVbrz, + pstrUsageVno, + pstrUsageFeatureNotification, + pstrUsageResolutionMultiplier +}; +const char * const ReportDescParserBase::genDesktopTitles2[] PROGMEM = { + pstrUsageSystemControl, + pstrUsageSystemPowerDown, + pstrUsageSystemSleep, + pstrUsageSystemWakeup, + pstrUsageSystemContextMenu, + pstrUsageSystemMainMenu, + pstrUsageSystemAppMenu, + pstrUsageSystemMenuHelp, + pstrUsageSystemMenuExit, + pstrUsageSystemMenuSelect, + pstrUsageSystemMenuRight, + pstrUsageSystemMenuLeft, + pstrUsageSystemMenuUp, + pstrUsageSystemMenuDown, + pstrUsageSystemColdRestart, + pstrUsageSystemWarmRestart, + pstrUsageDPadUp, + pstrUsageDPadDown, + pstrUsageDPadRight, + pstrUsageDPadLeft +}; +const char * const ReportDescParserBase::genDesktopTitles3[] PROGMEM = { + pstrUsageSystemDock, + pstrUsageSystemUndock, + pstrUsageSystemSetup, + pstrUsageSystemBreak, + pstrUsageSystemDebuggerBreak, + pstrUsageApplicationBreak, + pstrUsageApplicationDebuggerBreak, + pstrUsageSystemSpeakerMute, + pstrUsageSystemHibernate +}; +const char * const ReportDescParserBase::genDesktopTitles4[] PROGMEM = { + pstrUsageSystemDisplayInvert, + pstrUsageSystemDisplayInternal, + pstrUsageSystemDisplayExternal, + pstrUsageSystemDisplayBoth, + pstrUsageSystemDisplayDual, + pstrUsageSystemDisplayToggleIntExt, + pstrUsageSystemDisplaySwapPriSec, + pstrUsageSystemDisplayLCDAutoscale +}; +const char * const ReportDescParserBase::simuTitles0[] PROGMEM = { + pstrUsageFlightSimulationDevice, + pstrUsageAutomobileSimulationDevice, + pstrUsageTankSimulationDevice, + pstrUsageSpaceshipSimulationDevice, + pstrUsageSubmarineSimulationDevice, + pstrUsageSailingSimulationDevice, + pstrUsageMotocicleSimulationDevice, + pstrUsageSportsSimulationDevice, + pstrUsageAirplaneSimulationDevice, + pstrUsageHelicopterSimulationDevice, + pstrUsageMagicCarpetSimulationDevice, + pstrUsageBicycleSimulationDevice +}; +const char * const ReportDescParserBase::simuTitles1[] PROGMEM = { + pstrUsageFlightControlStick, + pstrUsageFlightStick, + pstrUsageCyclicControl, + pstrUsageCyclicTrim, + pstrUsageFlightYoke, + pstrUsageTrackControl +}; +const char * const ReportDescParserBase::simuTitles2[] PROGMEM = { + pstrUsageAileron, + pstrUsageAileronTrim, + pstrUsageAntiTorqueControl, + pstrUsageAutopilotEnable, + pstrUsageChaffRelease, + pstrUsageCollectiveControl, + pstrUsageDiveBrake, + pstrUsageElectronicCountermeasures, + pstrUsageElevator, + pstrUsageElevatorTrim, + pstrUsageRudder, + pstrUsageThrottle, + pstrUsageFlightCommunications, + pstrUsageFlareRelease, + pstrUsageLandingGear, + pstrUsageToeBrake, + pstrUsageTrigger, + pstrUsageWeaponsArm, + pstrUsageWeaponsSelect, + pstrUsageWingFlaps, + pstrUsageAccelerator, + pstrUsageBrake, + pstrUsageClutch, + pstrUsageShifter, + pstrUsageSteering, + pstrUsageTurretDirection, + pstrUsageBarrelElevation, + pstrUsageDivePlane, + pstrUsageBallast, + pstrUsageBicycleCrank, + pstrUsageHandleBars, + pstrUsageFrontBrake, + pstrUsageRearBrake +}; +const char * const ReportDescParserBase::vrTitles0[] PROGMEM = { + pstrUsageBelt, + pstrUsageBodySuit, + pstrUsageFlexor, + pstrUsageGlove, + pstrUsageHeadTracker, + pstrUsageHeadMountedDisplay, + pstrUsageHandTracker, + pstrUsageOculometer, + pstrUsageVest, + pstrUsageAnimatronicDevice +}; +const char * const ReportDescParserBase::vrTitles1[] PROGMEM = { + pstrUsageStereoEnable, + pstrUsageDisplayEnable +}; +const char * const ReportDescParserBase::sportsCtrlTitles0[] PROGMEM = { + pstrUsageBaseballBat, + pstrUsageGolfClub, + pstrUsageRowingMachine, + pstrUsageTreadmill +}; +const char * const ReportDescParserBase::sportsCtrlTitles1[] PROGMEM = { + pstrUsageOar, + pstrUsageSlope, + pstrUsageRate, + pstrUsageStickSpeed, + pstrUsageStickFaceAngle, + pstrUsageStickHeelToe, + pstrUsageStickFollowThough, + pstrUsageStickTempo, + pstrUsageStickType, + pstrUsageStickHeight +}; +const char * const ReportDescParserBase::sportsCtrlTitles2[] PROGMEM = { + pstrUsagePutter, + pstrUsage1Iron, + pstrUsage2Iron, + pstrUsage3Iron, + pstrUsage4Iron, + pstrUsage5Iron, + pstrUsage6Iron, + pstrUsage7Iron, + pstrUsage8Iron, + pstrUsage9Iron, + pstrUsage10Iron, + pstrUsage11Iron, + pstrUsageSandWedge, + pstrUsageLoftWedge, + pstrUsagePowerWedge, + pstrUsage1Wood, + pstrUsage3Wood, + pstrUsage5Wood, + pstrUsage7Wood, + pstrUsage9Wood +}; +const char * const ReportDescParserBase::gameTitles0[] PROGMEM = { + pstrUsage3DGameController, + pstrUsagePinballDevice, + pstrUsageGunDevice +}; +const char * const ReportDescParserBase::gameTitles1[] PROGMEM = { + pstrUsagePointOfView, + pstrUsageTurnRightLeft, + pstrUsagePitchForwardBackward, + pstrUsageRollRightLeft, + pstrUsageMoveRightLeft, + pstrUsageMoveForwardBackward, + pstrUsageMoveUpDown, + pstrUsageLeanRightLeft, + pstrUsageLeanForwardBackward, + pstrUsageHeightOfPOV, + pstrUsageFlipper, + pstrUsageSecondaryFlipper, + pstrUsageBump, + pstrUsageNewGame, + pstrUsageShootBall, + pstrUsagePlayer, + pstrUsageGunBolt, + pstrUsageGunClip, + pstrUsageGunSelector, + pstrUsageGunSingleShot, + pstrUsageGunBurst, + pstrUsageGunAutomatic, + pstrUsageGunSafety, + pstrUsageGamepadFireJump, + pstrUsageGamepadTrigger +}; +const char * const ReportDescParserBase::genDevCtrlTitles[] PROGMEM = { + pstrUsageBatteryStrength, + pstrUsageWirelessChannel, + pstrUsageWirelessID, + pstrUsageDiscoverWirelessControl, + pstrUsageSecurityCodeCharEntered, + pstrUsageSecurityCodeCharErased, + pstrUsageSecurityCodeCleared +}; +const char * const ReportDescParserBase::ledTitles[] PROGMEM = { + pstrUsageNumLock, + pstrUsageCapsLock, + pstrUsageScrollLock, + pstrUsageCompose, + pstrUsageKana, + pstrUsagePower, + pstrUsageShift, + pstrUsageDoNotDisturb, + pstrUsageMute, + pstrUsageToneEnable, + pstrUsageHighCutFilter, + pstrUsageLowCutFilter, + pstrUsageEqualizerEnable, + pstrUsageSoundFieldOn, + pstrUsageSurroundOn, + pstrUsageRepeat, + pstrUsageStereo, + pstrUsageSamplingRateDetect, + pstrUsageSpinning, + pstrUsageCAV, + pstrUsageCLV, + pstrUsageRecordingFormatDetect, + pstrUsageOffHook, + pstrUsageRing, + pstrUsageMessageWaiting, + pstrUsageDataMode, + pstrUsageBatteryOperation, + pstrUsageBatteryOK, + pstrUsageBatteryLow, + pstrUsageSpeaker, + pstrUsageHeadSet, + pstrUsageHold, + pstrUsageMicrophone, + pstrUsageCoverage, + pstrUsageNightMode, + pstrUsageSendCalls, + pstrUsageCallPickup, + pstrUsageConference, + pstrUsageStandBy, + pstrUsageCameraOn, + pstrUsageCameraOff, + pstrUsageOnLine, + pstrUsageOffLine, + pstrUsageBusy, + pstrUsageReady, + pstrUsagePaperOut, + pstrUsagePaperJam, + pstrUsageRemote, + pstrUsageForward, + pstrUsageReverse, + pstrUsageStop, + pstrUsageRewind, + pstrUsageFastForward, + pstrUsagePlay, + pstrUsagePause, + pstrUsageRecord, + pstrUsageError, + pstrUsageSelectedIndicator, + pstrUsageInUseIndicator, + pstrUsageMultiModeIndicator, + pstrUsageIndicatorOn, + pstrUsageIndicatorFlash, + pstrUsageIndicatorSlowBlink, + pstrUsageIndicatorFastBlink, + pstrUsageIndicatorOff, + pstrUsageFlashOnTime, + pstrUsageSlowBlinkOnTime, + pstrUsageSlowBlinkOffTime, + pstrUsageFastBlinkOnTime, + pstrUsageFastBlinkOffTime, + pstrUsageIndicatorColor, + pstrUsageIndicatorRed, + pstrUsageIndicatorGreen, + pstrUsageIndicatorAmber, + pstrUsageGenericIndicator, + pstrUsageSystemSuspend, + pstrUsageExternalPowerConnected +}; +const char * const ReportDescParserBase::telTitles0 [] PROGMEM = { + pstrUsagePhone, + pstrUsageAnsweringMachine, + pstrUsageMessageControls, + pstrUsageHandset, + pstrUsageHeadset, + pstrUsageTelephonyKeyPad, + pstrUsageProgrammableButton +}; +const char * const ReportDescParserBase::telTitles1 [] PROGMEM = { + pstrUsageHookSwitch, + pstrUsageFlash, + pstrUsageFeature, + pstrUsageHold, + pstrUsageRedial, + pstrUsageTransfer, + pstrUsageDrop, + pstrUsagePark, + pstrUsageForwardCalls, + pstrUsageAlternateFunction, + pstrUsageLine, + pstrUsageSpeakerPhone, + pstrUsageConference, + pstrUsageRingEnable, + pstrUsageRingSelect, + pstrUsagePhoneMute, + pstrUsageCallerID, + pstrUsageSend +}; +const char * const ReportDescParserBase::telTitles2 [] PROGMEM = { + pstrUsageSpeedDial, + pstrUsageStoreNumber, + pstrUsageRecallNumber, + pstrUsagePhoneDirectory +}; +const char * const ReportDescParserBase::telTitles3 [] PROGMEM = { + pstrUsageVoiceMail, + pstrUsageScreenCalls, + pstrUsageDoNotDisturb, + pstrUsageMessage, + pstrUsageAnswerOnOff +}; +const char * const ReportDescParserBase::telTitles4 [] PROGMEM = { + pstrUsageInsideDialTone, + pstrUsageOutsideDialTone, + pstrUsageInsideRingTone, + pstrUsageOutsideRingTone, + pstrUsagePriorityRingTone, + pstrUsageInsideRingback, + pstrUsagePriorityRingback, + pstrUsageLineBusyTone, + pstrUsageReorderTone, + pstrUsageCallWaitingTone, + pstrUsageConfirmationTone1, + pstrUsageConfirmationTone2, + pstrUsageTonesOff, + pstrUsageOutsideRingback, + pstrUsageRinger +}; +const char * const ReportDescParserBase::telTitles5 [] PROGMEM = { + pstrUsagePhoneKey0, + pstrUsagePhoneKey1, + pstrUsagePhoneKey2, + pstrUsagePhoneKey3, + pstrUsagePhoneKey4, + pstrUsagePhoneKey5, + pstrUsagePhoneKey6, + pstrUsagePhoneKey7, + pstrUsagePhoneKey8, + pstrUsagePhoneKey9, + pstrUsagePhoneKeyStar, + pstrUsagePhoneKeyPound, + pstrUsagePhoneKeyA, + pstrUsagePhoneKeyB, + pstrUsagePhoneKeyC, + pstrUsagePhoneKeyD +}; +const char * const ReportDescParserBase::consTitles0[] PROGMEM = { + pstrUsageConsumerControl, + pstrUsageNumericKeyPad, + pstrUsageProgrammableButton, + pstrUsageMicrophone, + pstrUsageHeadphone, + pstrUsageGraphicEqualizer +}; +const char * const ReportDescParserBase::consTitles1[] PROGMEM = { + pstrUsagePlus10, + pstrUsagePlus100, + pstrUsageAMPM +}; +const char * const ReportDescParserBase::consTitles2[] PROGMEM = { + pstrUsagePower, + pstrUsageReset, + pstrUsageSleep, + pstrUsageSleepAfter, + pstrUsageSleepMode, + pstrUsageIllumination, + pstrUsageFunctionButtons + +}; +const char * const ReportDescParserBase::consTitles3[] PROGMEM = { + pstrUsageMenu, + pstrUsageMenuPick, + pstrUsageMenuUp, + pstrUsageMenuDown, + pstrUsageMenuLeft, + pstrUsageMenuRight, + pstrUsageMenuEscape, + pstrUsageMenuValueIncrease, + pstrUsageMenuValueDecrease +}; +const char * const ReportDescParserBase::consTitles4[] PROGMEM = { + pstrUsageDataOnScreen, + pstrUsageClosedCaption, + pstrUsageClosedCaptionSelect, + pstrUsageVCRTV, + pstrUsageBroadcastMode, + pstrUsageSnapshot, + pstrUsageStill +}; +const char * const ReportDescParserBase::consTitles5[] PROGMEM = { + pstrUsageSelection, + pstrUsageAssignSelection, + pstrUsageModeStep, + pstrUsageRecallLast, + pstrUsageEnterChannel, + pstrUsageOrderMovie, + pstrUsageChannel, + pstrUsageMediaSelection, + pstrUsageMediaSelectComputer, + pstrUsageMediaSelectTV, + pstrUsageMediaSelectWWW, + pstrUsageMediaSelectDVD, + pstrUsageMediaSelectTelephone, + pstrUsageMediaSelectProgramGuide, + pstrUsageMediaSelectVideoPhone, + pstrUsageMediaSelectGames, + pstrUsageMediaSelectMessages, + pstrUsageMediaSelectCD, + pstrUsageMediaSelectVCR, + pstrUsageMediaSelectTuner, + pstrUsageQuit, + pstrUsageHelp, + pstrUsageMediaSelectTape, + pstrUsageMediaSelectCable, + pstrUsageMediaSelectSatellite, + pstrUsageMediaSelectSecurity, + pstrUsageMediaSelectHome, + pstrUsageMediaSelectCall, + pstrUsageChannelIncrement, + pstrUsageChannelDecrement, + pstrUsageMediaSelectSAP, + pstrUsagePageReserved, + pstrUsageVCRPlus, + pstrUsageOnce, + pstrUsageDaily, + pstrUsageWeekly, + pstrUsageMonthly +}; +const char * const ReportDescParserBase::consTitles6[] PROGMEM = { + pstrUsagePlay, + pstrUsagePause, + pstrUsageRecord, + pstrUsageFastForward, + pstrUsageRewind, + pstrUsageScanNextTrack, + pstrUsageScanPreviousTrack, + pstrUsageStop, + pstrUsageEject, + pstrUsageRandomPlay, + pstrUsageSelectDisk, + pstrUsageEnterDisk, + pstrUsageRepeat, + pstrUsageTracking, + pstrUsageTrackNormal, + pstrUsageSlowTracking, + pstrUsageFrameForward, + pstrUsageFrameBackwards, + pstrUsageMark, + pstrUsageClearMark, + pstrUsageRepeatFromMark, + pstrUsageReturnToMark, + pstrUsageSearchMarkForward, + pstrUsageSearchMarkBackwards, + pstrUsageCounterReset, + pstrUsageShowCounter, + pstrUsageTrackingIncrement, + pstrUsageTrackingDecrement, + pstrUsageStopEject, + pstrUsagePlayPause, + pstrUsagePlaySkip +}; +const char * const ReportDescParserBase::consTitles7[] PROGMEM = { + pstrUsageVolume, + pstrUsageBalance, + pstrUsageMute, + pstrUsageBass, + pstrUsageTreble, + pstrUsageBassBoost, + pstrUsageSurroundMode, + pstrUsageLoudness, + pstrUsageMPX, + pstrUsageVolumeIncrement, + pstrUsageVolumeDecrement +}; +const char * const ReportDescParserBase::consTitles8[] PROGMEM = { + pstrUsageSpeedSelect, + pstrUsagePlaybackSpeed, + pstrUsageStandardPlay, + pstrUsageLongPlay, + pstrUsageExtendedPlay, + pstrUsageSlow +}; +const char * const ReportDescParserBase::consTitles9[] PROGMEM = { + pstrUsageFanEnable, + pstrUsageFanSpeed, + pstrUsageLightEnable, + pstrUsageLightIlluminationLevel, + pstrUsageClimateControlEnable, + pstrUsageRoomTemperature, + pstrUsageSecurityEnable, + pstrUsageFireAlarm, + pstrUsagePoliceAlarm, + pstrUsageProximity, + pstrUsageMotion, + pstrUsageDuresAlarm, + pstrUsageHoldupAlarm, + pstrUsageMedicalAlarm +}; +const char * const ReportDescParserBase::consTitlesA[] PROGMEM = { + pstrUsageBalanceRight, + pstrUsageBalanceLeft, + pstrUsageBassIncrement, + pstrUsageBassDecrement, + pstrUsageTrebleIncrement, + pstrUsageTrebleDecrement +}; +const char * const ReportDescParserBase::consTitlesB[] PROGMEM = { + pstrUsageSpeakerSystem, + pstrUsageChannelLeft, + pstrUsageChannelRight, + pstrUsageChannelCenter, + pstrUsageChannelFront, + pstrUsageChannelCenterFront, + pstrUsageChannelSide, + pstrUsageChannelSurround, + pstrUsageChannelLowFreqEnhancement, + pstrUsageChannelTop, + pstrUsageChannelUnknown +}; +const char * const ReportDescParserBase::consTitlesC[] PROGMEM = { + pstrUsageSubChannel, + pstrUsageSubChannelIncrement, + pstrUsageSubChannelDecrement, + pstrUsageAlternateAudioIncrement, + pstrUsageAlternateAudioDecrement +}; +const char * const ReportDescParserBase::consTitlesD[] PROGMEM = { + pstrUsageApplicationLaunchButtons, + pstrUsageALLaunchButtonConfigTool, + pstrUsageALProgrammableButton, + pstrUsageALConsumerControlConfig, + pstrUsageALWordProcessor, + pstrUsageALTextEditor, + pstrUsageALSpreadsheet, + pstrUsageALGraphicsEditor, + pstrUsageALPresentationApp, + pstrUsageALDatabaseApp, + pstrUsageALEmailReader, + pstrUsageALNewsreader, + pstrUsageALVoicemail, + pstrUsageALContactsAddressBook, + pstrUsageALCalendarSchedule, + pstrUsageALTaskProjectManager, + pstrUsageALLogJournalTimecard, + pstrUsageALCheckbookFinance, + pstrUsageALCalculator, + pstrUsageALAVCapturePlayback, + pstrUsageALLocalMachineBrowser, + pstrUsageALLANWANBrow, + pstrUsageALInternetBrowser, + pstrUsageALRemoteNetISPConnect, + pstrUsageALNetworkConference, + pstrUsageALNetworkChat, + pstrUsageALTelephonyDialer, + pstrUsageALLogon, + pstrUsageALLogoff, + pstrUsageALLogonLogoff, + pstrUsageALTermLockScrSav, + pstrUsageALControlPannel, + pstrUsageALCommandLineProcessorRun, + pstrUsageALProcessTaskManager, + pstrUsageALSelectTaskApplication, + pstrUsageALNextTaskApplication, + pstrUsageALPreviousTaskApplication, + pstrUsageALPreemptiveHaltTaskApp, + pstrUsageALIntegratedHelpCenter, + pstrUsageALDocuments, + pstrUsageALThesaurus, + pstrUsageALDictionary, + pstrUsageALDesktop, + pstrUsageALSpellCheck, + pstrUsageALGrammarCheck, + pstrUsageALWirelessStatus, + pstrUsageALKeyboardLayout, + pstrUsageALVirusProtection, + pstrUsageALEncryption, + pstrUsageALScreenSaver, + pstrUsageALAlarms, + pstrUsageALClock, + pstrUsageALFileBrowser, + pstrUsageALPowerStatus, + pstrUsageALImageBrowser, + pstrUsageALAudioBrowser, + pstrUsageALMovieBrowser, + pstrUsageALDigitalRightsManager, + pstrUsageALDigitalWallet, + pstrUsagePageReserved, + pstrUsageALInstantMessaging, + pstrUsageALOEMFeaturesBrowser, + pstrUsageALOEMHelp, + pstrUsageALOnlineCommunity, + pstrUsageALEntertainmentContentBrow, + pstrUsageALOnlineShoppingBrowser, + pstrUsageALSmartCardInfoHelp, + pstrUsageALMarketMonitorFinBrowser, + pstrUsageALCustomCorpNewsBrowser, + pstrUsageALOnlineActivityBrowser, + pstrUsageALResearchSearchBrowser, + pstrUsageALAudioPlayer +}; +const char * const ReportDescParserBase::consTitlesE[] PROGMEM = { + pstrUsageGenericGUIAppControls, + pstrUsageACNew, + pstrUsageACOpen, + pstrUsageACClose, + pstrUsageACExit, + pstrUsageACMaximize, + pstrUsageACMinimize, + pstrUsageACSave, + pstrUsageACPrint, + pstrUsageACProperties, + pstrUsageACUndo, + pstrUsageACCopy, + pstrUsageACCut, + pstrUsageACPaste, + pstrUsageACSelectAll, + pstrUsageACFind, + pstrUsageACFindAndReplace, + pstrUsageACSearch, + pstrUsageACGoto, + pstrUsageACHome, + pstrUsageACBack, + pstrUsageACForward, + pstrUsageACStop, + pstrUsageACRefresh, + pstrUsageACPreviousLink, + pstrUsageACNextLink, + pstrUsageACBookmarks, + pstrUsageACHistory, + pstrUsageACSubscriptions, + pstrUsageACZoomIn, + pstrUsageACZoomOut, + pstrUsageACZoom, + pstrUsageACFullScreenView, + pstrUsageACNormalView, + pstrUsageACViewToggle, + pstrUsageACScrollUp, + pstrUsageACScrollDown, + pstrUsageACScroll, + pstrUsageACPanLeft, + pstrUsageACPanRight, + pstrUsageACPan, + pstrUsageACNewWindow, + pstrUsageACTileHoriz, + pstrUsageACTileVert, + pstrUsageACFormat, + pstrUsageACEdit, + pstrUsageACBold, + pstrUsageACItalics, + pstrUsageACUnderline, + pstrUsageACStrikethrough, + pstrUsageACSubscript, + pstrUsageACSuperscript, + pstrUsageACAllCaps, + pstrUsageACRotate, + pstrUsageACResize, + pstrUsageACFlipHorizontal, + pstrUsageACFlipVertical, + pstrUsageACMirrorHorizontal, + pstrUsageACMirrorVertical, + pstrUsageACFontSelect, + pstrUsageACFontColor, + pstrUsageACFontSize, + pstrUsageACJustifyLeft, + pstrUsageACJustifyCenterH, + pstrUsageACJustifyRight, + pstrUsageACJustifyBlockH, + pstrUsageACJustifyTop, + pstrUsageACJustifyCenterV, + pstrUsageACJustifyBottom, + pstrUsageACJustifyBlockV, + pstrUsageACIndentDecrease, + pstrUsageACIndentIncrease, + pstrUsageACNumberedList, + pstrUsageACRestartNumbering, + pstrUsageACBulletedList, + pstrUsageACPromote, + pstrUsageACDemote, + pstrUsageACYes, + pstrUsageACNo, + pstrUsageACCancel, + pstrUsageACCatalog, + pstrUsageACBuyChkout, + pstrUsageACAddToCart, + pstrUsageACExpand, + pstrUsageACExpandAll, + pstrUsageACCollapse, + pstrUsageACCollapseAll, + pstrUsageACPrintPreview, + pstrUsageACPasteSpecial, + pstrUsageACInsertMode, + pstrUsageACDelete, + pstrUsageACLock, + pstrUsageACUnlock, + pstrUsageACProtect, + pstrUsageACUnprotect, + pstrUsageACAttachComment, + pstrUsageACDeleteComment, + pstrUsageACViewComment, + pstrUsageACSelectWord, + pstrUsageACSelectSentence, + pstrUsageACSelectParagraph, + pstrUsageACSelectColumn, + pstrUsageACSelectRow, + pstrUsageACSelectTable, + pstrUsageACSelectObject, + pstrUsageACRedoRepeat, + pstrUsageACSort, + pstrUsageACSortAscending, + pstrUsageACSortDescending, + pstrUsageACFilter, + pstrUsageACSetClock, + pstrUsageACViewClock, + pstrUsageACSelectTimeZone, + pstrUsageACEditTimeZone, + pstrUsageACSetAlarm, + pstrUsageACClearAlarm, + pstrUsageACSnoozeAlarm, + pstrUsageACResetAlarm, + pstrUsageACSyncronize, + pstrUsageACSendReceive, + pstrUsageACSendTo, + pstrUsageACReply, + pstrUsageACReplyAll, + pstrUsageACForwardMessage, + pstrUsageACSend, + pstrUsageACAttachFile, + pstrUsageACUpload, + pstrUsageACDownload, + pstrUsageACSetBorders, + pstrUsageACInsertRow, + pstrUsageACInsertColumn, + pstrUsageACInsertFile, + pstrUsageACInsertPicture, + pstrUsageACInsertObject, + pstrUsageACInsertSymbol, + pstrUsageACSaveAndClose, + pstrUsageACRename, + pstrUsageACMerge, + pstrUsageACSplit, + pstrUsageACDistributeHorizontaly, + pstrUsageACDistributeVerticaly +}; +const char * const ReportDescParserBase::digitTitles0[] PROGMEM = { + pstrUsageDigitizer, + pstrUsagePen, + pstrUsageLightPen, + pstrUsageTouchScreen, + pstrUsageTouchPad, + pstrUsageWhiteBoard, + pstrUsageCoordinateMeasuringMachine, + pstrUsage3DDigitizer, + pstrUsageStereoPlotter, + pstrUsageArticulatedArm, + pstrUsageArmature, + pstrUsageMultiplePointDigitizer, + pstrUsageFreeSpaceWand +}; +const char * const ReportDescParserBase::digitTitles1[] PROGMEM = { + pstrUsageStylus, + pstrUsagePuck, + pstrUsageFinger + +}; +const char * const ReportDescParserBase::digitTitles2[] PROGMEM = { + pstrUsageTipPressure, + pstrUsageBarrelPressure, + pstrUsageInRange, + pstrUsageTouch, + pstrUsageUntouch, + pstrUsageTap, + pstrUsageQuality, + pstrUsageDataValid, + pstrUsageTransducerIndex, + pstrUsageTabletFunctionKeys, + pstrUsageProgramChangeKeys, + pstrUsageBatteryStrength, + pstrUsageInvert, + pstrUsageXTilt, + pstrUsageYTilt, + pstrUsageAzimuth, + pstrUsageAltitude, + pstrUsageTwist, + pstrUsageTipSwitch, + pstrUsageSecondaryTipSwitch, + pstrUsageBarrelSwitch, + pstrUsageEraser, + pstrUsageTabletPick +}; +const char * const ReportDescParserBase::aplphanumTitles0[] PROGMEM = { + pstrUsageAlphanumericDisplay, + pstrUsageBitmappedDisplay +}; +const char * const ReportDescParserBase::aplphanumTitles1[] PROGMEM = { + pstrUsageDisplayAttributesReport, + pstrUsageASCIICharacterSet, + pstrUsageDataReadBack, + pstrUsageFontReadBack, + pstrUsageDisplayControlReport, + pstrUsageClearDisplay, + pstrUsageDisplayEnable, + pstrUsageScreenSaverDelay, + pstrUsageScreenSaverEnable, + pstrUsageVerticalScroll, + pstrUsageHorizontalScroll, + pstrUsageCharacterReport, + pstrUsageDisplayData, + pstrUsageDisplayStatus, + pstrUsageStatusNotReady, + pstrUsageStatusReady, + pstrUsageErrorNotALoadableCharacter, + pstrUsageErrorFotDataCanNotBeRead, + pstrUsageCursorPositionReport, + pstrUsageRow, + pstrUsageColumn, + pstrUsageRows, + pstrUsageColumns, + pstrUsageCursorPixelPosition, + pstrUsageCursorMode, + pstrUsageCursorEnable, + pstrUsageCursorBlink, + pstrUsageFontReport, + pstrUsageFontData, + pstrUsageCharacterWidth, + pstrUsageCharacterHeight, + pstrUsageCharacterSpacingHorizontal, + pstrUsageCharacterSpacingVertical, + pstrUsageUnicodeCharset, + pstrUsageFont7Segment, + pstrUsage7SegmentDirectMap, + pstrUsageFont14Segment, + pstrUsage14SegmentDirectMap, + pstrUsageDisplayBrightness, + pstrUsageDisplayContrast, + pstrUsageCharacterAttribute, + pstrUsageAttributeReadback, + pstrUsageAttributeData, + pstrUsageCharAttributeEnhance, + pstrUsageCharAttributeUnderline, + pstrUsageCharAttributeBlink +}; +const char * const ReportDescParserBase::aplphanumTitles2[] PROGMEM = { + pstrUsageBitmapSizeX, + pstrUsageBitmapSizeY, + pstrUsagePageReserved, + pstrUsageBitDepthFormat, + pstrUsageDisplayOrientation, + pstrUsagePaletteReport, + pstrUsagePaletteDataSize, + pstrUsagePaletteDataOffset, + pstrUsagePaletteData, + pstrUsageBlitReport, + pstrUsageBlitRectangleX1, + pstrUsageBlitRectangleY1, + pstrUsageBlitRectangleX2, + pstrUsageBlitRectangleY2, + pstrUsageBlitData, + pstrUsageSoftButton, + pstrUsageSoftButtonID, + pstrUsageSoftButtonSide, + pstrUsageSoftButtonOffset1, + pstrUsageSoftButtonOffset2, + pstrUsageSoftButtonReport +}; +const char * const ReportDescParserBase::medInstrTitles0[] PROGMEM = { + pstrUsageVCRAcquisition, + pstrUsageFreezeThaw, + pstrUsageClipStore, + pstrUsageUpdate, + pstrUsageNext, + pstrUsageSave, + pstrUsagePrint, + pstrUsageMicrophoneEnable +}; +const char * const ReportDescParserBase::medInstrTitles1[] PROGMEM = { + pstrUsageCine, + pstrUsageTransmitPower, + pstrUsageVolume, + pstrUsageFocus, + pstrUsageDepth +}; +const char * const ReportDescParserBase::medInstrTitles2[] PROGMEM = { + pstrUsageSoftStepPrimary, + pstrUsageSoftStepSecondary +}; +const char * const ReportDescParserBase::medInstrTitles3[] PROGMEM = { + pstrUsageZoomSelect, + pstrUsageZoomAdjust, + pstrUsageSpectralDopplerModeSelect, + pstrUsageSpectralDopplerModeAdjust, + pstrUsageColorDopplerModeSelect, + pstrUsageColorDopplerModeAdjust, + pstrUsageMotionModeSelect, + pstrUsageMotionModeAdjust, + pstrUsage2DModeSelect, + pstrUsage2DModeAdjust +}; +const char * const ReportDescParserBase::medInstrTitles4[] PROGMEM = { + pstrUsageSoftControlSelect, + pstrUsageSoftControlAdjust +}; + +void ReportDescParserBase::Parse(const uint32_t len, const uint8_t *pbuf, const uint32_t & /* offset */) { + uint32_t cntdn = (uint32_t)len; + uint8_t *p = (uint8_t*)pbuf; + + + totalSize = 0; + + while(cntdn) { + //USB_HOST_SERIAL.println(""); + //PrintHex(offset + len - cntdn); + //USB_HOST_SERIAL.print(":"); + + ParseItem(&p, &cntdn); + + //if (ParseItem(&p, &cntdn)) + // return; + } + //USBTRACE2("Total:", totalSize); +} + +void ReportDescParserBase::PrintValue(uint8_t *p, uint8_t len) { + E_Notify(PSTR("("), 0x80); + for(; len; p++, len--) + PrintHex (*p, 0x80); + E_Notify(PSTR(")"), 0x80); +} + +void ReportDescParserBase::PrintByteValue(uint8_t data) { + E_Notify(PSTR("("), 0x80); + PrintHex (data, 0x80); + E_Notify(PSTR(")"), 0x80); +} + +void ReportDescParserBase::PrintItemTitle(uint8_t prefix) { + switch(prefix & (TYPE_MASK | TAG_MASK)) { + case (TYPE_GLOBAL | TAG_GLOBAL_PUSH): + E_Notify(PSTR("\r\nPush"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_POP): + E_Notify(PSTR("\r\nPop"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_USAGEPAGE): + E_Notify(PSTR("\r\nUsage Page"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMIN): + E_Notify(PSTR("\r\nLogical Min"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMAX): + E_Notify(PSTR("\r\nLogical Max"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMIN): + E_Notify(PSTR("\r\nPhysical Min"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMAX): + E_Notify(PSTR("\r\nPhysical Max"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_UNITEXP): + E_Notify(PSTR("\r\nUnit Exp"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_UNIT): + E_Notify(PSTR("\r\nUnit"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTSIZE): + E_Notify(PSTR("\r\nReport Size"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTCOUNT): + E_Notify(PSTR("\r\nReport Count"), 0x80); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID): + E_Notify(PSTR("\r\nReport Id"), 0x80); + break; + case (TYPE_LOCAL | TAG_LOCAL_USAGE): + E_Notify(PSTR("\r\nUsage"), 0x80); + break; + case (TYPE_LOCAL | TAG_LOCAL_USAGEMIN): + E_Notify(PSTR("\r\nUsage Min"), 0x80); + break; + case (TYPE_LOCAL | TAG_LOCAL_USAGEMAX): + E_Notify(PSTR("\r\nUsage Max"), 0x80); + break; + case (TYPE_MAIN | TAG_MAIN_COLLECTION): + E_Notify(PSTR("\r\nCollection"), 0x80); + break; + case (TYPE_MAIN | TAG_MAIN_ENDCOLLECTION): + E_Notify(PSTR("\r\nEnd Collection"), 0x80); + break; + case (TYPE_MAIN | TAG_MAIN_INPUT): + E_Notify(PSTR("\r\nInput"), 0x80); + break; + case (TYPE_MAIN | TAG_MAIN_OUTPUT): + E_Notify(PSTR("\r\nOutput"), 0x80); + break; + case (TYPE_MAIN | TAG_MAIN_FEATURE): + E_Notify(PSTR("\r\nFeature"), 0x80); + break; + } // switch (**pp & (TYPE_MASK | TAG_MASK)) +} + +uint8_t ReportDescParserBase::ParseItem(uint8_t **pp, uint32_t *pcntdn) { + //uint8_t ret = enErrorSuccess; + //reinterpret_cast<>(varBuffer); + switch(itemParseState) { + case 0: + if(**pp == HID_LONG_ITEM_PREFIX) + USBTRACE("\r\nLONG\r\n"); + else { + uint8_t size = ((**pp) & DATA_SIZE_MASK); + + itemPrefix = (**pp); + itemSize = 1 + ((size == DATA_SIZE_4) ? 4 : size); + + PrintItemTitle(itemPrefix); + } + (*pp)++; + (*pcntdn)--; + itemSize--; + itemParseState = 1; + + if(!itemSize) + break; + + if(!pcntdn) + return enErrorIncomplete; + case 1: + //USBTRACE2("\r\niSz:",itemSize); + + theBuffer.valueSize = itemSize; + valParser.Initialize(&theBuffer); + itemParseState = 2; + case 2: + if(!valParser.Parse(pp, pcntdn)) + return enErrorIncomplete; + itemParseState = 3; + case 3: + { + uint8_t data = *((uint8_t*)varBuffer); + + switch(itemPrefix & (TYPE_MASK | TAG_MASK)) { + case (TYPE_LOCAL | TAG_LOCAL_USAGE): + if(pfUsage) { + if(theBuffer.valueSize > 1) { + uint16_t* ui16 = reinterpret_cast(varBuffer); + pfUsage(*ui16); + } else + pfUsage(data); + } + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTSIZE): + rptSize = data; + PrintByteValue(data); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTCOUNT): + rptCount = data; + PrintByteValue(data); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMIN): + case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMAX): + case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMIN): + case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMAX): + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID): + case (TYPE_LOCAL | TAG_LOCAL_USAGEMIN): + case (TYPE_LOCAL | TAG_LOCAL_USAGEMAX): + case (TYPE_GLOBAL | TAG_GLOBAL_UNITEXP): + case (TYPE_GLOBAL | TAG_GLOBAL_UNIT): + PrintValue(varBuffer, theBuffer.valueSize); + break; + case (TYPE_GLOBAL | TAG_GLOBAL_PUSH): + case (TYPE_GLOBAL | TAG_GLOBAL_POP): + break; + case (TYPE_GLOBAL | TAG_GLOBAL_USAGEPAGE): + SetUsagePage(data); + PrintUsagePage(data); + PrintByteValue(data); + break; + case (TYPE_MAIN | TAG_MAIN_COLLECTION): + case (TYPE_MAIN | TAG_MAIN_ENDCOLLECTION): + switch(data) { + case 0x00: + E_Notify(PSTR(" Physical"), 0x80); + break; + case 0x01: + E_Notify(PSTR(" Application"), 0x80); + break; + case 0x02: + E_Notify(PSTR(" Logical"), 0x80); + break; + case 0x03: + E_Notify(PSTR(" Report"), 0x80); + break; + case 0x04: + E_Notify(PSTR(" Named Array"), 0x80); + break; + case 0x05: + E_Notify(PSTR(" Usage Switch"), 0x80); + break; + case 0x06: + E_Notify(PSTR(" Usage Modifier"), 0x80); + break; + default: + E_Notify(PSTR(" Vendor Defined("), 0x80); + PrintHex (data, 0x80); + E_Notify(PSTR(")"), 0x80); + } + break; + case (TYPE_MAIN | TAG_MAIN_INPUT): + case (TYPE_MAIN | TAG_MAIN_OUTPUT): + case (TYPE_MAIN | TAG_MAIN_FEATURE): + totalSize += (uint16_t)rptSize * (uint16_t)rptCount; + rptSize = 0; + rptCount = 0; + E_Notify(PSTR("("), 0x80); + PrintBin (data, 0x80); + E_Notify(PSTR(")"), 0x80); + break; + } // switch (**pp & (TYPE_MASK | TAG_MASK)) + } + } // switch (itemParseState) + itemParseState = 0; + return enErrorSuccess; +} + +ReportDescParserBase::UsagePageFunc ReportDescParserBase::usagePageFunctions[] /*PROGMEM*/ = { + &ReportDescParserBase::PrintGenericDesktopPageUsage, + &ReportDescParserBase::PrintSimulationControlsPageUsage, + &ReportDescParserBase::PrintVRControlsPageUsage, + &ReportDescParserBase::PrintSportsControlsPageUsage, + &ReportDescParserBase::PrintGameControlsPageUsage, + &ReportDescParserBase::PrintGenericDeviceControlsPageUsage, + NULL, // Keyboard/Keypad + &ReportDescParserBase::PrintLEDPageUsage, + &ReportDescParserBase::PrintButtonPageUsage, + &ReportDescParserBase::PrintOrdinalPageUsage, + &ReportDescParserBase::PrintTelephonyPageUsage, + &ReportDescParserBase::PrintConsumerPageUsage, + &ReportDescParserBase::PrintDigitizerPageUsage, + NULL, // Reserved + NULL, // PID + NULL // Unicode +}; + +void ReportDescParserBase::SetUsagePage(uint16_t page) { + pfUsage = NULL; + + if(VALUE_BETWEEN(page, 0x00, 0x11)) + pfUsage = (usagePageFunctions[page - 1]); + + // Dead code... + // + // pfUsage = (UsagePageFunc)pgm_read_pointer(usagePageFunctions[page - 1]); + //else if (page > 0x7f && page < 0x84) + // E_Notify(pstrUsagePageMonitor); + //else if (page > 0x83 && page < 0x8c) + // E_Notify(pstrUsagePagePower); + //else if (page > 0x8b && page < 0x92) + // E_Notify((char*)pgm_read_pointer(&usagePageTitles1[page - 0x8c])); + //else if (page > 0xfeff && page <= 0xffff) + // E_Notify(pstrUsagePageVendorDefined); + // + else + switch(page) { + case 0x14: + pfUsage = &ReportDescParserBase::PrintAlphanumDisplayPageUsage; + break; + case 0x40: + pfUsage = &ReportDescParserBase::PrintMedicalInstrumentPageUsage; + break; + } +} + +void ReportDescParserBase::PrintUsagePage(uint16_t page) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(page, 0x00, 0x11, w, E_Notify, usagePageTitles0, 0x80) + else output_if_between(page, 0x8b, 0x92, w, E_Notify, usagePageTitles1, 0x80) + else if(VALUE_BETWEEN(page, 0x7f, 0x84)) + E_Notify(pstrUsagePageMonitor, 0x80); + else if(VALUE_BETWEEN(page, 0x83, 0x8c)) + E_Notify(pstrUsagePagePower, 0x80); + else if(page > 0xfeff /* && page <= 0xffff */) + E_Notify(pstrUsagePageVendorDefined, 0x80); + else + switch(page) { + case 0x14: + E_Notify(pstrUsagePageAlphaNumericDisplay, 0x80); + break; + case 0x40: + E_Notify(pstrUsagePageMedicalInstruments, 0x80); + break; + default: + E_Notify(pstrUsagePageUndefined, 0x80); + } +} + +void ReportDescParserBase::PrintButtonPageUsage(uint16_t usage) { + E_Notify(pstrSpace, 0x80); + E_Notify(PSTR("Btn"), 0x80); + PrintHex (usage, 0x80); + E_Notify(PSTR("\r\n"), 0x80); + //USB_HOST_SERIAL.print(usage, HEX); +} + +void ReportDescParserBase::PrintOrdinalPageUsage(uint16_t usage) { + E_Notify(pstrSpace, 0x80); + E_Notify(PSTR("Inst"), 0x80); + // Sorry, HEX for now... + PrintHex (usage, 0x80); + E_Notify(PSTR("\r\n"), 0x80); + //USB_HOST_SERIAL.print(usage, DEC); +} + +void ReportDescParserBase::PrintGenericDesktopPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x0a, w, E_Notify, genDesktopTitles0, 0x80) + else output_if_between(usage, 0x2f, 0x49, w, E_Notify, genDesktopTitles1, 0x80) + else output_if_between(usage, 0x7f, 0x94, w, E_Notify, genDesktopTitles2, 0x80) + else output_if_between(usage, 0x9f, 0xa9, w, E_Notify, genDesktopTitles3, 0x80) + else output_if_between(usage, 0xaf, 0xb8, w, E_Notify, genDesktopTitles4, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintSimulationControlsPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x0d, w, E_Notify, simuTitles0, 0x80) + else output_if_between(usage, 0x1f, 0x26, w, E_Notify, simuTitles1, 0x80) + else output_if_between(usage, 0xaf, 0xd1, w, E_Notify, simuTitles2, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintVRControlsPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x0b, w, E_Notify, vrTitles0, 0x80) + else output_if_between(usage, 0x1f, 0x22, w, E_Notify, vrTitles1, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintSportsControlsPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x05, w, E_Notify, sportsCtrlTitles0, 0x80) + else output_if_between(usage, 0x2f, 0x3a, w, E_Notify, sportsCtrlTitles1, 0x80) + else output_if_between(usage, 0x4f, 0x64, w, E_Notify, sportsCtrlTitles2, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintGameControlsPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x04, w, E_Notify, gameTitles0, 0x80) + else output_if_between(usage, 0x1f, 0x3a, w, E_Notify, gameTitles1, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintGenericDeviceControlsPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x1f, 0x27, w, E_Notify, genDevCtrlTitles, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintLEDPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x4e, w, E_Notify, ledTitles, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintTelephonyPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x08, w, E_Notify, telTitles0, 0x80) + else output_if_between(usage, 0x1f, 0x32, w, E_Notify, telTitles1, 0x80) + else output_if_between(usage, 0x4f, 0x54, w, E_Notify, telTitles2, 0x80) + else output_if_between(usage, 0x6f, 0x75, w, E_Notify, telTitles3, 0x80) + else output_if_between(usage, 0x8f, 0x9f, w, E_Notify, telTitles4, 0x80) + else output_if_between(usage, 0xaf, 0xc0, w, E_Notify, telTitles5, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintConsumerPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x07, w, E_Notify, consTitles0, 0x80) + else output_if_between(usage, 0x1f, 0x23, w, E_Notify, consTitles1, 0x80) + else output_if_between(usage, 0x2f, 0x37, w, E_Notify, consTitles2, 0x80) + else output_if_between(usage, 0x3f, 0x49, w, E_Notify, consTitles3, 0x80) + else output_if_between(usage, 0x5f, 0x67, w, E_Notify, consTitles4, 0x80) + else output_if_between(usage, 0x7f, 0xa5, w, E_Notify, consTitles5, 0x80) + else output_if_between(usage, 0xaf, 0xcf, w, E_Notify, consTitles6, 0x80) + else output_if_between(usage, 0xdf, 0xeb, w, E_Notify, consTitles7, 0x80) + else output_if_between(usage, 0xef, 0xf6, w, E_Notify, consTitles8, 0x80) + else output_if_between(usage, 0xff, 0x10e, w, E_Notify, consTitles9, 0x80) + else output_if_between(usage, 0x14f, 0x156, w, E_Notify, consTitlesA, 0x80) + else output_if_between(usage, 0x15f, 0x16b, w, E_Notify, consTitlesB, 0x80) + else output_if_between(usage, 0x16f, 0x175, w, E_Notify, consTitlesC, 0x80) + else output_if_between(usage, 0x17f, 0x1c8, w, E_Notify, consTitlesD, 0x80) + else output_if_between(usage, 0x1ff, 0x29d, w, E_Notify, consTitlesE, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintDigitizerPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x0e, w, E_Notify, digitTitles0, 0x80) + else output_if_between(usage, 0x1f, 0x23, w, E_Notify, digitTitles1, 0x80) + else output_if_between(usage, 0x2f, 0x47, w, E_Notify, digitTitles2, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintAlphanumDisplayPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + output_if_between(usage, 0x00, 0x03, w, E_Notify, aplphanumTitles0, 0x80) + else output_if_between(usage, 0x1f, 0x4e, w, E_Notify, aplphanumTitles1, 0x80) + else output_if_between(usage, 0x7f, 0x96, w, E_Notify, digitTitles2, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +void ReportDescParserBase::PrintMedicalInstrumentPageUsage(uint16_t usage) { + const char * const * w; + E_Notify(pstrSpace, 0x80); + + if(usage == 1) E_Notify(pstrUsageMedicalUltrasound, 0x80); + else if(usage == 0x70) + E_Notify(pstrUsageDepthGainCompensation, 0x80); + else output_if_between(usage, 0x1f, 0x28, w, E_Notify, medInstrTitles0, 0x80) + else output_if_between(usage, 0x3f, 0x45, w, E_Notify, medInstrTitles1, 0x80) + else output_if_between(usage, 0x5f, 0x62, w, E_Notify, medInstrTitles2, 0x80) + else output_if_between(usage, 0x7f, 0x8a, w, E_Notify, medInstrTitles3, 0x80) + else output_if_between(usage, 0x9f, 0xa2, w, E_Notify, medInstrTitles4, 0x80) + else E_Notify(pstrUsagePageUndefined, 0x80); +} + +uint8_t ReportDescParser2::ParseItem(uint8_t **pp, uint32_t *pcntdn) { + //uint8_t ret = enErrorSuccess; + + switch(itemParseState) { + case 0: + if(**pp == HID_LONG_ITEM_PREFIX) + USBTRACE("\r\nLONG\r\n"); + else { + uint8_t size = ((**pp) & DATA_SIZE_MASK); + itemPrefix = (**pp); + itemSize = 1 + ((size == DATA_SIZE_4) ? 4 : size); + } + (*pp)++; + (*pcntdn)--; + itemSize--; + itemParseState = 1; + + if(!itemSize) + break; + + if(!pcntdn) + return enErrorIncomplete; + case 1: + theBuffer.valueSize = itemSize; + valParser.Initialize(&theBuffer); + itemParseState = 2; + case 2: + if(!valParser.Parse(pp, pcntdn)) + return enErrorIncomplete; + itemParseState = 3; + case 3: + { + uint8_t data = *((uint8_t*)varBuffer); + + switch(itemPrefix & (TYPE_MASK | TAG_MASK)) { + case (TYPE_LOCAL | TAG_LOCAL_USAGE): + if(pfUsage) { + if(theBuffer.valueSize > 1) { + uint16_t* ui16 = reinterpret_cast(varBuffer); + pfUsage(*ui16); + } else + pfUsage(data); + } + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTSIZE): + rptSize = data; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTCOUNT): + rptCount = data; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID): + rptId = data; + break; + case (TYPE_LOCAL | TAG_LOCAL_USAGEMIN): + useMin = data; + break; + case (TYPE_LOCAL | TAG_LOCAL_USAGEMAX): + useMax = data; + break; + case (TYPE_GLOBAL | TAG_GLOBAL_USAGEPAGE): + SetUsagePage(data); + break; + case (TYPE_MAIN | TAG_MAIN_OUTPUT): + case (TYPE_MAIN | TAG_MAIN_FEATURE): + rptSize = 0; + rptCount = 0; + useMin = 0; + useMax = 0; + break; + case (TYPE_MAIN | TAG_MAIN_INPUT): + OnInputItem(data); + + totalSize += (uint16_t)rptSize * (uint16_t)rptCount; + + rptSize = 0; + rptCount = 0; + useMin = 0; + useMax = 0; + break; + } // switch (**pp & (TYPE_MASK | TAG_MASK)) + } + } // switch (itemParseState) + itemParseState = 0; + return enErrorSuccess; +} + +void ReportDescParser2::OnInputItem(uint8_t itm) { + uint8_t byte_offset = (totalSize >> 3); // calculate offset to the next unhandled byte i = (int)(totalCount / 8); + uint32_t tmp = (byte_offset << 3); + uint8_t bit_offset = totalSize - tmp; // number of bits in the current byte already handled + uint8_t *p = pBuf + byte_offset; // current byte pointer + + if(bit_offset) + *p >>= bit_offset; + + uint8_t usage = useMin; + + bool print_usemin_usemax = ((useMin < useMax) && ((itm & 3) == 2) && pfUsage) ? true : false; + + uint8_t bits_of_byte = 8; + + // for each field in field array defined by rptCount + for(uint8_t field = 0; field < rptCount; field++, usage++) { + + union { + uint8_t bResult[4]; + uint16_t wResult[2]; + uint32_t dwResult; + } result; + + result.dwResult = 0; + uint8_t mask = 0; + + if(print_usemin_usemax) + pfUsage(usage); + + // bits_left - number of bits in the field(array of fields, depending on Report Count) left to process + // bits_of_byte - number of bits in current byte left to process + // bits_to_copy - number of bits to copy to result buffer + + // for each bit in a field + for(uint8_t bits_left = rptSize, bits_to_copy = 0; bits_left; + bits_left -= bits_to_copy) { + bits_to_copy = (bits_left > bits_of_byte) ? bits_of_byte : bits_left; + + result.dwResult <<= bits_to_copy; // Result buffer is shifted by the number of bits to be copied into it + + uint8_t val = *p; + + val >>= (8 - bits_of_byte); // Shift by the number of bits already processed + + mask = 0; + + for(uint8_t j = bits_to_copy; j; j--) { + mask <<= 1; + mask |= 1; + } + + result.bResult[0] = (result.bResult[0] | (val & mask)); + + bits_of_byte -= bits_to_copy; + + if(bits_of_byte < 1) { + bits_of_byte = 8; + p++; + } + } + PrintByteValue(result.dwResult); + } + E_Notify(PSTR("\r\n"), 0x80); +} + +void UniversalReportParser::Parse(HID *hid, uint32_t /* is_rpt_id */, uint32_t len, uint8_t *buf) { + ReportDescParser2 prs(len, buf); + + uint8_t ret = hid->GetReportDescr(0, &prs); + + if(ret) + ErrorMessage (PSTR("GetReportDescr-2"), ret); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidescriptorparser.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidescriptorparser.h new file mode 100644 index 00000000000..920b4ee7534 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidescriptorparser.h @@ -0,0 +1,173 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ +#if !defined(__HIDDESCRIPTORPARSER_H__) +#define __HIDDESCRIPTORPARSER_H__ + +#include "hid.h" + +class ReportDescParserBase : public USBReadParser { +public: + typedef void (*UsagePageFunc)(uint16_t usage); + + static void PrintGenericDesktopPageUsage(uint16_t usage); + static void PrintSimulationControlsPageUsage(uint16_t usage); + static void PrintVRControlsPageUsage(uint16_t usage); + static void PrintSportsControlsPageUsage(uint16_t usage); + static void PrintGameControlsPageUsage(uint16_t usage); + static void PrintGenericDeviceControlsPageUsage(uint16_t usage); + static void PrintLEDPageUsage(uint16_t usage); + static void PrintButtonPageUsage(uint16_t usage); + static void PrintOrdinalPageUsage(uint16_t usage); + static void PrintTelephonyPageUsage(uint16_t usage); + static void PrintConsumerPageUsage(uint16_t usage); + static void PrintDigitizerPageUsage(uint16_t usage); + static void PrintAlphanumDisplayPageUsage(uint16_t usage); + static void PrintMedicalInstrumentPageUsage(uint16_t usage); + + static void PrintValue(uint8_t *p, uint8_t len); + static void PrintByteValue(uint8_t data); + + static void PrintItemTitle(uint8_t prefix); + + static const char * const usagePageTitles0[]; + static const char * const usagePageTitles1[]; + static const char * const genDesktopTitles0[]; + static const char * const genDesktopTitles1[]; + static const char * const genDesktopTitles2[]; + static const char * const genDesktopTitles3[]; + static const char * const genDesktopTitles4[]; + static const char * const simuTitles0[]; + static const char * const simuTitles1[]; + static const char * const simuTitles2[]; + static const char * const vrTitles0[]; + static const char * const vrTitles1[]; + static const char * const sportsCtrlTitles0[]; + static const char * const sportsCtrlTitles1[]; + static const char * const sportsCtrlTitles2[]; + static const char * const gameTitles0[]; + static const char * const gameTitles1[]; + static const char * const genDevCtrlTitles[]; + static const char * const ledTitles[]; + static const char * const telTitles0[]; + static const char * const telTitles1[]; + static const char * const telTitles2[]; + static const char * const telTitles3[]; + static const char * const telTitles4[]; + static const char * const telTitles5[]; + static const char * const consTitles0[]; + static const char * const consTitles1[]; + static const char * const consTitles2[]; + static const char * const consTitles3[]; + static const char * const consTitles4[]; + static const char * const consTitles5[]; + static const char * const consTitles6[]; + static const char * const consTitles7[]; + static const char * const consTitles8[]; + static const char * const consTitles9[]; + static const char * const consTitlesA[]; + static const char * const consTitlesB[]; + static const char * const consTitlesC[]; + static const char * const consTitlesD[]; + static const char * const consTitlesE[]; + static const char * const digitTitles0[]; + static const char * const digitTitles1[]; + static const char * const digitTitles2[]; + static const char * const aplphanumTitles0[]; + static const char * const aplphanumTitles1[]; + static const char * const aplphanumTitles2[]; + static const char * const medInstrTitles0[]; + static const char * const medInstrTitles1[]; + static const char * const medInstrTitles2[]; + static const char * const medInstrTitles3[]; + static const char * const medInstrTitles4[]; + +protected: + static UsagePageFunc usagePageFunctions[]; + + MultiValueBuffer theBuffer; + MultiByteValueParser valParser; + ByteSkipper theSkipper; + uint8_t varBuffer[sizeof (USB_CONFIGURATION_DESCRIPTOR)]; + + uint8_t itemParseState; // Item parser state variable + uint8_t itemSize; // Item size + uint8_t itemPrefix; // Item prefix (first byte) + uint8_t rptSize; // Report Size + uint8_t rptCount; // Report Count + + uint16_t totalSize; // Report size in bits + + virtual uint8_t ParseItem(uint8_t **pp, uint32_t *pcntdn); + + UsagePageFunc pfUsage; + + static void PrintUsagePage(uint16_t page); + void SetUsagePage(uint16_t page); + +public: + + ReportDescParserBase() : + itemParseState(0), + itemSize(0), + itemPrefix(0), + rptSize(0), + rptCount(0), + pfUsage(NULL) { + theBuffer.pValue = varBuffer; + valParser.Initialize(&theBuffer); + theSkipper.Initialize(&theBuffer); + }; + + virtual void Parse(const uint32_t len, const uint8_t *pbuf, const uint32_t &offset); + + enum { + enErrorSuccess = 0 + , enErrorIncomplete // value or record is partialy read in buffer + , enErrorBufferTooSmall + }; +}; + +class ReportDescParser : public ReportDescParserBase { +}; + +class ReportDescParser2 : public ReportDescParserBase { + uint8_t rptId; // Report ID + uint8_t useMin; // Usage Minimum + uint8_t useMax; // Usage Maximum + uint8_t fieldCount; // Number of field being currently processed + + void OnInputItem(uint8_t itm); // Method which is called every time Input item is found + + uint8_t *pBuf; // Report buffer pointer + uint8_t bLen; // Report length + +protected: + virtual uint8_t ParseItem(uint8_t **pp, uint32_t *pcntdn); + +public: + + ReportDescParser2(uint16_t len, uint8_t *pbuf) : + ReportDescParserBase(), rptId(0), useMin(0), useMax(0), fieldCount(0), pBuf(pbuf), bLen(len) { + }; +}; + +class UniversalReportParser : public HIDReportParser { +public: + virtual void Parse(HID *hid, uint32_t is_rpt_id, uint32_t len, uint8_t *buf); +}; + +#endif // __HIDDESCRIPTORPARSER_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hiduniversal.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hiduniversal.cpp new file mode 100644 index 00000000000..7c6764b9e88 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hiduniversal.cpp @@ -0,0 +1,423 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#include "Arduino.h" +#include "hiduniversal.h" + +HIDUniversal::HIDUniversal(USBHost *p) : +HID(p), +qNextPollTime(0), +pollInterval(0), +bPollEnable(false), +bHasReportId(false) { + Initialize(); + + if(pUsb) + pUsb->RegisterDeviceClass(this); +} + +uint16_t HIDUniversal::GetHidClassDescrLen(uint8_t type, uint8_t num) { + for(uint8_t i = 0, n = 0; i < HID_MAX_HID_CLASS_DESCRIPTORS; i++) { + if(descrInfo[i].bDescrType == type) { + if(n == num) + return descrInfo[i].wDescriptorLength; + n++; + } + } + return 0; +} + +void HIDUniversal::Initialize() { + for(uint8_t i = 0; i < MAX_REPORT_PARSERS; i++) { + rptParsers[i].rptId = 0; + rptParsers[i].rptParser = NULL; + } + for(uint8_t i = 0; i < HID_MAX_HID_CLASS_DESCRIPTORS; i++) { + descrInfo[i].bDescrType = 0; + descrInfo[i].wDescriptorLength = 0; + } + for(uint8_t i = 0; i < maxHidInterfaces; i++) { + hidInterfaces[i].bmInterface = 0; + hidInterfaces[i].bmProtocol = 0; + + for(uint8_t j = 0; j < maxEpPerInterface; j++) + hidInterfaces[i].epIndex[j] = 0; + } + for(uint8_t i = 0; i < totalEndpoints; i++) { + epInfo[i].epAddr = 0; + epInfo[i].maxPktSize = (i) ? 0 : 8; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; + epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; + } + bNumEP = 1; + bNumIface = 0; + bConfNum = 0; + pollInterval = 0; + + ZeroMemory(constBuffLen, prevBuf); +} + +uint32_t HIDUniversal::SetReportParser(uint32_t id, HIDReportParser *prs) { + for(uint8_t i = 0; i < MAX_REPORT_PARSERS; i++) { + if(rptParsers[i].rptId == 0 && rptParsers[i].rptParser == NULL) { + rptParsers[i].rptId = id; + rptParsers[i].rptParser = prs; + return true; + } + } + return false; +} + +HIDReportParser* HIDUniversal::GetReportParser(uint32_t id) { + if(!bHasReportId) + return ((rptParsers[0].rptParser) ? rptParsers[0].rptParser : NULL); + + for(uint8_t i = 0; i < MAX_REPORT_PARSERS; i++) { + if(rptParsers[i].rptId == id) + return rptParsers[i].rptParser; + } + return NULL; +} + +uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) { + const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); + + uint8_t buf[constBufSize]; + USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast(buf); + uint8_t rcode; + UsbDeviceDefinition *p = NULL; + EpInfo *oldep_ptr = NULL; + uint8_t len = 0; + + uint8_t num_of_conf; // number of configurations + //uint8_t num_of_intf; // number of interfaces + + AddressPool &addrPool = pUsb->GetAddressPool(); + + USBTRACE("HU Init\r\n"); + + if(bAddress) + return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; + + // Get pointer to pseudo device with address 0 assigned + p = addrPool.GetUsbDevicePtr(0); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + if(!p->epinfo) { + USBTRACE("epinfo\r\n"); + return USB_ERROR_EPINFO_IS_NULL; + } + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + + p->lowspeed = lowspeed; + + // Get device descriptor + rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf); + + if(!rcode) + len = (buf[0] > constBufSize) ? constBufSize : buf[0]; + + if(rcode) { + // Restore p->epinfo + p->epinfo = oldep_ptr; + + goto FailGetDevDescr; + } + + // Restore p->epinfo + p->epinfo = oldep_ptr; + + // Allocate new address according to device class + bAddress = addrPool.AllocAddress(parent, false, port); + + if(!bAddress) + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + + // Extract Max Packet Size from the device descriptor + epInfo[0].maxPktSize = udd->bMaxPacketSize0; + + // Assign new address to the device + rcode = pUsb->setAddr(0, 0, bAddress); + + if(rcode) { + p->lowspeed = false; + addrPool.FreeAddress(bAddress); + bAddress = 0; + USBTRACE2("setAddr:", rcode); + return rcode; + } + + //delay(2); //per USB 2.0 sect.9.2.6.3 + + USBTRACE2("Addr:", bAddress); + + p->lowspeed = false; + + p = addrPool.GetUsbDevicePtr(bAddress); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + p->lowspeed = lowspeed; + + if(len) + rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf); + + if(rcode) + goto FailGetDevDescr; + + VID = udd->idVendor; // Can be used by classes that inherits this class to check the VID and PID of the connected device + PID = udd->idProduct; + + num_of_conf = udd->bNumConfigurations; + + // Assign epInfo to epinfo pointer + rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); + + if(rcode) + goto FailSetDevTblEntry; + + USBTRACE2("NC:", num_of_conf); + + for(uint8_t i = 0; i < num_of_conf; i++) { + //HexDumper HexDump; + ConfigDescParser confDescrParser(this); + + //rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); + rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); + + if(rcode) + goto FailGetConfDescr; + + if(bNumEP > 1) + break; + } // for + + if(bNumEP < 2) + return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + + // Assign epInfo to epinfo pointer + rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); + + USBTRACE2("Cnf:", bConfNum); + + // Set Configuration Value + rcode = pUsb->setConf(bAddress, 0, bConfNum); + + if(rcode) + goto FailSetConfDescr; + + for(uint8_t i = 0; i < bNumIface; i++) { + if(hidInterfaces[i].epIndex[epInterruptInIndex] == 0) + continue; + + rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0); + + if(rcode)/* && rcode != hrSTALL) */ + goto FailSetIdle; + } + + USBTRACE("HU configured\r\n"); + + OnInitSuccessful(); + + bPollEnable = true; + return 0; + +FailGetDevDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetDevDescr(); + goto Fail; +#endif + +FailSetDevTblEntry: +#ifdef DEBUG_USB_HOST + NotifyFailSetDevTblEntry(); + goto Fail; +#endif + +FailGetConfDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetConfDescr(); + goto Fail; +#endif + +FailSetConfDescr: +#ifdef DEBUG_USB_HOST + NotifyFailSetConfDescr(); + goto Fail; +#endif + + +FailSetIdle: +#ifdef DEBUG_USB_HOST + USBTRACE("SetIdle:"); +#endif + +#ifdef DEBUG_USB_HOST +Fail: + NotifyFail(rcode); +#endif + Release(); + return rcode; +} + +HIDUniversal::HIDInterface* HIDUniversal::FindInterface(uint8_t iface, uint8_t alt, uint8_t proto) { + for(uint8_t i = 0; i < bNumIface && i < maxHidInterfaces; i++) + if(hidInterfaces[i].bmInterface == iface && hidInterfaces[i].bmAltSet == alt + && hidInterfaces[i].bmProtocol == proto) + return hidInterfaces + i; + return NULL; +} + +void HIDUniversal::EndpointXtract(uint32_t conf, uint32_t iface, uint32_t alt, uint32_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) { + // If the first configuration satisfies, the others are not concidered. + if(bNumEP > 1 && conf != bConfNum) + return; + + //ErrorMessage(PSTR("\r\nConf.Val"), conf); + //ErrorMessage(PSTR("Iface Num"), iface); + //ErrorMessage(PSTR("Alt.Set"), alt); + + bConfNum = conf; + + uint8_t index = 0; + HIDInterface *piface = FindInterface(iface, alt, proto); + + // Fill in interface structure in case of new interface + if(!piface) { + piface = hidInterfaces + bNumIface; + piface->bmInterface = iface; + piface->bmAltSet = alt; + piface->bmProtocol = proto; + bNumIface++; + } + + if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) + index = epInterruptInIndex; + else + index = epInterruptOutIndex; + + if(index) { + // Fill in the endpoint info structure + epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); + epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; + epInfo[bNumEP].bmSndToggle = 0; + epInfo[bNumEP].bmRcvToggle = 0; + epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT; + + // Fill in the endpoint index list + piface->epIndex[index] = bNumEP; //(pep->bEndpointAddress & 0x0F); + + if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints + pollInterval = pep->bInterval; + + bNumEP++; + } + //PrintEndpointDescriptor(pep); +} + +uint32_t HIDUniversal::Release() { + pUsb->GetAddressPool().FreeAddress(bAddress); + + bNumEP = 1; + bAddress = 0; + qNextPollTime = 0; + bPollEnable = false; + return 0; +} + +bool HIDUniversal::BuffersIdentical(uint8_t len, uint8_t *buf1, uint8_t *buf2) { + for(uint8_t i = 0; i < len; i++) + if(buf1[i] != buf2[i]) + return false; + return true; +} + +void HIDUniversal::ZeroMemory(uint8_t len, uint8_t *buf) { + for(uint8_t i = 0; i < len; i++) + buf[i] = 0; +} + +void HIDUniversal::SaveBuffer(uint8_t len, uint8_t *src, uint8_t *dest) { + for(uint8_t i = 0; i < len; i++) + dest[i] = src[i]; +} + +uint32_t HIDUniversal::Poll() { + uint32_t rcode = 0; + + if(!bPollEnable) + return 0; + + if((long)(millis() - qNextPollTime) >= 0L) { + qNextPollTime = millis() + pollInterval; + + uint8_t buf[constBuffLen]; + + for(uint8_t i = 0; i < bNumIface; i++) { + uint8_t index = hidInterfaces[i].epIndex[epInterruptInIndex]; + uint16_t read = (uint8_t)epInfo[index].maxPktSize; + + ZeroMemory(constBuffLen, buf); + + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[index].epAddr, (uint8_t*)&read, buf); + + if(rcode) { + if(rcode != USB_ERRORFLOW/*hrNAK*/) + USBTRACE3("(hiduniversal.h) Poll:", rcode, 0x81); + return rcode; + } + + if(read > constBuffLen) + read = constBuffLen; + + bool identical = BuffersIdentical(read, buf, prevBuf); + + SaveBuffer(read, buf, prevBuf); + + if(identical) + return 0; +#if 0 + Notify(PSTR("\r\nBuf: "), 0x80); + + for(uint8_t i = 0; i < read; i++) { + D_PrintHex (buf[i], 0x80); + Notify(PSTR(" "), 0x80); + } + + Notify(PSTR("\r\n"), 0x80); +#endif + ParseHIDData(this, bHasReportId, (uint8_t)read, buf); + + HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0)); + + if(prs) + prs->Parse(this, bHasReportId, (uint8_t)read, buf); + } + } + return rcode; +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hiduniversal.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hiduniversal.h new file mode 100644 index 00000000000..3387619e907 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hiduniversal.h @@ -0,0 +1,105 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#if !defined(__HIDUNIVERSAL_H__) +#define __HIDUNIVERSAL_H__ + +#include "hid.h" +//#include "hidescriptorparser.h" + +class HIDUniversal : public HID { + + struct ReportParser { + uint8_t rptId; + HIDReportParser *rptParser; + } rptParsers[MAX_REPORT_PARSERS]; + + // HID class specific descriptor type and length info obtained from HID descriptor + HID_CLASS_DESCRIPTOR_LEN_AND_TYPE descrInfo[HID_MAX_HID_CLASS_DESCRIPTORS]; + + // Returns HID class specific descriptor length by its type and order number + uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num); + + struct HIDInterface { + struct { + uint8_t bmInterface : 3; + uint8_t bmAltSet : 3; + uint8_t bmProtocol : 2; + }; + uint8_t epIndex[maxEpPerInterface]; + }; + + uint8_t bConfNum; // configuration number + uint8_t bNumIface; // number of interfaces in the configuration + uint8_t bNumEP; // total number of EP in the configuration + uint32_t qNextPollTime; // next poll time + uint8_t pollInterval; + bool bPollEnable; // poll enable flag + + static const uint16_t constBuffLen = 64; // event buffer length + uint8_t prevBuf[constBuffLen]; // previous event buffer + + void Initialize(); + HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto); + + void ZeroMemory(uint8_t len, uint8_t *buf); + bool BuffersIdentical(uint8_t len, uint8_t *buf1, uint8_t *buf2); + void SaveBuffer(uint8_t len, uint8_t *src, uint8_t *dest); + +protected: + EpInfo epInfo[totalEndpoints]; + HIDInterface hidInterfaces[maxHidInterfaces]; + + bool bHasReportId; + + uint16_t PID, VID; // PID and VID of connected device + + // HID implementation + virtual HIDReportParser* GetReportParser(uint32_t id); + + virtual uint32_t OnInitSuccessful() { + return 0; + }; + + virtual void ParseHIDData(HID * /* hid */, bool /* is_rpt_id */, uint8_t /* len */, uint8_t * /* buf */) { + return; + }; + +public: + HIDUniversal(USBHost *p); + + // HID implementation + virtual uint32_t SetReportParser(uint32_t id, HIDReportParser *prs); + + // USBDeviceConfig implementation + virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); + virtual uint32_t Release(); + virtual uint32_t Poll(); + + virtual uint32_t GetAddress() { + return bAddress; + }; + + virtual uint32_t isReady() { + return bPollEnable; + }; + + // UsbConfigXtracter implementation + virtual void EndpointXtract(uint32_t conf, uint32_t iface, uint32_t alt, uint32_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); +}; + +#endif // __HIDUNIVERSAL_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidusagestr.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidusagestr.h new file mode 100644 index 00000000000..71e53787399 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/hidusagestr.h @@ -0,0 +1,977 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#if !defined( __HIDUSAGESTR_H__) +#define __HIDUSAGESTR_H__ + +#include "Usb.h" + +const char pstrSpace [] PROGMEM = " "; +const char pstrCRLF [] PROGMEM = "\r\n"; +const char pstrSingleTab [] PROGMEM = "\t"; +const char pstrDoubleTab [] PROGMEM = "\t\t"; +const char pstrTripleTab [] PROGMEM = "\t\t\t"; + +// Usage Page String Titles +const char pstrUsagePageUndefined [] PROGMEM = "Undef"; +const char pstrUsagePageGenericDesktopControls [] PROGMEM = "Gen Desktop Ctrls"; +const char pstrUsagePageSimulationControls [] PROGMEM = "Simu Ctrls"; +const char pstrUsagePageVRControls [] PROGMEM = "VR Ctrls"; +const char pstrUsagePageSportControls [] PROGMEM = "Sport Ctrls"; +const char pstrUsagePageGameControls [] PROGMEM = "Game Ctrls"; +const char pstrUsagePageGenericDeviceControls [] PROGMEM = "Gen Dev Ctrls"; +const char pstrUsagePageKeyboardKeypad [] PROGMEM = "Kbrd/Keypad"; +const char pstrUsagePageLEDs [] PROGMEM = "LEDs"; +const char pstrUsagePageButton [] PROGMEM = "Button"; +const char pstrUsagePageOrdinal [] PROGMEM = "Ordinal"; +const char pstrUsagePageTelephone [] PROGMEM = "Tel"; +const char pstrUsagePageConsumer [] PROGMEM = "Consumer"; +const char pstrUsagePageDigitizer [] PROGMEM = "Digitizer"; +const char pstrUsagePagePID [] PROGMEM = "PID"; +const char pstrUsagePageUnicode [] PROGMEM = "Unicode"; +const char pstrUsagePageAlphaNumericDisplay [] PROGMEM = "Alpha Num Disp"; +const char pstrUsagePageMedicalInstruments [] PROGMEM = "Medical Instr"; +const char pstrUsagePageMonitor [] PROGMEM = "Monitor"; +const char pstrUsagePagePower [] PROGMEM = "Power"; +const char pstrUsagePageBarCodeScanner [] PROGMEM = "Bar Code Scan"; +const char pstrUsagePageScale [] PROGMEM = "Scale"; +const char pstrUsagePageMSRDevices [] PROGMEM = "Magn Stripe Read Dev"; +const char pstrUsagePagePointOfSale [] PROGMEM = "POS"; +const char pstrUsagePageCameraControl [] PROGMEM = "Cam Ctrl"; +const char pstrUsagePageArcade [] PROGMEM = "Arcade"; +const char pstrUsagePageReserved [] PROGMEM = "Reserved"; +const char pstrUsagePageVendorDefined [] PROGMEM = "Vendor Def"; + +// Generic Desktop Controls Page +const char pstrUsagePointer [] PROGMEM = "Pointer"; +const char pstrUsageMouse [] PROGMEM = "Mouse"; +const char pstrUsageJoystick [] PROGMEM = "Joystick"; +const char pstrUsageGamePad [] PROGMEM = "Game Pad"; +const char pstrUsageKeyboard [] PROGMEM = "Kbrd"; +const char pstrUsageKeypad [] PROGMEM = "Keypad"; +const char pstrUsageMultiAxisController [] PROGMEM = "Multi-axis Ctrl"; +const char pstrUsageTabletPCSystemControls [] PROGMEM = "Tablet PC Sys Ctrls"; +const char pstrUsageX [] PROGMEM = "X"; +const char pstrUsageY [] PROGMEM = "Y"; +const char pstrUsageZ [] PROGMEM = "Z"; +const char pstrUsageRx [] PROGMEM = "Rx"; +const char pstrUsageRy [] PROGMEM = "Ry"; +const char pstrUsageRz [] PROGMEM = "Rz"; +const char pstrUsageSlider [] PROGMEM = "Slider"; +const char pstrUsageDial [] PROGMEM = "Dial"; +const char pstrUsageWheel [] PROGMEM = "Wheel"; +const char pstrUsageHatSwitch [] PROGMEM = "Hat Switch"; +const char pstrUsageCountedBuffer [] PROGMEM = "Counted Buf"; +const char pstrUsageByteCount [] PROGMEM = "Byte Count"; +const char pstrUsageMotionWakeup [] PROGMEM = "Motion Wakeup"; +const char pstrUsageStart [] PROGMEM = "Start"; +const char pstrUsageSelect [] PROGMEM = "Sel"; +const char pstrUsageVx [] PROGMEM = "Vx"; +const char pstrUsageVy [] PROGMEM = "Vy"; +const char pstrUsageVz [] PROGMEM = "Vz"; +const char pstrUsageVbrx [] PROGMEM = "Vbrx"; +const char pstrUsageVbry [] PROGMEM = "Vbry"; +const char pstrUsageVbrz [] PROGMEM = "Vbrz"; +const char pstrUsageVno [] PROGMEM = "Vno"; +const char pstrUsageFeatureNotification [] PROGMEM = "Feature Notif"; +const char pstrUsageResolutionMultiplier [] PROGMEM = "Res Mult"; +const char pstrUsageSystemControl [] PROGMEM = "Sys Ctrl"; +const char pstrUsageSystemPowerDown [] PROGMEM = "Sys Pwr Down"; +const char pstrUsageSystemSleep [] PROGMEM = "Sys Sleep"; +const char pstrUsageSystemWakeup [] PROGMEM = "Sys Wakeup"; +const char pstrUsageSystemContextMenu [] PROGMEM = "Sys Context Menu"; +const char pstrUsageSystemMainMenu [] PROGMEM = "Sys Main Menu"; +const char pstrUsageSystemAppMenu [] PROGMEM = "Sys App Menu"; +const char pstrUsageSystemMenuHelp [] PROGMEM = "Sys Menu Help"; +const char pstrUsageSystemMenuExit [] PROGMEM = "Sys Menu Exit"; +const char pstrUsageSystemMenuSelect [] PROGMEM = "Sys Menu Select"; +const char pstrUsageSystemMenuRight [] PROGMEM = "Sys Menu Right"; +const char pstrUsageSystemMenuLeft [] PROGMEM = "Sys Menu Left"; +const char pstrUsageSystemMenuUp [] PROGMEM = "Sys Menu Up"; +const char pstrUsageSystemMenuDown [] PROGMEM = "Sys Menu Down"; +const char pstrUsageSystemColdRestart [] PROGMEM = "Sys Cold Restart"; +const char pstrUsageSystemWarmRestart [] PROGMEM = "Sys Warm Restart"; +const char pstrUsageDPadUp [] PROGMEM = "D-pad Up"; +const char pstrUsageDPadDown [] PROGMEM = "D-pad Down"; +const char pstrUsageDPadRight [] PROGMEM = "D-pad Right"; +const char pstrUsageDPadLeft [] PROGMEM = "D-pad Left"; +const char pstrUsageSystemDock [] PROGMEM = "Sys Dock"; +const char pstrUsageSystemUndock [] PROGMEM = "Sys Undock"; +const char pstrUsageSystemSetup [] PROGMEM = "Sys Setup"; +const char pstrUsageSystemBreak [] PROGMEM = "Sys Break"; +const char pstrUsageSystemDebuggerBreak [] PROGMEM = "Sys Dbg Brk"; +const char pstrUsageApplicationBreak [] PROGMEM = "App Break"; +const char pstrUsageApplicationDebuggerBreak [] PROGMEM = "App Dbg Brk"; +const char pstrUsageSystemSpeakerMute [] PROGMEM = "Sys Spk Mute"; +const char pstrUsageSystemHibernate [] PROGMEM = "Sys Hiber"; +const char pstrUsageSystemDisplayInvert [] PROGMEM = "Sys Disp Inv"; +const char pstrUsageSystemDisplayInternal [] PROGMEM = "Sys Disp Int"; +const char pstrUsageSystemDisplayExternal [] PROGMEM = "Sys Disp Ext"; +const char pstrUsageSystemDisplayBoth [] PROGMEM = "Sys Disp Both"; +const char pstrUsageSystemDisplayDual [] PROGMEM = "Sys Disp Dual"; +const char pstrUsageSystemDisplayToggleIntExt [] PROGMEM = "Sys Disp Tgl Int/Ext"; +const char pstrUsageSystemDisplaySwapPriSec [] PROGMEM = "Sys Disp Swap Pri/Sec"; +const char pstrUsageSystemDisplayLCDAutoscale [] PROGMEM = "Sys Disp LCD Autoscale"; + +// Simulation Controls Page +const char pstrUsageFlightSimulationDevice [] PROGMEM = "Flight Simu Dev"; +const char pstrUsageAutomobileSimulationDevice [] PROGMEM = "Auto Simu Dev"; +const char pstrUsageTankSimulationDevice [] PROGMEM = "Tank Simu Dev"; +const char pstrUsageSpaceshipSimulationDevice [] PROGMEM = "Space Simu Dev"; +const char pstrUsageSubmarineSimulationDevice [] PROGMEM = "Subm Simu Dev"; +const char pstrUsageSailingSimulationDevice [] PROGMEM = "Sail Simu Dev"; +const char pstrUsageMotocicleSimulationDevice [] PROGMEM = "Moto Simu Dev"; +const char pstrUsageSportsSimulationDevice [] PROGMEM = "Sport Simu Dev"; +const char pstrUsageAirplaneSimulationDevice [] PROGMEM = "Airp Simu Dev"; +const char pstrUsageHelicopterSimulationDevice [] PROGMEM = "Heli Simu Dev"; +const char pstrUsageMagicCarpetSimulationDevice [] PROGMEM = "Magic Carpet Simu Dev"; +const char pstrUsageBicycleSimulationDevice [] PROGMEM = "Bike Simu Dev"; +const char pstrUsageFlightControlStick [] PROGMEM = "Flight Ctrl Stick"; +const char pstrUsageFlightStick [] PROGMEM = "Flight Stick"; +const char pstrUsageCyclicControl [] PROGMEM = "Cyclic Ctrl"; +const char pstrUsageCyclicTrim [] PROGMEM = "Cyclic Trim"; +const char pstrUsageFlightYoke [] PROGMEM = "Flight Yoke"; +const char pstrUsageTrackControl [] PROGMEM = "Track Ctrl"; +const char pstrUsageAileron [] PROGMEM = "Aileron"; +const char pstrUsageAileronTrim [] PROGMEM = "Aileron Trim"; +const char pstrUsageAntiTorqueControl [] PROGMEM = "Anti-Torque Ctrl"; +const char pstrUsageAutopilotEnable [] PROGMEM = "Autopilot Enable"; +const char pstrUsageChaffRelease [] PROGMEM = "Chaff Release"; +const char pstrUsageCollectiveControl [] PROGMEM = "Collective Ctrl"; +const char pstrUsageDiveBrake [] PROGMEM = "Dive Brake"; +const char pstrUsageElectronicCountermeasures [] PROGMEM = "El Countermeasures"; +const char pstrUsageElevator [] PROGMEM = "Elevator"; +const char pstrUsageElevatorTrim [] PROGMEM = "Elevator Trim"; +const char pstrUsageRudder [] PROGMEM = "Rudder"; +const char pstrUsageThrottle [] PROGMEM = "Throttle"; +const char pstrUsageFlightCommunications [] PROGMEM = "Flight Comm"; +const char pstrUsageFlareRelease [] PROGMEM = "Flare Release"; +const char pstrUsageLandingGear [] PROGMEM = "Landing Gear"; +const char pstrUsageToeBrake [] PROGMEM = "Toe Brake"; +const char pstrUsageTrigger [] PROGMEM = "Trigger"; +const char pstrUsageWeaponsArm [] PROGMEM = "Weapons Arm"; +const char pstrUsageWeaponsSelect [] PROGMEM = "Weapons Sel"; +const char pstrUsageWingFlaps [] PROGMEM = "Wing Flaps"; +const char pstrUsageAccelerator [] PROGMEM = "Accel"; +const char pstrUsageBrake [] PROGMEM = "Brake"; +const char pstrUsageClutch [] PROGMEM = "Clutch"; +const char pstrUsageShifter [] PROGMEM = "Shifter"; +const char pstrUsageSteering [] PROGMEM = "Steering"; +const char pstrUsageTurretDirection [] PROGMEM = "Turret Dir"; +const char pstrUsageBarrelElevation [] PROGMEM = "Barrel Ele"; +const char pstrUsageDivePlane [] PROGMEM = "Dive Plane"; +const char pstrUsageBallast [] PROGMEM = "Ballast"; +const char pstrUsageBicycleCrank [] PROGMEM = "Bicycle Crank"; +const char pstrUsageHandleBars [] PROGMEM = "Handle Bars"; +const char pstrUsageFrontBrake [] PROGMEM = "Front Brake"; +const char pstrUsageRearBrake [] PROGMEM = "Rear Brake"; + +// VR Controls Page +const char pstrUsageBelt [] PROGMEM = "Belt"; +const char pstrUsageBodySuit [] PROGMEM = "Body Suit"; +const char pstrUsageFlexor [] PROGMEM = "Flexor"; +const char pstrUsageGlove [] PROGMEM = "Glove"; +const char pstrUsageHeadTracker [] PROGMEM = "Head Track"; +const char pstrUsageHeadMountedDisplay [] PROGMEM = "Head Disp"; +const char pstrUsageHandTracker [] PROGMEM = "Hand Track"; +const char pstrUsageOculometer [] PROGMEM = "Oculometer"; +const char pstrUsageVest [] PROGMEM = "Vest"; +const char pstrUsageAnimatronicDevice [] PROGMEM = "Animat Dev"; +const char pstrUsageStereoEnable [] PROGMEM = "Stereo Enbl"; +const char pstrUsageDisplayEnable [] PROGMEM = "Display Enbl"; + +// Sport Controls Page +const char pstrUsageBaseballBat [] PROGMEM = "Baseball Bat"; +const char pstrUsageGolfClub [] PROGMEM = "Golf Club"; +const char pstrUsageRowingMachine [] PROGMEM = "Rowing Mach"; +const char pstrUsageTreadmill [] PROGMEM = "Treadmill"; +const char pstrUsageOar [] PROGMEM = "Oar"; +const char pstrUsageSlope [] PROGMEM = "Slope"; +const char pstrUsageRate [] PROGMEM = "Rate"; +const char pstrUsageStickSpeed [] PROGMEM = "Stick Speed"; +const char pstrUsageStickFaceAngle [] PROGMEM = "Stick Face Ang"; +const char pstrUsageStickHeelToe [] PROGMEM = "Stick Heel/Toe"; +const char pstrUsageStickFollowThough [] PROGMEM = "Stick Flw Thru"; +const char pstrUsageStickTempo [] PROGMEM = "Stick Tempo"; +const char pstrUsageStickType [] PROGMEM = "Stick Type"; +const char pstrUsageStickHeight [] PROGMEM = "Stick Hght"; +const char pstrUsagePutter [] PROGMEM = "Putter"; +const char pstrUsage1Iron [] PROGMEM = "1 Iron"; +const char pstrUsage2Iron [] PROGMEM = "2 Iron"; +const char pstrUsage3Iron [] PROGMEM = "3 Iron"; +const char pstrUsage4Iron [] PROGMEM = "4 Iron"; +const char pstrUsage5Iron [] PROGMEM = "5 Iron"; +const char pstrUsage6Iron [] PROGMEM = "6 Iron"; +const char pstrUsage7Iron [] PROGMEM = "7 Iron"; +const char pstrUsage8Iron [] PROGMEM = "8 Iron"; +const char pstrUsage9Iron [] PROGMEM = "9 Iron"; +const char pstrUsage10Iron [] PROGMEM = "10 Iron"; +const char pstrUsage11Iron [] PROGMEM = "11 Iron"; +const char pstrUsageSandWedge [] PROGMEM = "Sand Wedge"; +const char pstrUsageLoftWedge [] PROGMEM = "Loft Wedge"; +const char pstrUsagePowerWedge [] PROGMEM = "Pwr Wedge"; +const char pstrUsage1Wood [] PROGMEM = "1 Wood"; +const char pstrUsage3Wood [] PROGMEM = "3 Wood"; +const char pstrUsage5Wood [] PROGMEM = "5 Wood"; +const char pstrUsage7Wood [] PROGMEM = "7 Wood"; +const char pstrUsage9Wood [] PROGMEM = "9 Wood"; + +// Game Controls Page +const char pstrUsage3DGameController [] PROGMEM = "3D Game Ctrl"; +const char pstrUsagePinballDevice [] PROGMEM = "Pinball Dev"; +const char pstrUsageGunDevice [] PROGMEM = "Gun Dev"; +const char pstrUsagePointOfView [] PROGMEM = "POV"; +const char pstrUsageTurnRightLeft [] PROGMEM = "Turn Right Left"; +const char pstrUsagePitchForwardBackward [] PROGMEM = "Pitch Fwd/Back"; +const char pstrUsageRollRightLeft [] PROGMEM = "Roll Right/Left"; +const char pstrUsageMoveRightLeft [] PROGMEM = "Move Right/Left"; +const char pstrUsageMoveForwardBackward [] PROGMEM = "Move Fwd/Back"; +const char pstrUsageMoveUpDown [] PROGMEM = "Move Up/Down"; +const char pstrUsageLeanRightLeft [] PROGMEM = "Lean Right/Left"; +const char pstrUsageLeanForwardBackward [] PROGMEM = "Lean Fwd/Back"; +const char pstrUsageHeightOfPOV [] PROGMEM = "Height of POV"; +const char pstrUsageFlipper [] PROGMEM = "Flipper"; +const char pstrUsageSecondaryFlipper [] PROGMEM = "Second Flipper"; +const char pstrUsageBump [] PROGMEM = "Bump"; +const char pstrUsageNewGame [] PROGMEM = "New Game"; +const char pstrUsageShootBall [] PROGMEM = "Shoot Ball"; +const char pstrUsagePlayer [] PROGMEM = "Player"; +const char pstrUsageGunBolt [] PROGMEM = "Gun Bolt"; +const char pstrUsageGunClip [] PROGMEM = "Gun Clip"; +const char pstrUsageGunSelector [] PROGMEM = "Gun Sel"; +const char pstrUsageGunSingleShot [] PROGMEM = "Gun Sngl Shot"; +const char pstrUsageGunBurst [] PROGMEM = "Gun Burst"; +const char pstrUsageGunAutomatic [] PROGMEM = "Gun Auto"; +const char pstrUsageGunSafety [] PROGMEM = "Gun Safety"; +const char pstrUsageGamepadFireJump [] PROGMEM = "Gamepad Fire/Jump"; +const char pstrUsageGamepadTrigger [] PROGMEM = "Gamepad Trig"; + +// Generic Device Controls Page +const char pstrUsageBatteryStrength [] PROGMEM = "Bat Strength"; +const char pstrUsageWirelessChannel [] PROGMEM = "Wireless Ch"; +const char pstrUsageWirelessID [] PROGMEM = "Wireless ID"; +const char pstrUsageDiscoverWirelessControl [] PROGMEM = "Discover Wireless Ctrl"; +const char pstrUsageSecurityCodeCharEntered [] PROGMEM = "Sec Code Char Entrd"; +const char pstrUsageSecurityCodeCharErased [] PROGMEM = "Sec Code Char Erased"; +const char pstrUsageSecurityCodeCleared [] PROGMEM = "Sec Code Cleared"; + +// LED Page +const char pstrUsageNumLock [] PROGMEM = "Num Lock"; +const char pstrUsageCapsLock [] PROGMEM = "Caps Lock"; +const char pstrUsageScrollLock [] PROGMEM = "Scroll Lock"; +const char pstrUsageCompose [] PROGMEM = "Compose"; +const char pstrUsageKana [] PROGMEM = "Kana"; +const char pstrUsagePower [] PROGMEM = "Pwr"; +const char pstrUsageShift [] PROGMEM = "Shift"; +const char pstrUsageDoNotDisturb [] PROGMEM = "DND"; +const char pstrUsageMute [] PROGMEM = "Mute"; +const char pstrUsageToneEnable [] PROGMEM = "Tone Enbl"; +const char pstrUsageHighCutFilter [] PROGMEM = "High Cut Fltr"; +const char pstrUsageLowCutFilter [] PROGMEM = "Low Cut Fltr"; +const char pstrUsageEqualizerEnable [] PROGMEM = "Eq Enbl"; +const char pstrUsageSoundFieldOn [] PROGMEM = "Sound Field On"; +const char pstrUsageSurroundOn [] PROGMEM = "Surround On"; +const char pstrUsageRepeat [] PROGMEM = "Repeat"; +const char pstrUsageStereo [] PROGMEM = "Stereo"; +const char pstrUsageSamplingRateDetect [] PROGMEM = "Smpl Rate Detect"; +const char pstrUsageSpinning [] PROGMEM = "Spinning"; +const char pstrUsageCAV [] PROGMEM = "CAV"; +const char pstrUsageCLV [] PROGMEM = "CLV"; +const char pstrUsageRecordingFormatDetect [] PROGMEM = "Rec Format Detect"; +const char pstrUsageOffHook [] PROGMEM = "Off Hook"; +const char pstrUsageRing [] PROGMEM = "Ring"; +const char pstrUsageMessageWaiting [] PROGMEM = "Msg Wait"; +const char pstrUsageDataMode [] PROGMEM = "Data Mode"; +const char pstrUsageBatteryOperation [] PROGMEM = "Bat Op"; +const char pstrUsageBatteryOK [] PROGMEM = "Bat OK"; +const char pstrUsageBatteryLow [] PROGMEM = "Bat Low"; +const char pstrUsageSpeaker [] PROGMEM = "Speaker"; +const char pstrUsageHeadSet [] PROGMEM = "Head Set"; +const char pstrUsageHold [] PROGMEM = "Hold"; +const char pstrUsageMicrophone [] PROGMEM = "Mic"; +const char pstrUsageCoverage [] PROGMEM = "Coverage"; +const char pstrUsageNightMode [] PROGMEM = "Night Mode"; +const char pstrUsageSendCalls [] PROGMEM = "Send Calls"; +const char pstrUsageCallPickup [] PROGMEM = "Call Pickup"; +const char pstrUsageConference [] PROGMEM = "Conf"; +const char pstrUsageStandBy [] PROGMEM = "Stand-by"; +const char pstrUsageCameraOn [] PROGMEM = "Cam On"; +const char pstrUsageCameraOff [] PROGMEM = "Cam Off"; +const char pstrUsageOnLine [] PROGMEM = "On-Line"; +const char pstrUsageOffLine [] PROGMEM = "Off-Line"; +const char pstrUsageBusy [] PROGMEM = "Busy"; +const char pstrUsageReady [] PROGMEM = "Ready"; +const char pstrUsagePaperOut [] PROGMEM = "Paper Out"; +const char pstrUsagePaperJam [] PROGMEM = "Paper Jam"; +const char pstrUsageRemote [] PROGMEM = "Remote"; +const char pstrUsageForward [] PROGMEM = "Fwd"; +const char pstrUsageReverse [] PROGMEM = "Rev"; +const char pstrUsageStop [] PROGMEM = "Stop"; +const char pstrUsageRewind [] PROGMEM = "Rewind"; +const char pstrUsageFastForward [] PROGMEM = "Fast Fwd"; +const char pstrUsagePlay [] PROGMEM = "Play"; +const char pstrUsagePause [] PROGMEM = "Pause"; +const char pstrUsageRecord [] PROGMEM = "Rec"; +const char pstrUsageError [] PROGMEM = "Error"; +const char pstrUsageSelectedIndicator [] PROGMEM = "Usage Sel Ind"; +const char pstrUsageInUseIndicator [] PROGMEM = "Usage In Use Ind"; +const char pstrUsageMultiModeIndicator [] PROGMEM = "Usage Multi Mode Ind"; +const char pstrUsageIndicatorOn [] PROGMEM = "Ind On"; +const char pstrUsageIndicatorFlash [] PROGMEM = "Ind Flash"; +const char pstrUsageIndicatorSlowBlink [] PROGMEM = "Ind Slow Blk"; +const char pstrUsageIndicatorFastBlink [] PROGMEM = "Ind Fast Blk"; +const char pstrUsageIndicatorOff [] PROGMEM = "Ind Off"; +const char pstrUsageFlashOnTime [] PROGMEM = "Flash On Time"; +const char pstrUsageSlowBlinkOnTime [] PROGMEM = "Slow Blk On Time"; +const char pstrUsageSlowBlinkOffTime [] PROGMEM = "Slow Blk Off Time"; +const char pstrUsageFastBlinkOnTime [] PROGMEM = "Fast Blk On Time"; +const char pstrUsageFastBlinkOffTime [] PROGMEM = "Fast Blk Off Time"; +const char pstrUsageIndicatorColor [] PROGMEM = "Usage Ind Color"; +const char pstrUsageIndicatorRed [] PROGMEM = "Ind Red"; +const char pstrUsageIndicatorGreen [] PROGMEM = "Ind Green"; +const char pstrUsageIndicatorAmber [] PROGMEM = "Ind Amber"; +const char pstrUsageGenericIndicator [] PROGMEM = "Gen Ind"; +const char pstrUsageSystemSuspend [] PROGMEM = "Sys Suspend"; +const char pstrUsageExternalPowerConnected [] PROGMEM = "Ext Pwr Conn"; + +// Telephony Usage Page +const char pstrUsagePhone [] PROGMEM = "Phone"; +const char pstrUsageAnsweringMachine [] PROGMEM = "Answ Mach"; +const char pstrUsageMessageControls [] PROGMEM = "Msg Ctrls"; +const char pstrUsageHandset [] PROGMEM = "Handset"; +const char pstrUsageHeadset [] PROGMEM = "Headset"; +const char pstrUsageTelephonyKeyPad [] PROGMEM = "Tel Key Pad"; +const char pstrUsageProgrammableButton [] PROGMEM = "Prog Button"; +const char pstrUsageHookSwitch [] PROGMEM = "Hook Sw"; +const char pstrUsageFlash [] PROGMEM = "Flash"; +const char pstrUsageFeature [] PROGMEM = "Feature"; +//const char pstrUsageHold [] PROGMEM = "Hold"; +const char pstrUsageRedial [] PROGMEM = "Redial"; +const char pstrUsageTransfer [] PROGMEM = "Transfer"; +const char pstrUsageDrop [] PROGMEM = "Drop"; +const char pstrUsagePark [] PROGMEM = "Park"; +const char pstrUsageForwardCalls [] PROGMEM = "Fwd Calls"; +const char pstrUsageAlternateFunction [] PROGMEM = "Alt Func"; +const char pstrUsageLine [] PROGMEM = "Line"; +const char pstrUsageSpeakerPhone [] PROGMEM = "Spk Phone"; +//const char pstrUsageConference [] PROGMEM = "Conference"; +const char pstrUsageRingEnable [] PROGMEM = "Ring Enbl"; +const char pstrUsageRingSelect [] PROGMEM = "Ring Sel"; +const char pstrUsagePhoneMute [] PROGMEM = "Phone Mute"; +const char pstrUsageCallerID [] PROGMEM = "Caller ID"; +const char pstrUsageSend [] PROGMEM = "Send"; +const char pstrUsageSpeedDial [] PROGMEM = "Speed Dial"; +const char pstrUsageStoreNumber [] PROGMEM = "Store Num"; +const char pstrUsageRecallNumber [] PROGMEM = "Recall Num"; +const char pstrUsagePhoneDirectory [] PROGMEM = "Phone Dir"; +const char pstrUsageVoiceMail [] PROGMEM = "Voice Mail"; +const char pstrUsageScreenCalls [] PROGMEM = "Screen Calls"; +//const char pstrUsageDoNotDisturb [] PROGMEM = "Do Not Disturb"; +const char pstrUsageMessage [] PROGMEM = "Msg"; +const char pstrUsageAnswerOnOff [] PROGMEM = "Answer On/Off"; +const char pstrUsageInsideDialTone [] PROGMEM = "Inside Dial Tone"; +const char pstrUsageOutsideDialTone [] PROGMEM = "Outside Dial Tone"; +const char pstrUsageInsideRingTone [] PROGMEM = "Inside Ring Tone"; +const char pstrUsageOutsideRingTone [] PROGMEM = "Outside Ring Tone"; +const char pstrUsagePriorityRingTone [] PROGMEM = "Prior Ring Tone"; +const char pstrUsageInsideRingback [] PROGMEM = "Inside Ringback"; +const char pstrUsagePriorityRingback [] PROGMEM = "Priority Ringback"; +const char pstrUsageLineBusyTone [] PROGMEM = "Ln Busy Tone"; +const char pstrUsageReorderTone [] PROGMEM = "Reorder Tone"; +const char pstrUsageCallWaitingTone [] PROGMEM = "Call Wait Tone"; +const char pstrUsageConfirmationTone1 [] PROGMEM = "Cnfrm Tone1"; +const char pstrUsageConfirmationTone2 [] PROGMEM = "Cnfrm Tone2"; +const char pstrUsageTonesOff [] PROGMEM = "Tones Off"; +const char pstrUsageOutsideRingback [] PROGMEM = "Outside Ringback"; +const char pstrUsageRinger [] PROGMEM = "Ringer"; +const char pstrUsagePhoneKey0 [] PROGMEM = "0"; +const char pstrUsagePhoneKey1 [] PROGMEM = "1"; +const char pstrUsagePhoneKey2 [] PROGMEM = "2"; +const char pstrUsagePhoneKey3 [] PROGMEM = "3"; +const char pstrUsagePhoneKey4 [] PROGMEM = "4"; +const char pstrUsagePhoneKey5 [] PROGMEM = "5"; +const char pstrUsagePhoneKey6 [] PROGMEM = "6"; +const char pstrUsagePhoneKey7 [] PROGMEM = "7"; +const char pstrUsagePhoneKey8 [] PROGMEM = "8"; +const char pstrUsagePhoneKey9 [] PROGMEM = "9"; +const char pstrUsagePhoneKeyStar [] PROGMEM = "*"; +const char pstrUsagePhoneKeyPound [] PROGMEM = "#"; +const char pstrUsagePhoneKeyA [] PROGMEM = "A"; +const char pstrUsagePhoneKeyB [] PROGMEM = "B"; +const char pstrUsagePhoneKeyC [] PROGMEM = "C"; +const char pstrUsagePhoneKeyD [] PROGMEM = "D"; + +// Consumer Usage Page +const char pstrUsageConsumerControl [] PROGMEM = "Consumer Ctrl"; +const char pstrUsageNumericKeyPad [] PROGMEM = "Num Key Pad"; +//const char pstrUsageProgrammableButton [] PROGMEM = "Prog Btn"; +//const char pstrUsageMicrophone [] PROGMEM = "Mic"; +const char pstrUsageHeadphone [] PROGMEM = "Headphone"; +const char pstrUsageGraphicEqualizer [] PROGMEM = "Graph Eq"; +const char pstrUsagePlus10 [] PROGMEM = "+10"; +const char pstrUsagePlus100 [] PROGMEM = "+100"; +const char pstrUsageAMPM [] PROGMEM = "AM/PM"; +//const char pstrUsagePower [] PROGMEM = "Pwr"; +const char pstrUsageReset [] PROGMEM = "Reset"; +const char pstrUsageSleep [] PROGMEM = "Sleep"; +const char pstrUsageSleepAfter [] PROGMEM = "Sleep After"; +const char pstrUsageSleepMode [] PROGMEM = "Sleep Mode"; +const char pstrUsageIllumination [] PROGMEM = "Illumin"; +const char pstrUsageFunctionButtons [] PROGMEM = "Func Btns"; +const char pstrUsageMenu [] PROGMEM = "Menu"; +const char pstrUsageMenuPick [] PROGMEM = "Menu Pick"; +const char pstrUsageMenuUp [] PROGMEM = "Menu Up"; +const char pstrUsageMenuDown [] PROGMEM = "Menu Down"; +const char pstrUsageMenuLeft [] PROGMEM = "Menu Left"; +const char pstrUsageMenuRight [] PROGMEM = "Menu Right"; +const char pstrUsageMenuEscape [] PROGMEM = "Menu Esc"; +const char pstrUsageMenuValueIncrease [] PROGMEM = "Menu Val Inc"; +const char pstrUsageMenuValueDecrease [] PROGMEM = "Menu Val Dec"; +const char pstrUsageDataOnScreen [] PROGMEM = "Data On Scr"; +const char pstrUsageClosedCaption [] PROGMEM = "Closed Cptn"; +const char pstrUsageClosedCaptionSelect [] PROGMEM = "Closed Cptn Sel"; +const char pstrUsageVCRTV [] PROGMEM = "VCR/TV"; +const char pstrUsageBroadcastMode [] PROGMEM = "Brdcast Mode"; +const char pstrUsageSnapshot [] PROGMEM = "Snapshot"; +const char pstrUsageStill [] PROGMEM = "Still"; +const char pstrUsageSelection [] PROGMEM = "Sel"; +const char pstrUsageAssignSelection [] PROGMEM = "Assign Sel"; +const char pstrUsageModeStep [] PROGMEM = "Mode Step"; +const char pstrUsageRecallLast [] PROGMEM = "Recall Last"; +const char pstrUsageEnterChannel [] PROGMEM = "Entr Channel"; +const char pstrUsageOrderMovie [] PROGMEM = "Ord Movie"; +const char pstrUsageChannel [] PROGMEM = "Channel"; +const char pstrUsageMediaSelection [] PROGMEM = "Med Sel"; +const char pstrUsageMediaSelectComputer [] PROGMEM = "Med Sel Comp"; +const char pstrUsageMediaSelectTV [] PROGMEM = "Med Sel TV"; +const char pstrUsageMediaSelectWWW [] PROGMEM = "Med Sel WWW"; +const char pstrUsageMediaSelectDVD [] PROGMEM = "Med Sel DVD"; +const char pstrUsageMediaSelectTelephone [] PROGMEM = "Med Sel Tel"; +const char pstrUsageMediaSelectProgramGuide [] PROGMEM = "Med Sel PG"; +const char pstrUsageMediaSelectVideoPhone [] PROGMEM = "Med Sel Vid"; +const char pstrUsageMediaSelectGames [] PROGMEM = "Med Sel Games"; +const char pstrUsageMediaSelectMessages [] PROGMEM = "Med Sel Msg"; +const char pstrUsageMediaSelectCD [] PROGMEM = "Med Sel CD"; +const char pstrUsageMediaSelectVCR [] PROGMEM = "Med Sel VCR"; +const char pstrUsageMediaSelectTuner [] PROGMEM = "Med Sel Tuner"; +const char pstrUsageQuit [] PROGMEM = "Quit"; +const char pstrUsageHelp [] PROGMEM = "Help"; +const char pstrUsageMediaSelectTape [] PROGMEM = "Med Sel Tape"; +const char pstrUsageMediaSelectCable [] PROGMEM = "Med Sel Cbl"; +const char pstrUsageMediaSelectSatellite [] PROGMEM = "Med Sel Sat"; +const char pstrUsageMediaSelectSecurity [] PROGMEM = "Med Sel Secur"; +const char pstrUsageMediaSelectHome [] PROGMEM = "Med Sel Home"; +const char pstrUsageMediaSelectCall [] PROGMEM = "Med Sel Call"; +const char pstrUsageChannelIncrement [] PROGMEM = "Ch Inc"; +const char pstrUsageChannelDecrement [] PROGMEM = "Ch Dec"; +const char pstrUsageMediaSelectSAP [] PROGMEM = "Med Sel SAP"; +const char pstrUsageVCRPlus [] PROGMEM = "VCR+"; +const char pstrUsageOnce [] PROGMEM = "Once"; +const char pstrUsageDaily [] PROGMEM = "Daily"; +const char pstrUsageWeekly [] PROGMEM = "Weekly"; +const char pstrUsageMonthly [] PROGMEM = "Monthly"; +//const char pstrUsagePlay [] PROGMEM = "Play"; +//const char pstrUsagePause [] PROGMEM = "Pause"; +//const char pstrUsageRecord [] PROGMEM = "Rec"; +//const char pstrUsageFastForward [] PROGMEM = "FF"; +//const char pstrUsageRewind [] PROGMEM = "Rewind"; +const char pstrUsageScanNextTrack [] PROGMEM = "Next Track"; +const char pstrUsageScanPreviousTrack [] PROGMEM = "Prev Track"; +//const char pstrUsageStop [] PROGMEM = "Stop"; +const char pstrUsageEject [] PROGMEM = "Eject"; +const char pstrUsageRandomPlay [] PROGMEM = "Random"; +const char pstrUsageSelectDisk [] PROGMEM = "Sel Disk"; +const char pstrUsageEnterDisk [] PROGMEM = "Ent Disk"; +//const char pstrUsageRepeat [] PROGMEM = "Repeat"; +const char pstrUsageTracking [] PROGMEM = "Tracking"; +const char pstrUsageTrackNormal [] PROGMEM = "Trk Norm"; +const char pstrUsageSlowTracking [] PROGMEM = "Slow Trk"; +const char pstrUsageFrameForward [] PROGMEM = "Frm Fwd"; +const char pstrUsageFrameBackwards [] PROGMEM = "Frm Back"; +const char pstrUsageMark [] PROGMEM = "Mark"; +const char pstrUsageClearMark [] PROGMEM = "Clr Mark"; +const char pstrUsageRepeatFromMark [] PROGMEM = "Rpt Mark"; +const char pstrUsageReturnToMark [] PROGMEM = "Ret to Mark"; +const char pstrUsageSearchMarkForward [] PROGMEM = "Search Mark Fwd"; +const char pstrUsageSearchMarkBackwards [] PROGMEM = "Search Mark Back"; +const char pstrUsageCounterReset [] PROGMEM = "Counter Reset"; +const char pstrUsageShowCounter [] PROGMEM = "Show Counter"; +const char pstrUsageTrackingIncrement [] PROGMEM = "Track Inc"; +const char pstrUsageTrackingDecrement [] PROGMEM = "Track Dec"; +const char pstrUsageStopEject [] PROGMEM = "Stop/Eject"; +const char pstrUsagePlayPause [] PROGMEM = "Play/Pause"; +const char pstrUsagePlaySkip [] PROGMEM = "Play/Skip"; +const char pstrUsageVolume [] PROGMEM = "Vol"; +const char pstrUsageBalance [] PROGMEM = "Balance"; +//const char pstrUsageMute [] PROGMEM = "Mute"; +const char pstrUsageBass [] PROGMEM = "Bass"; +const char pstrUsageTreble [] PROGMEM = "Treble"; +const char pstrUsageBassBoost [] PROGMEM = "Bass Boost"; +const char pstrUsageSurroundMode [] PROGMEM = "Surround"; +const char pstrUsageLoudness [] PROGMEM = "Loud"; +const char pstrUsageMPX [] PROGMEM = "MPX"; +const char pstrUsageVolumeIncrement [] PROGMEM = "Vol Inc"; +const char pstrUsageVolumeDecrement [] PROGMEM = "Vol Dec"; +const char pstrUsageSpeedSelect [] PROGMEM = "Speed"; +const char pstrUsagePlaybackSpeed [] PROGMEM = "Play Speed"; +const char pstrUsageStandardPlay [] PROGMEM = "Std Play"; +const char pstrUsageLongPlay [] PROGMEM = "Long Play"; +const char pstrUsageExtendedPlay [] PROGMEM = "Ext Play"; +const char pstrUsageSlow [] PROGMEM = "Slow"; +const char pstrUsageFanEnable [] PROGMEM = "Fan Enbl"; +const char pstrUsageFanSpeed [] PROGMEM = "Fan Speed"; +const char pstrUsageLightEnable [] PROGMEM = "Light Enbl"; +const char pstrUsageLightIlluminationLevel [] PROGMEM = "Light Illum Lev"; +const char pstrUsageClimateControlEnable [] PROGMEM = "Climate Enbl"; +const char pstrUsageRoomTemperature [] PROGMEM = "Room Temp"; +const char pstrUsageSecurityEnable [] PROGMEM = "Secur Enbl"; +const char pstrUsageFireAlarm [] PROGMEM = "Fire Alm"; +const char pstrUsagePoliceAlarm [] PROGMEM = "Police Alm"; +const char pstrUsageProximity [] PROGMEM = "Prox"; +const char pstrUsageMotion [] PROGMEM = "Motion"; +const char pstrUsageDuresAlarm [] PROGMEM = "Dures Alm"; +const char pstrUsageHoldupAlarm [] PROGMEM = "Holdup Alm"; +const char pstrUsageMedicalAlarm [] PROGMEM = "Med Alm"; +const char pstrUsageBalanceRight [] PROGMEM = "Balance Right"; +const char pstrUsageBalanceLeft [] PROGMEM = "Balance Left"; +const char pstrUsageBassIncrement [] PROGMEM = "Bass Inc"; +const char pstrUsageBassDecrement [] PROGMEM = "Bass Dec"; +const char pstrUsageTrebleIncrement [] PROGMEM = "Treble Inc"; +const char pstrUsageTrebleDecrement [] PROGMEM = "Treble Dec"; +const char pstrUsageSpeakerSystem [] PROGMEM = "Spk Sys"; +const char pstrUsageChannelLeft [] PROGMEM = "Ch Left"; +const char pstrUsageChannelRight [] PROGMEM = "Ch Right"; +const char pstrUsageChannelCenter [] PROGMEM = "Ch Center"; +const char pstrUsageChannelFront [] PROGMEM = "Ch Front"; +const char pstrUsageChannelCenterFront [] PROGMEM = "Ch Cntr Front"; +const char pstrUsageChannelSide [] PROGMEM = "Ch Side"; +const char pstrUsageChannelSurround [] PROGMEM = "Ch Surround"; +const char pstrUsageChannelLowFreqEnhancement [] PROGMEM = "Ch Low Freq Enh"; +const char pstrUsageChannelTop [] PROGMEM = "Ch Top"; +const char pstrUsageChannelUnknown [] PROGMEM = "Ch Unk"; +const char pstrUsageSubChannel [] PROGMEM = "Sub-ch"; +const char pstrUsageSubChannelIncrement [] PROGMEM = "Sub-ch Inc"; +const char pstrUsageSubChannelDecrement [] PROGMEM = "Sub-ch Dec"; +const char pstrUsageAlternateAudioIncrement [] PROGMEM = "Alt Aud Inc"; +const char pstrUsageAlternateAudioDecrement [] PROGMEM = "Alt Aud Dec"; +const char pstrUsageApplicationLaunchButtons [] PROGMEM = "App Launch Btns"; +const char pstrUsageALLaunchButtonConfigTool [] PROGMEM = "AL Launch Conf Tl"; +const char pstrUsageALProgrammableButton [] PROGMEM = "AL Pgm Btn"; +const char pstrUsageALConsumerControlConfig [] PROGMEM = "AL Cons Ctrl Cfg"; +const char pstrUsageALWordProcessor [] PROGMEM = "AL Word Proc"; +const char pstrUsageALTextEditor [] PROGMEM = "AL Txt Edtr"; +const char pstrUsageALSpreadsheet [] PROGMEM = "AL Sprdsheet"; +const char pstrUsageALGraphicsEditor [] PROGMEM = "AL Graph Edtr"; +const char pstrUsageALPresentationApp [] PROGMEM = "AL Present App"; +const char pstrUsageALDatabaseApp [] PROGMEM = "AL DB App"; +const char pstrUsageALEmailReader [] PROGMEM = "AL E-mail Rdr"; +const char pstrUsageALNewsreader [] PROGMEM = "AL Newsrdr"; +const char pstrUsageALVoicemail [] PROGMEM = "AL Voicemail"; +const char pstrUsageALContactsAddressBook [] PROGMEM = "AL Addr Book"; +const char pstrUsageALCalendarSchedule [] PROGMEM = "AL Clndr/Schdlr"; +const char pstrUsageALTaskProjectManager [] PROGMEM = "AL Task/Prj Mgr"; +const char pstrUsageALLogJournalTimecard [] PROGMEM = "AL Log/Jrnl/Tmcrd"; +const char pstrUsageALCheckbookFinance [] PROGMEM = "AL Chckbook/Fin"; +const char pstrUsageALCalculator [] PROGMEM = "AL Calc"; +const char pstrUsageALAVCapturePlayback [] PROGMEM = "AL A/V Capt/Play"; +const char pstrUsageALLocalMachineBrowser [] PROGMEM = "AL Loc Mach Brow"; +const char pstrUsageALLANWANBrow [] PROGMEM = "AL LAN/WAN Brow"; +const char pstrUsageALInternetBrowser [] PROGMEM = "AL I-net Brow"; +const char pstrUsageALRemoteNetISPConnect [] PROGMEM = "AL Rem Net Con"; +const char pstrUsageALNetworkConference [] PROGMEM = "AL Net Conf"; +const char pstrUsageALNetworkChat [] PROGMEM = "AL Net Chat"; +const char pstrUsageALTelephonyDialer [] PROGMEM = "AL Tel/Dial"; +const char pstrUsageALLogon [] PROGMEM = "AL Logon"; +const char pstrUsageALLogoff [] PROGMEM = "AL Logoff"; +const char pstrUsageALLogonLogoff [] PROGMEM = "AL Logon/Logoff"; +const char pstrUsageALTermLockScrSav [] PROGMEM = "AL Term Lock/Scr Sav"; +const char pstrUsageALControlPannel [] PROGMEM = "AL Ctrl Pan"; +const char pstrUsageALCommandLineProcessorRun [] PROGMEM = "AL Cmd/Run"; +const char pstrUsageALProcessTaskManager [] PROGMEM = "AL Task Mgr"; +const char pstrUsageALSelectTaskApplication [] PROGMEM = "AL Sel App"; +const char pstrUsageALNextTaskApplication [] PROGMEM = "AL Next App"; +const char pstrUsageALPreviousTaskApplication [] PROGMEM = "AL Prev App"; +const char pstrUsageALPreemptiveHaltTaskApp [] PROGMEM = "AL Prmpt Halt App"; +const char pstrUsageALIntegratedHelpCenter [] PROGMEM = "AL Hlp Cntr"; +const char pstrUsageALDocuments [] PROGMEM = "AL Docs"; +const char pstrUsageALThesaurus [] PROGMEM = "AL Thsrs"; +const char pstrUsageALDictionary [] PROGMEM = "AL Dict"; +const char pstrUsageALDesktop [] PROGMEM = "AL Desktop"; +const char pstrUsageALSpellCheck [] PROGMEM = "AL Spell Chk"; +const char pstrUsageALGrammarCheck [] PROGMEM = "AL Gram Chk"; +const char pstrUsageALWirelessStatus [] PROGMEM = "AL Wireless Sts"; +const char pstrUsageALKeyboardLayout [] PROGMEM = "AL Kbd Layout"; +const char pstrUsageALVirusProtection [] PROGMEM = "AL Vir Protect"; +const char pstrUsageALEncryption [] PROGMEM = "AL Encrypt"; +const char pstrUsageALScreenSaver [] PROGMEM = "AL Scr Sav"; +const char pstrUsageALAlarms [] PROGMEM = "AL Alarms"; +const char pstrUsageALClock [] PROGMEM = "AL Clock"; +const char pstrUsageALFileBrowser [] PROGMEM = "AL File Brow"; +const char pstrUsageALPowerStatus [] PROGMEM = "AL Pwr Sts"; +const char pstrUsageALImageBrowser [] PROGMEM = "AL Img Brow"; +const char pstrUsageALAudioBrowser [] PROGMEM = "AL Aud Brow"; +const char pstrUsageALMovieBrowser [] PROGMEM = "AL Mov Brow"; +const char pstrUsageALDigitalRightsManager [] PROGMEM = "AL Dig Rights Mgr"; +const char pstrUsageALDigitalWallet [] PROGMEM = "AL Dig Wallet"; +const char pstrUsageALInstantMessaging [] PROGMEM = "AL Inst Msg"; +const char pstrUsageALOEMFeaturesBrowser [] PROGMEM = "AL OEM Tips Brow"; +const char pstrUsageALOEMHelp [] PROGMEM = "AL OEM Hlp"; +const char pstrUsageALOnlineCommunity [] PROGMEM = "AL Online Com"; +const char pstrUsageALEntertainmentContentBrow [] PROGMEM = "AL Ent Cont Brow"; +const char pstrUsageALOnlineShoppingBrowser [] PROGMEM = "AL Online Shop Brow"; +const char pstrUsageALSmartCardInfoHelp [] PROGMEM = "AL SmartCard Inf"; +const char pstrUsageALMarketMonitorFinBrowser [] PROGMEM = "AL Market Brow"; +const char pstrUsageALCustomCorpNewsBrowser [] PROGMEM = "AL Cust Corp News Brow"; +const char pstrUsageALOnlineActivityBrowser [] PROGMEM = "AL Online Act Brow"; +const char pstrUsageALResearchSearchBrowser [] PROGMEM = "AL Search Brow"; +const char pstrUsageALAudioPlayer [] PROGMEM = "AL Aud Player"; +const char pstrUsageGenericGUIAppControls [] PROGMEM = "Gen GUI App Ctrl"; +const char pstrUsageACNew [] PROGMEM = "AC New"; +const char pstrUsageACOpen [] PROGMEM = "AC Open"; +const char pstrUsageACClose [] PROGMEM = "AC Close"; +const char pstrUsageACExit [] PROGMEM = "AC Exit"; +const char pstrUsageACMaximize [] PROGMEM = "AC Max"; +const char pstrUsageACMinimize [] PROGMEM = "AC Min"; +const char pstrUsageACSave [] PROGMEM = "AC Save"; +const char pstrUsageACPrint [] PROGMEM = "AC Print"; +const char pstrUsageACProperties [] PROGMEM = "AC Prop"; +const char pstrUsageACUndo [] PROGMEM = "AC Undo"; +const char pstrUsageACCopy [] PROGMEM = "AC Copy"; +const char pstrUsageACCut [] PROGMEM = "AC Cut"; +const char pstrUsageACPaste [] PROGMEM = "AC Paste"; +const char pstrUsageACSelectAll [] PROGMEM = "AC Sel All"; +const char pstrUsageACFind [] PROGMEM = "AC Find"; +const char pstrUsageACFindAndReplace [] PROGMEM = "AC Find/Replace"; +const char pstrUsageACSearch [] PROGMEM = "AC Search"; +const char pstrUsageACGoto [] PROGMEM = "AC Goto"; +const char pstrUsageACHome [] PROGMEM = "AC Home"; +const char pstrUsageACBack [] PROGMEM = "AC Back"; +const char pstrUsageACForward [] PROGMEM = "AC Fwd"; +const char pstrUsageACStop [] PROGMEM = "AC Stop"; +const char pstrUsageACRefresh [] PROGMEM = "AC Refresh"; +const char pstrUsageACPreviousLink [] PROGMEM = "AC Prev Link"; +const char pstrUsageACNextLink [] PROGMEM = "AC Next Link"; +const char pstrUsageACBookmarks [] PROGMEM = "AC Bkmarks"; +const char pstrUsageACHistory [] PROGMEM = "AC Hist"; +const char pstrUsageACSubscriptions [] PROGMEM = "AC Subscr"; +const char pstrUsageACZoomIn [] PROGMEM = "AC Zoom In"; +const char pstrUsageACZoomOut [] PROGMEM = "AC Zoom Out"; +const char pstrUsageACZoom [] PROGMEM = "AC Zoom"; +const char pstrUsageACFullScreenView [] PROGMEM = "AC Full Scr"; +const char pstrUsageACNormalView [] PROGMEM = "AC Norm View"; +const char pstrUsageACViewToggle [] PROGMEM = "AC View Tgl"; +const char pstrUsageACScrollUp [] PROGMEM = "AC Scroll Up"; +const char pstrUsageACScrollDown [] PROGMEM = "AC Scroll Down"; +const char pstrUsageACScroll [] PROGMEM = "AC Scroll"; +const char pstrUsageACPanLeft [] PROGMEM = "AC Pan Left"; +const char pstrUsageACPanRight [] PROGMEM = "AC Pan Right"; +const char pstrUsageACPan [] PROGMEM = "AC Pan"; +const char pstrUsageACNewWindow [] PROGMEM = "AC New Wnd"; +const char pstrUsageACTileHoriz [] PROGMEM = "AC Tile Horiz"; +const char pstrUsageACTileVert [] PROGMEM = "AC Tile Vert"; +const char pstrUsageACFormat [] PROGMEM = "AC Frmt"; +const char pstrUsageACEdit [] PROGMEM = "AC Edit"; +const char pstrUsageACBold [] PROGMEM = "AC Bold"; +const char pstrUsageACItalics [] PROGMEM = "AC Ital"; +const char pstrUsageACUnderline [] PROGMEM = "AC Under"; +const char pstrUsageACStrikethrough [] PROGMEM = "AC Strike"; +const char pstrUsageACSubscript [] PROGMEM = "AC Sub"; +const char pstrUsageACSuperscript [] PROGMEM = "AC Super"; +const char pstrUsageACAllCaps [] PROGMEM = "AC All Caps"; +const char pstrUsageACRotate [] PROGMEM = "AC Rotate"; +const char pstrUsageACResize [] PROGMEM = "AC Resize"; +const char pstrUsageACFlipHorizontal [] PROGMEM = "AC Flp H"; +const char pstrUsageACFlipVertical [] PROGMEM = "AC Flp V"; +const char pstrUsageACMirrorHorizontal [] PROGMEM = "AC Mir H"; +const char pstrUsageACMirrorVertical [] PROGMEM = "AC Mir V"; +const char pstrUsageACFontSelect [] PROGMEM = "AC Fnt Sel"; +const char pstrUsageACFontColor [] PROGMEM = "AC Fnt Clr"; +const char pstrUsageACFontSize [] PROGMEM = "AC Fnt Size"; +const char pstrUsageACJustifyLeft [] PROGMEM = "AC Just Left"; +const char pstrUsageACJustifyCenterH [] PROGMEM = "AC Just Cent H"; +const char pstrUsageACJustifyRight [] PROGMEM = "AC Just Right"; +const char pstrUsageACJustifyBlockH [] PROGMEM = "AC Just Block H"; +const char pstrUsageACJustifyTop [] PROGMEM = "AC Just Top"; +const char pstrUsageACJustifyCenterV [] PROGMEM = "AC Just Cent V"; +const char pstrUsageACJustifyBottom [] PROGMEM = "AC Just Bot"; +const char pstrUsageACJustifyBlockV [] PROGMEM = "AC Just Block V"; +const char pstrUsageACIndentDecrease [] PROGMEM = "AC Indent Dec"; +const char pstrUsageACIndentIncrease [] PROGMEM = "AC Indent Inc"; +const char pstrUsageACNumberedList [] PROGMEM = "AC Num List"; +const char pstrUsageACRestartNumbering [] PROGMEM = "AC Res Num"; +const char pstrUsageACBulletedList [] PROGMEM = "AC Blt List"; +const char pstrUsageACPromote [] PROGMEM = "AC Promote"; +const char pstrUsageACDemote [] PROGMEM = "AC Demote"; +const char pstrUsageACYes [] PROGMEM = "AC Yes"; +const char pstrUsageACNo [] PROGMEM = "AC No"; +const char pstrUsageACCancel [] PROGMEM = "AC Cancel"; +const char pstrUsageACCatalog [] PROGMEM = "AC Ctlg"; +const char pstrUsageACBuyChkout [] PROGMEM = "AC Buy"; +const char pstrUsageACAddToCart [] PROGMEM = "AC Add2Cart"; +const char pstrUsageACExpand [] PROGMEM = "AC Xpnd"; +const char pstrUsageACExpandAll [] PROGMEM = "AC Xpand All"; +const char pstrUsageACCollapse [] PROGMEM = "AC Collapse"; +const char pstrUsageACCollapseAll [] PROGMEM = "AC Collapse All"; +const char pstrUsageACPrintPreview [] PROGMEM = "AC Prn Prevw"; +const char pstrUsageACPasteSpecial [] PROGMEM = "AC Paste Spec"; +const char pstrUsageACInsertMode [] PROGMEM = "AC Ins Mode"; +const char pstrUsageACDelete [] PROGMEM = "AC Del"; +const char pstrUsageACLock [] PROGMEM = "AC Lock"; +const char pstrUsageACUnlock [] PROGMEM = "AC Unlock"; +const char pstrUsageACProtect [] PROGMEM = "AC Prot"; +const char pstrUsageACUnprotect [] PROGMEM = "AC Unprot"; +const char pstrUsageACAttachComment [] PROGMEM = "AC Attach Cmnt"; +const char pstrUsageACDeleteComment [] PROGMEM = "AC Del Cmnt"; +const char pstrUsageACViewComment [] PROGMEM = "AC View Cmnt"; +const char pstrUsageACSelectWord [] PROGMEM = "AC Sel Word"; +const char pstrUsageACSelectSentence [] PROGMEM = "AC Sel Sntc"; +const char pstrUsageACSelectParagraph [] PROGMEM = "AC Sel Para"; +const char pstrUsageACSelectColumn [] PROGMEM = "AC Sel Col"; +const char pstrUsageACSelectRow [] PROGMEM = "AC Sel Row"; +const char pstrUsageACSelectTable [] PROGMEM = "AC Sel Tbl"; +const char pstrUsageACSelectObject [] PROGMEM = "AC Sel Obj"; +const char pstrUsageACRedoRepeat [] PROGMEM = "AC Redo"; +const char pstrUsageACSort [] PROGMEM = "AC Sort"; +const char pstrUsageACSortAscending [] PROGMEM = "AC Sort Asc"; +const char pstrUsageACSortDescending [] PROGMEM = "AC Sort Desc"; +const char pstrUsageACFilter [] PROGMEM = "AC Filt"; +const char pstrUsageACSetClock [] PROGMEM = "AC Set Clk"; +const char pstrUsageACViewClock [] PROGMEM = "AC View Clk"; +const char pstrUsageACSelectTimeZone [] PROGMEM = "AC Sel Time Z"; +const char pstrUsageACEditTimeZone [] PROGMEM = "AC Edt Time Z"; +const char pstrUsageACSetAlarm [] PROGMEM = "AC Set Alm"; +const char pstrUsageACClearAlarm [] PROGMEM = "AC Clr Alm"; +const char pstrUsageACSnoozeAlarm [] PROGMEM = "AC Snz Alm"; +const char pstrUsageACResetAlarm [] PROGMEM = "AC Rst Alm"; +const char pstrUsageACSyncronize [] PROGMEM = "AC Sync"; +const char pstrUsageACSendReceive [] PROGMEM = "AC Snd/Rcv"; +const char pstrUsageACSendTo [] PROGMEM = "AC Snd To"; +const char pstrUsageACReply [] PROGMEM = "AC Reply"; +const char pstrUsageACReplyAll [] PROGMEM = "AC Reply All"; +const char pstrUsageACForwardMessage [] PROGMEM = "AC Fwd Msg"; +const char pstrUsageACSend [] PROGMEM = "AC Snd"; +const char pstrUsageACAttachFile [] PROGMEM = "AC Att File"; +const char pstrUsageACUpload [] PROGMEM = "AC Upld"; +const char pstrUsageACDownload [] PROGMEM = "AC Dnld"; +const char pstrUsageACSetBorders [] PROGMEM = "AC Set Brd"; +const char pstrUsageACInsertRow [] PROGMEM = "AC Ins Row"; +const char pstrUsageACInsertColumn [] PROGMEM = "AC Ins Col"; +const char pstrUsageACInsertFile [] PROGMEM = "AC Ins File"; +const char pstrUsageACInsertPicture [] PROGMEM = "AC Ins Pic"; +const char pstrUsageACInsertObject [] PROGMEM = "AC Ins Obj"; +const char pstrUsageACInsertSymbol [] PROGMEM = "AC Ins Sym"; +const char pstrUsageACSaveAndClose [] PROGMEM = "AC Sav&Cls"; +const char pstrUsageACRename [] PROGMEM = "AC Rename"; +const char pstrUsageACMerge [] PROGMEM = "AC Merge"; +const char pstrUsageACSplit [] PROGMEM = "AC Split"; +const char pstrUsageACDistributeHorizontaly [] PROGMEM = "AC Dist Hor"; +const char pstrUsageACDistributeVerticaly [] PROGMEM = "AC Dist Ver"; + +// Digitaizers +const char pstrUsageDigitizer [] PROGMEM = "Digitizer"; +const char pstrUsagePen [] PROGMEM = "Pen"; +const char pstrUsageLightPen [] PROGMEM = "Light Pen"; +const char pstrUsageTouchScreen [] PROGMEM = "Touch Scr"; +const char pstrUsageTouchPad [] PROGMEM = "Touch Pad"; +const char pstrUsageWhiteBoard [] PROGMEM = "White Brd"; +const char pstrUsageCoordinateMeasuringMachine [] PROGMEM = "Coord Meas Mach"; +const char pstrUsage3DDigitizer [] PROGMEM = "3D Dgtz"; +const char pstrUsageStereoPlotter [] PROGMEM = "Stereo Plot"; +const char pstrUsageArticulatedArm [] PROGMEM = "Art Arm"; +const char pstrUsageArmature [] PROGMEM = "Armature"; +const char pstrUsageMultiplePointDigitizer [] PROGMEM = "Multi Point Dgtz"; +const char pstrUsageFreeSpaceWand [] PROGMEM = "Free Space Wand"; +const char pstrUsageStylus [] PROGMEM = "Stylus"; +const char pstrUsagePuck [] PROGMEM = "Puck"; +const char pstrUsageFinger [] PROGMEM = "Finger"; +const char pstrUsageTipPressure [] PROGMEM = "Tip Press"; +const char pstrUsageBarrelPressure [] PROGMEM = "Brl Press"; +const char pstrUsageInRange [] PROGMEM = "In Range"; +const char pstrUsageTouch [] PROGMEM = "Touch"; +const char pstrUsageUntouch [] PROGMEM = "Untouch"; +const char pstrUsageTap [] PROGMEM = "Tap"; +const char pstrUsageQuality [] PROGMEM = "Qlty"; +const char pstrUsageDataValid [] PROGMEM = "Data Valid"; +const char pstrUsageTransducerIndex [] PROGMEM = "Transducer Ind"; +const char pstrUsageTabletFunctionKeys [] PROGMEM = "Tabl Func Keys"; +const char pstrUsageProgramChangeKeys [] PROGMEM = "Pgm Chng Keys"; +//const char pstrUsageBatteryStrength [] PROGMEM = "Bat Strength"; +const char pstrUsageInvert [] PROGMEM = "Invert"; +const char pstrUsageXTilt [] PROGMEM = "X Tilt"; +const char pstrUsageYTilt [] PROGMEM = "Y Tilt"; +const char pstrUsageAzimuth [] PROGMEM = "Azimuth"; +const char pstrUsageAltitude [] PROGMEM = "Altitude"; +const char pstrUsageTwist [] PROGMEM = "Twist"; +const char pstrUsageTipSwitch [] PROGMEM = "Tip Sw"; +const char pstrUsageSecondaryTipSwitch [] PROGMEM = "Scnd Tip Sw"; +const char pstrUsageBarrelSwitch [] PROGMEM = "Brl Sw"; +const char pstrUsageEraser [] PROGMEM = "Eraser"; +const char pstrUsageTabletPick [] PROGMEM = "Tbl Pick"; + +// Alphanumeric Display Page +const char pstrUsageAlphanumericDisplay [] PROGMEM = "Alphanum Disp"; +const char pstrUsageBitmappedDisplay [] PROGMEM = "Bmp Disp"; +const char pstrUsageDisplayAttributesReport [] PROGMEM = "Disp Attr Rpt"; +const char pstrUsageASCIICharacterSet [] PROGMEM = "ASCII chset"; +const char pstrUsageDataReadBack [] PROGMEM = "Data Rd Back"; +const char pstrUsageFontReadBack [] PROGMEM = "Fnt Rd Back"; +const char pstrUsageDisplayControlReport [] PROGMEM = "Disp Ctrl Rpt"; +const char pstrUsageClearDisplay [] PROGMEM = "Clr Disp"; +//const char pstrUsageDisplayEnable [] PROGMEM = "Disp Enbl"; +const char pstrUsageScreenSaverDelay [] PROGMEM = "Scr Sav Delay"; +const char pstrUsageScreenSaverEnable [] PROGMEM = "Scr Sav Enbl"; +const char pstrUsageVerticalScroll [] PROGMEM = "V Scroll"; +const char pstrUsageHorizontalScroll [] PROGMEM = "H Scroll"; +const char pstrUsageCharacterReport [] PROGMEM = "Char Rpt"; +const char pstrUsageDisplayData [] PROGMEM = "Disp Data"; +const char pstrUsageDisplayStatus [] PROGMEM = "Disp Stat"; +const char pstrUsageStatusNotReady [] PROGMEM = "Stat !Ready"; +const char pstrUsageStatusReady [] PROGMEM = "Stat Ready"; +const char pstrUsageErrorNotALoadableCharacter [] PROGMEM = "Err Not Ld Char"; +const char pstrUsageErrorFotDataCanNotBeRead [] PROGMEM = "Fnt Data Rd Err"; +const char pstrUsageCursorPositionReport [] PROGMEM = "Cur Pos Rpt"; +const char pstrUsageRow [] PROGMEM = "Row"; +const char pstrUsageColumn [] PROGMEM = "Col"; +const char pstrUsageRows [] PROGMEM = "Rows"; +const char pstrUsageColumns [] PROGMEM = "Cols"; +const char pstrUsageCursorPixelPosition [] PROGMEM = "Cur Pix Pos"; +const char pstrUsageCursorMode [] PROGMEM = "Cur Mode"; +const char pstrUsageCursorEnable [] PROGMEM = "Cur Enbl"; +const char pstrUsageCursorBlink [] PROGMEM = "Cur Blnk"; +const char pstrUsageFontReport [] PROGMEM = "Fnt Rpt"; +const char pstrUsageFontData [] PROGMEM = "Fnt Data"; +const char pstrUsageCharacterWidth [] PROGMEM = "Char Wdth"; +const char pstrUsageCharacterHeight [] PROGMEM = "Char Hght"; +const char pstrUsageCharacterSpacingHorizontal [] PROGMEM = "Char Space H"; +const char pstrUsageCharacterSpacingVertical [] PROGMEM = "Char Space V"; +const char pstrUsageUnicodeCharset [] PROGMEM = "Unicode Char"; +const char pstrUsageFont7Segment [] PROGMEM = "Fnt 7-seg"; +const char pstrUsage7SegmentDirectMap [] PROGMEM = "7-seg map"; +const char pstrUsageFont14Segment [] PROGMEM = "Fnt 14-seg"; +const char pstrUsage14SegmentDirectMap [] PROGMEM = "14-seg map"; +const char pstrUsageDisplayBrightness [] PROGMEM = "Disp Bright"; +const char pstrUsageDisplayContrast [] PROGMEM = "Disp Cntrst"; +const char pstrUsageCharacterAttribute [] PROGMEM = "Char Attr"; +const char pstrUsageAttributeReadback [] PROGMEM = "Attr Readbk"; +const char pstrUsageAttributeData [] PROGMEM = "Attr Data"; +const char pstrUsageCharAttributeEnhance [] PROGMEM = "Char Attr Enh"; +const char pstrUsageCharAttributeUnderline [] PROGMEM = "Char Attr Undl"; +const char pstrUsageCharAttributeBlink [] PROGMEM = "Char Attr Blnk"; +const char pstrUsageBitmapSizeX [] PROGMEM = "Bmp Size X"; +const char pstrUsageBitmapSizeY [] PROGMEM = "Bmp Size Y"; +const char pstrUsageBitDepthFormat [] PROGMEM = "Bit Dpth Fmt"; +const char pstrUsageDisplayOrientation [] PROGMEM = "Disp Ornt"; +const char pstrUsagePaletteReport [] PROGMEM = "Pal Rpt"; +const char pstrUsagePaletteDataSize [] PROGMEM = "Pal Data Size"; +const char pstrUsagePaletteDataOffset [] PROGMEM = "Pal Data Off"; +const char pstrUsagePaletteData [] PROGMEM = "Pal Data"; +const char pstrUsageBlitReport [] PROGMEM = "Blit Rpt"; +const char pstrUsageBlitRectangleX1 [] PROGMEM = "Blit Rect X1"; +const char pstrUsageBlitRectangleY1 [] PROGMEM = "Blit Rect Y1"; +const char pstrUsageBlitRectangleX2 [] PROGMEM = "Blit Rect X2"; +const char pstrUsageBlitRectangleY2 [] PROGMEM = "Blit Rect Y2"; +const char pstrUsageBlitData [] PROGMEM = "Blit Data"; +const char pstrUsageSoftButton [] PROGMEM = "Soft Btn"; +const char pstrUsageSoftButtonID [] PROGMEM = "Soft Btn ID"; +const char pstrUsageSoftButtonSide [] PROGMEM = "Soft Btn Side"; +const char pstrUsageSoftButtonOffset1 [] PROGMEM = "Soft Btn Off1"; +const char pstrUsageSoftButtonOffset2 [] PROGMEM = "Soft Btn Off2"; +const char pstrUsageSoftButtonReport [] PROGMEM = "Soft Btn Rpt"; + +// Medical Instrument Page +const char pstrUsageMedicalUltrasound [] PROGMEM = "Med Ultrasnd"; +const char pstrUsageVCRAcquisition [] PROGMEM = "VCR/Acq"; +const char pstrUsageFreezeThaw [] PROGMEM = "Freeze"; +const char pstrUsageClipStore [] PROGMEM = "Clip Store"; +const char pstrUsageUpdate [] PROGMEM = "Update"; +const char pstrUsageNext [] PROGMEM = "Next"; +const char pstrUsageSave [] PROGMEM = "Save"; +const char pstrUsagePrint [] PROGMEM = "Print"; +const char pstrUsageMicrophoneEnable [] PROGMEM = "Mic Enbl"; +const char pstrUsageCine [] PROGMEM = "Cine"; +const char pstrUsageTransmitPower [] PROGMEM = "Trans Pwr"; +//const char pstrUsageVolume [] PROGMEM = "Vol"; +const char pstrUsageFocus [] PROGMEM = "Focus"; +const char pstrUsageDepth [] PROGMEM = "Depth"; +const char pstrUsageSoftStepPrimary [] PROGMEM = "Soft Stp-Pri"; +const char pstrUsageSoftStepSecondary [] PROGMEM = "Soft Stp-Sec"; +const char pstrUsageDepthGainCompensation [] PROGMEM = "Dpth Gain Comp"; +const char pstrUsageZoomSelect [] PROGMEM = "Zoom Sel"; +const char pstrUsageZoomAdjust [] PROGMEM = "Zoom Adj"; +const char pstrUsageSpectralDopplerModeSelect [] PROGMEM = "Spec Dop Mode Sel"; +const char pstrUsageSpectralDopplerModeAdjust [] PROGMEM = "Spec Dop Mode Adj"; +const char pstrUsageColorDopplerModeSelect [] PROGMEM = "Color Dop Mode Sel"; +const char pstrUsageColorDopplerModeAdjust [] PROGMEM = "Color Dop Mode Adj"; +const char pstrUsageMotionModeSelect [] PROGMEM = "Motion Mode Sel"; +const char pstrUsageMotionModeAdjust [] PROGMEM = "Motion Mode Adj"; +const char pstrUsage2DModeSelect [] PROGMEM = "2D Mode Sel"; +const char pstrUsage2DModeAdjust [] PROGMEM = "2D Mode Adj"; +const char pstrUsageSoftControlSelect [] PROGMEM = "Soft Ctrl Sel"; +const char pstrUsageSoftControlAdjust [] PROGMEM = "Soft Ctrl Adj"; + +//extern const char *usagePageTitles0[15]; +//const char *usagePageTitles1[]; +//const char *genDesktopTitles0[]; +//const char *genDesktopTitles1[]; +//const char *genDesktopTitles2[]; +//const char *genDesktopTitles3[]; +//const char *genDesktopTitles4[]; +//const char *simuTitles0[]; +//const char *simuTitles1[]; +//const char *simuTitles2[]; +//const char *vrTitles0[]; +//const char *vrTitles1[]; +//const char *sportsCtrlTitles0[]; +//const char *sportsCtrlTitles1[]; +//const char *sportsCtrlTitles2[]; +//const char *gameTitles0[]; +//const char *gameTitles1[]; +//const char *genDevCtrlTitles[]; +//const char *ledTitles[]; +//const char *telTitles0[]; +//const char *telTitles1[]; +//const char *telTitles2[]; +//const char *telTitles3[]; +//const char *telTitles4[]; +//const char *telTitles5[]; +//const char *consTitles0[]; +//const char *consTitles1[]; +//const char *consTitles2[]; +//const char *consTitles3[]; +//const char *consTitles4[]; +//const char *consTitles5[]; +//const char *consTitles6[]; +//const char *consTitles7[]; +//const char *consTitles8[]; +//const char *consTitles9[]; +//const char *consTitlesA[]; +//const char *consTitlesB[]; +//const char *consTitlesC[]; +//const char *consTitlesD[]; +//const char *consTitlesE[]; +//const char *digitTitles0[]; +//const char *digitTitles1[]; +//const char *digitTitles2[]; +//const char *aplphanumTitles0[]; +//const char *aplphanumTitles1[]; +//const char *aplphanumTitles2[]; +//const char *medInstrTitles0[]; +//const char *medInstrTitles1[]; +//const char *medInstrTitles2[]; +//const char *medInstrTitles3[]; +//const char *medInstrTitles4[]; + +#endif //__HIDUSAGESTR_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/macros.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/macros.h new file mode 100644 index 00000000000..5df3faff8ab --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/macros.h @@ -0,0 +1,82 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#if !defined(_usb_h_) || defined(MACROS_H) +#error "Never include macros.h directly; include Usb.h instead" +#else +#define MACROS_H + +//////////////////////////////////////////////////////////////////////////////// +// HANDY MACROS +//////////////////////////////////////////////////////////////////////////////// + +#define VALUE_BETWEEN(v,l,h) (((v)>(l)) && ((v)<(h))) +#define VALUE_WITHIN(v,l,h) (((v)>=(l)) && ((v)<=(h))) +#define output_pgm_message(wa,fp,mp,el) wa = &mp, fp((char *)/*pgm_read_pointer*/(wa), el) +#define output_if_between(v,l,h,wa,fp,mp,el) if(VALUE_BETWEEN(v,l,h)) output_pgm_message(wa,fp,mp[v-(l+1)],el); + +#define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) +#ifndef __BYTE_GRABBING_DEFINED__ +#define __BYTE_GRABBING_DEFINED__ 1 +#ifdef BROKEN_OPTIMIZER_LITTLE_ENDIAN +// Note: Use this if your compiler generates horrible assembler! +#define BGRAB0(__usi__) (((uint8_t *)&(__usi__))[0]) +#define BGRAB1(__usi__) (((uint8_t *)&(__usi__))[1]) +#define BGRAB2(__usi__) (((uint8_t *)&(__usi__))[2]) +#define BGRAB3(__usi__) (((uint8_t *)&(__usi__))[3]) +#define BGRAB4(__usi__) (((uint8_t *)&(__usi__))[4]) +#define BGRAB5(__usi__) (((uint8_t *)&(__usi__))[5]) +#define BGRAB6(__usi__) (((uint8_t *)&(__usi__))[6]) +#define BGRAB7(__usi__) (((uint8_t *)&(__usi__))[7]) +#else +// Note: The cast alone to uint8_t is actually enough. +// GCC throws out the "& 0xff", and the size is no different. +// Some compilers need it. +#define BGRAB0(__usi__) ((uint8_t)((__usi__) & 0xff )) +#define BGRAB1(__usi__) ((uint8_t)(((__usi__) >> 8) & 0xff)) +#define BGRAB2(__usi__) ((uint8_t)(((__usi__) >> 16) & 0xff)) +#define BGRAB3(__usi__) ((uint8_t)(((__usi__) >> 24) & 0xff)) +#define BGRAB4(__usi__) ((uint8_t)(((__usi__) >> 32) & 0xff)) +#define BGRAB5(__usi__) ((uint8_t)(((__usi__) >> 40) & 0xff)) +#define BGRAB6(__usi__) ((uint8_t)(((__usi__) >> 48) & 0xff)) +#define BGRAB7(__usi__) ((uint8_t)(((__usi__) >> 56) & 0xff)) +#endif +#define BOVER1(__usi__) ((uint16_t)(__usi__) << 8) +#define BOVER2(__usi__) ((uint32_t)(__usi__) << 16) +#define BOVER3(__usi__) ((uint32_t)(__usi__) << 24) +#define BOVER4(__usi__) ((uint64_t)(__usi__) << 32) +#define BOVER5(__usi__) ((uint64_t)(__usi__) << 40) +#define BOVER6(__usi__) ((uint64_t)(__usi__) << 48) +#define BOVER7(__usi__) ((uint64_t)(__usi__) << 56) + +// These are the smallest and fastest ways I have found so far in pure C/C++. +#define BMAKE16(__usc1__,__usc0__) ((uint16_t)((uint16_t)(__usc0__) | (uint16_t)BOVER1(__usc1__))) +#define BMAKE32(__usc3__,__usc2__,__usc1__,__usc0__) ((uint32_t)((uint32_t)(__usc0__) | (uint32_t)BOVER1(__usc1__) | (uint32_t)BOVER2(__usc2__) | (uint32_t)BOVER3(__usc3__))) +#define BMAKE64(__usc7__,__usc6__,__usc5__,__usc4__,__usc3__,__usc2__,__usc1__,__usc0__) ((uint64_t)((uint64_t)__usc0__ | (uint64_t)BOVER1(__usc1__) | (uint64_t)BOVER2(__usc2__) | (uint64_t)BOVER3(__usc3__) | (uint64_t)BOVER4(__usc4__) | (uint64_t)BOVER5(__usc5__) | (uint64_t)BOVER6(__usc6__) | (uint64_t)BOVER1(__usc7__))) +#endif + +/* + * Debug macros: Strings are stored in progmem (flash) instead of RAM. + */ +#define USBTRACE(s) (Notify(PSTR(s), 0x80)) +#define USBTRACE1(s,l) (Notify(PSTR(s), l)) +#define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), D_PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80)) +#define USBTRACE3(s,r,l) (Notify(PSTR(s), l), D_PrintHex((r), l), Notify(PSTR("\r\n"), l)) + + +#endif /* MACROS_H */ + diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/message.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/message.cpp new file mode 100644 index 00000000000..960a9fb4426 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/message.cpp @@ -0,0 +1,116 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#include "Usb.h" +// 0x80 is the default (i.e. trace) to turn off set this global to something lower. +// this allows for 126 other debugging levels. +// TO-DO: Allow assignment to a different serial port by software +int UsbDEBUGlvl = 0x80; + +void E_Notifyc(char c, int lvl) { + if(UsbDEBUGlvl < lvl) return; +#if defined(ARDUINO) && ARDUINO >=100 + USB_HOST_SERIAL.print(c); +#else + USB_HOST_SERIAL.print(c, BYTE); +#endif + //USB_HOST_SERIAL.flush(); +} + +void E_Notify(char const * msg, int lvl) { + if(UsbDEBUGlvl < lvl) return; + if(!msg) return; + char c; + + while((c = pgm_read_byte(msg++))) E_Notifyc(c, lvl); +} + +void E_NotifyStr(char const * msg, int lvl) { + if(UsbDEBUGlvl < lvl) return; + if(!msg) return; + char c; + + while((c = *msg++)) E_Notifyc(c, lvl); +} + +void E_Notify(uint8_t b, int lvl) { + if(UsbDEBUGlvl < lvl) return; +#if defined(ARDUINO) && ARDUINO >=100 + USB_HOST_SERIAL.print(b); +#else + USB_HOST_SERIAL.print(b, DEC); +#endif + //USB_HOST_SERIAL.flush(); +} + +void E_Notify(double d, int lvl) { + if(UsbDEBUGlvl < lvl) return; + USB_HOST_SERIAL.print(d); + //USB_HOST_SERIAL.flush(); +} + +#ifdef DEBUG_USB_HOST + +void NotifyFailGetDevDescr(void) { + Notify(PSTR("\r\ngetDevDescr "), 0x80); +} + +void NotifyFailSetDevTblEntry(void) { + Notify(PSTR("\r\nsetDevTblEn "), 0x80); +} + +void NotifyFailGetConfDescr(void) { + Notify(PSTR("\r\ngetConf "), 0x80); +} + +void NotifyFailSetConfDescr(void) { + Notify(PSTR("\r\nsetConf "), 0x80); +} + +void NotifyFailGetDevDescr(uint8_t reason) { + NotifyFailGetDevDescr(); + NotifyFail(reason); +} + +void NotifyFailSetDevTblEntry(uint8_t reason) { + NotifyFailSetDevTblEntry(); + NotifyFail(reason); + +} + +void NotifyFailGetConfDescr(uint8_t reason) { + NotifyFailGetConfDescr(); + NotifyFail(reason); +} + +void NotifyFailSetConfDescr(uint8_t reason) { + NotifyFailSetConfDescr(); + NotifyFail(reason); +} + +void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID) { + Notify(PSTR("\r\nUnknown Device Connected - VID: "), 0x80); + D_PrintHex (VID, 0x80); + Notify(PSTR(" PID: "), 0x80); + D_PrintHex (PID, 0x80); +} + +void NotifyFail(uint8_t rcode) { + D_PrintHex (rcode, 0x80); + Notify(PSTR("\r\n"), 0x80); +} +#endif diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/message.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/message.h new file mode 100644 index 00000000000..6144b56de6e --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/message.h @@ -0,0 +1,84 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ +#if !defined(_usb_h_) || defined(__MESSAGE_H__) +#error "Never include message.h directly; include Usb.h instead" +#else +#define __MESSAGE_H__ + +extern int UsbDEBUGlvl; + +void E_Notify(char const * msg, int lvl); +void E_Notify(uint8_t b, int lvl); +void E_NotifyStr(char const * msg, int lvl); +void E_Notifyc(char c, int lvl); + +#ifdef DEBUG_USB_HOST +#define Notify E_Notify +#define NotifyStr E_NotifyStr +#define Notifyc E_Notifyc +void NotifyFailGetDevDescr(uint8_t reason); +void NotifyFailSetDevTblEntry(uint8_t reason); +void NotifyFailGetConfDescr(uint8_t reason); +void NotifyFailSetConfDescr(uint8_t reason); +void NotifyFailGetDevDescr(void); +void NotifyFailSetDevTblEntry(void); +void NotifyFailGetConfDescr(void); +void NotifyFailSetConfDescr(void); +void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID); +void NotifyFail(uint8_t rcode); +#else +#define Notify(...) ((void)0) +#define NotifyStr(...) ((void)0) +#define Notifyc(...) ((void)0) +#define NotifyFailGetDevDescr(...) ((void)0) +#define NotifyFailSetDevTblEntry(...) ((void)0) +#define NotifyFailGetConfDescr(...) ((void)0) +#define NotifyFailGetDevDescr(...) ((void)0) +#define NotifyFailSetDevTblEntry(...) ((void)0) +#define NotifyFailGetConfDescr(...) ((void)0) +#define NotifyFailSetConfDescr(...) ((void)0) +#define NotifyFailUnknownDevice(...) ((void)0) +#define NotifyFail(...) ((void)0) +#endif + +#ifdef DEBUG_USB_HOST +template +void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { + Notify(msg, level); + Notify(PSTR(": "), level); + D_PrintHex (rcode, level); + Notify(PSTR("\r\n"), level); +} + +template +void ErrorMessage(char const * msg, ERROR_TYPE rcode = 0) { + Notify(msg, 0x80); + Notify(PSTR(": "), 0x80); + D_PrintHex (rcode, 0x80); + Notify(PSTR("\r\n"), 0x80); +} +#else +template +void ErrorMessage(uint8_t, char const *, ERROR_TYPE = 0) { +} + +template +void ErrorMessage(char const *, ERROR_TYPE = 0) { +} +#endif + +#endif // __MESSAGE_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/parsetools.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/parsetools.cpp new file mode 100644 index 00000000000..00ca9e6427f --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/parsetools.cpp @@ -0,0 +1,67 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#include "Usb.h" + +bool MultiByteValueParser::Parse(uint8_t **pp, uint32_t *pcntdn) { + if(!pBuf) { + Notify(PSTR("Buffer pointer is NULL!\r\n"), 0x80); + return false; + } + for (; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++) + pBuf[valueSize - countDown] = (**pp); + + if(countDown) + return false; + + countDown = valueSize; + return true; +} + +bool PTPListParser::Parse(uint8_t **pp, uint32_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me) { + switch(nStage) { + case 0: + pBuf->valueSize = lenSize; + theParser.Initialize(pBuf); + nStage = 1; + + case 1: + if(!theParser.Parse(pp, pcntdn)) + return false; + + arLen = 0; + arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue)); + arLenCntdn = arLen; + nStage = 2; + + case 2: + pBuf->valueSize = valSize; + theParser.Initialize(pBuf); + nStage = 3; + + case 3: + for(; arLenCntdn; arLenCntdn--) { + if(!theParser.Parse(pp, pcntdn)) + return false; + + if(pf) + pf(pBuf, (arLen - arLenCntdn), me); + } + + nStage = 0; + } + return true; +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/parsetools.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/parsetools.h new file mode 100644 index 00000000000..d463358913f --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/parsetools.h @@ -0,0 +1,143 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ + +#if !defined(_usb_h_) || defined(__PARSETOOLS_H__) +#error "Never include parsetools.h directly; include Usb.h instead" +#else +#define __PARSETOOLS_H__ + +#include +//#include "Arduino.h" + +struct MultiValueBuffer { + uint8_t valueSize; + void *pValue; +}; + +class MultiByteValueParser { + uint8_t *pBuf; + uint32_t countDown; + uint32_t valueSize; + +public: + + MultiByteValueParser() : pBuf(NULL), countDown(0), valueSize(0) { + }; + + const uint8_t* GetBuffer() { + return pBuf; + }; + + void Initialize(MultiValueBuffer * const pbuf) { + pBuf = (uint8_t*)pbuf->pValue; + countDown = valueSize = pbuf->valueSize; + }; + + bool Parse(uint8_t **pp, uint32_t *pcntdn); +}; + +class ByteSkipper { + uint8_t *pBuf; + uint32_t nStage; + uint32_t countDown; + +public: + + ByteSkipper() : pBuf(NULL), nStage(0), countDown(0) { + }; + + void Initialize(MultiValueBuffer *pbuf) { + pBuf = (uint8_t*)pbuf->pValue; + countDown = 0; + }; + + bool Skip(uint8_t **pp, uint32_t *pcntdn, uint32_t bytes_to_skip) { + switch(nStage) { + case 0: + countDown = bytes_to_skip; + nStage++; + case 1: + for(; countDown && (*pcntdn); countDown--, (*pp)++, (*pcntdn)--); + + if(!countDown) + nStage = 0; + }; + return (!countDown); + }; +}; + +// Pointer to a callback function triggered for each element of PTP array when used with PTPArrayParser +typedef void (*PTP_ARRAY_EL_FUNC)(const MultiValueBuffer * const p, uint32_t count, const void *me); + +class PTPListParser { +public: + + enum ParseMode { + modeArray, modeRange/*, modeEnum*/ + }; + +private: + uint32_t nStage; + uint32_t enStage; + + uint32_t arLen; + uint32_t arLenCntdn; + + uint32_t lenSize; // size of the array length field in bytes + uint32_t valSize; // size of the array element in bytes + + MultiValueBuffer *pBuf; + + // The only parser for both size and array element parsing + MultiByteValueParser theParser; + + uint32_t /*ParseMode*/ prsMode; + +public: + + PTPListParser() : + nStage(0), + enStage(0), + arLen(0), + arLenCntdn(0), + lenSize(0), + valSize(0), + pBuf(NULL), + prsMode(modeArray) { + }; + + void Initialize(const uint32_t len_size, const uint32_t val_size, MultiValueBuffer * const p, const uint32_t mode = modeArray) { + pBuf = p; + lenSize = len_size; + valSize = val_size; + prsMode = mode; + + if(prsMode == modeRange) { + arLenCntdn = arLen = 3; + nStage = 2; + } else { + arLenCntdn = arLen = 0; + nStage = 0; + } + enStage = 0; + theParser.Initialize(p); + }; + + bool Parse(uint8_t **pp, uint32_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me = NULL); +}; + +#endif // __PARSETOOLS_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/printhex.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/printhex.h new file mode 100644 index 00000000000..60dcd064fcc --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/printhex.h @@ -0,0 +1,91 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#if !defined(_usb_h_) || defined(__PRINTHEX_H__) +#error "Never include printhex.h directly; include Usb.h instead" +#else +#define __PRINTHEX_H__ + +#include + +void E_Notifyc(char c, int lvl); + +template +void PrintHex(T val, int lvl) { + int num_nibbles = sizeof (T) * 2; + + do { + char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f); + if(v > 57) v += 7; + E_Notifyc(v, lvl); + } while(--num_nibbles); +} + +template +void PrintBin(T val, int lvl) { + for(T mask = (((T)1) << ((sizeof (T) << 3) - 1)); mask; mask >>= 1) + if(val & mask) + E_Notifyc('1', lvl); + else + E_Notifyc('0', lvl); +} + +template +void SerialPrintHex(T val) { + int num_nibbles = sizeof (T) * 2; + + do { + char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f); + if(v > 57) v += 7; + USB_HOST_SERIAL.print(v); + } while(--num_nibbles); +} + +template +void PrintHex2(Print *prn, T val) { + T mask = (((T)1) << (((sizeof (T) << 1) - 1) << 2)); + + while(mask > 1) { + if(val < mask) + prn->print("0"); + + mask >>= 4; + } + prn->print((T)val, HEX); +} + +#ifdef DEBUG_USB_HOST +template void D_PrintHex(T val, int lvl) { + PrintHex (val, lvl); +} + +template +void D_PrintBin(T val, int lvl) { + PrintBin (val, lvl); +} +#else +template void D_PrintHex(T, int) { +} + +template +void D_PrintBin(T, int) { +} +#endif + + + +#endif // __PRINTHEX_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/sink_parser.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/sink_parser.h new file mode 100644 index 00000000000..f1c7386a359 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/sink_parser.h @@ -0,0 +1,41 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ +#if !defined(_usb_h_) || defined(__SINK_PARSER_H__) +#error "Never include hexdump.h directly; include Usb.h instead" +#else +#define __SINK_PARSER_H__ + +extern int UsbDEBUGlvl; + +// This parser does absolutely nothing with the data, just swallows it. + +template +class SinkParser : public BASE_CLASS { +public: + + SinkParser() { + }; + + void Initialize() { + }; + + void Parse(const LEN_TYPE /* len */, const uint8_t * /* pbuf */, const OFFSET_TYPE & /* offset */) { + }; +}; + + +#endif // __HEXDUMP_H__ diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usb_ch9.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usb_ch9.h new file mode 100644 index 00000000000..09dd94b9b46 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usb_ch9.h @@ -0,0 +1,174 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ + +#if !defined(_usb_h_) || defined(_ch9_h_) +#error "Never include usb_ch9.h directly; include Usb.h instead" +#else + +/* USB chapter 9 structures */ +#define _ch9_h_ + +#include + +/* Misc.USB constants */ +#define DEV_DESCR_LEN 18 //device descriptor length +#define CONF_DESCR_LEN 9 //configuration descriptor length +#define INTR_DESCR_LEN 9 //interface descriptor length +#define EP_DESCR_LEN 7 //endpoint descriptor length + +/* Standard Device Requests */ + +#define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS +#define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE +#define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE +#define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS +#define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR +#define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR +#define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION +#define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION +#define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE +#define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE +#define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME + +#define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt +#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up +#define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode + +/* Setup Data Constants */ + +#define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer +#define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer +#define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard +#define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class +#define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor +#define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device +#define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface +#define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint +#define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other + +/* USB descriptors */ + +#define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor. +#define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor. +#define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor. +#define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor. +#define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor. +#define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier. +#define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration. +#define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power. +#define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor. + +#define HID_DESCRIPTOR_HID 0x21 + + + +/* OTG SET FEATURE Constants */ +#define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP +#define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP +#define OTG_FEATURE_A_ALT_HNP_SUPPORT 5 // SET FEATURE OTG - Another port on the A device supports HNP + +/* USB Endpoint Transfer Types */ +#define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint. +#define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint. +#define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint. +#define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint. +#define bmUSB_TRANSFER_TYPE 0x03 // bit mask to separate transfer type from ISO attributes + + +/* Standard Feature Selectors for CLEAR_FEATURE Requests */ +#define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient +#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient +#define USB_FEATURE_TEST_MODE 2 // Device recipient + +_Pragma("pack(1)") + +/* descriptor data structures */ + +/* Device descriptor structure */ +typedef struct { + uint8_t bLength; // Length of this descriptor. + uint8_t bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE). + uint16_t bcdUSB; // USB Spec Release Number (BCD). + uint8_t bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. + uint8_t bDeviceSubClass; // Subclass code (assigned by the USB-IF). + uint8_t bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. + uint8_t bMaxPacketSize0; // Maximum packet size for endpoint 0. + uint16_t idVendor; // Vendor ID (assigned by the USB-IF). + uint16_t idProduct; // Product ID (assigned by the manufacturer). + uint16_t bcdDevice; // Device release number (BCD). + uint8_t iManufacturer; // Index of String Descriptor describing the manufacturer. + uint8_t iProduct; // Index of String Descriptor describing the product. + uint8_t iSerialNumber; // Index of String Descriptor with the device's serial number. + uint8_t bNumConfigurations; // Number of possible configurations. +} USB_DEVICE_DESCRIPTOR; + +/* Configuration descriptor structure */ +typedef struct { + uint8_t bLength; // Length of this descriptor. + uint8_t bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION). + uint16_t wTotalLength; // Total length of all descriptors for this configuration. + uint8_t bNumInterfaces; // Number of interfaces in this configuration. + uint8_t bConfigurationValue; // Value of this configuration (1 based). + uint8_t iConfiguration; // Index of String Descriptor describing the configuration. + uint8_t bmAttributes; // Configuration characteristics. + uint8_t bMaxPower; // Maximum power consumed by this configuration. +} USB_CONFIGURATION_DESCRIPTOR; + +/* Interface descriptor structure */ +typedef struct { + uint8_t bLength; // Length of this descriptor. + uint8_t bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE). + uint8_t bInterfaceNumber; // Number of this interface (0 based). + uint8_t bAlternateSetting; // Value of this alternate interface setting. + uint8_t bNumEndpoints; // Number of endpoints in this interface. + uint8_t bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. + uint8_t bInterfaceSubClass; // Subclass code (assigned by the USB-IF). + uint8_t bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. + uint8_t iInterface; // Index of String Descriptor describing the interface. +} USB_INTERFACE_DESCRIPTOR; + +/* Endpoint descriptor structure */ +typedef struct { + uint8_t bLength; // Length of this descriptor. + uint8_t bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT). + uint8_t bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN). + uint8_t bmAttributes; // Endpoint transfer type. + uint16_t wMaxPacketSize; // Maximum packet size. + uint8_t bInterval; // Polling interval in frames. +} USB_ENDPOINT_DESCRIPTOR; + + +/* HID descriptor */ +typedef struct { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdHID; // HID class specification release + uint8_t bCountryCode; + uint8_t bNumDescriptors; // Number of additional class specific descriptors + uint8_t bDescrType; // Type of class descriptor + uint16_t wDescriptorLength; // Total size of the Report descriptor +} USB_HID_DESCRIPTOR; + +typedef struct { + uint8_t bDescrType; // Type of class descriptor + uint16_t wDescriptorLength; // Total size of the Report descriptor +} HID_CLASS_DESCRIPTOR_LEN_AND_TYPE; + +_Pragma("pack()") + +#endif // _ch9_h_ + diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usbhub.cpp b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usbhub.cpp new file mode 100644 index 00000000000..f79a60bc8be --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usbhub.cpp @@ -0,0 +1,428 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ +#include "usbhub.h" +#include "api/Common.h" + +bool USBHub::bResetInitiated = false; + +USBHub::USBHub(USBHost *p) : +pUsb(p), +bAddress(0), +bNbrPorts(0), +//bInitState(0), +qNextPollTime(0), +bPollEnable(false) { + epInfo[0].epAddr = 0; + epInfo[0].maxPktSize = 8; + epInfo[0].bmSndToggle = 0; + epInfo[0].bmRcvToggle = 0; + epInfo[0].bmNakPower = USB_NAK_MAX_POWER; + + epInfo[1].epAddr = 1; + epInfo[1].maxPktSize = 8; //kludge + epInfo[1].bmSndToggle = 0; + epInfo[1].bmRcvToggle = 0; + epInfo[1].bmNakPower = USB_NAK_NOWAIT; + + if(pUsb) + pUsb->RegisterDeviceClass(this); +} + +uint32_t USBHub::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { + uint8_t buf[32]; + USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast(buf); + HubDescriptor* hd = reinterpret_cast(buf); + USB_CONFIGURATION_DESCRIPTOR * ucd = reinterpret_cast(buf); + uint32_t rcode; + UsbDeviceDefinition *p = NULL; + EpInfo *oldep_ptr = NULL; + uint32_t len = 0; + uint32_t cd_len = 0; + + //USBTRACE("\r\nHub Init Start "); + //D_PrintHex (bInitState, 0x80); + + AddressPool &addrPool = pUsb->GetAddressPool(); + + //switch (bInitState) { + // case 0: + if(bAddress) + return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; + + // Get pointer to pseudo device with address 0 assigned + p = addrPool.GetUsbDevicePtr(0); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + if(!p->epinfo) + return USB_ERROR_EPINFO_IS_NULL; + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + + p->lowspeed = lowspeed; + + // Get device descriptor + rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf); + + p->lowspeed = false; + + if(!rcode) + len = (buf[0] > 32) ? 32 : buf[0]; + + if(rcode) { + // Restore p->epinfo + p->epinfo = oldep_ptr; + return rcode; + } + + // Extract device class from device descriptor + // If device class is not a hub return + if(udd->bDeviceClass != 0x09) + return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + + // Allocate new address according to device class + bAddress = addrPool.AllocAddress(parent, (udd->bDeviceClass == 0x09) ? true : false, port); + + if(!bAddress) + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + + // Extract Max Packet Size from the device descriptor + epInfo[0].maxPktSize = udd->bMaxPacketSize0; + + // Assign new address to the device + rcode = pUsb->setAddr(0, 0, bAddress); + + if(rcode) { + // Restore p->epinfo + p->epinfo = oldep_ptr; + addrPool.FreeAddress(bAddress); + bAddress = 0; + return rcode; + } + + //USBTRACE2("\r\nHub address: ", bAddress ); + + // Restore p->epinfo + p->epinfo = oldep_ptr; + + if(len) + rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf); + + if(rcode) + goto FailGetDevDescr; + + // Assign epInfo to epinfo pointer + rcode = pUsb->setEpInfoEntry(bAddress, 2, epInfo); + + if(rcode) + goto FailSetDevTblEntry; + + // bInitState = 1; + + // case 1: + // Get hub descriptor + rcode = GetHubDescriptor(0, 8, buf); + + if(rcode) + goto FailGetHubDescr; + + // Save number of ports for future use + bNbrPorts = hd->bNbrPorts; + + // bInitState = 2; + + // case 2: + // Read configuration Descriptor in Order To Obtain Proper Configuration Value + rcode = pUsb->getConfDescr(bAddress, 0, 8, 0, buf); + + if(!rcode) { + cd_len = ucd->wTotalLength; + rcode = pUsb->getConfDescr(bAddress, 0, cd_len, 0, buf); + } + if(rcode) + goto FailGetConfDescr; + + // The following code is of no practical use in real life applications. + // It only intended for the usb protocol sniffer to properly parse hub-class requests. + { + uint8_t buf2[24]; + + rcode = pUsb->getConfDescr(bAddress, 0, buf[0], 0, buf2); + + if(rcode) + goto FailGetConfDescr; + } + + // Set Configuration Value + rcode = pUsb->setConf(bAddress, 0, buf[5]); + + if(rcode) + goto FailSetConfDescr; + + // bInitState = 3; + + // case 3: + // Power on all ports + for(uint32_t j = 1; j <= bNbrPorts; j++) + SetPortFeature(HUB_FEATURE_PORT_POWER, j, 0); //HubPortPowerOn(j); + + pUsb->SetHubPreMask(); + bPollEnable = true; + // bInitState = 0; + //} + //bInitState = 0; + //USBTRACE("...OK\r\n"); + return 0; + + // Oleg, No debugging?? -- xxxajk +FailGetDevDescr: + goto Fail; + +FailSetDevTblEntry: + goto Fail; + +FailGetHubDescr: + goto Fail; + +FailGetConfDescr: + goto Fail; + +FailSetConfDescr: + goto Fail; + +Fail: + USBTRACE("...FAIL\r\n"); + return rcode; +} + +uint32_t USBHub::Release() { + pUsb->GetAddressPool().FreeAddress(bAddress); + + if(bAddress == 0x41) + pUsb->SetHubPreMask(); + + bAddress = 0; + bNbrPorts = 0; + qNextPollTime = 0; + bPollEnable = false; + return 0; +} + +uint32_t USBHub::Poll() { + uint32_t rcode = 0; + + if(!bPollEnable) + return 0; + + if(((long)(millis() - qNextPollTime) >= 0L)) { + rcode = CheckHubStatus(); + qNextPollTime = millis() + 100; + } + return rcode; +} + +uint32_t USBHub::CheckHubStatus() { + uint32_t rcode; + uint8_t buf[8]; + uint32_t read = 1; + + rcode = pUsb->inTransfer(bAddress, 1, (uint8_t*)&read, buf); + + if(rcode) + return rcode; + + //if (buf[0] & 0x01) // Hub Status Change + //{ + // pUsb->PrintHubStatus(addr); + // rcode = GetHubStatus(1, 0, 1, 4, buf); + // if (rcode) + // { + // USB_HOST_SERIAL.print("GetHubStatus Error"); + // USB_HOST_SERIAL.println(rcode, HEX); + // return rcode; + // } + //} + for(uint32_t port = 1, mask = 0x02; port < 8; mask <<= 1, port++) { + if(buf[0] & mask) { + HubEvent evt; + evt.bmEvent = 0; + + rcode = GetPortStatus(port, 4, evt.evtBuff); + + if(rcode) + continue; + + rcode = PortStatusChange(port, evt); + + if(rcode == HUB_ERROR_PORT_HAS_BEEN_RESET) + return 0; + + if(rcode) + return rcode; + } + } // for + + for(uint32_t port = 1; port <= bNbrPorts; port++) { + HubEvent evt; + evt.bmEvent = 0; + + rcode = GetPortStatus(port, 4, evt.evtBuff); + + if(rcode) + continue; + + if((evt.bmStatus & bmHUB_PORT_STATE_CHECK_DISABLED) != bmHUB_PORT_STATE_DISABLED) + continue; + + // Emulate connection event for the port + evt.bmChange |= bmHUB_PORT_STATUS_C_PORT_CONNECTION; + + rcode = PortStatusChange(port, evt); + + if(rcode == HUB_ERROR_PORT_HAS_BEEN_RESET) + return 0; + + if(rcode) + return rcode; + } // for + return 0; +} + +void USBHub::ResetHubPort(uint32_t port) { + HubEvent evt; + evt.bmEvent = 0; + uint8_t rcode; + + ClearPortFeature(HUB_FEATURE_C_PORT_ENABLE, port, 0); + ClearPortFeature(HUB_FEATURE_C_PORT_CONNECTION, port, 0); + SetPortFeature(HUB_FEATURE_PORT_RESET, port, 0); + + + for(int i = 0; i < 3; i++) { + rcode = GetPortStatus(port, 4, evt.evtBuff); + if(rcode) break; // Some kind of error, bail. + if(evt.bmEvent == bmHUB_PORT_EVENT_RESET_COMPLETE || evt.bmEvent == bmHUB_PORT_EVENT_LS_RESET_COMPLETE) { + break; + } + delay(100); // simulate polling. + } + ClearPortFeature(HUB_FEATURE_C_PORT_RESET, port, 0); + ClearPortFeature(HUB_FEATURE_C_PORT_CONNECTION, port, 0); + delay(20); +} + +uint32_t USBHub::PortStatusChange(uint32_t port, HubEvent &evt) { + switch(evt.bmEvent) { + // Device connected event + case bmHUB_PORT_EVENT_CONNECT: + case bmHUB_PORT_EVENT_LS_CONNECT: + if(bResetInitiated) + return 0; + + ClearPortFeature(HUB_FEATURE_C_PORT_ENABLE, port, 0); + ClearPortFeature(HUB_FEATURE_C_PORT_CONNECTION, port, 0); + SetPortFeature(HUB_FEATURE_PORT_RESET, port, 0); + bResetInitiated = true; + return HUB_ERROR_PORT_HAS_BEEN_RESET; + + // Device disconnected event + case bmHUB_PORT_EVENT_DISCONNECT: + ClearPortFeature(HUB_FEATURE_C_PORT_ENABLE, port, 0); + ClearPortFeature(HUB_FEATURE_C_PORT_CONNECTION, port, 0); + bResetInitiated = false; + + UsbDeviceAddress a; + a.devAddress = 0; + a.bmHub = 0; + a.bmParent = bAddress; + a.bmAddress = port; + pUsb->ReleaseDevice(a.devAddress); + return 0; + + // Reset complete event + case bmHUB_PORT_EVENT_RESET_COMPLETE: + case bmHUB_PORT_EVENT_LS_RESET_COMPLETE: + ClearPortFeature(HUB_FEATURE_C_PORT_RESET, port, 0); + ClearPortFeature(HUB_FEATURE_C_PORT_CONNECTION, port, 0); + + delay(20); + + a.devAddress = bAddress; + + pUsb->Configuring(a.bmAddress, port, (evt.bmStatus & bmHUB_PORT_STATUS_PORT_LOW_SPEED)); + bResetInitiated = false; + break; + + } // switch (evt.bmEvent) + return 0; +} + +void PrintHubPortStatus(USBHub *hubptr, uint32_t /* addr */, uint32_t port, uint32_t print_changes) { + uint8_t rcode = 0; + HubEvent evt; + + rcode = hubptr->GetPortStatus(port, 4, evt.evtBuff); + + if(rcode) { + USB_HOST_SERIAL.println("ERROR!"); + return; + } + USB_HOST_SERIAL.print("\r\nPort "); + USB_HOST_SERIAL.println(port, DEC); + + USB_HOST_SERIAL.println("Status"); + USB_HOST_SERIAL.print("CONNECTION:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_CONNECTION) > 0, DEC); + USB_HOST_SERIAL.print("ENABLE:\t\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_ENABLE) > 0, DEC); + USB_HOST_SERIAL.print("SUSPEND:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_SUSPEND) > 0, DEC); + USB_HOST_SERIAL.print("OVER_CURRENT:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_OVER_CURRENT) > 0, DEC); + USB_HOST_SERIAL.print("RESET:\t\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_RESET) > 0, DEC); + USB_HOST_SERIAL.print("POWER:\t\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_POWER) > 0, DEC); + USB_HOST_SERIAL.print("LOW_SPEED:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_LOW_SPEED) > 0, DEC); + USB_HOST_SERIAL.print("HIGH_SPEED:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_HIGH_SPEED) > 0, DEC); + USB_HOST_SERIAL.print("TEST:\t\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_TEST) > 0, DEC); + USB_HOST_SERIAL.print("INDICATOR:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_INDICATOR) > 0, DEC); + + if(!print_changes) + return; + + USB_HOST_SERIAL.println("\r\nChange"); + USB_HOST_SERIAL.print("CONNECTION:\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_CONNECTION) > 0, DEC); + USB_HOST_SERIAL.print("ENABLE:\t\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_ENABLE) > 0, DEC); + USB_HOST_SERIAL.print("SUSPEND:\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_SUSPEND) > 0, DEC); + USB_HOST_SERIAL.print("OVER_CURRENT:\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_OVER_CURRENT) > 0, DEC); + USB_HOST_SERIAL.print("RESET:\t\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_RESET) > 0, DEC); +} diff --git a/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usbhub.h b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usbhub.h new file mode 100644 index 00000000000..a785f9a1899 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/USBHost/src/usbhub.h @@ -0,0 +1,252 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ +#if !defined(__USBHUB_H__) +#define __USBHUB_H__ + +#include "Usb.h" + +#define USB_DESCRIPTOR_HUB 0x09 // Hub descriptor type + +// Hub Requests +#define bmREQ_CLEAR_HUB_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE +#define bmREQ_CLEAR_PORT_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER +#define bmREQ_CLEAR_TT_BUFFER USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER +#define bmREQ_GET_HUB_DESCRIPTOR USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE +#define bmREQ_GET_HUB_STATUS USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE +#define bmREQ_GET_PORT_STATUS USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER +#define bmREQ_RESET_TT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER +#define bmREQ_SET_HUB_DESCRIPTOR USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE +#define bmREQ_SET_HUB_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE +#define bmREQ_SET_PORT_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER +#define bmREQ_GET_TT_STATE USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER +#define bmREQ_STOP_TT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER + +// Hub Class Requests +#define HUB_REQUEST_CLEAR_TT_BUFFER 8 +#define HUB_REQUEST_RESET_TT 9 +#define HUB_REQUEST_GET_TT_STATE 10 +#define HUB_REQUEST_STOP_TT 11 + +// Hub Features +#define HUB_FEATURE_C_HUB_LOCAL_POWER 0 +#define HUB_FEATURE_C_HUB_OVER_CURRENT 1 +#define HUB_FEATURE_PORT_CONNECTION 0 +#define HUB_FEATURE_PORT_ENABLE 1 +#define HUB_FEATURE_PORT_SUSPEND 2 +#define HUB_FEATURE_PORT_OVER_CURRENT 3 +#define HUB_FEATURE_PORT_RESET 4 +#define HUB_FEATURE_PORT_POWER 8 +#define HUB_FEATURE_PORT_LOW_SPEED 9 +#define HUB_FEATURE_C_PORT_CONNECTION 16 +#define HUB_FEATURE_C_PORT_ENABLE 17 +#define HUB_FEATURE_C_PORT_SUSPEND 18 +#define HUB_FEATURE_C_PORT_OVER_CURRENT 19 +#define HUB_FEATURE_C_PORT_RESET 20 +#define HUB_FEATURE_PORT_TEST 21 +#define HUB_FEATURE_PORT_INDICATOR 22 + +// Hub Port Test Modes +#define HUB_PORT_TEST_MODE_J 1 +#define HUB_PORT_TEST_MODE_K 2 +#define HUB_PORT_TEST_MODE_SE0_NAK 3 +#define HUB_PORT_TEST_MODE_PACKET 4 +#define HUB_PORT_TEST_MODE_FORCE_ENABLE 5 + +// Hub Port Indicator Color +#define HUB_PORT_INDICATOR_AUTO 0 +#define HUB_PORT_INDICATOR_AMBER 1 +#define HUB_PORT_INDICATOR_GREEN 2 +#define HUB_PORT_INDICATOR_OFF 3 + +// Hub Port Status Bitmasks +#define bmHUB_PORT_STATUS_PORT_CONNECTION 0x0001 +#define bmHUB_PORT_STATUS_PORT_ENABLE 0x0002 +#define bmHUB_PORT_STATUS_PORT_SUSPEND 0x0004 +#define bmHUB_PORT_STATUS_PORT_OVER_CURRENT 0x0008 +#define bmHUB_PORT_STATUS_PORT_RESET 0x0010 +#define bmHUB_PORT_STATUS_PORT_POWER 0x0100 +#define bmHUB_PORT_STATUS_PORT_LOW_SPEED 0x0200 +#define bmHUB_PORT_STATUS_PORT_HIGH_SPEED 0x0400 +#define bmHUB_PORT_STATUS_PORT_TEST 0x0800 +#define bmHUB_PORT_STATUS_PORT_INDICATOR 0x1000 + +// Hub Port Status Change Bitmasks (used one byte instead of two) +#define bmHUB_PORT_STATUS_C_PORT_CONNECTION 0x0001 +#define bmHUB_PORT_STATUS_C_PORT_ENABLE 0x0002 +#define bmHUB_PORT_STATUS_C_PORT_SUSPEND 0x0004 +#define bmHUB_PORT_STATUS_C_PORT_OVER_CURRENT 0x0008 +#define bmHUB_PORT_STATUS_C_PORT_RESET 0x0010 + +// Hub Status Bitmasks (used one byte instead of two) +#define bmHUB_STATUS_LOCAL_POWER_SOURCE 0x01 +#define bmHUB_STATUS_OVER_CURRENT 0x12 + +// Hub Status Change Bitmasks (used one byte instead of two) +#define bmHUB_STATUS_C_LOCAL_POWER_SOURCE 0x01 +#define bmHUB_STATUS_C_OVER_CURRENT 0x12 + + +// Hub Port Configuring Substates +#define USB_STATE_HUB_PORT_CONFIGURING 0xb0 +#define USB_STATE_HUB_PORT_POWERED_OFF 0xb1 +#define USB_STATE_HUB_PORT_WAIT_FOR_POWER_GOOD 0xb2 +#define USB_STATE_HUB_PORT_DISCONNECTED 0xb3 +#define USB_STATE_HUB_PORT_DISABLED 0xb4 +#define USB_STATE_HUB_PORT_RESETTING 0xb5 +#define USB_STATE_HUB_PORT_ENABLED 0xb6 + +// Additional Error Codes +#define HUB_ERROR_PORT_HAS_BEEN_RESET 0xb1 + +// The bit mask to check for all necessary state bits +#define bmHUB_PORT_STATUS_ALL_MAIN ((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION | bmHUB_PORT_STATUS_C_PORT_ENABLE | bmHUB_PORT_STATUS_C_PORT_SUSPEND | bmHUB_PORT_STATUS_C_PORT_RESET) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_SUSPEND) + +// Bit mask to check for DISABLED state in HubEvent::bmStatus field +#define bmHUB_PORT_STATE_CHECK_DISABLED (0x0000 | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_SUSPEND) + +// Hub Port States +#define bmHUB_PORT_STATE_DISABLED (0x0000 | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_CONNECTION) + +// Hub Port Events +#define bmHUB_PORT_EVENT_CONNECT (((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_CONNECTION) +#define bmHUB_PORT_EVENT_DISCONNECT (((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION) << 16) | bmHUB_PORT_STATUS_PORT_POWER) +#define bmHUB_PORT_EVENT_RESET_COMPLETE (((0UL | bmHUB_PORT_STATUS_C_PORT_RESET) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION) + +#define bmHUB_PORT_EVENT_LS_CONNECT (((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_LOW_SPEED) +#define bmHUB_PORT_EVENT_LS_RESET_COMPLETE (((0UL | bmHUB_PORT_STATUS_C_PORT_RESET) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_LOW_SPEED) +#define bmHUB_PORT_EVENT_LS_PORT_ENABLED (((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION | bmHUB_PORT_STATUS_C_PORT_ENABLE) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_LOW_SPEED) + +struct HubDescriptor { + uint32_t bDescLength; // descriptor length + uint32_t bDescriptorType; // descriptor type + uint32_t bNbrPorts; // number of ports a hub equiped with + + struct { + uint32_t LogPwrSwitchMode : 2; + uint32_t CompoundDevice : 1; + uint32_t OverCurrentProtectMode : 2; + uint32_t TTThinkTime : 2; + uint32_t PortIndicatorsSupported : 1; + uint32_t Reserved : 24; + } __attribute__((packed)); + + uint32_t bPwrOn2PwrGood; + uint32_t bHubContrCurrent; +} __attribute__((packed)); + +struct HubEvent { + + union { + + struct { + uint32_t bmStatus; // port status bits + uint32_t bmChange; // port status change bits + } __attribute__((packed)); + uint32_t bmEvent; + uint8_t evtBuff[4]; + }; +} __attribute__((packed)); + +class USBHub : USBDeviceConfig { + static bool bResetInitiated; // True when reset is triggered + + USBHost *pUsb; // USB class instance pointer + + EpInfo epInfo[2]; // interrupt endpoint info structure + + uint32_t bAddress; // address + uint32_t bNbrPorts; // number of ports + // uint8_t bInitState; // initialization state variable + uint32_t qNextPollTime; // next poll time + uint32_t bPollEnable; // poll enable flag + + uint32_t CheckHubStatus(); + uint32_t PortStatusChange(uint32_t port, HubEvent &evt); + +public: + USBHub(USBHost *p); + + uint32_t ClearHubFeature(uint32_t fid); + uint32_t ClearPortFeature(uint32_t fid, uint32_t port, uint32_t sel = 0); + uint32_t GetHubDescriptor(uint32_t index, uint32_t nbytes, uint8_t *dataptr); + uint32_t GetHubStatus(uint32_t nbytes, uint8_t* dataptr); + uint32_t GetPortStatus(uint32_t port, uint32_t nbytes, uint8_t* dataptr); + uint32_t SetHubDescriptor(uint32_t port, uint32_t nbytes, uint8_t* dataptr); + uint32_t SetHubFeature(uint32_t fid); + uint32_t SetPortFeature(uint32_t fid, uint32_t port, uint32_t sel = 0); + + void PrintHubStatus(); + + virtual uint32_t Init(uint32_t parent, uint32_t port, uint32_t lowspeed); + virtual uint32_t Release(); + virtual uint32_t Poll(); + virtual void ResetHubPort(uint32_t port); + + virtual uint32_t GetAddress() { + return bAddress; + }; + + virtual uint32_t DEVCLASSOK(uint32_t klass) { + return (klass == 0x09); + } + +}; + +// Clear Hub Feature + +inline uint32_t USBHub::ClearHubFeature(uint32_t fid) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CLEAR_HUB_FEATURE, USB_REQUEST_CLEAR_FEATURE, fid, 0, 0, 0, 0, NULL, NULL)); +} +// Clear Port Feature + +inline uint32_t USBHub::ClearPortFeature(uint32_t fid, uint32_t port, uint32_t sel) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CLEAR_PORT_FEATURE, USB_REQUEST_CLEAR_FEATURE, fid, 0, ((0x0000 | port) | (sel << 8)), 0, 0, NULL, NULL)); +} +// Get Hub Descriptor + +inline uint32_t USBHub::GetHubDescriptor(uint32_t index, uint32_t nbytes, uint8_t *dataptr) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_GET_HUB_DESCRIPTOR, USB_REQUEST_GET_DESCRIPTOR, index, 0x29, 0, nbytes, nbytes, dataptr, NULL)); +} +// Get Hub Status + +inline uint32_t USBHub::GetHubStatus(uint32_t nbytes, uint8_t* dataptr) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_GET_HUB_STATUS, USB_REQUEST_GET_STATUS, 0, 0, 0x0000, nbytes, nbytes, dataptr, NULL)); +} +// Get Port Status + +inline uint32_t USBHub::GetPortStatus(uint32_t port, uint32_t nbytes, uint8_t* dataptr) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_GET_PORT_STATUS, USB_REQUEST_GET_STATUS, 0, 0, port, nbytes, nbytes, dataptr, NULL)); +} +// Set Hub Descriptor + +inline uint32_t USBHub::SetHubDescriptor(uint32_t port, uint32_t nbytes, uint8_t* dataptr) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_SET_HUB_DESCRIPTOR, USB_REQUEST_SET_DESCRIPTOR, 0, 0, port, nbytes, nbytes, dataptr, NULL)); +} +// Set Hub Feature + +inline uint32_t USBHub::SetHubFeature(uint32_t fid) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_SET_HUB_FEATURE, USB_REQUEST_SET_FEATURE, fid, 0, 0, 0, 0, NULL, NULL)); +} +// Set Port Feature + +inline uint32_t USBHub::SetPortFeature(uint32_t fid, uint32_t port, uint32_t sel) { + return ( pUsb->ctrlReq(bAddress, 0, bmREQ_SET_PORT_FEATURE, USB_REQUEST_SET_FEATURE, fid, 0, (((0x0000 | sel) << 8) | port), 0, 0, NULL, NULL)); +} + +void PrintHubPortStatus(USBHost *usbptr, uint32_t addr, uint32_t port, uint32_t print_changes = false); + +#endif // __USBHUB_H__ diff --git a/legacy/builder/test/dependent_libraries/library1/library1.h b/internal/integrationtest/compile_4/testdata/libraries/library1/library1.h similarity index 100% rename from legacy/builder/test/dependent_libraries/library1/library1.h rename to internal/integrationtest/compile_4/testdata/libraries/library1/library1.h diff --git a/legacy/builder/test/dependent_libraries/library2/library2.h b/internal/integrationtest/compile_4/testdata/libraries/library2/library2.h similarity index 100% rename from legacy/builder/test/dependent_libraries/library2/library2.h rename to internal/integrationtest/compile_4/testdata/libraries/library2/library2.h diff --git a/legacy/builder/test/dependent_libraries/library3/library3.cpp b/internal/integrationtest/compile_4/testdata/libraries/library3/library3.cpp similarity index 100% rename from legacy/builder/test/dependent_libraries/library3/library3.cpp rename to internal/integrationtest/compile_4/testdata/libraries/library3/library3.cpp diff --git a/legacy/builder/test/dependent_libraries/library3/library3.h b/internal/integrationtest/compile_4/testdata/libraries/library3/library3.h similarity index 100% rename from legacy/builder/test/dependent_libraries/library3/library3.h rename to internal/integrationtest/compile_4/testdata/libraries/library3/library3.h diff --git a/internal/integrationtest/compile_4/testdata/libraries/library4/library4.h b/internal/integrationtest/compile_4/testdata/libraries/library4/library4.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/testlib1/testlib1.h b/internal/integrationtest/compile_4/testdata/libraries/testlib1/testlib1.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/testlib2/testlib2.h b/internal/integrationtest/compile_4/testdata/libraries/testlib2/testlib2.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/testlib3/testlib3.h b/internal/integrationtest/compile_4/testdata/libraries/testlib3/testlib3.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/libraries/testlib4/testlib4.h b/internal/integrationtest/compile_4/testdata/libraries/testlib4/testlib4.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/legacy/builder/test/builder_test.go b/legacy/builder/test/builder_test.go index 3d5740d659d..58a372d6e41 100644 --- a/legacy/builder/test/builder_test.go +++ b/legacy/builder/test/builder_test.go @@ -17,7 +17,6 @@ package test import ( "fmt" - "os/exec" "path/filepath" "testing" "time" @@ -30,7 +29,6 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/phases" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/go-paths-helper" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" ) @@ -127,237 +125,6 @@ func TestBuilderEmptySketch(t *testing.T) { require.True(t, exist) } -func TestBuilderBridge(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) - - buildPath := ctx.BuildPath - exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_SKETCH, "Bridge.ino.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("Bridge.ino.elf").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("Bridge.ino.hex").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) -} - -func TestBuilderSketchWithConfig(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_config", "sketch_with_config.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) - - buildPath := ctx.BuildPath - exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_SKETCH, "sketch_with_config.ino.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("sketch_with_config.ino.elf").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("sketch_with_config.ino.hex").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) -} - -func TestBuilderBridgeTwice(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) - - // Run builder again - command = builder.Builder{} - err = command.Run(ctx) - NoError(t, err) - - buildPath := ctx.BuildPath - exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_SKETCH, "Bridge.ino.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("Bridge.ino.elf").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("Bridge.ino.hex").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) -} - -func TestBuilderBridgeSAM(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:sam:arduino_due_x_dbg") - ctx.WarningsLevel = "all" - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) - - buildPath := ctx.BuildPath - exist, err := buildPath.Join(constants.FOLDER_CORE, "syscalls_sam3.c.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_CORE, "USB", "PluggableUSB.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_CORE, "avr", "dtostrf.c.d").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_SKETCH, "Bridge.ino.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("Bridge.ino.elf").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("Bridge.ino.bin").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - - cmd := exec.Command(filepath.Join("downloaded_tools", "arm-none-eabi-gcc", "4.8.3-2014q1", "bin", "arm-none-eabi-objdump"), "-f", buildPath.Join(constants.FOLDER_CORE, "core.a").String()) - bytes, err := cmd.CombinedOutput() - NoError(t, err) - require.NotContains(t, string(bytes), "variant.cpp.o") -} - -func TestBuilderBridgeRedBearLab(t *testing.T) { - ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "downloaded_board_manager_stuff"), - BuiltInLibrariesDirs: paths.New("downloaded_libraries"), - OtherLibrariesDirs: paths.NewPathList("libraries"), - } - ctx = prepareBuilderTestContext(t, ctx, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "RedBearLab:avr:blend") - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) - - buildPath := ctx.BuildPath - exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_SKETCH, "Bridge.ino.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("Bridge.ino.elf").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("Bridge.ino.hex").ExistCheck() - NoError(t, err) - require.True(t, exist) - exist, err = buildPath.Join("libraries", "Bridge", "Mailbox.cpp.o").ExistCheck() - NoError(t, err) - require.True(t, exist) -} - -func TestBuilderSketchNoFunctions(t *testing.T) { - ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "downloaded_board_manager_stuff"), - BuiltInLibrariesDirs: paths.New("downloaded_libraries"), - OtherLibrariesDirs: paths.NewPathList("libraries"), - } - ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch_no_functions", "sketch_no_functions.ino"), "RedBearLab:avr:blend") - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - require.Error(t, err) -} - -func TestBuilderSketchWithBackup(t *testing.T) { - ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "downloaded_board_manager_stuff"), - BuiltInLibrariesDirs: paths.New("downloaded_libraries"), - OtherLibrariesDirs: paths.NewPathList("libraries"), - } - ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch_with_backup_files", "sketch_with_backup_files.ino"), "arduino:avr:uno") - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) -} - -func TestBuilderSketchWithOldLib(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_old_lib", "sketch_with_old_lib.ino"), "arduino:avr:uno") - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) -} - -func TestBuilderSketchWithSubfolders(t *testing.T) { - logrus.SetLevel(logrus.DebugLevel) - ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"), "arduino:avr:uno") - defer cleanUpBuilderTestContext(t, ctx) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) -} - -func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - buildPath := ctx.BuildPath - NoError(t, buildPath.Join("libraries", "SPI").MkdirAll()) - - // Run builder - command := builder.Builder{} - err := command.Run(ctx) - NoError(t, err) - - exist, err := buildPath.Join("libraries", "SPI").ExistCheck() - NoError(t, err) - require.False(t, exist) - exist, err = buildPath.Join("libraries", "Bridge").ExistCheck() - NoError(t, err) - require.True(t, exist) -} - func TestBuilderWithBuildPathInSketchDir(t *testing.T) { buildPath, err := paths.New("sketch1", "build").Abs() NoError(t, err) diff --git a/legacy/builder/test/ctags_runner_test.go b/legacy/builder/test/ctags_runner_test.go deleted file mode 100644 index 557aa34f57d..00000000000 --- a/legacy/builder/test/ctags_runner_test.go +++ /dev/null @@ -1,111 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package test - -import ( - "strings" - "testing" - - bldr "github.com/arduino/arduino-cli/arduino/builder" - "github.com/arduino/arduino-cli/arduino/builder/preprocessor" - "github.com/arduino/arduino-cli/legacy/builder" - paths "github.com/arduino/go-paths-helper" - "github.com/stretchr/testify/require" -) - -func ctagsRunnerTestTemplate(t *testing.T, sketchLocation *paths.Path) []byte { - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - ctx.Verbose = true - - err := (&builder.ContainerSetupHardwareToolsLibsSketchAndProps{}).Run(ctx) - NoError(t, err) - - _, err = bldr.PrepareSketchBuildPath(ctx.Sketch, nil, ctx.SketchBuildPath) - NoError(t, err) - - source := loadPreprocessedSketch(t, ctx) - target := ctx.BuildPath.Join("ctags_target.cpp") - NoError(t, target.WriteFile([]byte(source))) - - ctagsOutput, _, err := preprocessor.RunCTags(target, ctx.BuildProperties) - NoError(t, err) - - return ctagsOutput -} - -func TestCTagsRunner(t *testing.T) { - sketchLocation := Abs(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino")) - ctagsOutput := ctagsRunnerTestTemplate(t, sketchLocation) - - quotedSketchLocation := strings.Replace(sketchLocation.String(), "\\", "\\\\", -1) - expectedOutput := "server " + quotedSketchLocation + " /^BridgeServer server;$/;\" kind:variable line:31\n" + - "setup " + quotedSketchLocation + " /^void setup() {$/;\" kind:function line:33 signature:() returntype:void\n" + - "loop " + quotedSketchLocation + " /^void loop() {$/;\" kind:function line:46 signature:() returntype:void\n" + - "process " + quotedSketchLocation + " /^void process(BridgeClient client) {$/;\" kind:function line:62 signature:(BridgeClient client) returntype:void\n" + - "digitalCommand " + quotedSketchLocation + " /^void digitalCommand(BridgeClient client) {$/;\" kind:function line:82 signature:(BridgeClient client) returntype:void\n" + - "analogCommand " + quotedSketchLocation + " /^void analogCommand(BridgeClient client) {$/;\" kind:function line:109 signature:(BridgeClient client) returntype:void\n" + - "modeCommand " + quotedSketchLocation + " /^void modeCommand(BridgeClient client) {$/;\" kind:function line:149 signature:(BridgeClient client) returntype:void\n" - require.Equal(t, expectedOutput, strings.Replace(string(ctagsOutput), "\r\n", "\n", -1)) -} - -func TestCTagsRunnerSketchWithClass(t *testing.T) { - sketchLocation := Abs(t, paths.New("sketch_with_class", "sketch_with_class.ino")) - ctagsOutput := ctagsRunnerTestTemplate(t, sketchLocation) - - quotedSketchLocation := strings.Replace(sketchLocation.String(), "\\", "\\\\", -1) - expectedOutput := "set_values\t" + quotedSketchLocation + "\t/^ void set_values (int,int);$/;\"\tkind:prototype\tline:4\tclass:Rectangle\tsignature:(int,int)\treturntype:void\n" + - "area\t" + quotedSketchLocation + "\t/^ int area() {return width*height;}$/;\"\tkind:function\tline:5\tclass:Rectangle\tsignature:()\treturntype:int\n" + - "set_values\t" + quotedSketchLocation + "\t/^void Rectangle::set_values (int x, int y) {$/;\"\tkind:function\tline:8\tclass:Rectangle\tsignature:(int x, int y)\treturntype:void\n" + - "setup\t" + quotedSketchLocation + "\t/^void setup() {$/;\"\tkind:function\tline:13\tsignature:()\treturntype:void\n" + - "loop\t" + quotedSketchLocation + "\t/^void loop() {$/;\"\tkind:function\tline:17\tsignature:()\treturntype:void\n" - require.Equal(t, expectedOutput, strings.Replace(string(ctagsOutput), "\r\n", "\n", -1)) -} - -func TestCTagsRunnerSketchWithTypename(t *testing.T) { - sketchLocation := Abs(t, paths.New("sketch_with_typename", "sketch_with_typename.ino")) - ctagsOutput := ctagsRunnerTestTemplate(t, sketchLocation) - - quotedSketchLocation := strings.Replace(sketchLocation.String(), "\\", "\\\\", -1) - expectedOutput := "Foo\t" + quotedSketchLocation + "\t/^ struct Foo{$/;\"\tkind:struct\tline:2\n" + - "setup\t" + quotedSketchLocation + "\t/^void setup() {$/;\"\tkind:function\tline:6\tsignature:()\treturntype:void\n" + - "loop\t" + quotedSketchLocation + "\t/^void loop() {}$/;\"\tkind:function\tline:10\tsignature:()\treturntype:void\n" + - "func\t" + quotedSketchLocation + "\t/^typename Foo::Bar func(){$/;\"\tkind:function\tline:12\tsignature:()\treturntype:Foo::Bar\n" - require.Equal(t, expectedOutput, strings.Replace(string(ctagsOutput), "\r\n", "\n", -1)) -} - -func TestCTagsRunnerSketchWithNamespace(t *testing.T) { - sketchLocation := Abs(t, paths.New("sketch_with_namespace", "sketch_with_namespace.ino")) - ctagsOutput := ctagsRunnerTestTemplate(t, sketchLocation) - - quotedSketchLocation := strings.Replace(sketchLocation.String(), "\\", "\\\\", -1) - expectedOutput := "value\t" + quotedSketchLocation + "\t/^\tint value() {$/;\"\tkind:function\tline:2\tnamespace:Test\tsignature:()\treturntype:int\n" + - "setup\t" + quotedSketchLocation + "\t/^void setup() {}$/;\"\tkind:function\tline:7\tsignature:()\treturntype:void\n" + - "loop\t" + quotedSketchLocation + "\t/^void loop() {}$/;\"\tkind:function\tline:8\tsignature:()\treturntype:void\n" - require.Equal(t, expectedOutput, strings.Replace(string(ctagsOutput), "\r\n", "\n", -1)) -} - -func TestCTagsRunnerSketchWithTemplates(t *testing.T) { - sketchLocation := Abs(t, paths.New("sketch_with_templates_and_shift", "sketch_with_templates_and_shift.ino")) - ctagsOutput := ctagsRunnerTestTemplate(t, sketchLocation) - - quotedSketchLocation := strings.Replace(sketchLocation.String(), "\\", "\\\\", -1) - expectedOutput := "printGyro\t" + quotedSketchLocation + "\t/^void printGyro()$/;\"\tkind:function\tline:10\tsignature:()\treturntype:void\n" + - "bVar\t" + quotedSketchLocation + "\t/^c< 8 > bVar;$/;\"\tkind:variable\tline:15\n" + - "aVar\t" + quotedSketchLocation + "\t/^c< 1<<8 > aVar;$/;\"\tkind:variable\tline:16\n" + - "func\t" + quotedSketchLocation + "\t/^template func( c< 1< & aParam) {$/;\"\tkind:function\tline:18\tsignature:( c< 1< & aParam)\treturntype:template\n" - require.Equal(t, expectedOutput, strings.Replace(string(ctagsOutput), "\r\n", "\n", -1)) -} diff --git a/legacy/builder/test/includes_to_include_folders_test.go b/legacy/builder/test/includes_to_include_folders_test.go index f457e518185..629fc382f92 100644 --- a/legacy/builder/test/includes_to_include_folders_test.go +++ b/legacy/builder/test/includes_to_include_folders_test.go @@ -51,55 +51,6 @@ func TestIncludesToIncludeFolders(t *testing.T) { require.Equal(t, "Bridge", importedLibraries[0].Name) } -func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("SketchWithIfDef", "SketchWithIfDef.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - importedLibraries := ctx.ImportedLibraries - require.Equal(t, 0, len(importedLibraries)) -} - -func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("sketch9", "sketch9.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - importedLibraries := ctx.ImportedLibraries - sort.Sort(ByLibraryName(importedLibraries)) - require.Equal(t, 2, len(importedLibraries)) - require.Equal(t, "Bridge", importedLibraries[0].Name) - require.Equal(t, "IRremote", importedLibraries[1].Name) -} - func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { ctx := prepareBuilderTestContext(t, nil, paths.New("sketch10", "sketch10.ino"), "arduino:avr:leonardo") defer cleanUpBuilderTestContext(t, ctx) @@ -188,62 +139,3 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo require.Equal(t, "SPI", importedLibraries[0].Name) requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("libraries", "SPI")) } - -func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { - ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), - BuiltInLibrariesDirs: paths.New("downloaded_libraries"), - OtherLibrariesDirs: paths.NewPathList("libraries"), - Verbose: true, - } - ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch_usbhost", "sketch_usbhost.ino"), "arduino:samd:arduino_zero_native") - defer cleanUpBuilderTestContext(t, ctx) - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - importedLibraries := ctx.ImportedLibraries - sort.Sort(ByLibraryName(importedLibraries)) - require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "USBHost", importedLibraries[0].Name) - requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("libraries", "USBHost", "src")) -} - -func TestIncludesToIncludeFoldersSubfolders(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - importedLibraries := ctx.ImportedLibraries - sort.Sort(ByLibraryName(importedLibraries)) - require.Equal(t, 3, len(importedLibraries)) - require.Equal(t, "testlib1", importedLibraries[0].Name) - require.Equal(t, "testlib2", importedLibraries[1].Name) - require.Equal(t, "testlib3", importedLibraries[2].Name) -} diff --git a/legacy/builder/test/prototypes_adder_test.go b/legacy/builder/test/prototypes_adder_test.go deleted file mode 100644 index 024d86cf265..00000000000 --- a/legacy/builder/test/prototypes_adder_test.go +++ /dev/null @@ -1,658 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// Copyright 2015 Matthijs Kooijman -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package test - -import ( - "path/filepath" - "strings" - "testing" - - bldr "github.com/arduino/arduino-cli/arduino/builder" - "github.com/arduino/arduino-cli/arduino/builder/cpp" - "github.com/arduino/arduino-cli/legacy/builder" - "github.com/arduino/arduino-cli/legacy/builder/types" - paths "github.com/arduino/go-paths-helper" - "github.com/stretchr/testify/require" -) - -func loadPreprocessedSketch(t *testing.T, ctx *types.Context) string { - res, err := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp").ReadFile() - NoError(t, err) - return string(res) -} - -func TestPrototypesAdderBridgeExample(t *testing.T) { - sketchLocation := paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Contains(t, preprocessedSketch, "#line 33 "+quotedSketchLocation+"\nvoid setup();\n#line 46 "+quotedSketchLocation+"\nvoid loop();\n#line 62 "+quotedSketchLocation+"\nvoid process(BridgeClient client);\n#line 82 "+quotedSketchLocation+"\nvoid digitalCommand(BridgeClient client);\n#line 109 "+quotedSketchLocation+"\nvoid analogCommand(BridgeClient client);\n#line 149 "+quotedSketchLocation+"\nvoid modeCommand(BridgeClient client);\n#line 33 "+quotedSketchLocation+"\n") -} - -func TestPrototypesAdderSketchWithIfDef(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("SketchWithIfDef", "SketchWithIfDef.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessed := LoadAndInterpolate(t, filepath.Join("SketchWithIfDef", "SketchWithIfDef.preprocessed.txt"), ctx) - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Equal(t, preprocessed, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderBaladuino(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("Baladuino", "Baladuino.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessed := LoadAndInterpolate(t, filepath.Join("Baladuino", "Baladuino.preprocessed.txt"), ctx) - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Equal(t, preprocessed, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessed := LoadAndInterpolate(t, filepath.Join("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.preprocessed.txt"), ctx) - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Equal(t, preprocessed, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.ino"), "arduino:sam:arduino_due_x_dbg") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessed := LoadAndInterpolate(t, filepath.Join("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.preprocessed.txt"), ctx) - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Equal(t, preprocessed, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderLineContinuations(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("LineContinuations", "LineContinuations.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessed := LoadAndInterpolate(t, filepath.Join("LineContinuations", "LineContinuations.preprocessed.txt"), ctx) - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Equal(t, preprocessed, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderStringWithComment(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("StringWithComment", "StringWithComment.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessed := LoadAndInterpolate(t, filepath.Join("StringWithComment", "StringWithComment.preprocessed.txt"), ctx) - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Equal(t, preprocessed, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderSketchWithStruct(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("SketchWithStruct", "SketchWithStruct.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessed := LoadAndInterpolate(t, filepath.Join("SketchWithStruct", "SketchWithStruct.preprocessed.txt"), ctx) - preprocessedSketch := loadPreprocessedSketch(t, ctx) - obtained := strings.Replace(preprocessedSketch, "\r\n", "\n", -1) - // ctags based preprocessing removes the space after "dostuff", but this is still OK - // TODO: remove this exception when moving to a more powerful parser - preprocessed = strings.Replace(preprocessed, "void dostuff (A_NEW_TYPE * bar);", "void dostuff(A_NEW_TYPE * bar);", 1) - obtained = strings.Replace(obtained, "void dostuff (A_NEW_TYPE * bar);", "void dostuff(A_NEW_TYPE * bar);", 1) - require.Equal(t, preprocessed, obtained) -} - -func TestPrototypesAdderSketchWithConfig(t *testing.T) { - sketchLocation := paths.New("sketch_with_config", "sketch_with_config.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Contains(t, preprocessedSketch, "#line 13 "+quotedSketchLocation+"\nvoid setup();\n#line 17 "+quotedSketchLocation+"\nvoid loop();\n#line 13 "+quotedSketchLocation+"\n") - - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), ctx) - require.Equal(t, preprocessed, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { - sketchLocation := paths.New("sketch_no_functions_two_files", "sketch_no_functions_two_files.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_no_functions_two_files", "sketch_no_functions_two_files.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - mergedSketch := loadPreprocessedSketch(t, ctx) - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Equal(t, mergedSketch, preprocessedSketch) // No prototypes added -} - -func TestPrototypesAdderSketchNoFunctions(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_no_functions", "sketch_no_functions.ino"), "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - sketchLocation := paths.New("sketch_no_functions", "sketch_no_functions.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - mergedSketch := loadPreprocessedSketch(t, ctx) - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Equal(t, mergedSketch, preprocessedSketch) // No prototypes added -} - -func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { - sketchLocation := paths.New("sketch_with_default_args", "sketch_with_default_args.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Contains(t, preprocessedSketch, "#line 4 "+quotedSketchLocation+"\nvoid setup();\n#line 7 "+quotedSketchLocation+"\nvoid loop();\n#line 1 "+quotedSketchLocation+"\n") -} - -func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { - sketchLocation := paths.New("sketch_with_inline_function", "sketch_with_inline_function.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - - expected := "#line 1 " + quotedSketchLocation + "\nvoid setup();\n#line 2 " + quotedSketchLocation + "\nvoid loop();\n#line 4 " + quotedSketchLocation + "\nshort unsigned int testInt();\n#line 8 " + quotedSketchLocation + "\nstatic int8_t testInline();\n#line 12 " + quotedSketchLocation + "\n__attribute__((always_inline)) uint8_t testAttribute();\n#line 1 " + quotedSketchLocation + "\n" - obtained := preprocessedSketch - // ctags based preprocessing removes "inline" but this is still OK - // TODO: remove this exception when moving to a more powerful parser - expected = strings.Replace(expected, "static inline int8_t testInline();", "static int8_t testInline();", -1) - obtained = strings.Replace(obtained, "static inline int8_t testInline();", "static int8_t testInline();", -1) - // ctags based preprocessing removes "__attribute__ ....." but this is still OK - // TODO: remove this exception when moving to a more powerful parser - expected = strings.Replace(expected, "__attribute__((always_inline)) uint8_t testAttribute();", "uint8_t testAttribute();", -1) - obtained = strings.Replace(obtained, "__attribute__((always_inline)) uint8_t testAttribute();", "uint8_t testAttribute();", -1) - require.Contains(t, obtained, expected) -} - -func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { - sketchLocation := paths.New("sketch_with_function_signature_inside_ifdef", "sketch_with_function_signature_inside_ifdef.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Contains(t, preprocessedSketch, "#line 1 "+quotedSketchLocation+"\nvoid setup();\n#line 3 "+quotedSketchLocation+"\nvoid loop();\n#line 15 "+quotedSketchLocation+"\nint8_t adalight();\n#line 1 "+quotedSketchLocation+"\n") -} - -func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { - sketchLocation := paths.New("sketch_with_usbcon", "sketch_with_usbcon.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), - OtherLibrariesDirs: paths.NewPathList("libraries"), - BuiltInLibrariesDirs: paths.New("downloaded_libraries"), - Verbose: true, - } - ctx = prepareBuilderTestContext(t, ctx, sketchLocation, "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Contains(t, preprocessedSketch, "#line 5 "+quotedSketchLocation+"\nvoid ciao();\n#line 10 "+quotedSketchLocation+"\nvoid setup();\n#line 15 "+quotedSketchLocation+"\nvoid loop();\n#line 5 "+quotedSketchLocation+"\n") -} - -func TestPrototypesAdderSketchWithTypename(t *testing.T) { - sketchLocation := paths.New("sketch_with_typename", "sketch_with_typename.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"), - BuiltInLibrariesDirs: paths.New("libraries", "downloaded_libraries"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), - Verbose: true, - } - ctx = prepareBuilderTestContext(t, ctx, sketchLocation, "arduino:avr:leonardo") - defer cleanUpBuilderTestContext(t, ctx) - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - expected := "#line 6 " + quotedSketchLocation + "\nvoid setup();\n#line 10 " + quotedSketchLocation + "\nvoid loop();\n#line 12 " + quotedSketchLocation + "\ntypename Foo::Bar func();\n#line 6 " + quotedSketchLocation + "\n" - obtained := preprocessedSketch - // ctags based preprocessing ignores line with typename - // TODO: remove this exception when moving to a more powerful parser - expected = strings.Replace(expected, "#line 12 "+quotedSketchLocation+"\ntypename Foo::Bar func();\n", "", -1) - obtained = strings.Replace(obtained, "#line 12 "+quotedSketchLocation+"\ntypename Foo::Bar func();\n", "", -1) - require.Contains(t, obtained, expected) -} - -func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { - sketchLocation := paths.New("sketch_with_ifdef", "sketch_with_ifdef.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:yun") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Contains(t, preprocessedSketch, "#line 5 "+quotedSketchLocation+"\nvoid elseBranch();\n#line 9 "+quotedSketchLocation+"\nvoid f1();\n#line 10 "+quotedSketchLocation+"\nvoid f2();\n#line 12 "+quotedSketchLocation+"\nvoid setup();\n#line 14 "+quotedSketchLocation+"\nvoid loop();\n#line 5 "+quotedSketchLocation+"\n") - - expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), ctx) - require.Equal(t, expectedSource, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { - sketchLocation := paths.New("sketch_with_ifdef", "sketch_with_ifdef.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:sam:arduino_due_x_dbg") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Contains(t, preprocessedSketch, "#line 2 "+quotedSketchLocation+"\nvoid ifBranch();\n#line 9 "+quotedSketchLocation+"\nvoid f1();\n#line 10 "+quotedSketchLocation+"\nvoid f2();\n#line 12 "+quotedSketchLocation+"\nvoid setup();\n#line 14 "+quotedSketchLocation+"\nvoid loop();\n#line 2 "+quotedSketchLocation+"\n") - - expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), ctx) - require.Equal(t, expectedSource, strings.Replace(preprocessedSketch, "\r\n", "\n", -1)) -} - -func TestPrototypesAdderSketchWithConst(t *testing.T) { - sketchLocation := paths.New("sketch_with_const", "sketch_with_const.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:uno") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "#include \n#line 1 "+quotedSketchLocation+"\n") - require.Contains(t, preprocessedSketch, "#line 1 "+quotedSketchLocation+"\nvoid setup();\n#line 2 "+quotedSketchLocation+"\nvoid loop();\n#line 4 "+quotedSketchLocation+"\nconst __FlashStringHelper* test();\n#line 6 "+quotedSketchLocation+"\nconst int test3();\n#line 8 "+quotedSketchLocation+"\nvolatile __FlashStringHelper* test2();\n#line 10 "+quotedSketchLocation+"\nvolatile int test4();\n#line 1 "+quotedSketchLocation+"\n") -} - -func TestPrototypesAdderSketchWithDosEol(t *testing.T) { - ctx := prepareBuilderTestContext(t, nil, paths.New("eol_processing", "eol_processing.ino"), "arduino:avr:uno") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - // only requires no error as result -} - -func TestPrototypesAdderSketchWithSubstringFunctionMember(t *testing.T) { - sketchLocation := paths.New("sketch_with_class_and_method_substring", "sketch_with_class_and_method_substring.ino") - quotedSketchLocation := cpp.QuoteString(Abs(t, sketchLocation).String()) - - ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:uno") - defer cleanUpBuilderTestContext(t, ctx) - - ctx.Verbose = true - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - NoError(t, builder.PreprocessSketch(ctx)) - - preprocessedSketch := loadPreprocessedSketch(t, ctx) - require.Contains(t, preprocessedSketch, "class Foo {\nint blooper(int x) { return x+1; }\n};\n\nFoo foo;\n\n#line 7 "+quotedSketchLocation+"\nvoid setup();") -} diff --git a/legacy/builder/test/sketch_with_dependend_libraries/sketch_with_dependend_libraries.ino b/legacy/builder/test/sketch_with_dependend_libraries/sketch_with_dependend_libraries.ino deleted file mode 100644 index ad070592a92..00000000000 --- a/legacy/builder/test/sketch_with_dependend_libraries/sketch_with_dependend_libraries.ino +++ /dev/null @@ -1 +0,0 @@ -#include \ No newline at end of file diff --git a/legacy/builder/test/sketch_with_ifdef/sketch.preprocessed.SAM.txt b/legacy/builder/test/sketch_with_ifdef/sketch.preprocessed.SAM.txt deleted file mode 100644 index c3c0d7c06d1..00000000000 --- a/legacy/builder/test/sketch_with_ifdef/sketch.preprocessed.SAM.txt +++ /dev/null @@ -1,28 +0,0 @@ -#include -#line 1 {{QuoteCppString .sketch.MainFile}} -#if __SAM3X8E__ -#line 2 {{QuoteCppString .sketch.MainFile}} -void ifBranch(); -#line 9 {{QuoteCppString .sketch.MainFile}} -void f1(); -#line 10 {{QuoteCppString .sketch.MainFile}} -void f2(); -#line 12 {{QuoteCppString .sketch.MainFile}} -void setup(); -#line 14 {{QuoteCppString .sketch.MainFile}} -void loop(); -#line 2 {{QuoteCppString .sketch.MainFile}} -void ifBranch() { -} -#else -void elseBranch() { -} -#endif - -void f1(){ f2(); } -void f2(){;} - -void setup() { -} -void loop() { -} diff --git a/legacy/builder/test/sketch_with_ifdef/sketch.preprocessed.txt b/legacy/builder/test/sketch_with_ifdef/sketch.preprocessed.txt deleted file mode 100644 index 7fcfe26c389..00000000000 --- a/legacy/builder/test/sketch_with_ifdef/sketch.preprocessed.txt +++ /dev/null @@ -1,28 +0,0 @@ -#include -#line 1 {{QuoteCppString .sketch.MainFile}} -#if __SAM3X8E__ -void ifBranch() { -} -#else -#line 5 {{QuoteCppString .sketch.MainFile}} -void elseBranch(); -#line 9 {{QuoteCppString .sketch.MainFile}} -void f1(); -#line 10 {{QuoteCppString .sketch.MainFile}} -void f2(); -#line 12 {{QuoteCppString .sketch.MainFile}} -void setup(); -#line 14 {{QuoteCppString .sketch.MainFile}} -void loop(); -#line 5 {{QuoteCppString .sketch.MainFile}} -void elseBranch() { -} -#endif - -void f1(){ f2(); } -void f2(){;} - -void setup() { -} -void loop() { -} diff --git a/legacy/builder/test/try_build_of_problematic_sketch_test.go b/legacy/builder/test/try_build_of_problematic_sketch_test.go index 90f3633f2b6..2c1e01b89ac 100644 --- a/legacy/builder/test/try_build_of_problematic_sketch_test.go +++ b/legacy/builder/test/try_build_of_problematic_sketch_test.go @@ -26,136 +26,11 @@ import ( paths "github.com/arduino/go-paths-helper" ) -func TestTryBuild001(t *testing.T) { - tryBuild(t, paths.New("sketch_with_inline_function", "sketch_with_inline_function.ino")) -} - -func TestTryBuild002(t *testing.T) { - tryBuild(t, paths.New("sketch_with_function_signature_inside_ifdef", "sketch_with_function_signature_inside_ifdef.ino")) -} - -func TestTryBuild003(t *testing.T) { - tryPreprocess(t, paths.New("sketch_no_functions", "sketch_no_functions.ino")) -} - -func TestTryBuild004(t *testing.T) { - tryBuild(t, paths.New("sketch_with_const", "sketch_with_const.ino")) -} - -func TestTryBuild005(t *testing.T) { - tryBuild(t, paths.New("sketch_with_old_lib", "sketch_with_old_lib.ino")) -} - -func TestTryBuild006(t *testing.T) { - tryBuild(t, paths.New("sketch_with_macosx_garbage", "sketch_with_macosx_garbage.ino")) -} - -func TestTryBuild007(t *testing.T) { - tryBuild(t, paths.New("sketch_with_config", "sketch_with_config.ino")) -} - -// XXX: Failing sketch, typename not supported -//func TestTryBuild008(t *testing.T) { -// tryBuild(t, paths.New("sketch_with_typename", "sketch.ino")) -//} - -func TestTryBuild009(t *testing.T) { - tryBuild(t, paths.New("sketch_with_usbcon", "sketch_with_usbcon.ino")) -} - -func TestTryBuild010(t *testing.T) { - tryBuild(t, paths.New("sketch_with_namespace", "sketch_with_namespace.ino")) -} - -func TestTryBuild011(t *testing.T) { - tryBuild(t, paths.New("sketch_with_inline_function", "sketch_with_inline_function.ino")) -} - -func TestTryBuild012(t *testing.T) { - tryBuild(t, paths.New("sketch_with_default_args", "sketch_with_default_args.ino")) -} - -func TestTryBuild013(t *testing.T) { - tryBuild(t, paths.New("sketch_with_class", "sketch_with_class.ino")) -} - -func TestTryBuild014(t *testing.T) { - tryBuild(t, paths.New("sketch_with_backup_files", "sketch_with_backup_files.ino")) -} - -func TestTryBuild015(t *testing.T) { - tryBuild(t, paths.New("sketch_with_subfolders")) -} - // This is a sketch that fails to build on purpose //func TestTryBuild016(t *testing.T) { // tryBuild(t, paths.New("sketch_that_checks_if_SPI_has_transactions_and_includes_missing_Ethernet", "sketch.ino")) //} -func TestTryBuild017(t *testing.T) { - tryPreprocess(t, paths.New("sketch_no_functions_two_files", "sketch_no_functions_two_files.ino")) -} - -func TestTryBuild018(t *testing.T) { - tryBuild(t, paths.New("sketch_that_checks_if_SPI_has_transactions", "sketch_that_checks_if_SPI_has_transactions.ino")) -} - -func TestTryBuild019(t *testing.T) { - tryBuild(t, paths.New("sketch_with_ifdef", "sketch_with_ifdef.ino")) -} - -func TestTryBuild020(t *testing.T) { - ctx := makeDefaultContext() - ctx.OtherLibrariesDirs = paths.NewPathList("dependent_libraries", "libraries") - tryPreprocessWithContext(t, ctx, "arduino:avr:leonardo", paths.New("sketch_with_dependend_libraries", "sketch_with_dependend_libraries.ino")) -} - -func TestTryBuild021(t *testing.T) { - tryBuild(t, paths.New("sketch_with_function_pointer", "sketch_with_function_pointer.ino")) -} - -func TestTryBuild022(t *testing.T) { - ctx := makeDefaultContext() - tryBuildWithContext(t, ctx, "arduino:samd:arduino_zero_native", paths.New("sketch_usbhost", "sketch_usbhost.ino")) -} - -func TestTryBuild023(t *testing.T) { - tryBuild(t, paths.New("sketch1", "sketch1.ino")) -} - -func TestTryBuild024(t *testing.T) { - tryBuild(t, paths.New("SketchWithIfDef", "SketchWithIfDef.ino")) -} - -// The library for this sketch is missing -//func TestTryBuild025(t *testing.T) { -// tryBuild(t, paths.New("sketch3", "Baladuino.ino")) -//} - -func TestTryBuild026(t *testing.T) { - tryBuild(t, paths.New("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.ino")) -} - -func TestTryBuild027(t *testing.T) { - tryBuild(t, paths.New("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.ino")) -} - -func TestTryBuild028(t *testing.T) { - tryBuild(t, paths.New("LineContinuations", "LineContinuations.ino")) -} - -func TestTryBuild029(t *testing.T) { - tryBuild(t, paths.New("StringWithComment", "StringWithComment.ino")) -} - -func TestTryBuild030(t *testing.T) { - tryBuild(t, paths.New("SketchWithStruct", "SketchWithStruct.ino")) -} - -func TestTryBuild031(t *testing.T) { - tryBuild(t, paths.New("sketch9", "sketch9.ino")) -} - func TestTryBuild032(t *testing.T) { tryBuild(t, paths.New("sketch10", "sketch10.ino")) } @@ -224,15 +99,3 @@ func tryBuildWithContext(t *testing.T, ctx *types.Context, fqbn string, sketchLo err := builder.RunBuilder(ctx) NoError(t, err, "Build error for "+sketchLocation.String()) } - -func tryPreprocess(t *testing.T, sketchLocation *paths.Path) { - tryPreprocessWithContext(t, makeDefaultContext(), "arduino:avr:leonardo", sketchLocation) -} - -func tryPreprocessWithContext(t *testing.T, ctx *types.Context, fqbn string, sketchLocation *paths.Path) { - ctx = prepareBuilderTestContext(t, ctx, sketchLocation, fqbn) - defer cleanUpBuilderTestContext(t, ctx) - - err := builder.RunPreprocess(ctx) - NoError(t, err, "Build error for "+sketchLocation.String()) -}