├── .gitignore ├── ArduinoWiringTestSuite ├── ArduinoWiringTestSuite.ino ├── ArduinoWiringTestSuite.sln ├── ArduinoWiringTestSuite.vcxproj ├── ArduinoWiringTestSuite.vcxproj.filters ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ └── Wide310x150Logo.scale-200.png ├── Package.appxmanifest ├── PinNumbers.h ├── StartupTask.cpp └── pch.h ├── LICENSE ├── Library ├── Lightning.sln ├── Lightning.vcxproj ├── Lightning.vcxproj.filters ├── custom.signconfig ├── dllmain.cpp ├── pch.cpp ├── pch.h └── targetver.h ├── Nuget ├── Microsoft.IoT.Lightning.Debug.nuspec ├── Microsoft.IoT.Lightning.Public.nuspec ├── Microsoft.IoT.Lightning.nuspec ├── Microsoft.IoT.Lightning.targets └── build-nupkg.cmd ├── PerformanceTestSuite ├── CPP │ ├── Assets │ │ ├── LockScreenLogo.scale-200.png │ │ ├── SplashScreen.scale-200.png │ │ ├── Square150x150Logo.scale-200.png │ │ ├── Square44x44Logo.scale-200.png │ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ │ ├── StoreLogo.png │ │ └── Wide310x150Logo.scale-200.png │ ├── GpioPerformanceTestCPP.vcxproj │ ├── GpioPerformanceTestCPP.vcxproj.filters │ ├── Package.appxmanifest │ ├── StartupTask.cpp │ ├── StartupTask.h │ ├── packages.config │ ├── pch.cpp │ └── pch.h ├── CS │ ├── Assets │ │ ├── LockScreenLogo.scale-200.png │ │ ├── SplashScreen.scale-200.png │ │ ├── Square150x150Logo.scale-200.png │ │ ├── Square44x44Logo.scale-200.png │ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ │ ├── StoreLogo.png │ │ └── Wide310x150Logo.scale-200.png │ ├── GpioPerformanceTestCS.csproj │ ├── Package.appxmanifest │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── Default.rd.xml │ ├── StartupTask.cs │ └── project.json ├── GpioPerformanceTest.sln ├── JS │ ├── GpioPerformanceTestJS.jsproj │ ├── images │ │ ├── LockScreenLogo.scale-200.png │ │ ├── SplashScreen.scale-200.png │ │ ├── Square150x150Logo.scale-200.png │ │ ├── Square44x44Logo.scale-200.png │ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ │ ├── StoreLogo.png │ │ └── Wide310x150Logo.scale-200.png │ ├── js │ │ └── startuptask.js │ └── package.appxmanifest └── Wiring │ ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ └── Wide310x150Logo.scale-200.png │ ├── GpioPerformanceTestWiring.ino │ ├── GpioPerformanceTestWiring.vcxproj │ ├── GpioPerformanceTestWiring.vcxproj.filters │ ├── Package.appxmanifest │ ├── PinNumbers.h │ ├── StartupTask.cpp │ ├── packages.config │ └── pch.h ├── Providers ├── AdcDeviceProvider.cpp ├── AdcDeviceProvider.h ├── ApiSupport.cpp ├── GpioDeviceProvider.cpp ├── GpioDeviceProvider.h ├── I2cDeviceProvider.cpp ├── I2cDeviceProvider.h ├── Microsoft.Iot.Lightning.Providers.vcxproj ├── Microsoft.Iot.Lightning.Providers.vcxproj.filters ├── Provider.cpp ├── Provider.h ├── PwmDeviceProvider.cpp ├── PwmDeviceProvider.h ├── SpiDeviceProvider.cpp ├── SpiDeviceProvider.h ├── pch.cpp └── pch.h ├── README.md ├── SDKFromArduino ├── include │ ├── Client.h │ ├── IPAddress.h │ ├── LiquidCrystal.h │ ├── Print.h │ ├── Printable.h │ ├── Server.h │ ├── Stepper.h │ ├── Stream.h │ ├── Udp.h │ ├── WCharacter.h │ ├── WString.h │ └── binary.h └── source │ ├── IPAddress.cpp │ ├── LiquidCrystal.cpp │ ├── Print.cpp │ ├── Stepper.cpp │ ├── Stream.cpp │ └── WString.cpp ├── WinSDK.extcomp ├── build.cmd ├── images ├── Add_SDK_Extensions.png ├── Not_Using_Precompiled_Headers_VS2015.png ├── Nuget_PackageManager.png ├── Nuget_PackageSourceConfig_VS2015.png ├── Nuget_TemplateConfig.png └── Update_Manifest.png ├── license.txt └── source ├── .gitignore ├── ADS1015Support.h ├── Adc.h ├── ArduinoCommon.h ├── ArduinoError.h ├── BcmI2cController.cpp ├── BcmI2cController.h ├── BcmSpiController.cpp ├── BcmSpiController.h ├── BoardPins.cpp ├── BoardPins.h ├── BtI2cController.cpp ├── BtI2cController.h ├── BtSpiController.cpp ├── BtSpiController.h ├── DMap.h ├── DmapErrors.cpp ├── DmapSupport.cpp ├── DmapSupport.h ├── ErrorCodes.h ├── ExpanderDefs.h ├── GpioController.cpp ├── GpioController.h ├── GpioInterrupt.cpp ├── GpioInterrupt.h ├── HardwareSerial.cpp ├── HardwareSerial.h ├── HiResTimer.h ├── I2c.cpp ├── I2c.h ├── I2cController.cpp ├── I2cController.h ├── I2cTransaction.cpp ├── I2cTransaction.h ├── I2cTransfer.h ├── Lightning.h ├── MCP3008support.h ├── MuxDefs.h ├── NetworkSerial.cpp ├── NetworkSerial.h ├── PCA9685Support.cpp ├── PCA9685Support.h ├── PulseIn.cpp ├── PulseIn.h ├── Servo.cpp ├── Servo.h ├── Spi.cpp ├── SpiController.cpp ├── SpiController.h ├── WInterrupt.cpp ├── WInterrupt.h ├── WindowsRandom.h ├── WindowsTime.h ├── Wire.h ├── arduino.cpp ├── arduino.h ├── avr ├── interrupt.h ├── macros.h └── pgmspace.h ├── eeprom.cpp ├── eeprom.h ├── pins_arduino.h └── spi.h /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | *.lck 10 | project.lock.json 11 | 12 | # Build results 13 | [Dd]ebug/ 14 | [Dd]ebugPublic/ 15 | [Rr]elease/ 16 | [Rr]eleases/ 17 | x64/ 18 | x86/ 19 | build/ 20 | bld/ 21 | [Bb]in/ 22 | BundleArtifacts/ 23 | [Oo]bj/ 24 | 25 | # Roslyn cache directories 26 | *.ide/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | #NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | 136 | # NuGet Packages 137 | *.nupkg 138 | # The packages folder can be ignored because of Package Restore 139 | **/packages/* 140 | # except build/, which is used as an MSBuild target. 141 | !**/packages/build/ 142 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 143 | #!**/packages/repositories.config 144 | 145 | # Windows Azure Build Output 146 | csx/ 147 | *.build.csdef 148 | 149 | # Windows Store app package directory 150 | AppPackages/ 151 | 152 | # Others 153 | sql/ 154 | *.Cache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | .vs/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | *.opendb 189 | Library/Lightning.VC.db 190 | Public/* 191 | -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/ArduinoWiringTestSuite.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArduinoWiringTestSuite", "ArduinoWiringTestSuite.vcxproj", "{32E975BE-FD8E-4344-9155-26A162D0BA71}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lightning", "..\Library\Lightning.vcxproj", "{5A83971A-3144-42C4-A59C-50CE291A5540}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|ARM = Debug|ARM 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|ARM = Release|ARM 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|ARM.ActiveCfg = Debug|ARM 21 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|ARM.Build.0 = Debug|ARM 22 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|ARM.Deploy.0 = Debug|ARM 23 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|x64.ActiveCfg = Debug|x64 24 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|x64.Build.0 = Debug|x64 25 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|x64.Deploy.0 = Debug|x64 26 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|x86.ActiveCfg = Debug|Win32 27 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|x86.Build.0 = Debug|Win32 28 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Debug|x86.Deploy.0 = Debug|Win32 29 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|ARM.ActiveCfg = Release|ARM 30 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|ARM.Build.0 = Release|ARM 31 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|ARM.Deploy.0 = Release|ARM 32 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|x64.ActiveCfg = Release|x64 33 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|x64.Build.0 = Release|x64 34 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|x64.Deploy.0 = Release|x64 35 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|x86.ActiveCfg = Release|Win32 36 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|x86.Build.0 = Release|Win32 37 | {32E975BE-FD8E-4344-9155-26A162D0BA71}.Release|x86.Deploy.0 = Release|Win32 38 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|ARM.ActiveCfg = Debug|ARM 39 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|ARM.Build.0 = Debug|ARM 40 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|x64.ActiveCfg = Debug|x64 41 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|x64.Build.0 = Debug|x64 42 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|x86.ActiveCfg = Debug|Win32 43 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|x86.Build.0 = Debug|Win32 44 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|ARM.ActiveCfg = Release|ARM 45 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|ARM.Build.0 = Release|ARM 46 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|x64.ActiveCfg = Release|x64 47 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|x64.Build.0 = Release|x64 48 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|x86.ActiveCfg = Release|Win32 49 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|x86.Build.0 = Release|Win32 50 | EndGlobalSection 51 | GlobalSection(SolutionProperties) = preSolution 52 | HideSolutionNode = FALSE 53 | EndGlobalSection 54 | EndGlobal 55 | -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/ArduinoWiringTestSuite.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 69ea24c9-6cc8-4286-a4af-8bd769e3125d 6 | pfx;appxmanifest;config 7 | 8 | 9 | 88b236f6-33a4-4653-af45-17650c0bf3f0 10 | png 11 | 12 | 13 | 2c626885-ce22-450e-bbb5-3b245f3ed09b 14 | 15 | 16 | 17 | 18 | Package Dependencies 19 | 20 | 21 | 22 | 23 | 24 | Package Dependencies\Include 25 | 26 | 27 | Package Dependencies\Include 28 | 29 | 30 | 31 | 32 | Package Dependencies\Assets 33 | 34 | 35 | Package Dependencies\Assets 36 | 37 | 38 | Package Dependencies\Assets 39 | 40 | 41 | Package Dependencies\Assets 42 | 43 | 44 | Package Dependencies\Assets 45 | 46 | 47 | Package Dependencies\Assets 48 | 49 | 50 | Package Dependencies\Assets 51 | 52 | 53 | 54 | 55 | Package Dependencies 56 | 57 | 58 | 59 | 60 | Package Dependencies 61 | 62 | 63 | -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/ArduinoWiringTestSuite/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/ArduinoWiringTestSuite/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/ArduinoWiringTestSuite/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/ArduinoWiringTestSuite/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/ArduinoWiringTestSuite/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/ArduinoWiringTestSuite/Assets/StoreLogo.png -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/ArduinoWiringTestSuite/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | ArduinoWiringTestSuite 19 | Microsoft 20 | Assets\StoreLogo.png 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/PinNumbers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This file contains the pin numbers mappings for MinnowBoard Max and Raspberry Pi2 controllers 4 | 5 | #if defined(_M_IX86) || defined(_M_X64) 6 | 7 | // Pin numbers mappings for MinnowBoard Max 8 | 9 | const UCHAR GPIO_0 = 21; 10 | const UCHAR GPIO_1 = 23; 11 | const UCHAR GPIO_2 = 25; 12 | const UCHAR GPIO_3 = 14; 13 | const UCHAR GPIO_4 = 16; 14 | const UCHAR GPIO_5 = 18; 15 | const UCHAR GPIO_6 = 20; 16 | const UCHAR GPIO_7 = 22; 17 | const UCHAR GPIO_8 = 24; 18 | const UCHAR GPIO_9 = 26; 19 | const UCHAR I2C_SCL = 13; 20 | const UCHAR I2C_SDA = 15; 21 | const UCHAR SPI_CS0 = 5; 22 | const UCHAR SPI_MISO = 7; 23 | const UCHAR SPI_MOSI = 9; 24 | const UCHAR SPI_SCLK = 11; 25 | const UCHAR UARAT1_CTS = 10; 26 | const UCHAR UARAT1_RTS = 12; 27 | const UCHAR UARAT1_RX = 8; 28 | const UCHAR UARAT1_TX = 6; 29 | const UCHAR UARAT2_RX = 19; 30 | const UCHAR UARAT2_TX = 17; 31 | 32 | #elif defined (_M_ARM) 33 | 34 | // Pin numbers mappings for Raspberry Pi2 35 | 36 | const UCHAR GPIO_2 = 3; 37 | const UCHAR GPIO_3 = 5; 38 | const UCHAR GPIO_4 = 7; 39 | const UCHAR GPIO_5 = 29; 40 | const UCHAR GPIO_6 = 31; 41 | const UCHAR GPIO_7 = 26; 42 | const UCHAR GPIO_8 = 24; 43 | const UCHAR GPIO_9 = 21; 44 | const UCHAR GPIO_10 = 19; 45 | const UCHAR GPIO_11 = 23; 46 | const UCHAR GPIO_12 = 32; 47 | const UCHAR GPIO_13 = 33; 48 | const UCHAR GPIO_14 = 8; 49 | const UCHAR GPIO_15 = 10; 50 | const UCHAR GPIO_16 = 36; 51 | const UCHAR GPIO_17 = 11; 52 | const UCHAR GPIO_18 = 12; 53 | const UCHAR GPIO_19 = 35; 54 | const UCHAR GPIO_20 = 38; 55 | const UCHAR GPIO_21 = 40; 56 | const UCHAR GPIO_22 = 15; 57 | const UCHAR GPIO_23 = 16; 58 | const UCHAR GPIO_24 = 18; 59 | const UCHAR GPIO_25 = 22; 60 | const UCHAR GPIO_26 = 37; 61 | const UCHAR GPIO_27 = 13; 62 | const UCHAR GPIO_GCLK = 7; 63 | const UCHAR GPIO_GEN0 = 11; 64 | const UCHAR GPIO_GEN1 = 12; 65 | const UCHAR GPIO_GEN2 = 13; 66 | const UCHAR GPIO_GEN3 = 15; 67 | const UCHAR GPIO_GEN4 = 16; 68 | const UCHAR GPIO_GEN5 = 18; 69 | const UCHAR I2C_SCL1 = 5; 70 | const UCHAR I2C_SDA1 = 3; 71 | const UCHAR SPI_CS0 = 24; 72 | const UCHAR SPI_CS1 = 26; 73 | const UCHAR SPI_CLK = 23; 74 | const UCHAR SPI_MISO = 21; 75 | const UCHAR SPI_MOSI = 19; 76 | const UCHAR RXD0 = 10; 77 | const UCHAR TXD0 = 8; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/StartupTask.cpp: -------------------------------------------------------------------------------- 1 | using namespace Windows::ApplicationModel::Background; 2 | 3 | // These functions should be defined in the sketch file 4 | void setup(); 5 | void loop(); 6 | 7 | namespace ArduinoWiringTestSuite 8 | { 9 | [Windows::Foundation::Metadata::WebHostHidden] 10 | public ref class StartupTask sealed : public IBackgroundTask 11 | { 12 | public: 13 | virtual void Run(Windows::ApplicationModel::Background::IBackgroundTaskInstance^ taskInstance) 14 | { 15 | auto deferral = taskInstance->GetDeferral(); 16 | 17 | setup(); 18 | while (true) 19 | { 20 | loop(); 21 | } 22 | } 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /ArduinoWiringTestSuite/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Library/Lightning.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lightning", "Lightning.vcxproj", "{5A83971A-3144-42C4-A59C-50CE291A5540}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.IoT.Lightning.Providers", "..\Providers\Microsoft.Iot.Lightning.Providers.vcxproj", "{46A913D5-F809-4026-9DC9-CF94F643A0FE}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|ARM = Debug|ARM 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|ARM = Release|ARM 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|ARM.ActiveCfg = Debug|ARM 21 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|ARM.Build.0 = Debug|ARM 22 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|x64.ActiveCfg = Debug|x64 23 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|x64.Build.0 = Debug|x64 24 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|x86.ActiveCfg = Debug|Win32 25 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Debug|x86.Build.0 = Debug|Win32 26 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|ARM.ActiveCfg = Release|ARM 27 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|ARM.Build.0 = Release|ARM 28 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|x64.ActiveCfg = Release|x64 29 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|x64.Build.0 = Release|x64 30 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|x86.ActiveCfg = Release|Win32 31 | {5A83971A-3144-42C4-A59C-50CE291A5540}.Release|x86.Build.0 = Release|Win32 32 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Debug|ARM.ActiveCfg = Debug|ARM 33 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Debug|ARM.Build.0 = Debug|ARM 34 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Debug|x64.ActiveCfg = Debug|x64 35 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Debug|x64.Build.0 = Debug|x64 36 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Debug|x86.ActiveCfg = Debug|Win32 37 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Debug|x86.Build.0 = Debug|Win32 38 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Release|ARM.ActiveCfg = Release|ARM 39 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Release|ARM.Build.0 = Release|ARM 40 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Release|x64.ActiveCfg = Release|x64 41 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Release|x64.Build.0 = Release|x64 42 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Release|x86.ActiveCfg = Release|Win32 43 | {46A913D5-F809-4026-9DC9-CF94F643A0FE}.Release|x86.Build.0 = Release|Win32 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /Library/custom.signconfig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Library/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | 3 | 4 | #pragma warning( push ) 5 | // Ignore compiler warning about Win32-style DLLMain when compiled with /ZW flag 6 | #pragma warning( disable : 4447 ) 7 | BOOL APIENTRY DllMain(HMODULE /* hModule */, DWORD ul_reason_for_call, LPVOID /* lpReserved */) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | #pragma warning( pop ) 20 | -------------------------------------------------------------------------------- /Library/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /Library/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "targetver.h" 4 | 5 | #ifndef WIN32_LEAN_AND_MEAN 6 | #define WIN32_LEAN_AND_MEAN 7 | #endif 8 | 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /Library/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /Nuget/Microsoft.IoT.Lightning.Debug.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.IoT.Lightning 5 | 1.1.0 6 | Microsoft IoT Lightning SDK 7 | Microsoft Open Technologies, Inc. 8 | Microsoft Open Technologies, Inc. 9 | http://www.microsoft.com/en-us/legal/intellectualproperty/copyright/default.aspx 10 | https://github.com/ms-iot/lightning 11 | false 12 | The Lightning SDK allows rapid creation of applications for Windows Iot Core devices using the familiar Arduino interface. 13 | Microsoft IoT Lightning SDK 14 | 15 | Copyright 2016 16 | lightning arduino microsoft native nativepackage 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Nuget/Microsoft.IoT.Lightning.Public.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.IoT.Lightning 5 | 1.1.0 6 | Microsoft IoT Lightning SDK 7 | Microsoft Open Technologies, Inc. 8 | Microsoft Open Technologies, Inc. 9 | http://www.microsoft.com/en-us/legal/intellectualproperty/copyright/default.aspx 10 | https://github.com/ms-iot/lightning 11 | false 12 | The Lightning SDK allows rapid creation of applications for Windows Iot Core devices using the familiar Arduino interface. 13 | Microsoft IoT Lightning SDK 14 | 15 | Copyright 2016 16 | lightning arduino microsoft native nativepackage 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Nuget/Microsoft.IoT.Lightning.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.IoT.Lightning 5 | 1.1.0 6 | Microsoft IoT Lightning SDK 7 | Microsoft Open Technologies, Inc. 8 | Microsoft Open Technologies, Inc. 9 | http://www.microsoft.com/en-us/legal/intellectualproperty/copyright/default.aspx 10 | https://github.com/ms-iot/lightning 11 | false 12 | The Lightning SDK allows rapid creation of applications for Windows Iot Core devices using the familiar Arduino interface. 13 | Microsoft IoT Lightning SDK 14 | 15 | Copyright 2016 16 | lightning arduino microsoft native nativepackage 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Nuget/Microsoft.IoT.Lightning.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | x86 6 | $(Platform) 7 | 8 | 9 | 10 | 11 | Microsoft.IoT.Lightning.Providers.dll 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | ARDUINO=100;%(PreprocessorDefinitions); 20 | NoExtensions 21 | $(MSBuildThisFileDirectory)..\..\include;%(AdditionalIncludeDirectories) 22 | $(MSBuildThisFileDirectory)..\..\include\avr;%(AdditionalIncludeDirectories) 23 | NotUsing 24 | 25 | 26 | $(MSBuildThisFileDirectory)..\..\include;%(AdditionalIncludeDirectories) 27 | $(MSBuildThisFileDirectory)..\..\include\avr;%(AdditionalIncludeDirectories) 28 | 29 | 30 | lightning.lib;%(AdditionalDependencies) 31 | $(MSBuildThisFileDirectory)..\..\lib\win10-$(targetPlatform)\native;%(AdditionalLibraryDirectories) 32 | 33 | 34 | 35 | 36 | 37 | NotSet 38 | 39 | 40 | 41 | 42 | 43 | NotSet 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Nuget/build-nupkg.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableextensions disabledelayedexpansion 3 | set NUSPEC="Microsoft.IoT.Lightning.nuspec" 4 | 5 | :: Parse options 6 | :GETOPTS 7 | if /I "%~1" == "/?" goto USAGE 8 | if /I "%~1" == "/Help" goto USAGE 9 | if /I "%~1" == "/clean" set CLEAN=1 10 | if /I "%~1" == "/nopack" set NOPACK=1 11 | if /I "%~1" == "/debug" set NUSPEC="Microsoft.IoT.Lightning.Debug.nuspec" 12 | if /I "%~1" == "/public" set NUSPEC="Microsoft.IoT.Lightning.Public.nuspec" 13 | shift 14 | if not (%1)==() goto GETOPTS 15 | 16 | echo Cleaning outputs 17 | del Microsoft.IoT.Lightning*.nupkg 2> NUL 18 | 19 | :: if a clean was requested, exit here 20 | if "%CLEAN%"=="1" goto end 21 | 22 | :: skip packaging step if requested 23 | if "%NOPACK%"=="1" goto end 24 | 25 | echo Creating NuGet Package 26 | nuget help > NUL 27 | IF ERRORLEVEL 1 ( 28 | echo Please install nuget.exe from http://nuget.org 29 | goto err 30 | ) 31 | nuget pack %NUSPEC% -NoPackageAnalysis || goto err 32 | 33 | :end 34 | 35 | echo Success 36 | exit /b 0 37 | 38 | :err 39 | echo Script failed! 40 | exit /b 1 -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CPP/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CPP/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CPP/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CPP/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CPP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CPP/Assets/StoreLogo.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CPP/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/GpioPerformanceTestCPP.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 4a360532-05e0-49e1-8f97-38e608df2009 6 | 7 | 8 | 191fd617-b34a-48d0-9cdc-a8bf920a6a6d 9 | bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | Assets 30 | 31 | 32 | Assets 33 | 34 | 35 | Assets 36 | 37 | 38 | Assets 39 | 40 | 41 | Assets 42 | 43 | 44 | Assets 45 | 46 | 47 | Assets 48 | 49 | 50 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | GpioPerformanceTestCPP 19 | t-ticast 20 | Assets\StoreLogo.png 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/StartupTask.cpp: -------------------------------------------------------------------------------- 1 | // Background application that sets a GPIO pin high and low as fast as possible 2 | 3 | #include "pch.h" 4 | #include "StartupTask.h" 5 | 6 | using namespace GpioPerformanceTestCPP; 7 | using namespace Microsoft::IoT::Lightning::Providers; 8 | 9 | using namespace Platform; 10 | using namespace Windows::ApplicationModel::Background; 11 | using namespace Windows::Devices; 12 | using namespace Windows::Devices::Enumeration; 13 | using namespace Windows::Devices::Gpio; 14 | 15 | static const int LED_PIN = 5; 16 | 17 | void StartupTask::Run(IBackgroundTaskInstance^ taskInstance) 18 | { 19 | bool hasLightning = LightningProvider::IsLightningEnabled; 20 | if (hasLightning) 21 | { 22 | // Set Lightning as the default provider 23 | LowLevelDevicesController::DefaultProvider = LightningProvider::GetAggregateProvider(); 24 | } 25 | else 26 | { 27 | OutputDebugString(L"Lightning NOT supported!\n"); 28 | } 29 | 30 | auto gpio = GpioController::GetDefault(); 31 | if (gpio == nullptr) 32 | { 33 | OutputDebugString(L"No GPIO controller found.\n"); 34 | return; 35 | } 36 | Windows::Devices::Gpio::GpioPin ^pin = gpio->OpenPin(LED_PIN); 37 | pin->SetDriveMode(GpioPinDriveMode::Output); 38 | for (;;) 39 | { 40 | pin->Write(GpioPinValue::High); 41 | pin->Write(GpioPinValue::Low); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/StartupTask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pch.h" 4 | 5 | namespace GpioPerformanceTestCPP 6 | { 7 | [Windows::Foundation::Metadata::WebHostHidden] 8 | public ref class StartupTask sealed : public Windows::ApplicationModel::Background::IBackgroundTask 9 | { 10 | public: 11 | virtual void Run(Windows::ApplicationModel::Background::IBackgroundTaskInstance^ taskInstance); 12 | 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/pch.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pch.cpp 3 | // Include the standard header and generate the precompiled header. 4 | // 5 | 6 | #include "pch.h" 7 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CPP/pch.h: -------------------------------------------------------------------------------- 1 | // 2 | // pch.h 3 | // Header for standard system include files. 4 | // 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CS/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CS/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CS/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CS/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CS/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CS/Assets/StoreLogo.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/CS/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | GpioPerformanceTestCS 19 | t-ticast 20 | Assets\StoreLogo.png 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("GpioPerformanceTestCS")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("GpioPerformanceTestCS")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/Properties/Default.rd.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/StartupTask.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IoT.Lightning.Providers; 2 | using System.Diagnostics; 3 | using Windows.ApplicationModel.Background; 4 | using Windows.Devices; 5 | using Windows.Devices.Gpio; 6 | 7 | // Background application that sets a GPIO pin high and low as fast as possible 8 | 9 | namespace GpioPerformanceTestCS 10 | { 11 | public sealed class StartupTask : IBackgroundTask 12 | { 13 | private const int LED_PIN = 5; 14 | 15 | public void Run(IBackgroundTaskInstance taskInstance) 16 | { 17 | if (LightningProvider.IsLightningEnabled) 18 | { 19 | LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); 20 | } 21 | else 22 | { 23 | Debug.WriteLine("Lightning NOT supported!"); 24 | } 25 | 26 | var gpioController = GpioController.GetDefault(); 27 | if (gpioController == null) 28 | { 29 | Debug.WriteLine("No GPIO Controller found."); 30 | return; 31 | } 32 | 33 | var pin = gpioController.OpenPin(LED_PIN); 34 | pin.SetDriveMode(GpioPinDriveMode.Output); 35 | for (;;) 36 | { 37 | pin.Write(GpioPinValue.High); 38 | pin.Write(GpioPinValue.Low); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /PerformanceTestSuite/CS/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "Microsoft.IoT.Lightning": "1.1.0", 4 | "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0" 5 | }, 6 | "frameworks": { 7 | "uap10.0": {} 8 | }, 9 | "runtimes": { 10 | "win10-arm": {}, 11 | "win10-arm-aot": {}, 12 | "win10-x86": {}, 13 | "win10-x86-aot": {}, 14 | "win10-x64": {}, 15 | "win10-x64-aot": {} 16 | } 17 | } -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/GpioPerformanceTestJS.jsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8 | 9 | Debug 10 | ARM 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Debug 18 | x86 19 | 20 | 21 | Release 22 | AnyCPU 23 | 24 | 25 | Release 26 | ARM 27 | true 28 | 29 | 30 | Release 31 | x64 32 | true 33 | 34 | 35 | Release 36 | x86 37 | true 38 | 39 | 40 | 41 | b57fdaf3-2d85-4ad3-ad4b-b30443c93e32 42 | 43 | 44 | 45 | 14.0 46 | 47 | 48 | 49 | 50 | true 51 | UAP 52 | 10.0.14393.0 53 | 10.0.10586.0 54 | $(VersionNumberMajor).$(VersionNumberMinor) 55 | en-US 56 | GPIOPerformanceTestJS_TemporaryKey.pfx 57 | true 58 | true 59 | True 60 | Always 61 | arm 62 | 63 | 64 | 65 | Designer 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 92 | -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/images/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/JS/images/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/images/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/JS/images/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/images/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/JS/images/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/images/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/JS/images/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/images/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/JS/images/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/images/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/JS/images/StoreLogo.png -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/images/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/JS/images/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/js/startuptask.js: -------------------------------------------------------------------------------- 1 | /*eslint no-constant-condition: ["error", { "checkLoops": false }]*/ 2 | // Background application that sets a GPIO pin high and low as fast as possible 3 | (function () { 4 | "use strict"; 5 | 6 | if (Microsoft.IoT.Lightning.Providers.LightningProvider.isLightningEnabled) { 7 | Windows.Devices.LowLevelDevicesController.defaultProvider = Microsoft.IoT.Lightning.Providers.LightningProvider.getAggregateProvider(); 8 | } else { 9 | console.log("Lightning NOT enabled!"); 10 | } 11 | 12 | var gpioController = Windows.Devices.Gpio.GpioController.getDefault(); 13 | if (gpioController == null) { 14 | console.log("No GPIO controller available"); 15 | return; 16 | } 17 | 18 | var pin = gpioController.openPin(5); 19 | pin.setDriveMode(Windows.Devices.Gpio.GpioPinDriveMode.output); 20 | 21 | while (true) { 22 | pin.write(Windows.Devices.Gpio.GpioPinValue.high); 23 | pin.write(Windows.Devices.Gpio.GpioPinValue.low); 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /PerformanceTestSuite/JS/package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | GPIOPerformanceTestJS 7 | t-ticast 8 | images\storelogo.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/Wiring/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/Wiring/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/Wiring/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/Wiring/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/Wiring/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/Wiring/Assets/StoreLogo.png -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/PerformanceTestSuite/Wiring/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/GpioPerformanceTestWiring.ino: -------------------------------------------------------------------------------- 1 | // Application that sets a GPIO pin high and low as fast as possible 2 | 3 | // Use GPIO pin 5 4 | const unsigned int LED_PIN = GPIO5; 5 | 6 | void setup() 7 | { 8 | pinMode(LED_PIN, OUTPUT); 9 | } 10 | 11 | void loop() 12 | { 13 | digitalWrite(LED_PIN, HIGH); 14 | digitalWrite(LED_PIN, LOW); 15 | } 16 | -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/GpioPerformanceTestWiring.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | fb8c868d-d9da-46b1-90e3-a3442e2de5c5 6 | pfx;appxmanifest;config 7 | 8 | 9 | 28dfa903-0f36-4dd4-accd-00750ee92ea9 10 | png 11 | 12 | 13 | c0fb3f78-baff-4401-b7c8-67929a3302b4 14 | 15 | 16 | 17 | 18 | Package Dependencies 19 | 20 | 21 | 22 | 23 | 24 | Package Dependencies\Include 25 | 26 | 27 | Package Dependencies\Include 28 | 29 | 30 | 31 | 32 | Package Dependencies\Assets 33 | 34 | 35 | Package Dependencies\Assets 36 | 37 | 38 | Package Dependencies\Assets 39 | 40 | 41 | Package Dependencies\Assets 42 | 43 | 44 | Package Dependencies\Assets 45 | 46 | 47 | Package Dependencies\Assets 48 | 49 | 50 | Package Dependencies\Assets 51 | 52 | 53 | 54 | 55 | Package Dependencies 56 | 57 | 58 | 59 | 60 | Package Dependencies 61 | 62 | 63 | Package Dependencies 64 | 65 | 66 | -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | GpioPerformanceTestWiring 19 | t-ticast 20 | Assets\StoreLogo.png 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/PinNumbers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This file contains the pin numbers mappings for MinnowBoard Max and Raspberry Pi2 controllers 4 | 5 | #if defined(_M_IX86) || defined(_M_X64) 6 | 7 | // Pin numbers mappings for MinnowBoard Max 8 | 9 | const UCHAR GPIO_0 = 21; 10 | const UCHAR GPIO_1 = 23; 11 | const UCHAR GPIO_2 = 25; 12 | const UCHAR GPIO_3 = 14; 13 | const UCHAR GPIO_4 = 16; 14 | const UCHAR GPIO_5 = 18; 15 | const UCHAR GPIO_6 = 20; 16 | const UCHAR GPIO_7 = 22; 17 | const UCHAR GPIO_8 = 24; 18 | const UCHAR GPIO_9 = 26; 19 | const UCHAR I2C_SCL = 13; 20 | const UCHAR I2C_SDA = 15; 21 | const UCHAR SPI_CS0 = 5; 22 | const UCHAR SPI_MISO = 7; 23 | const UCHAR SPI_MOSI = 9; 24 | const UCHAR SPI_SCLK = 11; 25 | const UCHAR UARAT1_CTS = 10; 26 | const UCHAR UARAT1_RTS = 12; 27 | const UCHAR UARAT1_RX = 8; 28 | const UCHAR UARAT1_TX = 6; 29 | const UCHAR UARAT2_RX = 19; 30 | const UCHAR UARAT2_TX = 17; 31 | 32 | #elif defined (_M_ARM) 33 | 34 | // Pin numbers mappings for Raspberry Pi2 35 | 36 | const UCHAR GPIO_2 = 3; 37 | const UCHAR GPIO_3 = 5; 38 | const UCHAR GPIO_4 = 7; 39 | const UCHAR GPIO_5 = 29; 40 | const UCHAR GPIO_6 = 31; 41 | const UCHAR GPIO_7 = 26; 42 | const UCHAR GPIO_8 = 24; 43 | const UCHAR GPIO_9 = 21; 44 | const UCHAR GPIO_10 = 19; 45 | const UCHAR GPIO_11 = 23; 46 | const UCHAR GPIO_12 = 32; 47 | const UCHAR GPIO_13 = 33; 48 | const UCHAR GPIO_14 = 8; 49 | const UCHAR GPIO_15 = 10; 50 | const UCHAR GPIO_16 = 36; 51 | const UCHAR GPIO_17 = 11; 52 | const UCHAR GPIO_18 = 12; 53 | const UCHAR GPIO_19 = 35; 54 | const UCHAR GPIO_20 = 38; 55 | const UCHAR GPIO_21 = 40; 56 | const UCHAR GPIO_22 = 15; 57 | const UCHAR GPIO_23 = 16; 58 | const UCHAR GPIO_24 = 18; 59 | const UCHAR GPIO_25 = 22; 60 | const UCHAR GPIO_26 = 37; 61 | const UCHAR GPIO_27 = 13; 62 | const UCHAR GPIO_GCLK = 7; 63 | const UCHAR GPIO_GEN0 = 11; 64 | const UCHAR GPIO_GEN1 = 12; 65 | const UCHAR GPIO_GEN2 = 13; 66 | const UCHAR GPIO_GEN3 = 15; 67 | const UCHAR GPIO_GEN4 = 16; 68 | const UCHAR GPIO_GEN5 = 18; 69 | const UCHAR I2C_SCL1 = 5; 70 | const UCHAR I2C_SDA1 = 3; 71 | const UCHAR SPI_CS0 = 24; 72 | const UCHAR SPI_CS1 = 26; 73 | const UCHAR SPI_CLK = 23; 74 | const UCHAR SPI_MISO = 21; 75 | const UCHAR SPI_MOSI = 19; 76 | const UCHAR RXD0 = 10; 77 | const UCHAR TXD0 = 8; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/StartupTask.cpp: -------------------------------------------------------------------------------- 1 | using namespace Windows::ApplicationModel::Background; 2 | 3 | // These functions should be defined in the sketch file 4 | void setup(); 5 | void loop(); 6 | 7 | namespace GpioPerformanceTestWiring 8 | { 9 | [Windows::Foundation::Metadata::WebHostHidden] 10 | public ref class StartupTask sealed : public IBackgroundTask 11 | { 12 | public: 13 | virtual void Run(Windows::ApplicationModel::Background::IBackgroundTaskInstance^ taskInstance) 14 | { 15 | auto deferral = taskInstance->GetDeferral(); 16 | 17 | setup(); 18 | while (true) 19 | { 20 | loop(); 21 | } 22 | } 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /PerformanceTestSuite/Wiring/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | -------------------------------------------------------------------------------- /Providers/AdcDeviceProvider.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | #include "pch.h" 3 | #include "AdcDeviceProvider.h" 4 | #include "Provider.h" 5 | #include "boardpins.h" 6 | 7 | using namespace Microsoft::IoT::Lightning::Providers; 8 | 9 | #pragma region LightningAdcProvider 10 | 11 | IAdcProvider^ LightningAdcProvider::providerSingleton = nullptr; 12 | 13 | IAdcProvider ^ LightningAdcProvider::GetAdcProvider() 14 | { 15 | if (providerSingleton == nullptr) 16 | { 17 | providerSingleton = ref new LightningAdcProvider(); 18 | } 19 | 20 | return providerSingleton; 21 | } 22 | 23 | #pragma endregion 24 | 25 | #pragma region LightningMCP3008AdcControllerProvider 26 | 27 | 28 | void LightningMCP3008AdcControllerProvider::AcquireChannel(int channel) 29 | { 30 | if (_channelsAcquired[channel]) 31 | { 32 | throw ref new Platform::AccessDeniedException(L"Channel already acquired"); 33 | } 34 | 35 | _channelsAcquired[channel] = true; 36 | } 37 | 38 | void LightningMCP3008AdcControllerProvider::ReleaseChannel(int channel) 39 | { 40 | if (!_channelsAcquired[channel]) 41 | { 42 | throw ref new Platform::AccessDeniedException(L"Channel not acquired"); 43 | } 44 | 45 | _channelsAcquired[channel] = false; 46 | } 47 | 48 | int LightningMCP3008AdcControllerProvider::ReadValue(int channelNumber) 49 | { 50 | if (!_channelsAcquired[channelNumber]) 51 | { 52 | throw ref new Platform::AccessDeniedException(L"Channel not acquired"); 53 | } 54 | 55 | ULONG value = 0;; 56 | ULONG bits = 0; 57 | _addOnAdc->readValue(channelNumber, value, bits); 58 | 59 | // Scale the digitized analog value to the currently set analog read resolution. 60 | if (_resolutionInBits > (int)bits) 61 | { 62 | value = value << (_resolutionInBits - (int)bits); 63 | } 64 | else if ((int)bits > _resolutionInBits) 65 | { 66 | value = value >> ((int)bits - _resolutionInBits); 67 | } 68 | 69 | return (int)value; 70 | } 71 | 72 | LightningMCP3008AdcControllerProvider::LightningMCP3008AdcControllerProvider() : 73 | _resolutionInBits(MCP3008_ADC_BIT_RESOLUTION) 74 | { 75 | Initialize(); 76 | } 77 | 78 | LightningMCP3008AdcControllerProvider::~LightningMCP3008AdcControllerProvider() 79 | { 80 | _addOnAdc->end(); 81 | } 82 | 83 | void LightningMCP3008AdcControllerProvider::Initialize() 84 | { 85 | BoardPinsClass::BOARD_TYPE boardType; 86 | HRESULT hr = g_pins.getBoardType(boardType); 87 | 88 | if (FAILED(hr)) 89 | { 90 | LightningProvider::ThrowError(hr, L"An error occurred determining board type."); 91 | } 92 | 93 | if (!(boardType == BoardPinsClass::BOARD_TYPE::MBM_BARE || 94 | boardType == BoardPinsClass::BOARD_TYPE::PI2_BARE)) 95 | { 96 | throw ref new Platform::NotImplementedException(L"This board type has not been implemented."); 97 | } 98 | 99 | _addOnAdc.reset(new MCP3008Device()); 100 | 101 | hr = _addOnAdc->begin(); 102 | if (FAILED(hr)) 103 | { 104 | LightningProvider::ThrowError(hr, L"An error occurred Initializing ADC."); 105 | } 106 | 107 | _channelsAcquired.resize(MCP3008_ADC_CHANNEL_COUNT, false); 108 | } 109 | 110 | IVectorView^ LightningAdcProvider::GetControllers( 111 | void 112 | ) 113 | { 114 | auto controllerCollection = ref new Vector(); 115 | controllerCollection->Append(ref new LightningMCP3008AdcControllerProvider()); 116 | return controllerCollection->GetView(); 117 | } 118 | 119 | #pragma endregion 120 | -------------------------------------------------------------------------------- /Providers/AdcDeviceProvider.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | 6 | #define MCP3008_ADC_CHANNEL_COUNT 8 7 | #define MCP3008_ADC_MIN 0 8 | #define MCP3008_ADC_MAX 1023 9 | #define MCP3008_ADC_BIT_RESOLUTION 10 10 | 11 | using namespace Windows::Devices::Adc::Provider; 12 | 13 | namespace Microsoft { 14 | namespace IoT { 15 | namespace Lightning { 16 | namespace Providers { 17 | 18 | public ref class LightningAdcProvider sealed : public IAdcProvider 19 | { 20 | public: 21 | virtual IVectorView^ GetControllers(); 22 | static IAdcProvider^ GetAdcProvider(); 23 | 24 | private: 25 | LightningAdcProvider() { } 26 | static IAdcProvider^ providerSingleton; 27 | }; 28 | 29 | public ref class LightningMCP3008AdcControllerProvider sealed : public IAdcControllerProvider 30 | { 31 | public: 32 | // Inherited via IAdcControllerProvider 33 | virtual property int ChannelCount 34 | { 35 | int get() { return MCP3008_ADC_CHANNEL_COUNT; } 36 | } 37 | 38 | virtual property int MaxValue 39 | { 40 | int get() { return MCP3008_ADC_MAX; } 41 | } 42 | virtual property int MinValue 43 | { 44 | int get() { return MCP3008_ADC_MIN; } 45 | } 46 | 47 | virtual property int ResolutionInBits 48 | { 49 | int get() { return _resolutionInBits; } 50 | } 51 | 52 | virtual property ProviderAdcChannelMode ChannelMode 53 | { 54 | ProviderAdcChannelMode get() { return _channelMode; } 55 | void set(ProviderAdcChannelMode value) 56 | { 57 | if (value != ProviderAdcChannelMode::SingleEnded) 58 | throw ref new Platform::Exception(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); 59 | _channelMode = value; 60 | } 61 | } 62 | 63 | virtual bool IsChannelModeSupported(ProviderAdcChannelMode channelMode) 64 | { 65 | if (channelMode != ProviderAdcChannelMode::SingleEnded) 66 | return false; 67 | 68 | return true; 69 | } 70 | 71 | virtual void AcquireChannel(int channel); 72 | virtual void ReleaseChannel(int channel); 73 | 74 | virtual int ReadValue(int channelNumber); 75 | 76 | virtual ~LightningMCP3008AdcControllerProvider(); 77 | 78 | internal: 79 | LightningMCP3008AdcControllerProvider(); 80 | 81 | private: 82 | std::shared_ptr _addOnAdc; 83 | std::vector _channelsAcquired; 84 | int _resolutionInBits; 85 | ProviderAdcChannelMode _channelMode; 86 | 87 | void Initialize(); 88 | 89 | }; 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Providers/ApiSupport.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | // This file has been added as a workaround for a bug in one of Windows SDK tools, WinMDExp. 3 | // A limitation of the tool is that it requires refrence assemblies count to be >= refernce types 4 | // However, because the provider references both the IOT and Extensions SDK, with several 5 | // assemblies referenced in each, that breaks the tool. 6 | // This class references more types to overcome that issue. 7 | // 8 | // Note: Future versions of the Windows SDK; i.e. > 10, will not have that limitation. 9 | // 10 | namespace Microsoft { 11 | namespace IoT { 12 | namespace Lightning { 13 | namespace Providers { 14 | public ref class ApiSupport sealed 15 | { 16 | public: 17 | ApiSupport() {} 18 | void Func( 19 | Windows::Devices::Adc::AdcChannel^ a, 20 | Windows::Devices::Adc::AdcController^ a2, 21 | Windows::Devices::Adc::AdcChannelMode a3, 22 | Windows::Devices::Gpio::GpioController^ a4, 23 | Windows::Devices::Gpio::GpioOpenStatus a5, 24 | Windows::Devices::Gpio::GpioPin^ a6, 25 | Windows::Devices::Gpio::GpioPinDriveMode a7, 26 | Windows::Devices::Gpio::GpioPinEdge a8, 27 | Windows::Devices::Gpio::GpioPinValue a9, 28 | Windows::Devices::Gpio::GpioSharingMode a10, 29 | Windows::Devices::Spi::SpiBusInfo^ a11, 30 | Windows::Devices::Spi::SpiConnectionSettings^ a12, 31 | Windows::Devices::Spi::SpiController^ a13, 32 | Windows::Devices::Spi::SpiDevice^ a14, 33 | Windows::Devices::Spi::SpiMode a15, 34 | Windows::Devices::Spi::SpiSharingMode a16, 35 | Windows::Devices::I2c::I2cBusSpeed a17, 36 | Windows::Devices::I2c::I2cConnectionSettings^ a18, 37 | Windows::Devices::I2c::I2cController^ a19, 38 | Windows::Devices::I2c::I2cDevice^ a20, 39 | Windows::Devices::I2c::I2cSharingMode a21, 40 | Windows::Devices::I2c::I2cTransferResult a22, 41 | Windows::Devices::I2c::I2cTransferStatus a23, 42 | Windows::Devices::I2c::II2cDeviceStatics^ a24 43 | ) 44 | { 45 | } 46 | }; 47 | 48 | } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Providers/GpioDeviceProvider.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | #include "pch.h" 3 | #include "GpioDeviceProvider.h" 4 | #include "Provider.h" 5 | #include "boardpins.h" 6 | 7 | using namespace Microsoft::IoT::Lightning::Providers; 8 | 9 | #define MBM_PIN_COUNT 26 10 | #define RPI_PIN_COUNT 53 11 | 12 | #pragma region LightningGpioProvider 13 | 14 | IGpioProvider^ LightningGpioProvider::providerSingleton = nullptr; 15 | 16 | IGpioProvider ^ LightningGpioProvider::GetGpioProvider() 17 | { 18 | if (providerSingleton == nullptr) 19 | { 20 | providerSingleton = ref new LightningGpioProvider(); 21 | } 22 | 23 | return providerSingleton; 24 | } 25 | 26 | #pragma endregion 27 | 28 | #pragma region LightningGpioControllerProvider 29 | 30 | LightningGpioControllerProvider::LightningGpioControllerProvider() 31 | { 32 | Initialize(); 33 | } 34 | 35 | void LightningGpioControllerProvider::Initialize() 36 | { 37 | HRESULT hr = g_pins.getBoardType(_boardType); 38 | 39 | if (FAILED(hr)) 40 | { 41 | LightningProvider::ThrowError(hr, L"An error occurred determining board type."); 42 | } 43 | 44 | if (_boardType == BoardPinsClass::BOARD_TYPE::MBM_BARE) 45 | { 46 | _pinCount = MBM_PIN_COUNT; 47 | } 48 | else if (_boardType == BoardPinsClass::BOARD_TYPE::PI2_BARE) 49 | { 50 | _pinCount = RPI_PIN_COUNT; 51 | } 52 | else 53 | { 54 | throw ref new Platform::NotImplementedException(L"This board type has not been implemented."); 55 | } 56 | } 57 | 58 | IGpioPinProvider^ LightningGpioControllerProvider::OpenPinProvider( 59 | int pin, 60 | ProviderGpioSharingMode sharingMode 61 | ) 62 | { 63 | int mappedPin = LightningProvider::MapGpioPin(_boardType, pin); 64 | 65 | return OpenPinProviderNoMapping(pin, mappedPin, sharingMode); 66 | } 67 | 68 | 69 | IGpioPinProvider^ LightningGpioControllerProvider::OpenPinProviderNoMapping(int pin, int mappedPin, ProviderGpioSharingMode sharingMode) 70 | { 71 | HRESULT hr = g_pins.verifyPinFunction(mappedPin, FUNC_DIO, BoardPinsClass::NO_LOCK_CHANGE); 72 | 73 | if (FAILED(hr)) 74 | { 75 | LightningProvider::ThrowError(hr, L"Invalid function for pin."); 76 | } 77 | 78 | return ref new LightningGpioPinProvider(pin, mappedPin, sharingMode, this->_boardType); 79 | } 80 | 81 | IVectorView^ LightningGpioProvider::GetControllers( 82 | void 83 | ) 84 | { 85 | auto controllerCollection = ref new Vector(); 86 | controllerCollection->Append(ref new LightningGpioControllerProvider()); 87 | return controllerCollection->GetView(); 88 | } 89 | 90 | #pragma endregion 91 | 92 | #pragma region LightningGpioPinProvider 93 | 94 | void LightningGpioPinProvider::SetDriveMode( 95 | ProviderGpioPinDriveMode value 96 | ) 97 | { 98 | if ((!_driveModeSet) || (_driveModeSet && _DriveMode != value)) 99 | { 100 | SetDriveModeInternal(value); 101 | } 102 | } 103 | 104 | void LightningGpioPinProvider::SetDriveModeInternal( 105 | ProviderGpioPinDriveMode value 106 | ) 107 | { 108 | HRESULT hr = S_OK; 109 | ULONG direction = DIRECTION_IN; 110 | BOOL pullUp = FALSE; 111 | switch (value) 112 | { 113 | case ProviderGpioPinDriveMode::Input: 114 | break; 115 | case ProviderGpioPinDriveMode::Output: 116 | direction = DIRECTION_OUT; 117 | break; 118 | case ProviderGpioPinDriveMode::InputPullUp: 119 | pullUp = TRUE; 120 | break; 121 | default: 122 | throw ref new Platform::NotImplementedException(L"Pin drive mode not implemented"); 123 | } 124 | 125 | hr = g_pins.setPinMode(_MappedPinNumber, direction, pullUp); 126 | 127 | if (FAILED(hr)) 128 | { 129 | LightningProvider::ThrowError(hr, L"Error setting pin drive mode."); 130 | } 131 | 132 | // set the member variable 133 | _DriveMode = value; 134 | _driveModeSet = true; 135 | } 136 | 137 | void LightningGpioPinProvider::Write( 138 | ProviderGpioPinValue value 139 | ) 140 | { 141 | // It's safe to cast these value to a state expected by setPinState 142 | // ProviderGpioPinValue::Low == 0 == LOW 143 | // ProviderGpioPinValue::High == 1 == HIGH 144 | ULONG state = safe_cast(value); 145 | 146 | if (!_driveModeSet) 147 | { 148 | SetDriveModeInternal(ProviderGpioPinDriveMode::Output); 149 | } 150 | 151 | HRESULT hr = g_pins.setPinState(_MappedPinNumber, state); 152 | if (FAILED(hr)) 153 | { 154 | LightningProvider::ThrowError(hr, L"Could not write pin value."); 155 | } 156 | } 157 | 158 | ProviderGpioPinValue LightningGpioPinProvider::Read() 159 | { 160 | ULONG state = 0; 161 | 162 | if (!_driveModeSet) 163 | { 164 | SetDriveModeInternal(ProviderGpioPinDriveMode::Input); 165 | } 166 | 167 | HRESULT hr = g_pins.getPinState(_MappedPinNumber, state); 168 | if (FAILED(hr)) 169 | { 170 | LightningProvider::ThrowError(hr, L"Could not read pin value."); 171 | } 172 | 173 | if (state == HIGH) 174 | { 175 | return ProviderGpioPinValue::High; 176 | } 177 | 178 | return ProviderGpioPinValue::Low; 179 | } 180 | 181 | #pragma endregion 182 | -------------------------------------------------------------------------------- /Providers/I2cDeviceProvider.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | #pragma once 3 | #include "I2cController.h" 4 | 5 | namespace Microsoft { 6 | namespace IoT { 7 | namespace Lightning { 8 | namespace Providers { 9 | public ref class LightningI2cProvider sealed : public II2cProvider 10 | { 11 | public: 12 | virtual IAsyncOperation^>^ GetControllersAsync(); 13 | static II2cProvider^ GetI2cProvider(); 14 | 15 | private: 16 | LightningI2cProvider() { } 17 | static II2cProvider^ providerSingleton; 18 | }; 19 | 20 | public ref class LightningI2cControllerProvider sealed : public II2cControllerProvider 21 | { 22 | 23 | public: 24 | // Inherited via II2cControllerProvider 25 | virtual II2cDeviceProvider ^ GetDeviceProvider(ProviderI2cConnectionSettings ^settings); 26 | 27 | internal: 28 | explicit LightningI2cControllerProvider(ULONG busNumber) : _busNumber(busNumber) { } 29 | 30 | private: 31 | LightningI2cControllerProvider() { } 32 | /// The bus number for the I2C Controller associated with this object. 33 | ULONG _busNumber; 34 | }; 35 | 36 | public ref class LightningI2cDeviceProvider sealed : public II2cDeviceProvider 37 | { 38 | 39 | public: 40 | // Inherited via II2cDeviceProvider 41 | virtual property Platform::String ^ DeviceId 42 | { 43 | Platform::String^ get(); 44 | } 45 | 46 | virtual ProviderI2cTransferResult WritePartial( 47 | const Platform::Array ^buffer); 48 | 49 | virtual ProviderI2cTransferResult ReadPartial( 50 | Platform::WriteOnlyArray ^buffer); 51 | 52 | virtual ProviderI2cTransferResult WriteReadPartial( 53 | const Platform::Array ^writeBuffer, 54 | Platform::WriteOnlyArray ^readBuffer); 55 | 56 | virtual void Write( 57 | const Platform::Array ^buffer); 58 | 59 | virtual void Read( 60 | Platform::WriteOnlyArray ^buffer); 61 | 62 | virtual void WriteRead( 63 | const Platform::Array ^writeBuffer, 64 | Platform::WriteOnlyArray ^readBuffer); 65 | 66 | virtual ~LightningI2cDeviceProvider(); 67 | 68 | internal: 69 | LightningI2cDeviceProvider(ProviderI2cConnectionSettings ^settings, ULONG busNumber); 70 | 71 | private: 72 | LightningI2cDeviceProvider() { } 73 | ProviderI2cConnectionSettings ^_ConnectionSettings; 74 | std::unique_ptr _I2cController; 75 | ULONG _busNumber; 76 | std::unique_ptr< I2cTransactionClass> _i2cTransaction; 77 | }; 78 | 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Providers/Microsoft.Iot.Lightning.Providers.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {8e086a04-3e6f-4b05-8632-aa6778921990} 6 | 7 | 8 | {fce8ddb6-24fb-4dbc-af5c-69a964538bbd} 9 | 10 | 11 | {4f3c2e96-909d-45b7-ab2f-d62797f00765} 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Dependencies 24 | 25 | 26 | Lightning 27 | 28 | 29 | Lightning 30 | 31 | 32 | Lightning 33 | 34 | 35 | Lightning 36 | 37 | 38 | Lightning 39 | 40 | 41 | Lightning 42 | 43 | 44 | Lightning 45 | 46 | 47 | Lightning 48 | 49 | 50 | Lightning 51 | 52 | 53 | Lightning 54 | 55 | 56 | Lightning 57 | 58 | 59 | Lightning 60 | 61 | 62 | Lightning 63 | 64 | 65 | Lightning 66 | 67 | 68 | Lightning 69 | 70 | 71 | Lightning 72 | 73 | 74 | Lightning 75 | 76 | 77 | Lightning 78 | 79 | 80 | Lightning 81 | 82 | 83 | Lightning 84 | 85 | 86 | Lightning 87 | 88 | 89 | SDKFromArduino 90 | 91 | 92 | SDKFromArduino 93 | 94 | 95 | SDKFromArduino 96 | 97 | 98 | SDKFromArduino 99 | 100 | 101 | SDKFromArduino 102 | 103 | 104 | SDKFromArduino 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /Providers/Provider.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved 2 | 3 | #include "pch.h" 4 | #include "Provider.h" 5 | 6 | #include "GpioDeviceProvider.h" 7 | #include "I2cDeviceProvider.h" 8 | #include "SpiDeviceProvider.h" 9 | #include "AdcDeviceProvider.h" 10 | #include "PwmDeviceProvider.h" 11 | 12 | #include "errorcodes.h" 13 | #include "pins_arduino.h" 14 | 15 | using namespace Microsoft::IoT::Lightning::Providers; 16 | 17 | #pragma region Declarations 18 | 19 | #if defined(_M_IX86) || defined(_M_X64) 20 | 21 | // Pin numbers mappings for MinnowBoard Max 22 | 23 | const std::map MBM_GPIO_Pins = 24 | { 25 | { 0, GPIO0 }, 26 | { 1, GPIO1 }, 27 | { 2, GPIO2 }, 28 | { 3, GPIO3 }, 29 | { 4, GPIO4 }, 30 | { 5, GPIO5 }, 31 | { 6, GPIO6 }, 32 | { 7, GPIO7 }, 33 | { 8, GPIO8 }, 34 | { 9, GPIO9 } 35 | }; 36 | 37 | #elif defined (_M_ARM) 38 | 39 | // Pin numbers mappings for Raspberry Pi2 40 | 41 | const std::map RPI2_GPIO_Pins = 42 | { 43 | { 2, GPIO2 }, 44 | { 3, GPIO3 }, 45 | { 4, GPIO4 }, 46 | { 5, GPIO5 }, 47 | { 6, GPIO6 }, 48 | { 7, GPIO7 }, 49 | { 8, GPIO8 }, 50 | { 9, GPIO9 }, 51 | { 10, GPIO10 }, 52 | { 11, GPIO11 }, 53 | { 12, GPIO12 }, 54 | { 13, GPIO13 }, 55 | { 14, GPIO14 }, 56 | { 15, GPIO15 }, 57 | { 16, GPIO16 }, 58 | { 17, GPIO17 }, 59 | { 18, GPIO18 }, 60 | { 19, GPIO19 }, 61 | { 20, GPIO20 }, 62 | { 21, GPIO21 }, 63 | { 22, GPIO22 }, 64 | { 23, GPIO23 }, 65 | { 24, GPIO24 }, 66 | { 25, GPIO25 }, 67 | { 26, GPIO26 }, 68 | { 27, GPIO27 }, 69 | { 47, GPIO47 } 70 | }; 71 | 72 | #endif // defined (_M_ARM) 73 | 74 | #pragma endregion 75 | 76 | #pragma region LightningProvider 77 | 78 | IAdcControllerProvider ^ LightningProvider::AdcControllerProvider::get() 79 | { 80 | return ref new LightningMCP3008AdcControllerProvider(); 81 | } 82 | 83 | IGpioControllerProvider ^ LightningProvider::GpioControllerProvider::get() 84 | { 85 | return ref new LightningGpioControllerProvider(); 86 | } 87 | 88 | II2cControllerProvider ^ LightningProvider::I2cControllerProvider::get() 89 | { 90 | return ref new LightningI2cControllerProvider(EXTERNAL_I2C_BUS); 91 | } 92 | 93 | IPwmControllerProvider ^ LightningProvider::PwmControllerProvider::get() 94 | { 95 | return ref new LightningPCA9685PwmControllerProvider(); 96 | } 97 | 98 | ISpiControllerProvider ^ LightningProvider::SpiControllerProvider::get() 99 | { 100 | return ref new LightningSpiControllerProvider(); 101 | } 102 | 103 | bool LightningProvider::IsLightningEnabled::get() 104 | { 105 | ULONG state; 106 | if (g_pins.getPinState(10, state) == DMAP_E_DEVICE_NOT_FOUND_ON_SYSTEM) 107 | { 108 | return false; 109 | } 110 | 111 | return true; 112 | } 113 | 114 | void LightningProvider::ThrowError(HRESULT hr, LPCWSTR errorMessage) 115 | { 116 | Platform::String^ errMessage = ref new Platform::String(errorMessage); 117 | 118 | auto it = DmapErrors.find(hr); 119 | if (it != DmapErrors.end()) 120 | { 121 | errMessage += L"Additional Information: "; 122 | errMessage += ref new Platform::String(it->second); 123 | } 124 | 125 | throw ref new Platform::Exception(hr, errMessage); 126 | 127 | } 128 | 129 | int LightningProvider::MapGpioPin(BoardPinsClass::BOARD_TYPE boardType, int pin) 130 | { 131 | int mappedPin = -1; 132 | 133 | #if defined(_M_IX86) || defined(_M_X64) 134 | 135 | 136 | // Pin numbers mappings for Raspberry Pi2 137 | 138 | if (boardType == BoardPinsClass::BOARD_TYPE::MBM_BARE) 139 | { 140 | auto it = MBM_GPIO_Pins.find(pin); 141 | if (it == MBM_GPIO_Pins.end()) 142 | { 143 | throw ref new Platform::InvalidArgumentException(L"Gpio Pin could not be mapped."); 144 | } 145 | mappedPin = it->second; 146 | } 147 | 148 | #elif defined (_M_ARM) 149 | 150 | if (boardType == BoardPinsClass::BOARD_TYPE::PI2_BARE) 151 | { 152 | auto it = RPI2_GPIO_Pins.find(pin); 153 | if (it == RPI2_GPIO_Pins.end()) 154 | { 155 | throw ref new Platform::InvalidArgumentException(L"Gpio Pin could not be mapped."); 156 | } 157 | mappedPin = it->second; 158 | } 159 | 160 | #endif 161 | return mappedPin; 162 | } 163 | 164 | ILowLevelDevicesAggregateProvider^ LightningProvider::providerSingleton = nullptr; 165 | 166 | ILowLevelDevicesAggregateProvider ^ LightningProvider::GetAggregateProvider() 167 | { 168 | if (providerSingleton == nullptr) 169 | { 170 | providerSingleton = ref new LightningProvider(); 171 | } 172 | 173 | return providerSingleton; 174 | } 175 | 176 | #pragma endregion 177 | -------------------------------------------------------------------------------- /Providers/Provider.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | #pragma once 3 | 4 | using namespace Windows::Devices; 5 | using namespace Windows::Devices::Adc::Provider; 6 | using namespace Windows::Devices::Pwm::Provider; 7 | using namespace Windows::Devices::Gpio::Provider; 8 | using namespace Windows::Devices::I2c::Provider; 9 | using namespace Windows::Devices::Spi::Provider; 10 | 11 | namespace Microsoft { 12 | namespace IoT { 13 | namespace Lightning { 14 | namespace Providers { 15 | 16 | public ref class LightningProvider sealed : public ILowLevelDevicesAggregateProvider 17 | { 18 | public: 19 | 20 | // Inherited via ILowLevelDevicesAggregateProvider 21 | virtual property IAdcControllerProvider ^ AdcControllerProvider 22 | { 23 | IAdcControllerProvider ^get(); 24 | } 25 | 26 | virtual property IGpioControllerProvider ^ GpioControllerProvider 27 | { 28 | IGpioControllerProvider ^get(); 29 | } 30 | 31 | virtual property II2cControllerProvider ^ I2cControllerProvider 32 | { 33 | II2cControllerProvider ^get(); 34 | } 35 | 36 | virtual property IPwmControllerProvider ^ PwmControllerProvider 37 | { 38 | IPwmControllerProvider ^get(); 39 | } 40 | 41 | virtual property ISpiControllerProvider ^ SpiControllerProvider 42 | { 43 | ISpiControllerProvider ^get(); 44 | } 45 | 46 | static property bool IsLightningEnabled 47 | { 48 | bool get(); 49 | } 50 | 51 | static ILowLevelDevicesAggregateProvider^ GetAggregateProvider(); 52 | 53 | internal: 54 | static void ThrowError(HRESULT hr, LPCWSTR errorMessage); 55 | static int MapGpioPin(BoardPinsClass::BOARD_TYPE boardType, int pin); 56 | 57 | private: 58 | LightningProvider() { } 59 | static ILowLevelDevicesAggregateProvider^ providerSingleton; 60 | 61 | }; 62 | } 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /Providers/SpiDeviceProvider.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | using namespace Windows::Devices::Spi::Provider; 8 | 9 | namespace Microsoft { 10 | namespace IoT { 11 | namespace Lightning { 12 | namespace Providers { 13 | 14 | public ref class LightningSpiProvider sealed : public ISpiProvider 15 | { 16 | public: 17 | virtual IAsyncOperation^>^ GetControllersAsync(); 18 | static ISpiProvider^ GetSpiProvider(); 19 | private: 20 | LightningSpiProvider() { } 21 | static ISpiProvider^ providerSingleton; 22 | }; 23 | 24 | public ref class LightningSpiControllerProvider sealed : public ISpiControllerProvider 25 | { 26 | 27 | public: 28 | // Inherited via ISpiControllerProvider 29 | virtual ISpiDeviceProvider ^ GetDeviceProvider(ProviderSpiConnectionSettings ^settings); 30 | 31 | internal: 32 | LightningSpiControllerProvider() { } 33 | }; 34 | 35 | public ref class LightningSpiDeviceProvider sealed : public ISpiDeviceProvider 36 | { 37 | 38 | public: 39 | // Inherited via ISpiDeviceProvider 40 | virtual property Platform::String ^ DeviceId 41 | { 42 | Platform::String^ get(); 43 | } 44 | 45 | virtual property ProviderSpiConnectionSettings ^ ConnectionSettings 46 | { 47 | ProviderSpiConnectionSettings^ get(); 48 | } 49 | 50 | virtual void Read(Platform::WriteOnlyArray^ buffer); 51 | virtual void TransferFullDuplex(const Platform::Array ^writeBuffer, Platform::WriteOnlyArray ^readBuffer); 52 | virtual void TransferSequential(const Platform::Array ^writeBuffer, Platform::WriteOnlyArray ^readBuffer); 53 | virtual void Write(const Platform::Array ^buffer); 54 | 55 | 56 | virtual ~LightningSpiDeviceProvider(); 57 | 58 | internal: 59 | LightningSpiDeviceProvider(ProviderSpiConnectionSettings ^settings); 60 | 61 | private: 62 | LightningSpiDeviceProvider() { } 63 | ProviderSpiConnectionSettings ^_ConnectionSettings; 64 | std::unique_ptr _SpiController; 65 | IGpioPinProvider^ _chipSelectPin; 66 | 67 | HRESULT TransferFullDuplexInternal(const Platform::Array ^writeBuffer, Platform::WriteOnlyArray ^readBuffer); 68 | 69 | inline USHORT flipShort(USHORT dataOut) 70 | { 71 | return (dataOut << 8) | ((dataOut >> 8) & 0xFF); 72 | } 73 | 74 | inline ULONG flipLong(ULONG dataOut) 75 | { 76 | return (dataOut << 24) | ((dataOut << 8) & 0xFF0000) | ((dataOut >> 8) & 0xFF00) | ((dataOut >> 24) & 0xFF); 77 | } 78 | 79 | }; 80 | 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Providers/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /Providers/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | using namespace Concurrency; 10 | 11 | using namespace Platform::Collections; 12 | 13 | using namespace Windows::Devices::Custom; 14 | using namespace Windows::Devices::Enumeration; 15 | using namespace Windows::Foundation; 16 | using namespace Windows::Foundation::Collections; 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **Microsoft.IoT.Lightning Nuget package** 2 | 3 | This repository is for generating the Microsoft.IoT.Lightning Nuget package. This package contains code which is compiled into an application deployed to a board running Microsoft Windows IoT Core. 4 | 5 | Also, the nuget package is periodically published to nuget.org. For more information on installing the published nuget package, please refer to [https://www.nuget.org/packages/Microsoft.IoT.Lightning/](https://www.nuget.org/packages/Microsoft.IoT.Lightning/) 6 | 7 | This project has adopted the [Microsoft Open Source Code of Conduct](http://microsoft.github.io/codeofconduct). For more information see the [Code of Conduct FAQ](http://microsoft.github.io/codeofconduct/faq.md) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 8 | 9 | ## Build the Nuget package 10 | - nuget.exe is required to build the Nuget package, so please download the Nuget command line utility [nuget.exe](http://nuget.org/nuget.exe) and make sure it's in the PATH. 11 | - Visual Studio 2017 is also required to build the sources ([Visual Studio Downloads](https://www.visualstudio.com/downloads/)) 12 | - Clone or download this repository 13 | - Assuming F:\Github\lightning is your local repo root folder and all prerequisites above are met, run this command to both build the sources and create the Nuget package. 14 | 15 | ~~~ 16 | F:\Github\lightning>build.cmd 17 | ~~~ 18 | 19 | - Alternatively, if the sources are already built, run this command from the \Nuget folder to create the Nuget package only. 20 | 21 | ~~~ 22 | F:\Github\lightning\Nuget>build-nupkg.cmd 23 | ~~~ 24 | 25 | ### Set Nuget package source location 26 | 27 | In order to install Nuget packages from your local builds, you'll need to add the folder where the Nuget package has been created (or copied) to the list of nuget package manager sources in Visual Studio. Following the below instructions for each sdk source: 28 | 29 | In Visual Studio 2017, nativate to *Tools -> Library Package Manager -> Package Manager Settings* 30 | 31 | ![Package Config](images/Nuget_PackageSourceConfig_VS2015.png) 32 | 33 | 1. Click the "+" button to add a new source 34 | 1. Set the name to something descriptive 35 | 1. Click the "..." button and navigate to your local folder where the Nuget package has been created; e.g. *F:\Github\lightning\Nuget* 36 | 1. Click the "Update" button to save the Package Sources changes 37 | 38 | ### Including prerelease Lightning packages 39 | 40 | In order to install the latest prerelease version of Lightning as well as receive prerelease updates to the Lightning package, make sure to set the "Include prerelease" option in the Nuget Package Manager. 41 | 42 | ![Package Config](images/Nuget_PackageManager.png) 43 | 44 | 1. Right click References in your project 45 | 1. Click "Manager Nuget Packages..." 46 | 1. Select package sources for Lightning nuget 47 | 1. Click "Include prerelease". 48 | 1. Click "Install" to install the nuget package to your project 49 | 50 | ### Add required UWP Extensions 51 | 52 | The IOT and Desktop UWP SDK Extensions are both required for building Lightning applications. 53 | 54 | ![Package Config](images/Add_SDK_Extensions.png) 55 | 56 | 1. Right click "References" in your Visual C++ UWP Project 57 | 1. Choose "Add Reference..." 58 | 1. Open Universal Windows | Extensions 59 | 1. Choose Both "Windows Desktop Extensions for the UWP" and "Windows IoT Extensions for the UWP". 60 | 61 | ### Update Application Package manifest 62 | 63 | Also, you need to update the Application Package manifest manually to reference the Lightning device interface. 64 | 65 | ![Package Config](images/Update_Manifest.png) 66 | 67 | 1. Right click "Package.appxmanifest" in your Visual C++ UWP Project 68 | 2. Click "Open With.." 69 | 3. In the "Open With" dialog box, choose XML (Text) Editor and click OK 70 | 4. Edit the the Capabilities section in your application to add the following: 71 | ```XML 72 | 73 | 74 | ``` 75 | 5. The first is a capability that will enable the application to access custom devices. 76 | 6. The second is the device guid id for the Lightning interface 77 | 7. Save the file 78 | 79 | Build your project to verify all prerequisites to use Lightning were successfully added. 80 | -------------------------------------------------------------------------------- /SDKFromArduino/include/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream { 27 | 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /SDKFromArduino/include/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.h - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef IPAddress_h 21 | #define IPAddress_h 22 | 23 | #include 24 | #include "Printable.h" 25 | #include "WString.h" 26 | #include "Lightning.h" 27 | 28 | // A class to make it easier to handle and pass around IP addresses 29 | 30 | class IPAddress : public Printable { 31 | private: 32 | union { 33 | uint8_t bytes[4]; // IPv4 address 34 | uint32_t dword; 35 | } _address; 36 | 37 | // Access the raw byte array containing the address. Because this returns a pointer 38 | // to the internal structure rather than a copy of the address this function should only 39 | // be used when you know that the usage of the returned uint8_t* will be transient and not 40 | // stored. 41 | uint8_t* raw_address() { return _address.bytes; }; 42 | 43 | public: 44 | // Constructors 45 | LIGHTNING_DLL_API IPAddress(); 46 | LIGHTNING_DLL_API IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 47 | LIGHTNING_DLL_API IPAddress(uint32_t address); 48 | LIGHTNING_DLL_API IPAddress(const uint8_t *address); 49 | 50 | LIGHTNING_DLL_API bool fromString(const char *address); 51 | LIGHTNING_DLL_API bool fromString(const String &address) { return fromString(address.c_str()); } 52 | 53 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 54 | // to a four-byte uint8_t array is expected 55 | LIGHTNING_DLL_API operator uint32_t() const { return _address.dword; }; 56 | LIGHTNING_DLL_API bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; 57 | LIGHTNING_DLL_API bool operator==(const uint8_t* addr) const; 58 | 59 | // Overloaded index operator to allow getting and setting individual octets of the address 60 | LIGHTNING_DLL_API uint8_t operator[](int index) const { return _address.bytes[index]; }; 61 | LIGHTNING_DLL_API uint8_t& operator[](int index) { return _address.bytes[index]; }; 62 | 63 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 64 | LIGHTNING_DLL_API IPAddress& operator=(const uint8_t *address); 65 | LIGHTNING_DLL_API IPAddress& operator=(uint32_t address); 66 | 67 | LIGHTNING_DLL_API virtual size_t printTo(Print& p) const; 68 | 69 | friend class EthernetClass; 70 | friend class UDP; 71 | friend class Client; 72 | friend class Server; 73 | friend class DhcpClass; 74 | friend class DNSClient; 75 | }; 76 | 77 | const IPAddress INADDR_NONE(0,0,0,0); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /SDKFromArduino/include/LiquidCrystal.h: -------------------------------------------------------------------------------- 1 | #ifndef LiquidCrystal_h 2 | #define LiquidCrystal_h 3 | 4 | #include 5 | #include "Print.h" 6 | #include "Lightning.h" 7 | 8 | // commands 9 | #define LCD_CLEARDISPLAY 0x01 10 | #define LCD_RETURNHOME 0x02 11 | #define LCD_ENTRYMODESET 0x04 12 | #define LCD_DISPLAYCONTROL 0x08 13 | #define LCD_CURSORSHIFT 0x10 14 | #define LCD_FUNCTIONSET 0x20 15 | #define LCD_SETCGRAMADDR 0x40 16 | #define LCD_SETDDRAMADDR 0x80 17 | 18 | // flags for display entry mode 19 | #define LCD_ENTRYRIGHT 0x00 20 | #define LCD_ENTRYLEFT 0x02 21 | #define LCD_ENTRYSHIFTINCREMENT 0x01 22 | #define LCD_ENTRYSHIFTDECREMENT 0x00 23 | 24 | // flags for display on/off control 25 | #define LCD_DISPLAYON 0x04 26 | #define LCD_DISPLAYOFF 0x00 27 | #define LCD_CURSORON 0x02 28 | #define LCD_CURSOROFF 0x00 29 | #define LCD_BLINKON 0x01 30 | #define LCD_BLINKOFF 0x00 31 | 32 | // flags for display/cursor shift 33 | #define LCD_DISPLAYMOVE 0x08 34 | #define LCD_CURSORMOVE 0x00 35 | #define LCD_MOVERIGHT 0x04 36 | #define LCD_MOVELEFT 0x00 37 | 38 | // flags for function set 39 | #define LCD_8BITMODE 0x10 40 | #define LCD_4BITMODE 0x00 41 | #define LCD_2LINE 0x08 42 | #define LCD_1LINE 0x00 43 | #define LCD_5x10DOTS 0x04 44 | #define LCD_5x8DOTS 0x00 45 | 46 | class LiquidCrystal : public Print { 47 | public: 48 | LIGHTNING_DLL_API LiquidCrystal(uint8_t rs, uint8_t enable, 49 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 50 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 51 | LIGHTNING_DLL_API LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, 52 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 53 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 54 | LIGHTNING_DLL_API LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, 55 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 56 | LIGHTNING_DLL_API LiquidCrystal(uint8_t rs, uint8_t enable, 57 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 58 | 59 | LIGHTNING_DLL_API void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 60 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 61 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 62 | 63 | LIGHTNING_DLL_API void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 64 | 65 | LIGHTNING_DLL_API void clear(); 66 | LIGHTNING_DLL_API void home(); 67 | 68 | LIGHTNING_DLL_API void noDisplay(); 69 | LIGHTNING_DLL_API void display(); 70 | LIGHTNING_DLL_API void noBlink(); 71 | LIGHTNING_DLL_API void blink(); 72 | LIGHTNING_DLL_API void noCursor(); 73 | LIGHTNING_DLL_API void cursor(); 74 | LIGHTNING_DLL_API void scrollDisplayLeft(); 75 | LIGHTNING_DLL_API void scrollDisplayRight(); 76 | LIGHTNING_DLL_API void leftToRight(); 77 | LIGHTNING_DLL_API void rightToLeft(); 78 | LIGHTNING_DLL_API void autoscroll(); 79 | LIGHTNING_DLL_API void noAutoscroll(); 80 | 81 | LIGHTNING_DLL_API void setRowOffsets(int row1, int row2, int row3, int row4); 82 | LIGHTNING_DLL_API void createChar(uint8_t, uint8_t[]); 83 | LIGHTNING_DLL_API void setCursor(uint8_t, uint8_t); 84 | LIGHTNING_DLL_API virtual size_t write(uint8_t); 85 | LIGHTNING_DLL_API void command(uint8_t); 86 | 87 | using Print::write; 88 | private: 89 | void send(uint8_t, uint8_t); 90 | void write4bits(uint8_t); 91 | void write8bits(uint8_t); 92 | void pulseEnable(); 93 | 94 | uint8_t _rs_pin; // LOW: command. HIGH: character. 95 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. 96 | uint8_t _enable_pin; // activated by a HIGH pulse. 97 | uint8_t _data_pins[8]; 98 | 99 | uint8_t _displayfunction; 100 | uint8_t _displaycontrol; 101 | uint8_t _displaymode; 102 | 103 | uint8_t _initialized; 104 | 105 | uint8_t _numlines; 106 | uint8_t _row_offsets[4]; 107 | }; 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /SDKFromArduino/include/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #include "WString.h" 27 | #include "Printable.h" 28 | #include "Lightning.h" 29 | 30 | #define DEC 10 31 | #define HEX 16 32 | #define OCT 8 33 | #define BIN 2 34 | 35 | class Print 36 | { 37 | private: 38 | int write_error; 39 | size_t printNumber(unsigned long, uint8_t); 40 | size_t printFloat(double, uint8_t); 41 | void writeBufferToDebugOutput(const uint8_t *buffer, size_t size); 42 | void writeStringToDebugOutput(const char *str); 43 | protected: 44 | bool write_debug_output; 45 | void setWriteError(int err = 1) { write_error = err; } 46 | public: 47 | Print() : write_error(0), write_debug_output(true) {} 48 | 49 | int getWriteError() { return write_error; } 50 | void clearWriteError() { setWriteError(0); } 51 | 52 | virtual size_t write(uint8_t) = 0; 53 | size_t write(const char *str) { 54 | if (str == NULL) return 0; 55 | if (write_debug_output) 56 | writeStringToDebugOutput(str); 57 | return write((const uint8_t *)str, strlen(str)); 58 | } 59 | virtual size_t write(const uint8_t *buffer, size_t size); 60 | size_t write(const char *buffer, size_t size) { 61 | if (write_debug_output) 62 | writeBufferToDebugOutput((const uint8_t *)buffer, size); 63 | return write((const uint8_t *)buffer, size); 64 | } 65 | 66 | void enablePrintDebugOutput(bool isEnabled) { 67 | write_debug_output = isEnabled; 68 | } 69 | 70 | LIGHTNING_DLL_API size_t print(const __FlashStringHelper *); 71 | LIGHTNING_DLL_API size_t print(const String &); 72 | LIGHTNING_DLL_API size_t print(const char[]); 73 | LIGHTNING_DLL_API size_t print(char); 74 | LIGHTNING_DLL_API size_t print(unsigned char, int = DEC); 75 | LIGHTNING_DLL_API size_t print(int, int = DEC); 76 | LIGHTNING_DLL_API size_t print(unsigned int, int = DEC); 77 | LIGHTNING_DLL_API size_t print(long, int = DEC); 78 | LIGHTNING_DLL_API size_t print(unsigned long, int = DEC); 79 | LIGHTNING_DLL_API size_t print(double, int = 2); 80 | LIGHTNING_DLL_API size_t print(const Printable&); 81 | 82 | LIGHTNING_DLL_API size_t println(const __FlashStringHelper *); 83 | LIGHTNING_DLL_API size_t println(const String &s); 84 | LIGHTNING_DLL_API size_t println(const char[]); 85 | LIGHTNING_DLL_API size_t println(char); 86 | LIGHTNING_DLL_API size_t println(unsigned char, int = DEC); 87 | LIGHTNING_DLL_API size_t println(int, int = DEC); 88 | LIGHTNING_DLL_API size_t println(unsigned int, int = DEC); 89 | LIGHTNING_DLL_API size_t println(long, int = DEC); 90 | LIGHTNING_DLL_API size_t println(unsigned long, int = DEC); 91 | LIGHTNING_DLL_API size_t println(double, int = 2); 92 | LIGHTNING_DLL_API size_t println(const Printable&); 93 | LIGHTNING_DLL_API size_t println(void); 94 | }; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /SDKFromArduino/include/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable 34 | { 35 | public: 36 | virtual size_t printTo(Print& p) const = 0; 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /SDKFromArduino/include/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server : public Print { 26 | public: 27 | virtual void begin() =0; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /SDKFromArduino/include/Stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Stepper.h - Stepper library for Wiring/Arduino - Version 1.1.0 3 | * 4 | * Original library (0.1) by Tom Igoe. 5 | * Two-wire modifications (0.2) by Sebastian Gassner 6 | * Combination version (0.3) by Tom Igoe and David Mellis 7 | * Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley 8 | * High-speed stepping mod by Eugene Kozlenko 9 | * Timer rollover fix by Eugene Kozlenko 10 | * Five phase five wire (1.1.0) by Ryan Orendorff 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | * 26 | * 27 | * Drives a unipolar, bipolar, or five phase stepper motor. 28 | * 29 | * When wiring multiple stepper motors to a microcontroller, you quickly run 30 | * out of output pins, with each motor requiring 4 connections. 31 | * 32 | * By making use of the fact that at any time two of the four motor coils are 33 | * the inverse of the other two, the number of control connections can be 34 | * reduced from 4 to 2 for the unipolar and bipolar motors. 35 | * 36 | * A slightly modified circuit around a Darlington transistor array or an 37 | * L293 H-bridge connects to only 2 microcontroler pins, inverts the signals 38 | * received, and delivers the 4 (2 plus 2 inverted ones) output signals 39 | * required for driving a stepper motor. Similarly the Arduino motor shields 40 | * 2 direction pins may be used. 41 | * 42 | * The sequence of control signals for 5 phase, 5 control wires is as follows: 43 | * 44 | * Step C0 C1 C2 C3 C4 45 | * 1 0 1 1 0 1 46 | * 2 0 1 0 0 1 47 | * 3 0 1 0 1 1 48 | * 4 0 1 0 1 0 49 | * 5 1 1 0 1 0 50 | * 6 1 0 0 1 0 51 | * 7 1 0 1 1 0 52 | * 8 1 0 1 0 0 53 | * 9 1 0 1 0 1 54 | * 10 0 0 1 0 1 55 | * 56 | * The sequence of control signals for 4 control wires is as follows: 57 | * 58 | * Step C0 C1 C2 C3 59 | * 1 1 0 1 0 60 | * 2 0 1 1 0 61 | * 3 0 1 0 1 62 | * 4 1 0 0 1 63 | * 64 | * The sequence of controls signals for 2 control wires is as follows 65 | * (columns C1 and C2 from above): 66 | * 67 | * Step C0 C1 68 | * 1 0 1 69 | * 2 1 1 70 | * 3 1 0 71 | * 4 0 0 72 | * 73 | * The circuits can be found at 74 | * 75 | * http://www.arduino.cc/en/Tutorial/Stepper 76 | */ 77 | 78 | // ensure this library description is only included once 79 | #ifndef Stepper_h 80 | #define Stepper_h 81 | 82 | // library interface description 83 | class Stepper { 84 | public: 85 | // constructors: 86 | LIGHTNING_DLL_API Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2); 87 | LIGHTNING_DLL_API Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, 88 | int motor_pin_3, int motor_pin_4); 89 | LIGHTNING_DLL_API Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, 90 | int motor_pin_3, int motor_pin_4, 91 | int motor_pin_5); 92 | 93 | // speed setter method: 94 | LIGHTNING_DLL_API void setSpeed(long whatSpeed); 95 | 96 | // mover method: 97 | LIGHTNING_DLL_API void step(int number_of_steps); 98 | 99 | LIGHTNING_DLL_API int version(void); 100 | 101 | private: 102 | void stepMotor(int this_step); 103 | 104 | int direction; // Direction of rotation 105 | unsigned long step_delay; // delay between steps, in ms, based on speed 106 | int number_of_steps; // total number of steps this motor can take 107 | int pin_count; // how many pins are in use. 108 | int step_number; // which step the motor is on 109 | 110 | // motor pin numbers: 111 | int motor_pin_1; 112 | int motor_pin_2; 113 | int motor_pin_3; 114 | int motor_pin_4; 115 | int motor_pin_5; // Only 5 phase motor 116 | 117 | unsigned long last_step_time; // time stamp in us of when the last step was taken 118 | }; 119 | 120 | #endif 121 | 122 | -------------------------------------------------------------------------------- /SDKFromArduino/include/Udp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Udp.cpp: Library to send/receive UDP packets. 3 | * 4 | * NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these) 5 | * 1) UDP does not guarantee the order in which assembled UDP packets are received. This 6 | * might not happen often in practice, but in larger network topologies, a UDP 7 | * packet can be received out of sequence. 8 | * 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being 9 | * aware of it. Again, this may not be a concern in practice on small local networks. 10 | * For more information, see http://www.cafeaulait.org/course/week12/35.html 11 | * 12 | * MIT License: 13 | * Copyright (c) 2008 Bjoern Hartmann 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * bjoern@cs.stanford.edu 12/30/2008 33 | */ 34 | 35 | #ifndef udp_h 36 | #define udp_h 37 | 38 | #include 39 | #include 40 | 41 | class UDP : public Stream { 42 | 43 | public: 44 | virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 45 | virtual void stop() =0; // Finish with the UDP socket 46 | 47 | // Sending UDP packets 48 | 49 | // Start building up a packet to send to the remote host specific in ip and port 50 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 51 | virtual int beginPacket(IPAddress ip, uint16_t port) =0; 52 | // Start building up a packet to send to the remote host specific in host and port 53 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 54 | virtual int beginPacket(const char *host, uint16_t port) =0; 55 | // Finish off this packet and send it 56 | // Returns 1 if the packet was sent successfully, 0 if there was an error 57 | virtual int endPacket() =0; 58 | // Write a single byte into the packet 59 | virtual size_t write(uint8_t) =0; 60 | // Write size bytes from buffer into the packet 61 | virtual size_t write(const uint8_t *buffer, size_t size) =0; 62 | 63 | // Start processing the next available incoming packet 64 | // Returns the size of the packet in bytes, or 0 if no packets are available 65 | virtual int parsePacket() =0; 66 | // Number of bytes remaining in the current packet 67 | virtual int available() =0; 68 | // Read a single byte from the current packet 69 | virtual int read() =0; 70 | // Read up to len bytes from the current packet and place them into buffer 71 | // Returns the number of bytes read, or 0 if none are available 72 | virtual int read(unsigned char* buffer, size_t len) =0; 73 | // Read up to len characters from the current packet and place them into buffer 74 | // Returns the number of characters read, or 0 if none are available 75 | virtual int read(char* buffer, size_t len) =0; 76 | // Return the next byte from the current packet without moving on to the next byte 77 | virtual int peek() =0; 78 | virtual void flush() =0; // Finish reading the current packet 79 | 80 | // Return the IP address of the host who sent the current incoming packet 81 | virtual IPAddress remoteIP() =0; 82 | // Return the port of the host who sent the current incoming packet 83 | virtual uint16_t remotePort() =0; 84 | protected: 85 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 86 | }; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /SDKFromArduino/include/WCharacter.h: -------------------------------------------------------------------------------- 1 | /* 2 | WCharacter.h - Character utility functions for Wiring & Arduino 3 | Copyright (c) 2010 Hernando Barragan. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Character_h 21 | #define Character_h 22 | 23 | #include 24 | 25 | // WCharacter.h prototypes 26 | inline boolean isAlphaNumeric(int c) __attribute__((always_inline)); 27 | inline boolean isAlpha(int c) __attribute__((always_inline)); 28 | inline boolean isAscii(int c) __attribute__((always_inline)); 29 | inline boolean isWhitespace(int c) __attribute__((always_inline)); 30 | inline boolean isControl(int c) __attribute__((always_inline)); 31 | inline boolean isDigit(int c) __attribute__((always_inline)); 32 | inline boolean isGraph(int c) __attribute__((always_inline)); 33 | inline boolean isLowerCase(int c) __attribute__((always_inline)); 34 | inline boolean isPrintable(int c) __attribute__((always_inline)); 35 | inline boolean isPunct(int c) __attribute__((always_inline)); 36 | inline boolean isSpace(int c) __attribute__((always_inline)); 37 | inline boolean isUpperCase(int c) __attribute__((always_inline)); 38 | inline boolean isHexadecimalDigit(int c) __attribute__((always_inline)); 39 | inline int toAscii(int c) __attribute__((always_inline)); 40 | inline int toLowerCase(int c) __attribute__((always_inline)); 41 | inline int toUpperCase(int c)__attribute__((always_inline)); 42 | 43 | 44 | // Checks for an alphanumeric character. 45 | // It is equivalent to (isalpha(c) || isdigit(c)). 46 | inline boolean isAlphaNumeric(int c) 47 | { 48 | return ( isalnum(c) == 0 ? false : true); 49 | } 50 | 51 | 52 | // Checks for an alphabetic character. 53 | // It is equivalent to (isupper(c) || islower(c)). 54 | inline boolean isAlpha(int c) 55 | { 56 | return ( isalpha(c) == 0 ? false : true); 57 | } 58 | 59 | 60 | // Checks whether c is a 7-bit unsigned char value 61 | // that fits into the ASCII character set. 62 | inline boolean isAscii(int c) 63 | { 64 | return ( isascii (c) == 0 ? false : true); 65 | } 66 | 67 | 68 | // Checks for a blank character, that is, a space or a tab. 69 | inline boolean isWhitespace(int c) 70 | { 71 | return ( isblank (c) == 0 ? false : true); 72 | } 73 | 74 | 75 | // Checks for a control character. 76 | inline boolean isControl(int c) 77 | { 78 | return ( iscntrl (c) == 0 ? false : true); 79 | } 80 | 81 | 82 | // Checks for a digit (0 through 9). 83 | inline boolean isDigit(int c) 84 | { 85 | return ( isdigit (c) == 0 ? false : true); 86 | } 87 | 88 | 89 | // Checks for any printable character except space. 90 | inline boolean isGraph(int c) 91 | { 92 | return ( isgraph (c) == 0 ? false : true); 93 | } 94 | 95 | 96 | // Checks for a lower-case character. 97 | inline boolean isLowerCase(int c) 98 | { 99 | return (islower (c) == 0 ? false : true); 100 | } 101 | 102 | 103 | // Checks for any printable character including space. 104 | inline boolean isPrintable(int c) 105 | { 106 | return ( isprint (c) == 0 ? false : true); 107 | } 108 | 109 | 110 | // Checks for any printable character which is not a space 111 | // or an alphanumeric character. 112 | inline boolean isPunct(int c) 113 | { 114 | return ( ispunct (c) == 0 ? false : true); 115 | } 116 | 117 | 118 | // Checks for white-space characters. For the avr-libc library, 119 | // these are: space, formfeed ('\f'), newline ('\n'), carriage 120 | // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). 121 | inline boolean isSpace(int c) 122 | { 123 | return ( isspace (c) == 0 ? false : true); 124 | } 125 | 126 | 127 | // Checks for an uppercase letter. 128 | inline boolean isUpperCase(int c) 129 | { 130 | return ( isupper (c) == 0 ? false : true); 131 | } 132 | 133 | 134 | // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 135 | // 8 9 a b c d e f A B C D E F. 136 | inline boolean isHexadecimalDigit(int c) 137 | { 138 | return ( isxdigit (c) == 0 ? false : true); 139 | } 140 | 141 | 142 | // Converts c to a 7-bit unsigned char value that fits into the 143 | // ASCII character set, by clearing the high-order bits. 144 | inline int toAscii(int c) 145 | { 146 | return toascii (c); 147 | } 148 | 149 | 150 | // Warning: 151 | // Many people will be unhappy if you use this function. 152 | // This function will convert accented letters into random 153 | // characters. 154 | 155 | // Converts the letter c to lower case, if possible. 156 | inline int toLowerCase(int c) 157 | { 158 | return tolower (c); 159 | } 160 | 161 | 162 | // Converts the letter c to upper case, if possible. 163 | inline int toUpperCase(int c) 164 | { 165 | return toupper (c); 166 | } 167 | 168 | #endif -------------------------------------------------------------------------------- /SDKFromArduino/source/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.cpp - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | IPAddress::IPAddress() 24 | { 25 | _address.dword = 0; 26 | } 27 | 28 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 29 | { 30 | _address.bytes[0] = first_octet; 31 | _address.bytes[1] = second_octet; 32 | _address.bytes[2] = third_octet; 33 | _address.bytes[3] = fourth_octet; 34 | } 35 | 36 | IPAddress::IPAddress(uint32_t address) 37 | { 38 | _address.dword = address; 39 | } 40 | 41 | IPAddress::IPAddress(const uint8_t *address) 42 | { 43 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 44 | } 45 | 46 | bool IPAddress::fromString(const char *address) 47 | { 48 | // TODO: add support for "a", "a.b", "a.b.c" formats 49 | 50 | uint16_t acc = 0; // Accumulator 51 | uint8_t dots = 0; 52 | 53 | while (*address) 54 | { 55 | char c = *address++; 56 | if (c >= '0' && c <= '9') 57 | { 58 | acc = acc * 10 + (c - '0'); 59 | if (acc > 255) { 60 | // Value out of [0..255] range 61 | return false; 62 | } 63 | } 64 | else if (c == '.') 65 | { 66 | if (dots == 3) { 67 | // Too much dots (there must be 3 dots) 68 | return false; 69 | } 70 | _address.bytes[dots++] = (uint8_t)(acc & 0xFF); 71 | acc = 0; 72 | } 73 | else 74 | { 75 | // Invalid char 76 | return false; 77 | } 78 | } 79 | 80 | if (dots != 3) { 81 | // Too few dots (there must be 3 dots) 82 | return false; 83 | } 84 | _address.bytes[3] = (uint8_t)(acc & 0xFF); 85 | return true; 86 | } 87 | 88 | IPAddress& IPAddress::operator=(const uint8_t *address) 89 | { 90 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 91 | return *this; 92 | } 93 | 94 | IPAddress& IPAddress::operator=(uint32_t address) 95 | { 96 | _address.dword = address; 97 | return *this; 98 | } 99 | 100 | bool IPAddress::operator==(const uint8_t* addr) const 101 | { 102 | return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; 103 | } 104 | 105 | size_t IPAddress::printTo(Print& p) const 106 | { 107 | size_t n = 0; 108 | for (int i =0; i < 3; i++) 109 | { 110 | n += p.print(_address.bytes[i], DEC); 111 | n += p.print('.'); 112 | } 113 | n += p.print(_address.bytes[3], DEC); 114 | return n; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /WinSDK.extcomp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $/Xbox/XES/SDKs/Win10 6 | 10586 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | cd %~dp0 4 | 5 | if /i "%1"=="help" goto help 6 | if /i "%1"=="--help" goto help 7 | if /i "%1"=="-help" goto help 8 | if /i "%1"=="/help" goto help 9 | if /i "%1"=="?" goto help 10 | if /i "%1"=="-?" goto help 11 | if /i "%1"=="--?" goto help 12 | if /i "%1"=="/?" goto help 13 | 14 | @rem Process arguments. 15 | set config= 16 | set target=Build 17 | set noprojgen= 18 | set nobuild= 19 | set run= 20 | set vs_toolset=x86 21 | 22 | 23 | :next-arg 24 | if "%1"=="" goto args-done 25 | if /i "%1"=="debug" set config=Debug&goto arg-ok 26 | if /i "%1"=="release" set config=Release&goto arg-ok 27 | if /i "%1"=="clean" set target=Clean&goto arg-ok 28 | if /i "%1"=="nobuild" set nobuild=1&goto arg-ok 29 | :arg-ok 30 | shift 31 | goto next-arg 32 | :args-done 33 | 34 | if defined WindowsSDKDir goto select-target 35 | if defined VCINSTALLDIR goto select-target 36 | 37 | @rem Look for Visual Studio 2015 38 | if not defined VS140COMNTOOLS goto vc-set-2013 39 | if not exist "%VS140COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2013 40 | call "%VS140COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset% 41 | set GYP_MSVS_VERSION=2015 42 | echo Using Visual Studio 2015 43 | goto select-target 44 | 45 | :vc-set-2013 46 | @rem Look for Visual Studio 2013 47 | if not defined VS120COMNTOOLS goto vc-set-2012 48 | if not exist "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2012 49 | call "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset% 50 | set GYP_MSVS_VERSION=2013 51 | echo Using Visual Studio 2013 52 | goto select-target 53 | 54 | :vc-set-2012 55 | @rem Look for Visual Studio 2012 56 | if not defined VS110COMNTOOLS goto vc-set-2010 57 | if not exist "%VS110COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2010 58 | call "%VS110COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset% 59 | set GYP_MSVS_VERSION=2012 60 | echo Using Visual Studio 2012 61 | goto select-target 62 | 63 | :vc-set-2010 64 | @rem Look for Visual Studio 2010 65 | if not defined VS100COMNTOOLS goto vc-set-2008 66 | if not exist "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2008 67 | call "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset% 68 | set GYP_MSVS_VERSION=2010 69 | echo Using Visual Studio 2010 70 | goto select-target 71 | 72 | :vc-set-2008 73 | @rem Look for Visual Studio 2008 74 | if not defined VS90COMNTOOLS goto vc-set-notfound 75 | if not exist "%VS90COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-notfound 76 | call "%VS90COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset% 77 | set GYP_MSVS_VERSION=2008 78 | echo Using Visual Studio 2008 79 | goto select-target 80 | 81 | :vc-set-notfound 82 | echo Warning: Visual Studio not found 83 | 84 | :select-target 85 | if not "%config%"=="" goto msbuild 86 | set config=Release 87 | 88 | :msbuild 89 | @rem Skip project generation if requested. 90 | if defined nobuild goto pack 91 | 92 | @rem Check if VS build env is available 93 | if defined VCINSTALLDIR goto msbuild-found 94 | if defined WindowsSDKDir goto msbuild-found 95 | echo Build skipped. To build, this file needs to run from VS cmd prompt. 96 | goto run 97 | 98 | @rem Build the sln with msbuild. 99 | :msbuild-found 100 | msbuild Library\Lightning.sln /m /t:%target% /p:Configuration=%config% /p:Platform=ARM /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo 101 | if errorlevel 1 exit /b 1 102 | msbuild Library\Lightning.sln /m /t:%target% /p:Configuration=%config% /p:Platform=x86 /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo 103 | if errorlevel 1 exit /b 1 104 | msbuild Library\Lightning.sln /m /t:%target% /p:Configuration=%config% /p:Platform=x64 /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo 105 | if errorlevel 1 exit /b 1 106 | 107 | :pack 108 | cd Nuget 109 | 110 | if not "%config%"=="Debug" goto releasebuild 111 | CALL build-nupkg.cmd /debug 112 | cd .. 113 | goto exit 114 | 115 | :releasebuild 116 | CALL build-nupkg.cmd 117 | cd .. 118 | goto :exit 119 | 120 | :help 121 | echo build.bat [debug/release] [clean] [nobuild] 122 | echo Examples: 123 | echo build.bat : builds release build 124 | echo build.bat debug : builds debug build 125 | echo build.bat nobuild : Create nuget only 126 | goto exit 127 | 128 | :exit 129 | -------------------------------------------------------------------------------- /images/Add_SDK_Extensions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/images/Add_SDK_Extensions.png -------------------------------------------------------------------------------- /images/Not_Using_Precompiled_Headers_VS2015.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/images/Not_Using_Precompiled_Headers_VS2015.png -------------------------------------------------------------------------------- /images/Nuget_PackageManager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/images/Nuget_PackageManager.png -------------------------------------------------------------------------------- /images/Nuget_PackageSourceConfig_VS2015.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/images/Nuget_PackageSourceConfig_VS2015.png -------------------------------------------------------------------------------- /images/Nuget_TemplateConfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/images/Nuget_TemplateConfig.png -------------------------------------------------------------------------------- /images/Update_Manifest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/images/Update_Manifest.png -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Open Technologies, Inc. Licensed under the BSD 2-Clause License. 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 5 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 6 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /source/.gitignore: -------------------------------------------------------------------------------- 1 | nupkg/ 2 | *.nupkg 3 | nuget.exe 4 | -------------------------------------------------------------------------------- /source/Adc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef _ADC_H_ 6 | #define _ADC_H_ 7 | 8 | #include 9 | #include "ADS1015Support.h" 10 | #include "MCP3008support.h" 11 | 12 | class AdcClass 13 | { 14 | public: 15 | /// Constructor. 16 | AdcClass() 17 | { 18 | m_boardType = BoardPinsClass::BOARD_TYPE::NOT_SET; 19 | } 20 | 21 | /// Destructor. 22 | virtual ~AdcClass() 23 | { 24 | if (m_boardType == BoardPinsClass::BOARD_TYPE::MBM_IKA_LURE) 25 | { 26 | m_ikaLureAdc.end(); 27 | } 28 | else if (m_boardType == BoardPinsClass::BOARD_TYPE::MBM_BARE) 29 | { 30 | m_addOnAdc.end(); 31 | } 32 | else if (m_boardType == BoardPinsClass::BOARD_TYPE::PI2_BARE) 33 | { 34 | m_addOnAdc.end(); 35 | } 36 | } 37 | 38 | /// Take a reading with the ADC on the board. 39 | /** 40 | This method assumes the pin number passed in has been verified to be within 41 | the range of analog inputs. 42 | \param[in] pin Number of GPIO pin to read with the ADC. 43 | \param[out] value The value read from the ADC. 44 | \param[out] bits The size of the reading in "value" in bits. 45 | \return HRESULT success or error code. 46 | */ 47 | inline HRESULT readValue(ULONG pin, ULONG & value, ULONG & bits) 48 | { 49 | HRESULT hr = S_OK; 50 | 51 | ULONG channel; 52 | 53 | 54 | // Translate the pin number passed in to analog channel 0-5. 55 | // This calculation is based on the fact that all the ADCs we work with 56 | // have A0-An mapped to channels 0-n on the ADC. 57 | channel = pin - A0; 58 | 59 | // Verify we have initialized the correct ADC. 60 | hr = _verifyAdcInitialized(); 61 | 62 | if (SUCCEEDED(hr)) 63 | { 64 | if (m_boardType == BoardPinsClass::BOARD_TYPE::MBM_IKA_LURE) 65 | { 66 | hr = m_ikaLureAdc.readValue(channel, value, bits); 67 | } 68 | else if (m_boardType == BoardPinsClass::BOARD_TYPE::MBM_BARE) 69 | { 70 | hr = m_addOnAdc.readValue(channel, value, bits); 71 | } 72 | else if (m_boardType == BoardPinsClass::BOARD_TYPE::PI2_BARE) 73 | { 74 | hr = m_addOnAdc.readValue(channel, value, bits); 75 | } 76 | } 77 | 78 | return hr; 79 | } 80 | 81 | private: 82 | 83 | /// The board type for which this object has been initialized. 84 | BoardPinsClass::BOARD_TYPE m_boardType; 85 | 86 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) // If building a Win32 app: 87 | /// Gen2 ADC device. 88 | ADC108S102Device m_gen2Adc; 89 | 90 | /// Gen1 ADC device. 91 | AD7298Device m_gen1Adc; 92 | #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 93 | 94 | ADS1015Device m_ikaLureAdc; 95 | 96 | MCP3008Device m_addOnAdc; 97 | 98 | /// Initialize this object if it has not already been done. 99 | inline HRESULT _verifyAdcInitialized() 100 | { 101 | HRESULT hr = S_OK; 102 | 103 | 104 | // If the ADC has not yet been initialized: 105 | if (m_boardType == BoardPinsClass::BOARD_TYPE::NOT_SET) 106 | { 107 | // Get the board generation. 108 | hr = g_pins.getBoardType(m_boardType); 109 | 110 | if (SUCCEEDED(hr)) 111 | { 112 | if (m_boardType == BoardPinsClass::BOARD_TYPE::MBM_IKA_LURE) 113 | { 114 | hr = m_ikaLureAdc.begin(); 115 | } 116 | else if (m_boardType == BoardPinsClass::BOARD_TYPE::MBM_BARE) 117 | { 118 | hr = m_addOnAdc.begin(); 119 | } 120 | else if (m_boardType == BoardPinsClass::BOARD_TYPE::PI2_BARE) 121 | { 122 | hr = m_addOnAdc.begin(); 123 | } 124 | else 125 | { 126 | // If we have an unrecognized board or one that does not support ADC, 127 | // indicate ADC is uninitialized. 128 | m_boardType = BoardPinsClass::BOARD_TYPE::NOT_SET; 129 | } 130 | } 131 | } 132 | 133 | 134 | return hr; 135 | } 136 | 137 | }; 138 | 139 | /// Global object used to access the A-to-D converter. 140 | LIGHTNING_DLL_API extern AdcClass g_adc; 141 | 142 | #endif // _ADC_H_ -------------------------------------------------------------------------------- /source/ArduinoCommon.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef _ARDUINO_COMMON_H_ 6 | #define _ARDUINO_COMMON_H_ 7 | 8 | #include 9 | 10 | const UCHAR LOW = 0x00; 11 | const UCHAR HIGH = 0x01; 12 | 13 | const UCHAR DIRECTION_IN = 0x00; 14 | const UCHAR DIRECTION_OUT = 0x01; 15 | const UCHAR INPUT_PULLUP = 0x02; 16 | 17 | // INPUT pin mode 18 | #define INPUT DIRECTION_IN 19 | 20 | // OUTPUT pin mode 21 | #define OUTPUT DIRECTION_OUT 22 | 23 | const UCHAR LSBFIRST = 0x00; 24 | const UCHAR MSBFIRST = 0x01; 25 | 26 | const UCHAR NUM_ARDUINO_PINS = 20; 27 | 28 | const UCHAR RISING = 0x01; 29 | const UCHAR FALLING = 0x02; 30 | const UCHAR CHANGE = 0x03; 31 | 32 | const UCHAR NOT_AN_INTERRUPT = 0xFF; 33 | 34 | // Pin name to number mapping. 35 | const UCHAR D0 = 0; 36 | const UCHAR D1 = 1; 37 | const UCHAR D2 = 2; 38 | const UCHAR D3 = 3; 39 | const UCHAR D4 = 4; 40 | const UCHAR D5 = 5; 41 | const UCHAR D6 = 6; 42 | const UCHAR D7 = 7; 43 | const UCHAR D8 = 8; 44 | const UCHAR D9 = 9; 45 | const UCHAR D10 = 10; 46 | const UCHAR D11 = 11; 47 | const UCHAR D12 = 12; 48 | const UCHAR D13 = 13; 49 | 50 | const UCHAR A0 = 14; 51 | const UCHAR A1 = 15; 52 | const UCHAR A2 = 16; 53 | const UCHAR A3 = 17; 54 | const UCHAR A4 = 18; 55 | const UCHAR A5 = 19; 56 | const UCHAR A6 = 20; 57 | const UCHAR A7 = 21; 58 | 59 | // Pseudo pin numbers used PWM "pins" on off-board PWM chips. 60 | const UCHAR PWM0 = 50; 61 | const UCHAR PWM1 = 51; 62 | const UCHAR PWM2 = 52; 63 | const UCHAR PWM3 = 53; 64 | const UCHAR PWM4 = 54; 65 | const UCHAR PWM5 = 55; 66 | const UCHAR PWM6 = 56; 67 | const UCHAR PWM7 = 57; 68 | const UCHAR PWM8 = 58; 69 | const UCHAR PWM9 = 59; 70 | const UCHAR PWM10 = 60; 71 | const UCHAR PWM11 = 61; 72 | const UCHAR PWM12 = 62; 73 | const UCHAR PWM13 = 63; 74 | const UCHAR PWM14 = 64; 75 | const UCHAR PWM15 = 65; 76 | 77 | // SPI signal to pin mapping for Arduino compatible pin configuration. 78 | const UCHAR ARDUINO_PIN_CS0 = D10; ///< Pin used for Arduino SPI Chip Select 79 | const UCHAR ARDUINO_PIN_MOSI = D11; ///< Pin used for Arduino SPI MOSI signal 80 | const UCHAR ARDUINO_PIN_MISO = D12; ///< Pin used for Arduino SPI MISO signal 81 | const UCHAR ARDUINO_PIN_SCK = D13; ///< Pin used for Arduino SPI Clock signal 82 | 83 | // SPI signal to pin mapping for bare MBM. 84 | const UCHAR MBM_PIN_MISO = 7; ///< Pin used for MBM SPI MISO signal 85 | const UCHAR MBM_PIN_MOSI = 9; ///< Pin used for MBM SPI MOSI signal 86 | const UCHAR MBM_PIN_SCK = 11; ///< Pin used for MBM SPI Clock signal 87 | const UCHAR MBM_PIN_CS0 = 5; ///< Pin used for MBM SPI Chip select 88 | 89 | // SPI signal to pin mapping for bare PI2 SPI0. 90 | const UCHAR PI2_PIN_SPI0_MISO = 21; ///< Pin used for PI2 SPI0 MISO signal 91 | const UCHAR PI2_PIN_SPI0_MOSI = 19; ///< Pin used for PI2 SPI0 MOSI signal 92 | const UCHAR PI2_PIN_SPI0_SCK = 23; ///< Pin used for PI2 SPI0 Clock signal 93 | const UCHAR PI2_PIN_SPI0_CS0 = 24; ///< Pin used for PI2 SPI0 Chip select 0 94 | const UCHAR PI2_PIN_SPI0_CS1 = 26; ///< Pin used for PI2 SPI0 Chip select 1 95 | 96 | // SPI signal to pin mapping for bare PI2 SPI1. 97 | const UCHAR PI2_PIN_SPI1_MISO = 35; ///< Pin used for PI2 SPI1 MISO signal 98 | const UCHAR PI2_PIN_SPI1_MOSI = 38; ///< Pin used for PI2 SPI1 MOSI signal 99 | const UCHAR PI2_PIN_SPI1_SCK = 40; ///< Pin used for PI2 SPI1 Clock signal 100 | 101 | // I2C signal to pin mapping for Arduino pin configuration. 102 | const UCHAR ARDUINO_PIN_I2C_DAT = A4; ///< Pin used for Arduino I2C Data signal 103 | const UCHAR ARDUINO_PIN_I2C_CLK = A5; ///< Pin used for Arduino I2C Clock signal 104 | 105 | // I2C signal to pin mapping for MBM 26-pin connector. 106 | const UCHAR BARE_MBM_PIN_I2C_DAT = 15; ///< Pin used for MBM I2C Data signal 107 | const UCHAR BARE_MBM_PIN_I2C_CLK = 13; ///< Pin used for MBM I2C Clock signal 108 | 109 | // I2C signal to pin mapping for PI2 I2C1 40-pin connector. 110 | const UCHAR BARE_PI2_PIN_I2C1_DAT = 3; ///< Pin used for PI2 I2C1 Data signal 111 | const UCHAR BARE_PI2_PIN_I2C1_CLK = 5; ///< Pin used for PI2 I2C1 Clock signal 112 | 113 | // I2C signal to pin mapping for PI2 I2C0 40-pin connector. 114 | const UCHAR BARE_PI2_PIN_I2C0_DAT = 27; ///< Pin used for PI2 I2C0 Data signal 115 | const UCHAR BARE_PI2_PIN_I2C0_CLK = 28; ///< Pin used for PI2 I2C0 Clock signal 116 | 117 | #endif // _ARDUINO_COMMON_H_ -------------------------------------------------------------------------------- /source/ArduinoError.h: -------------------------------------------------------------------------------- 1 | /** \file ArduinoError.h 2 | * Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 3 | * Licensed under the BSD 2-Clause License. 4 | * See License.txt in the project root for license information. 5 | */ 6 | 7 | #ifndef ARDUINO_ERROR_H 8 | #define ARDUINO_ERROR_H 9 | 10 | #include 11 | #include 12 | 13 | /// \brief The error class for the Arduino 14 | /// \details The Arduino platform does not handle exceptions. This class is 15 | /// necessary to bubble out exceptions generated from the C++ implementation 16 | class _arduino_fatal_error : public std::runtime_error 17 | { 18 | public: 19 | typedef std::runtime_error _Mybase; 20 | 21 | /// \brief The error constructor 22 | /// \param [in] message A contextual message used to help diagnose the error 23 | explicit _arduino_fatal_error(const char *_Message) 24 | : _Mybase(_Message) 25 | { // construct from message string 26 | } 27 | }; 28 | 29 | /// \brief An exception used to exit the Arduino loop 30 | /// \details Typical Arduino sketches loop infinitely, even when errors 31 | /// occur. Such behavior no longer makes sense on an operating system 32 | /// and therefore the ability to exit is provided. 33 | class _arduino_quit_exception : public std::exception { }; 34 | 35 | /// \brief A function provided to allow the user to exit the Arduino sketch 36 | /// \note This is the preferred method to exit a sketch, because it allows 37 | /// for stack unwinding and deconstructors to to be called. 38 | inline void _exit_arduino_loop() 39 | { 40 | throw _arduino_quit_exception(); 41 | } 42 | 43 | /// \brief A wrapper function for _arduino_fatal_error 44 | /// \details Allows a formatted string to be provided, then built and passed 45 | /// along to the _arduino_fatal_error class. 46 | /// \param [in] hr HRESULT of the error 47 | /// \param [in] pszFormat If format includes format specifiers (subsequences 48 | /// beginning with %), the additional arguments following format are formatted 49 | /// and inserted in the resulting string replacing their respective specifiers. 50 | void ThrowError(_In_ HRESULT hr, _In_ _Printf_format_string_ STRSAFE_LPCSTR pszFormat, ...); 51 | 52 | #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) // If building a UWP app: 53 | /// \brief A wrapper function for _arduino_fatal_error 54 | /// \details Allows a formatted string to be provided, then built and passed 55 | /// along to the _arduino_fatal_error class. 56 | /// \param [in] hr HRESULT of the error 57 | /// \param [in] pszFormat If format includes format specifiers (subsequences 58 | /// beginning with %), the additional arguments following format are formatted 59 | /// and inserted in the resulting string replacing their respective specifiers. 60 | void ThrowError(_In_ HRESULT hr, _In_ _Printf_format_string_ STRSAFE_LPCWSTR pszFormat, ...); 61 | #endif // !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /source/DMap.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Module Name: 4 | 5 | DMap.h 6 | 7 | Abstract: 8 | 9 | This module contains the common declarations shared by driver 10 | and user applications. 11 | 12 | Environment: 13 | 14 | user and kernel 15 | 16 | --*/ 17 | #ifndef _DMAP_H_ 18 | #define _DMAP_H_ 19 | 20 | #include 21 | #include "Lightning.h" 22 | 23 | #define DMAP_NAME L"DmapGpio" 24 | 25 | #define DMAP_SYMBOLIC_NAME L"\\DosDevices\\" DMAP_NAME 26 | #define DMAP_USERMODE_PATH L"\\\\.\\" DMAP_NAME 27 | #define DMAP_USERMODE_PATH_SIZE sizeof(DMAP_USERMODE_PATH) 28 | 29 | 30 | // 31 | // Define an Interface Guid so that app can find the device and talk to it. 32 | // {109b86ad-f53d-4b76-aa5f-821e2ddf2141} 33 | // 34 | #define DMAP_INTERFACE {0x109b86ad,0xf53d,0x4b76,0xaa,0x5f,0x82,0x1e,0x2d,0xdf,0x21,0x41} 35 | DEFINE_GUID(GUID_DEVINTERFACE_DMap, 0x109b86ad, 0xf53d, 0x4b76, 0xaa, 0x5f, 0x82, 0x1e, 0x2d, 0xdf, 0x21, 0x41); 36 | 37 | #define FILE_DEVICE_DMAP 0x423 38 | 39 | #define IOCTL_DMAP_MAPMEMORY CTL_CODE(FILE_DEVICE_DMAP, 0x100, METHOD_BUFFERED, FILE_ANY_ACCESS) 40 | #define IOCTL_DMAP_WRITEPORT CTL_CODE(FILE_DEVICE_DMAP, 0x101, METHOD_BUFFERED, FILE_ANY_ACCESS) 41 | #define IOCTL_DMAP_READPORT CTL_CODE(FILE_DEVICE_DMAP, 0x102, METHOD_BUFFERED, FILE_ANY_ACCESS) 42 | #define IOCTL_DMAP_LOCK CTL_CODE(FILE_DEVICE_DMAP, 0x103, METHOD_NEITHER, FILE_ANY_ACCESS) 43 | #define IOCTL_DMAP_UNLOCK CTL_CODE(FILE_DEVICE_DMAP, 0x104, METHOD_NEITHER, FILE_ANY_ACCESS) 44 | #define IOCTL_DMAP_ATTACH_INTERRUPT CTL_CODE(FILE_DEVICE_DMAP, 0x105, METHOD_BUFFERED, FILE_ANY_ACCESS) 45 | #define IOCTL_DMAP_DETACH_INTERRUPT CTL_CODE(FILE_DEVICE_DMAP, 0x106, METHOD_BUFFERED, FILE_ANY_ACCESS) 46 | #define IOCTL_DMAP_WAIT_INTERRUPT CTL_CODE(FILE_DEVICE_DMAP, 0x107, METHOD_BUFFERED, FILE_ANY_ACCESS) 47 | 48 | typedef struct _DMAP_MAPMEMORY_OUTPUT_BUFFER 49 | { 50 | void* Address; 51 | uint32_t Length; 52 | } DMAP_MAPMEMORY_OUTPUT_BUFFER, *PDMAP_MAPMEMORY_OUTPUT_BUFFER; 53 | 54 | // Note: These must be bit fields, the first two of which combine to create the third. 55 | #define DMAP_INTERRUPT_MODE_RISING 0x1 56 | #define DMAP_INTERRUPT_MODE_FALLING 0x2 57 | #define DMAP_INTERRUPT_MODE_EITHER 0x3 58 | 59 | // Struct for the contents of a buffer sent to the driver with IOCTL_DMAP_ATTACH_INTERRUPT 60 | // to request that future state transitions of the given pin generate interrupts. 61 | typedef struct _DMAP_ATTACH_INTERRUPT_BUFFER 62 | { 63 | uint16_t IntNo; // Interrupt number for which to generate interrupts 64 | uint16_t Mode; // Type of pin events that should cause interrupts 65 | } DMAP_ATTACH_INTERRUPT_BUFFER, *PDMAP_ATTACH_INTERRUPT_BUFFER; 66 | 67 | // Struct for the contents of a buffer sent to the driver with IOCTL_DMAP_DETACH_INTERRUPT 68 | // to request that future state transistions of the given pin no longer generate interrupts. 69 | typedef struct _DMAP_DETACH_INTERRUPT_BUFFER 70 | { 71 | uint32_t IntNo; // Interrupt number which interrupts are no longer wanted 72 | } DMAP_DETACH_INTERRUPT_BUFFER, *PDMAP_DETACH_INTERRUPT_BUFFER; 73 | 74 | // Struct for the contents of a buffer sent to the driver with IOCTL_DMAP_WAIT_INTERRUPT 75 | // to request notification for the next (currently queued, or future) interrupt from the 76 | // specified pin. 77 | typedef struct _DMAP_WAIT_INTERRUPT_REQUEST_BUFFER 78 | { 79 | uint32_t IntNo; // Which interrupt to wait for 80 | } DMAP_WAIT_INTERRUPT_REQUEST_BUFFER, *PDMAP_WAIT_INTERRUPT_REQUEST_BUFFER; 81 | 82 | // Struct for the contents of a buffer sent by the driver on completion of an I/O operation 83 | // with IOCTL_DMAP_WAIT_INTERRUPT to notify the waiting thread that an interrupt has occurred. 84 | typedef struct _DMAP_WAIT_INTERRUPT_NOTIFY_BUFFER 85 | { 86 | uint16_t IntNo; // The number of the source for this interrupt 87 | uint16_t NewState; // The new state of the pin after the interrupt event 88 | uint32_t DropCount; // The count of interrupts dropped since the last interrupt notification 89 | uint64_t EventTime; // High resolution timer captured shortly after the pin event 90 | } DMAP_WAIT_INTERRUPT_NOTIFY_BUFFER, *PDMAP_WAIT_INTERRUPT_NOTIFY_BUFFER; 91 | 92 | #endif // #ifndef _DMAP_H_ 93 | -------------------------------------------------------------------------------- /source/DmapSupport.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #pragma once 6 | 7 | #include "DMap.h" 8 | 9 | // Define the device name strings used to access the controllers on the MBM. 10 | #define mbmGpioS0DeviceName L"\\\\.\\ACPI#INT33FC#1#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 11 | #define mbmGpioS5DeviceName L"\\\\.\\ACPI#INT33FC#3#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 12 | #define mbmPwm0DeviceName L"\\\\.\\ACPI#80860F09#1#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 13 | #define mbmPwm1DeviceNmae L"\\\\.\\ACPI#80860F09#2#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 14 | #define mbmSpiDeviceName L"\\\\.\\ACPI#80860F0E#0#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 15 | #define mbmI2cDeviceName L"\\\\.\\ACPI#80860F41#6#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 16 | 17 | // Define the device name strings used to access the controllers on the PI2. 18 | #define pi2Spi0DeviceName L"\\\\.\\ACPI#BCM2838#0#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 19 | #define pi2Spi1DeviceName L"\\\\.\\ACPI#BCM2839#1#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 20 | #define pi2I2c0DeviceName L"\\\\.\\ACPI#BCM2841#0#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 21 | #define pi2I2c1DeviceName L"\\\\.\\ACPI#BCM2841#1#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 22 | #define pi2PwmDeviceName L"\\\\.\\ACPI#BCM2844#0#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 23 | #define pi2GpioDeviceName L"\\\\.\\ACPI#BCM2845#0#{109b86ad-f53d-4b76-aa5f-821e2ddf2141}\\0" 24 | 25 | /// Routine to get the base address of a memory mapped controller with no sharing allowed. 26 | HRESULT GetControllerBaseAddress(PWCHAR deviceName, HANDLE & handle, PVOID & baseAddress); 27 | 28 | /// Routine to get the base address of a memory mapped controller with a sharing specification. 29 | HRESULT GetControllerBaseAddress(PWCHAR deviceName, HANDLE & handle, PVOID & baseAddress, DWORD shareMode); 30 | 31 | /// Routine to close a controller that has previously been opened. 32 | LIGHTNING_DLL_API void DmapCloseController(HANDLE & handle); 33 | 34 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) // If building a Win32 app: 35 | /// Routine to open a controller device in the SOC. 36 | HRESULT OpenControllerDevice(PWCHAR deviceName, HANDLE & handle, DWORD shareMode); 37 | #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 38 | 39 | #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) // If building a UWP app. 40 | HRESULT SendIOControlCodeToController( 41 | HANDLE handle, 42 | Windows::Devices::Custom::IOControlCode^ iOControlCode, 43 | Windows::Storage::Streams::IBuffer^ bufferToDriver, 44 | Windows::Storage::Streams::IBuffer^ bufferFromDriver, 45 | uint32_t timeOutMillis); 46 | HRESULT GetControllerLock(HANDLE & handle); 47 | HRESULT ReleaseControllerLock(HANDLE & handle); 48 | #endif 49 | -------------------------------------------------------------------------------- /source/ExpanderDefs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef _EXPANDER_DEFS_H_ 6 | #define _EXPANDER_DEFS_H_ 7 | 8 | // I/O Expander bit values. 9 | // Note: Values from P0_0 through P1_7 must fit in 4-bits for the 10 | // pin attributes table to work. 11 | #define P0_0 0 12 | #define P0_1 1 13 | #define P0_2 2 14 | #define P0_3 3 15 | #define P0_4 4 16 | #define P0_5 5 17 | #define P0_6 6 18 | #define P0_7 7 19 | 20 | #define P1_0 ((1*8)+0) 21 | #define P1_1 ((1*8)+1) 22 | #define P1_2 ((1*8)+2) 23 | #define P1_3 ((1*8)+3) 24 | #define P1_4 ((1*8)+4) 25 | #define P1_5 ((1*8)+5) 26 | #define P1_6 ((1*8)+6) 27 | #define P1_7 ((1*8)+7) 28 | 29 | #define P2_0 ((2*8)+0) 30 | #define P2_1 ((2*8)+1) 31 | #define P2_2 ((2*8)+2) 32 | #define P2_3 ((2*8)+3) 33 | 34 | #define P3_0 ((3*8)+0) 35 | #define P3_1 ((3*8)+1) 36 | #define P3_2 ((3*8)+2) 37 | #define P3_3 ((3*8)+3) 38 | #define P3_4 ((3*8)+4) 39 | #define P3_5 ((3*8)+5) 40 | #define P3_6 ((3*8)+6) 41 | #define P3_7 ((3*8)+7) 42 | 43 | #define P4_0 ((4*8)+0) 44 | #define P4_1 ((4*8)+1) 45 | #define P4_2 ((4*8)+2) 46 | #define P4_3 ((4*8)+3) 47 | #define P4_4 ((4*8)+4) 48 | #define P4_5 ((4*8)+5) 49 | #define P4_6 ((4*8)+6) 50 | #define P4_7 ((4*8)+7) 51 | 52 | #define P5_0 ((5*8)+0) 53 | #define P5_1 ((5*8)+1) 54 | #define P5_2 ((5*8)+2) 55 | #define P5_3 ((5*8)+3) 56 | 57 | #endif // _EXPANDER_DEFS_H_ -------------------------------------------------------------------------------- /source/GpioInterrupt.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef _GPIO_INTERRUPT_H_ 6 | #define _GPIO_INTERRUPT_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "DMap.h" 12 | 13 | /// Class used to control and receive GPIO interrupts. 14 | class GpioInterruptsClass 15 | { 16 | public: 17 | /// Constructor. 18 | GpioInterruptsClass() 19 | { 20 | m_hIntEnableEvent = CreateEvent(NULL, TRUE, TRUE, L"Local\\DMapIntEvent"); 21 | if (m_hIntEnableEvent == NULL) 22 | { 23 | m_hIntEnableEvent = INVALID_HANDLE_VALUE; 24 | } 25 | } 26 | 27 | /// Destructor. 28 | virtual ~GpioInterruptsClass() 29 | { 30 | if ((m_hIntEnableEvent != INVALID_HANDLE_VALUE) && (m_hIntEnableEvent != NULL)) 31 | { 32 | CloseHandle(m_hIntEnableEvent); 33 | m_hIntEnableEvent = INVALID_HANDLE_VALUE; 34 | } 35 | } 36 | 37 | /// Method to attach to an interrupt on a GPIO port bit. 38 | HRESULT attachInterrupt(ULONG pin, std::function func, ULONG mode, HANDLE hController); 39 | 40 | /// Method to attach to an interrupt on a GPIO port bit with information return. 41 | HRESULT attachInterruptEx(ULONG pin, std::function func, ULONG mode, HANDLE hController); 42 | 43 | /// Method to attach to an interrupt on a GPIO port bit with information return. 44 | HRESULT attachInterruptContext(ULONG pin, std::function func, PVOID context, ULONG mode, HANDLE hController); 45 | 46 | /// Method to detach an interrupt for a GPIO port bit. 47 | HRESULT detachInterrupt(ULONG pin, HANDLE hController); 48 | 49 | /// Method to enable delivery of GPIO interrupts. 50 | inline HRESULT enableInterrupts() 51 | { 52 | HRESULT hr = S_OK; 53 | if (SetEvent(m_hIntEnableEvent) == 0) 54 | { 55 | hr = HRESULT_FROM_WIN32(GetLastError()); 56 | } 57 | return hr; 58 | } 59 | 60 | /// Method to disable delivery of GPIO interrupts. 61 | inline HRESULT disableInterrupts() 62 | { 63 | HRESULT hr = S_OK; 64 | if (ResetEvent(m_hIntEnableEvent) == 0) 65 | { 66 | hr = HRESULT_FROM_WIN32(GetLastError()); 67 | } 68 | return hr; 69 | } 70 | 71 | private: 72 | 73 | /// Handle to the event used to enable and disable interrupt delivery. 74 | /** 75 | The event represented by this handle is set to the signaled state to enable interrupts. 76 | */ 77 | HANDLE m_hIntEnableEvent; 78 | 79 | // 80 | // GpioInterruptsClass private methods. 81 | // 82 | }; 83 | 84 | #endif // _GPIO_INTERRUPT_H_ 85 | -------------------------------------------------------------------------------- /source/HiResTimer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef _HI_RES_TIMER_H_ 6 | #define _HI_RES_TIMER_H_ 7 | 8 | #include 9 | 10 | /// Class that is used to work with the system high resolution timer. 11 | class HiResTimerClass 12 | { 13 | public: 14 | /// Constructor. 15 | HiResTimerClass() 16 | { 17 | QueryPerformanceFrequency(&m_frequency); 18 | m_startReading.QuadPart = 0; 19 | m_targetReading.QuadPart = 0; 20 | } 21 | 22 | /// Destructor. 23 | virtual ~HiResTimerClass() 24 | { 25 | m_frequency.QuadPart = 0; 26 | } 27 | 28 | /// Method to start a timeout. 29 | /** 30 | \param[in] microseconds The desired timeout time. 31 | */ 32 | inline void StartTimeout(ULONG microseconds) 33 | { 34 | LARGE_INTEGER nowTime = { 0 }; 35 | 36 | QueryPerformanceCounter(&nowTime); 37 | m_targetReading.QuadPart = (((LONGLONG)microseconds) * m_frequency.QuadPart) + 500000LL; 38 | m_targetReading.QuadPart = m_targetReading.QuadPart / 1000000LL; 39 | m_targetReading.QuadPart = m_targetReading.QuadPart + nowTime.QuadPart; 40 | } 41 | 42 | /// Method to determine whether the timeout has expired or not. 43 | /** 44 | This method returns TRUE if a previously started timeout interval is up. 45 | */ 46 | inline BOOL TimeIsUp() 47 | { 48 | LARGE_INTEGER nowTime; 49 | QueryPerformanceCounter(&nowTime); 50 | return (nowTime.QuadPart >= m_targetReading.QuadPart); 51 | } 52 | 53 | private: 54 | 55 | /// The high resolution timer frequencey on this system. 56 | LARGE_INTEGER m_frequency; 57 | 58 | /// The timer reading when the timer was started. 59 | LARGE_INTEGER m_startReading; 60 | 61 | /// The target timer reading. 62 | LARGE_INTEGER m_targetReading; 63 | }; 64 | 65 | #endif // _HI_RES_TIMER_H_ -------------------------------------------------------------------------------- /source/I2c.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #include "pch.h" 6 | 7 | #include "I2c.h" 8 | #include "BoardPins.h" 9 | #include "BcmI2cController.h" 10 | #include "BtI2cController.h" 11 | #include "HiResTimer.h" 12 | 13 | 14 | // 15 | // Global extern exports 16 | // 17 | I2cClass g_i2c(EXTERNAL_I2C_BUS); 18 | I2cClass g_i2c2nd(SECOND_EXTERNAL_I2C_BUS); 19 | 20 | // 21 | // I2cClass methods. 22 | // 23 | 24 | /// Prepare to use the I2C controller associated with this object. 25 | HRESULT I2cClass::begin() 26 | { 27 | HRESULT hr; 28 | BoardPinsClass::BOARD_TYPE board; 29 | 30 | EnterCriticalSection(&m_lock); 31 | 32 | hr = g_pins.getBoardType(board); 33 | 34 | // Create and initialize the I2C Controller object if we don't already have one. 35 | if (m_controller == nullptr) 36 | { 37 | switch (board) 38 | { 39 | case BoardPinsClass::BOARD_TYPE::PI2_BARE: 40 | m_controller = new BcmI2cControllerClass; 41 | if (m_busNumber == SECOND_EXTERNAL_I2C_BUS) 42 | { 43 | hr = m_controller->configurePins(BARE_PI2_PIN_I2C0_DAT, BARE_PI2_PIN_I2C0_CLK); 44 | } 45 | else 46 | { 47 | hr = m_controller->configurePins(BARE_PI2_PIN_I2C1_DAT, BARE_PI2_PIN_I2C1_CLK); 48 | } 49 | break; 50 | case BoardPinsClass::BOARD_TYPE::MBM_BARE: 51 | case BoardPinsClass::BOARD_TYPE::MBM_IKA_LURE: 52 | m_controller = new BtI2cControllerClass; 53 | hr = m_controller->configurePins(BARE_MBM_PIN_I2C_DAT, BARE_MBM_PIN_I2C_CLK); 54 | break; 55 | default: 56 | hr = DMAP_E_BOARD_TYPE_NOT_RECOGNIZED; 57 | } 58 | } 59 | 60 | hr = m_controller->begin(m_busNumber); 61 | 62 | if (SUCCEEDED(hr)) 63 | { 64 | m_refCount++; 65 | } 66 | 67 | LeaveCriticalSection(&m_lock); 68 | 69 | return hr; 70 | } 71 | 72 | /// Finish using the I2C controller associated with this object. 73 | void I2cClass::end() 74 | { 75 | EnterCriticalSection(&m_lock); 76 | 77 | if (m_refCount > 0) 78 | { 79 | m_refCount--; 80 | if (m_refCount == 0) 81 | { 82 | delete m_controller; 83 | m_controller = nullptr; 84 | } 85 | } 86 | 87 | LeaveCriticalSection(&m_lock); 88 | } 89 | -------------------------------------------------------------------------------- /source/I2c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef _I2C_H_ 6 | #define _I2C_H_ 7 | 8 | #include "I2cController.h" 9 | 10 | 11 | // 12 | // Base class for classes used to interact with I2C Controller hardware. 13 | // 14 | class I2cClass 15 | { 16 | public: 17 | I2cClass(ULONG busNumber) : 18 | m_sdaPin(0xFFFFFFFF), 19 | m_sclPin(0xFFFFFFFF), 20 | m_busNumber(busNumber), 21 | m_controller(nullptr), 22 | m_refCount(0) 23 | { 24 | InitializeCriticalSection(&m_lock); 25 | } 26 | 27 | virtual ~I2cClass() 28 | { 29 | DeleteCriticalSection(&m_lock); 30 | } 31 | 32 | /// Prepare to use the I2C controller associated with this object. 33 | LIGHTNING_DLL_API HRESULT begin(); 34 | 35 | /// Finish using the I2C controller associated with this object. 36 | LIGHTNING_DLL_API void end(); 37 | 38 | /// Method to get the address of the I2C Controller object. 39 | I2cControllerClass* getController() 40 | { 41 | if (m_controller == nullptr) 42 | { 43 | begin(); 44 | } 45 | return m_controller; 46 | } 47 | 48 | protected: 49 | 50 | /// I2C Serial Data pin number. 51 | ULONG m_sdaPin; 52 | 53 | /// I2C Serial Clock pin number. 54 | ULONG m_sclPin; 55 | 56 | private: 57 | 58 | // 59 | // I2cControllerClass private data members. 60 | // 61 | 62 | /// The bus number for the I2C Controller associated with this object. 63 | ULONG m_busNumber; 64 | 65 | /// The object we use to talk to the I2C Controller. 66 | I2cControllerClass* m_controller; 67 | 68 | /// Count of how many times this object is currently open by this process. 69 | LONG m_refCount; 70 | 71 | /// Lock used to serialize opening and closing the controller. 72 | RTL_CRITICAL_SECTION m_lock; 73 | }; 74 | 75 | /// The global object for the main I2C bus. 76 | LIGHTNING_DLL_API extern I2cClass g_i2c; 77 | 78 | /// The global object for the secondary I2C bus. 79 | LIGHTNING_DLL_API extern I2cClass g_i2c2nd; 80 | 81 | #endif // _I2C_H_ -------------------------------------------------------------------------------- /source/I2cController.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #include "pch.h" 6 | 7 | #include "I2c.h" 8 | #include "BoardPins.h" 9 | #include "HiResTimer.h" 10 | 11 | // 12 | // I2cControllerClass methods. 13 | // 14 | 15 | // This method returns the esternal I2C bus pins to their default configurations. 16 | HRESULT I2cControllerClass::revertPinsToGpio() 17 | { 18 | HRESULT hr = S_OK; 19 | HRESULT tmpHr = S_OK; 20 | 21 | if (m_sclPin != INVALID_PIN_NUMBER) 22 | { 23 | hr = g_pins.verifyPinFunction(m_sclPin, FUNC_DIO, BoardPinsClass::UNLOCK_FUNCTION); 24 | if (SUCCEEDED(hr)) 25 | { 26 | m_sclPin = INVALID_PIN_NUMBER; 27 | } 28 | } 29 | 30 | if (m_sdaPin != INVALID_PIN_NUMBER) 31 | { 32 | tmpHr = g_pins.verifyPinFunction(m_sdaPin, FUNC_DIO, BoardPinsClass::UNLOCK_FUNCTION); 33 | if (SUCCEEDED(hr)) 34 | { 35 | hr = tmpHr; 36 | m_sdaPin = INVALID_PIN_NUMBER; 37 | } 38 | } 39 | 40 | return hr; 41 | } 42 | 43 | 44 | // This method maps the I2C controller if needed. 45 | HRESULT I2cControllerClass::mapIfNeeded() 46 | { 47 | if (m_hController == INVALID_HANDLE_VALUE) 48 | { 49 | return _mapController(); 50 | } 51 | else 52 | { 53 | return S_OK; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /source/Lightning.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Common Lightning macros and declarations 4 | 5 | #if defined(LIGHTNING_DLL_EXPORTS) && !defined(LIGHTNING_DLL_API) 6 | #define LIGHTNING_DLL_API __declspec(dllexport) 7 | #elif !defined(LIGHTNING_DLL_API) 8 | #define LIGHTNING_DLL_API __declspec(dllimport) 9 | #endif 10 | -------------------------------------------------------------------------------- /source/MuxDefs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/source/MuxDefs.h -------------------------------------------------------------------------------- /source/NetworkSerial.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | 6 | #include "pch.h" 7 | 8 | #ifdef USE_NETWORKSERIAL 9 | #include "arduino.h" 10 | #include "NetworkSerial.h" 11 | #include 12 | #include 13 | 14 | // Need to link with Ws2_32.lib 15 | #pragma comment (lib, "Ws2_32.lib") 16 | 17 | #define DEFAULT_BUFLEN sizeof(uint8_t) 18 | 19 | // Network serial listens for connections on a specified port 20 | // By default, we chose 27015, but it can be any open port. 21 | // To specify a port, define NETWORK_SERIAL_PORT= in your project 22 | #ifndef NETWORKSERIAL_PORT 23 | #define NETWORKSERIAL_PORT 27015 24 | #endif 25 | 26 | #define NETWORKSERIAL_PORT_S STRINGIFY_MACRO(NETWORKSERIAL_PORT) 27 | 28 | NetworkSerial::NetworkSerial() 29 | : _listenSocket(INVALID_SOCKET) 30 | , _clientSocket(INVALID_SOCKET) 31 | { 32 | 33 | } 34 | 35 | void NetworkSerial::begin(unsigned long) 36 | { 37 | WSADATA wsaData; 38 | struct addrinfo *result = NULL; 39 | struct addrinfo hints = { 0 }; 40 | 41 | int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); 42 | if (iResult != 0) 43 | { 44 | printf("WSAStartup failed with error: %d\n", iResult); 45 | goto Exit; 46 | } 47 | ZeroMemory(&hints, sizeof(hints)); 48 | hints.ai_family = AF_INET; 49 | hints.ai_socktype = SOCK_STREAM; 50 | hints.ai_protocol = IPPROTO_TCP; 51 | hints.ai_flags = AI_PASSIVE; 52 | 53 | // Resolve the server address and port 54 | iResult = getaddrinfo(NULL, NETWORKSERIAL_PORT_S, &hints, &result); 55 | if (iResult != 0) 56 | { 57 | printf("getaddrinfo failed with error: %d\n", iResult); 58 | WSACleanup(); 59 | goto Exit; 60 | } 61 | 62 | // Create a SOCKET for connecting to server 63 | _listenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); 64 | if (_listenSocket == INVALID_SOCKET) 65 | { 66 | printf("socket failed with error: %ld\n", WSAGetLastError()); 67 | freeaddrinfo(result); 68 | WSACleanup(); 69 | goto Exit; 70 | } 71 | 72 | // Setup the TCP listening socket 73 | iResult = bind(_listenSocket, result->ai_addr, (int)result->ai_addrlen); 74 | if (iResult == SOCKET_ERROR) 75 | { 76 | printf("bind failed with error: %d\n", WSAGetLastError()); 77 | freeaddrinfo(result); 78 | closesocket(_listenSocket); 79 | WSACleanup(); 80 | goto Exit; 81 | } 82 | 83 | freeaddrinfo(result); 84 | 85 | iResult = listen(_listenSocket, SOMAXCONN); 86 | if (iResult == SOCKET_ERROR) 87 | { 88 | printf("listen failed with error: %d\n", WSAGetLastError()); 89 | closesocket(_listenSocket); 90 | WSACleanup(); 91 | goto Exit; 92 | } 93 | 94 | // Accept a client socket 95 | _clientSocket = accept(_listenSocket, NULL, NULL); 96 | if (_clientSocket == INVALID_SOCKET) 97 | { 98 | printf("accept failed with error: %d\n", WSAGetLastError()); 99 | closesocket(_listenSocket); 100 | WSACleanup(); 101 | goto Exit; 102 | } 103 | 104 | // No longer need server socket 105 | closesocket(_listenSocket); 106 | 107 | Exit: 108 | ; 109 | } 110 | 111 | int NetworkSerial::available(void) 112 | { 113 | unsigned char recvbuf; 114 | int recvbuflen = sizeof(recvbuf); 115 | int iResult = recv(_clientSocket, (char*)&recvbuf, recvbuflen, MSG_PEEK); 116 | return iResult > 0; 117 | } 118 | 119 | int NetworkSerial::read(void) 120 | { 121 | unsigned char recvbuf; 122 | int recvbuflen = sizeof(recvbuf); 123 | int iResult = recv(_clientSocket, (char*)&recvbuf, recvbuflen, 0); 124 | if (iResult > 0) 125 | { 126 | return (int)recvbuf; 127 | } 128 | else 129 | { 130 | begin(0); 131 | int iResult = recv(_clientSocket, (char*)&recvbuf, recvbuflen, 0); 132 | if (iResult > 0) 133 | { 134 | return (int)recvbuf; 135 | } 136 | } 137 | 138 | return 0; 139 | } 140 | 141 | size_t NetworkSerial::write(const uint8_t *buffer, size_t size) 142 | { 143 | // Echo the buffer back to the sender 144 | int iSendResult = send(_clientSocket, (const char*)buffer, size, 0); 145 | if (iSendResult == SOCKET_ERROR) 146 | { 147 | begin(0); 148 | return send(_clientSocket, (const char*)buffer, size, 0); 149 | } 150 | else 151 | { 152 | return iSendResult; 153 | } 154 | } 155 | 156 | 157 | NetworkSerial Serial; 158 | #endif 159 | -------------------------------------------------------------------------------- /source/NetworkSerial.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #pragma once 6 | #include "Stream.h" 7 | 8 | class NetworkSerial : public Stream 9 | { 10 | private: 11 | SOCKET _listenSocket = INVALID_SOCKET; 12 | SOCKET _clientSocket = INVALID_SOCKET; 13 | 14 | public: 15 | NetworkSerial(); 16 | void begin(unsigned long); 17 | virtual int available(void); 18 | virtual int read(void); 19 | virtual int peek() { return 0; } 20 | virtual void flush() { } 21 | virtual size_t write(uint8_t c) 22 | { 23 | return write(&c, 1); 24 | } 25 | 26 | virtual size_t write(const uint8_t *buffer, size_t size); 27 | }; 28 | 29 | extern NetworkSerial Serial; -------------------------------------------------------------------------------- /source/PCA9685Support.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef _PCA9685_SUPPORT_H_ 6 | #define _PCA9685_SUPPORT_H_ 7 | 8 | #include 9 | 10 | class PCA9685Device 11 | { 12 | public: 13 | 14 | /// Set a PWM chip output to constant on or constant off. 15 | static HRESULT SetBitState(ULONG i2cAdr, ULONG bit, ULONG state); 16 | 17 | /// Get the current state of a PWM chip output. 18 | static HRESULT GetBitState(ULONG i2cAdr, ULONG bit, ULONG & state); 19 | 20 | /// Set the PWM pulse width. 21 | static HRESULT SetPwmDutyCycle(ULONG i2cAdr, ULONG bit, ULONG pulseWidth); 22 | 23 | /// Set the PWM pulse repetition rate. 24 | static HRESULT SetPwmFrequency(ULONG i2cAdr, ULONG frequencyHz); 25 | 26 | /// Get the actual PWM pulse repetition rate. 27 | static ULONG GetActualPwmFrequency(ULONG i2cAdr); 28 | 29 | /// Method to get the resolution of this PWM chip. 30 | static ULONG GetResolution() 31 | { 32 | return PWM_BITS; 33 | } 34 | 35 | private: 36 | static const ULONG PWM_BITS; ///< Number of bits of resolution this PWM chip has 37 | static const ULONG MODE1_ADR; ///< Address of MODE1 register 38 | static const ULONG MODE2_ADR; ///< Address of MODE2 register 39 | static const ULONG SUBADR1_ADR; ///< Address of SUBADR1 register 40 | static const ULONG SUBADR2_ADR; //< Address of SUBADR2 register 41 | static const ULONG SUBADR3_ADR; ///< Address of SUBADR3 register 42 | static const ULONG ALLCALLADR_ADR; ///< Address of ALLCALLADR register 43 | static const ULONG LEDS_BASE_ADR; ///< Base address of LED output registers 44 | static const ULONG REGS_PER_LED; ///< Number of registers for each LED 45 | static const ULONG PRE_SCALE_ADR; ///< Address of frequency prescale register 46 | static const ULONG TestMode_ADR; ///< Address of TestMode register 47 | static const ULONG LED_COUNT; ///< Number of LEDs supported by PWM chip 48 | 49 | /// Struct with the layout of the PWM chip MODE1 register. 50 | typedef struct { 51 | UCHAR ALLCALL : 1; ///< 0: don't respond to LED all call address, 1: respond 52 | UCHAR SUB3 : 1; ///< 0: don't respond to sub-address 3, 1: respond 53 | UCHAR SUB2 : 1; ///< 0: don't respond to sub-address 2, 1: respond 54 | UCHAR SUB1 : 1; ///< 0: don't respond to sub-address 1, 1: respond 55 | UCHAR SLEEP : 1; ///< 0: normal operation, 1: sleep (oscillator off) 56 | UCHAR AI : 1; ///< 0: auto-increment address disabled, 1: enabled 57 | UCHAR EXTCLK : 1; ///< 0: use internal 25mhz clock, 1: use external clock 58 | UCHAR RESTART : 1; ///< 0: restart disabled, 1: restart enabled 59 | } MODE1, *PMODE1; 60 | 61 | /// Struct with the layout of the PWM chip MODE2 register. 62 | typedef struct { 63 | UCHAR OUTNE : 2; ///< Effect of _OE_ high (NA here, we wire _OE_ low) 64 | UCHAR OUTDRV : 1; ///< 0: outputs pull low, float high, 1: drive high & low 65 | UCHAR OCH : 1; ///< 0: outputs change on I2C STOP, 1: change on I2C ACK 66 | UCHAR INVRT : 1; ///< 0: outputs as written, 1: invert outputs 67 | UCHAR _rsv : 3; ///< Reserved 68 | } MODE2, *PMODE2; 69 | 70 | /// Constructor. 71 | PCA9685Device() 72 | { 73 | } 74 | 75 | /// Copy constructor. 76 | PCA9685Device(PCA9685Device&) 77 | { 78 | } 79 | 80 | /// Destructor. 81 | virtual ~PCA9685Device() 82 | { 83 | } 84 | 85 | // If/when multiple PCA9685 chips are supported, the data unique to the chip 86 | // should be indexed by I2C address. 87 | 88 | /// Set to TRUE when the chip is known to have been initialized. 89 | static BOOL m_chipIsInitialized; 90 | 91 | /// The current PWM pulse rate pre-scale value for all channels. 92 | static UCHAR m_freqPreScale; 93 | 94 | /// Method to take any necessary actions to initialize the PWM chip. 95 | static HRESULT _InitializeChip(ULONG i2cAdr); 96 | }; 97 | 98 | #endif // _PCA9685_SUPPORT_H_ -------------------------------------------------------------------------------- /source/PulseIn.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #include "pch.h" 6 | 7 | #include "Arduino.h" 8 | #include "PulseIn.h" 9 | 10 | ////////////////////////////////////////////////////////////////////////////////////////////////// 11 | 12 | unsigned long pulseIn(int iPin, int iValue, unsigned long ulTimeout) 13 | { 14 | // 15 | // start and end times 16 | // 17 | 18 | unsigned long ulStartTime = 0; 19 | unsigned long ulEndTime = 0; 20 | 21 | // 22 | // start the timer 23 | // 24 | 25 | ulStartTime = micros(); 26 | 27 | // 28 | // clear out the non desired reads to find the start of the pulese (LOW if iValue is HIGH, HIGH if iValue is LOW) 29 | // 30 | 31 | while (LOW == iValue ? HIGH == digitalRead(iPin) : LOW == digitalRead(iPin)) 32 | { 33 | // 34 | // with each cycle, see if we have waited longer then the designated timeout 35 | // 36 | 37 | ulEndTime = micros(); 38 | 39 | if (_Duration(ulStartTime, ulEndTime) > ulTimeout) 40 | { 41 | // 42 | // in the case of a timeout, the duration needs to be 0 43 | // 44 | 45 | ulStartTime = 0; 46 | ulEndTime = 0; 47 | 48 | // 49 | // this was a timeout expected error, so end the function 50 | // 51 | 52 | goto CleanUp; 53 | } 54 | } 55 | 56 | // 57 | // start the timer 58 | // 59 | 60 | ulStartTime = micros(); 61 | 62 | // 63 | // keep looping until the recieve pin is not high anymore 64 | // 65 | 66 | while (iValue == digitalRead(iPin)) 67 | { 68 | // 69 | // no code here 70 | // 71 | } 72 | 73 | // 74 | // get the amount of time the recieve pin was the expected value 75 | // 76 | 77 | ulEndTime = micros(); 78 | 79 | CleanUp: 80 | 81 | // 82 | // return the pulse length duration, compensating for timer overflow 83 | // 84 | 85 | return _Duration(ulStartTime, ulEndTime); 86 | } 87 | 88 | ////////////////////////////////////////////////////////////////////////////////////////////////// 89 | 90 | unsigned long _Duration(unsigned long ulStartTime, unsigned long ulEndTime) 91 | { 92 | unsigned long ulCurrentTime = 0; 93 | unsigned long ulDuration = 0; 94 | 95 | // 96 | // see if the there was a timer overflow 97 | // 98 | 99 | if (ulEndTime < ulStartTime) 100 | { 101 | // 102 | // there was a timer overflow, so compensate 103 | // 104 | 105 | ulCurrentTime = ULONG_MAX - ulStartTime; 106 | ulDuration = ulEndTime + ulCurrentTime; 107 | } 108 | else 109 | { 110 | // 111 | // calculate the final duration 112 | // 113 | 114 | ulDuration = ulEndTime - ulStartTime; 115 | } 116 | 117 | // 118 | // return the calculated duration 119 | // 120 | 121 | return ulDuration; 122 | } 123 | -------------------------------------------------------------------------------- /source/PulseIn.h: -------------------------------------------------------------------------------- 1 | /** \file pulsein.h 2 | * Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 3 | * Licensed under the BSD 2-Clause License. 4 | * See License.txt in the project root for license information. 5 | */ 6 | 7 | #pragma once 8 | 9 | /// \brief Time the duration of the pulse in microseconds 10 | /// \details Read a pulse on a pin(HIGH or LOW), and returns the duration of 11 | /// the pulse in microseconds. Returns 0 if the timeout is exceeded while 12 | /// waiting for a pulse. 13 | /// \param [in] iPin Pin number to read the pulse 14 | /// \param [in] iValue Pulse to read: HIGH or LOW 15 | /// \param [in] [ulTimeout] Wait time, in microseconds, for pulse start; 1 second default 16 | /// \return The duration of the pulse in microseconds 17 | /// \see origin: Arduino::pulseIn 18 | unsigned long pulseIn(int iPin, int iValue, unsigned long ulTimeout = 1000000UL); 19 | 20 | /// \brief Calculates the duration between start and end time in microseconds 21 | /// \param [in] ulStartTime Start time in microseconds 22 | /// \param [in] ulEndTime End time in microsseconds 23 | /// \return The duration in microseconds 24 | /// \note Compensates for timer overflow. 25 | unsigned long _Duration(unsigned long ulStartTime, unsigned long ulEndTime); 26 | -------------------------------------------------------------------------------- /source/Servo.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #define MIN_PULSE_WIDTH 544 6 | #define MAX_PULSE_WIDTH 2400 7 | #define DEFAULT_PULSE_WIDTH 1500 8 | #define REFRESH_INTERVAL 20000 // 20 ms 9 | 10 | // Use a pulse rate of 50 pulses per second to drive servos 11 | #define SERVO_FREQUENCY_HZ 50 12 | 13 | class Servo 14 | { 15 | private: 16 | int _attachedPin; 17 | int _min; 18 | int _max; 19 | ULONG _currentPulseMicroseconds; 20 | ULONG _actualPeriodMicroseconds; 21 | 22 | public: 23 | Servo(); 24 | void attach(int pin); 25 | void attach(int pin, int min, int max); 26 | void detach(); 27 | void write(int angle); 28 | void writeMicroseconds(int value); 29 | int read(); 30 | inline ULONG readMicroseconds(); 31 | inline bool attached(); 32 | 33 | }; 34 | 35 | /// Determine if attach() has been called successfully for this servo object. 36 | /** 37 | \return True if this object is attached, False otherwise. 38 | */ 39 | inline bool Servo::attached() 40 | { 41 | return (_attachedPin != -1); 42 | } 43 | 44 | /// Get the currently set pulse width in microseconds. 45 | /// \return the last pulse width that was set, in microseconds. 46 | inline ULONG Servo::readMicroseconds() 47 | { 48 | return _currentPulseMicroseconds; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /source/Spi.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #include "pch.h" 6 | 7 | #include "Spi.h" 8 | 9 | // 10 | // Global extern exports 11 | // 12 | SPIClass SPI; 13 | 14 | -------------------------------------------------------------------------------- /source/WInterrupt.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #include "arduino.h" 6 | 7 | using namespace std; 8 | 9 | //! Tracks interrupts assigned to a specific pin 10 | // Used to track pin number, mode, state and callback function. 11 | struct InterruptTracker 12 | { 13 | int pin; 14 | int mode; 15 | int lastState; 16 | InterruptFunction fxn; 17 | 18 | InterruptTracker(int p, InterruptFunction f, int m) 19 | : pin(p) 20 | , fxn(f) 21 | , mode(m) 22 | { 23 | // snap the state of the pin at create time. 24 | lastState = digitalRead(pin); 25 | } 26 | 27 | ~InterruptTracker() 28 | { 29 | } 30 | 31 | void handle() 32 | { 33 | int currentState = digitalRead(pin); 34 | 35 | switch (mode) 36 | { 37 | // Callback is executed as long as the condition is low 38 | case LOW: 39 | if (currentState == LOW) 40 | { 41 | fxn(); 42 | } 43 | break; 44 | 45 | // Callback is executed when the pin changes state 46 | case CHANGE: 47 | if (currentState != lastState) 48 | { 49 | fxn(); 50 | } 51 | break; 52 | 53 | // Callback is executed when the pin changes from LOW to HIGH 54 | case RISING: 55 | if (lastState == LOW && currentState == HIGH) 56 | { 57 | fxn(); 58 | } 59 | break; 60 | 61 | // Callback is executed when the pin changes from HIGH to LOW 62 | case FALLING: 63 | if (lastState == HIGH && currentState == LOW) 64 | { 65 | fxn(); 66 | } 67 | break; 68 | } 69 | 70 | lastState = currentState; 71 | } 72 | }; 73 | 74 | typedef std::map > InterruptPinMap; 75 | static InterruptPinMap s_interruptMap; 76 | static HANDLE s_sharedInterruptTimer = INVALID_HANDLE_VALUE; 77 | 78 | //! At a fixed frequency (INTERRUPT_FREQUENCY), this callback will iterate through outstanding fake 'interrupts' 79 | //! test the condition and call the callback. 80 | static void CALLBACK InterruptTimerHandler(void* arg, DWORD, DWORD) 81 | { 82 | UNREFERENCED_PARAMETER(arg); 83 | // During an interrupt handler, the caller can call detachInterrupt which modifies the list. 84 | // To handle this, we'll copy the list. 85 | std::vector> list; 86 | 87 | for (auto p : s_interruptMap) 88 | { 89 | list.push_back(p.second); 90 | } 91 | 92 | for (auto tracker : list) 93 | { 94 | tracker->handle(); 95 | } 96 | } 97 | 98 | void attachInterrupt(uint8_t pin, InterruptFunction fxn, int mode) 99 | { 100 | if (s_sharedInterruptTimer == INVALID_HANDLE_VALUE) 101 | { 102 | s_sharedInterruptTimer = CreateWaitableTimerEx(NULL, NULL, 0, TIMER_ALL_ACCESS); 103 | 104 | LARGE_INTEGER li = { 0 }; 105 | if (SetWaitableTimer(s_sharedInterruptTimer, &li, INTERRUPT_FREQUENCY, InterruptTimerHandler, nullptr, FALSE) == 0) 106 | { 107 | DWORD err = GetLastError(); 108 | ThrowError(HRESULT_FROM_WIN32(err) , "Error setting timer for interrupts: %d", err); 109 | } 110 | } 111 | 112 | auto it = s_interruptMap.find(pin); 113 | if (it != s_interruptMap.end()) 114 | { 115 | // Changing mode or function? 116 | it->second->fxn = fxn; 117 | it->second->mode = mode; 118 | } 119 | else 120 | { 121 | s_interruptMap[pin] = make_shared(pin, fxn, mode); 122 | } 123 | } 124 | 125 | void detachInterrupt(uint8_t pin) 126 | { 127 | s_interruptMap.erase(pin); 128 | 129 | if (s_interruptMap.size() == 0) 130 | { 131 | if (s_sharedInterruptTimer != INVALID_HANDLE_VALUE) 132 | { 133 | CancelWaitableTimer(s_sharedInterruptTimer); 134 | CloseHandle(s_sharedInterruptTimer); 135 | s_sharedInterruptTimer = INVALID_HANDLE_VALUE; 136 | } 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /source/WInterrupt.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | 6 | #pragma once 7 | 8 | typedef void (*InterruptFunction)(void); 9 | 10 | //! Default interrupt update frequency 11 | //! NOTE: We will tune this based on feedback 12 | //! If you have a specific scenario where you need finer grained interrupt handling, 13 | //! you can change this in the project settings by adding INTERRUPT_FREQUENCY=; 14 | //! to the preprocessor definitions 15 | #ifndef INTERRUPT_FREQUENCY 16 | #define INTERRUPT_FREQUENCY 100 17 | #endif 18 | 19 | 20 | //! noInterrupts 21 | //! stubbed as this does nothing 22 | inline void noInterrupts() 23 | { 24 | 25 | } 26 | 27 | //! interrupts 28 | //! stubbed as this does nothing 29 | inline void interrupts() 30 | { 31 | 32 | } 33 | 34 | //! Attach Fake Interrupt to a pin 35 | //! Hardware interrupts are not currently implemented. This function will set up a fake interrupt handler 36 | //! using a polling mechanism. 37 | //! \param pin - pin to attach an interrupt to 38 | //! \param fxn - funcion to call 39 | //! \param mode - one of 40 | //! * LOW - triggers whenever the pin is low 41 | //! * CHANGE - triggers when the pin changes value 42 | //! * RISING - triggers when the pin changes from low to high 43 | //! * FALLING - triggers when the pin changes from high to low 44 | void attachInterrupt(uint8_t pin, InterruptFunction fxn, int mode); 45 | 46 | //! Detatch Fake Interrupt 47 | //! Disables the function for this interrupt 48 | void detachInterrupt(uint8_t pin); 49 | -------------------------------------------------------------------------------- /source/WindowsRandom.h: -------------------------------------------------------------------------------- 1 | /** \file windowsrandom.h 2 | * Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 3 | * Licensed under the BSD 2-Clause License. 4 | * See License.txt in the project root for license information. 5 | */ 6 | 7 | #ifndef WINDOWS_RANDOM_H 8 | #define WINDOWS_RANDOM_H 9 | 10 | #include 11 | 12 | /// \brief Helper class to implement the Arduino random functions on Windows 13 | class WindowsRandom 14 | { 15 | private: 16 | std::mt19937 Engine; 17 | std::uniform_int_distribution Distribution; 18 | 19 | public: 20 | WindowsRandom() 21 | { 22 | } 23 | 24 | /// \brief Set seed value for random engine 25 | /// \param [in] seed Engine seed value 26 | void Seed(int seed) 27 | { 28 | Engine.seed(seed); 29 | } 30 | 31 | /// \brief Returns the next random number from the engine 32 | long Next() 33 | { 34 | return Distribution(Engine); 35 | } 36 | }; 37 | 38 | __declspec(selectany) WindowsRandom _WindowsRandom; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /source/WindowsTime.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms-iot/lightning/2742f7fc08787bb4b5a0fdc459ff9c14ae546280/source/WindowsTime.h -------------------------------------------------------------------------------- /source/avr/interrupt.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef INTERRUPT_H 6 | #define INTERRUPT_H 7 | 8 | /* 9 | * The avr/interrupt.h file providies a placeholder 10 | * necessary for compiling AVR. This file will be filled 11 | * with analogous functionality from Windows. 12 | */ 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /source/avr/macros.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef MACROS_H 6 | #define MACROS_H 7 | 8 | /* 9 | * The avr/macros.h file providies a set of macros 10 | * necessary for compiling AVR. These are provided 11 | * to offer analogous functionality on Windows. 12 | */ 13 | 14 | #define _BV(x) (1 << x) 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /source/eeprom.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #include "pch.h" 6 | 7 | #include "EEPROM.h" 8 | #include "wire.h" 9 | 10 | // I2C transaction code(s): 11 | namespace { 12 | const uint8_t EEPROM_ADDR7 = 0x50; 13 | } 14 | 15 | uint8_t 16 | EEPROMClass::read ( 17 | const int address 18 | ) const { 19 | // Request data from EEPROM 20 | Wire.begin(); 21 | Wire.beginTransmission(EEPROM_ADDR7); 22 | Wire.write(static_cast(address >> 8)); // high-byte 23 | Wire.write(static_cast(address)); // low-byte 24 | if ( TwoWire::ADDR_NACK_RECV == Wire.endTransmission(false) ) { return 0; } 25 | 26 | // Return response 27 | Wire.requestFrom(EEPROM_ADDR7, 1); 28 | return static_cast(Wire.read()); 29 | } 30 | 31 | void 32 | EEPROMClass::write ( 33 | const int address, 34 | const uint8_t value 35 | ) const { 36 | // Write data to EEPROM 37 | Wire.begin(); 38 | Wire.beginTransmission(EEPROM_ADDR7); 39 | Wire.write(static_cast(address >> 8)); // high-byte 40 | Wire.write(static_cast(address)); // low-byte 41 | Wire.write(value); 42 | Wire.endTransmission(true); 43 | } 44 | 45 | EEPROMClass EEPROM; 46 | -------------------------------------------------------------------------------- /source/eeprom.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef EEPROM_H 6 | #define EEPROM_H 7 | 8 | #include 9 | #include "Lightning.h" 10 | 11 | /// \brief A pseudo static class to support EEPROM usage 12 | /// \details EEPROM is a type of non-volatile memory used in computers 13 | /// and other electronic devices to store small amounts of data that 14 | /// must be saved when power is removed (e.g. calibration tables or 15 | /// device configuration). This class allows you to read and write from 16 | /// this memory. 17 | class EEPROMClass 18 | { 19 | public: 20 | /// \brief Reads a byte from the EEPROM. 21 | /// \param [in] address The location to read from, starting from 0 (int) 22 | /// \returns the value stored in that location (byte) 23 | /// \note Locations that have never been written to have the value of 255. 24 | LIGHTNING_DLL_API uint8_t 25 | read ( 26 | const int address 27 | ) const; 28 | 29 | /// \brief Write a byte to the EEPROM. 30 | /// \param [in] address The location to write to, starting from 0 (int) 31 | /// \param [in] value The value to write, from 0 to 255 (byte) 32 | /// \note An EEPROM write takes 3.3 ms to complete. The EEPROM memory has 33 | /// a specified life of 100,000 write/erase cycles, so you may need to be 34 | /// careful about how often you write to it. 35 | LIGHTNING_DLL_API void 36 | write ( 37 | const int address, 38 | const uint8_t value 39 | ) const; 40 | }; 41 | 42 | LIGHTNING_DLL_API extern EEPROMClass EEPROM; ///< This variable will provide global access to 43 | /// this pseudo-static class, and will be instantiated 44 | /// in the .cpp file. 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /source/pins_arduino.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | // Licensed under the BSD 2-Clause License. 3 | // See License.txt in the project root for license information. 4 | 5 | #ifndef _PINS_ARDUINO_H_ 6 | #define _PINS_ARDUINO_H_ 7 | 8 | 9 | #if defined(_M_IX86) || defined(_M_X64) 10 | 11 | // Pin numbers mappings for MinnowBoard Max 12 | 13 | const static uint8_t GPIO0 = 21; 14 | const static uint8_t GPIO1 = 23; 15 | const static uint8_t GPIO2 = 25; 16 | const static uint8_t GPIO3 = 14; 17 | const static uint8_t GPIO4 = 16; 18 | const static uint8_t GPIO5 = 18; 19 | const static uint8_t GPIO6 = 20; 20 | const static uint8_t GPIO7 = 22; 21 | const static uint8_t GPIO8 = 24; 22 | const static uint8_t GPIO9 = 26; 23 | const static uint8_t SCL = 13; 24 | const static uint8_t SDA = 15; 25 | const static uint8_t CS0 = 5; 26 | const static uint8_t CE0 = CS0; 27 | static const uint8_t SS = CS0; 28 | const static uint8_t MISO = 7; 29 | const static uint8_t MOSI = 9; 30 | const static uint8_t SCLK = 11; 31 | const static uint8_t SCK = SCLK; 32 | const static uint8_t CTS1 = 10; 33 | const static uint8_t RTS1 = 12; 34 | const static uint8_t RX1 = 8; 35 | const static uint8_t TX1 = 6; 36 | const static uint8_t RX2 = 19; 37 | const static uint8_t TX2 = 17; 38 | 39 | #elif defined (_M_ARM) 40 | 41 | // Pin numbers mappings for Raspberry Pi2 42 | 43 | const static uint8_t GPIO2 = 3; 44 | const static uint8_t GPIO3 = 5; 45 | const static uint8_t GPIO4 = 7; 46 | const static uint8_t GPIO5 = 29; 47 | const static uint8_t GPIO6 = 31; 48 | const static uint8_t GPIO7 = 26; 49 | const static uint8_t GPIO8 = 24; 50 | const static uint8_t GPIO9 = 21; 51 | const static uint8_t GPIO10 = 19; 52 | const static uint8_t GPIO11 = 23; 53 | const static uint8_t GPIO12 = 32; 54 | const static uint8_t GPIO13 = 33; 55 | const static uint8_t GPIO14 = 8; 56 | const static uint8_t GPIO15 = 10; 57 | const static uint8_t GPIO16 = 36; 58 | const static uint8_t GPIO17 = 11; 59 | const static uint8_t GPIO18 = 12; 60 | const static uint8_t GPIO19 = 35; 61 | const static uint8_t GPIO20 = 38; 62 | const static uint8_t GPIO21 = 40; 63 | const static uint8_t GPIO22 = 15; 64 | const static uint8_t GPIO23 = 16; 65 | const static uint8_t GPIO24 = 18; 66 | const static uint8_t GPIO25 = 22; 67 | const static uint8_t GPIO26 = 37; 68 | const static uint8_t GPIO27 = 13; 69 | const static uint8_t GPIO47 = 41; 70 | const static uint8_t GCLK = 7; 71 | const static uint8_t GEN0 = 11; 72 | const static uint8_t GEN1 = 12; 73 | const static uint8_t GEN2 = 13; 74 | const static uint8_t GEN3 = 15; 75 | const static uint8_t GEN4 = 16; 76 | const static uint8_t GEN5 = 18; 77 | const static uint8_t SCL1 = 5; 78 | const static uint8_t SDA1 = 3; 79 | const static uint8_t CS0 = 24; 80 | const static uint8_t CE0 = CS0; 81 | static const uint8_t SS = CS0; 82 | const static uint8_t CS1 = 26; 83 | const static uint8_t CE1 = CS1; 84 | const static uint8_t SCLK = 23; 85 | const static uint8_t SCK = SCLK; 86 | const static uint8_t MISO = 21; 87 | const static uint8_t MOSI = 19; 88 | const static uint8_t RXD = 10; 89 | const static uint8_t TXD = 8; 90 | 91 | static const uint8_t LED_BUILTIN = 41; 92 | 93 | #endif // defined (_M_ARM) 94 | 95 | #endif // _PINS_ARDUINO_H_ 96 | --------------------------------------------------------------------------------