NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Direct Memory Mapped GPIO driver

Mon Nov 16, 2015 12:55 am

Has anyone had any success with the "Direct Memory Mapped Driver" which can be selected in the web interface under Devices -> Default Controller Driver ? I've read that this can increase GPIO performance by several hundred times. However, when I select that driver, any attempt to even open a GPIO pin throws an exception.

Has anyone got it to work? Do you have to do something special in the code?

Thanks,

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: Direct Memory Mapped GPIO driver

Mon Nov 16, 2015 9:44 am

https://ms-iot.github.io/content/en-US/ ... viders.htm defines how to setup/use the Lightning Memory mapped drivers for GPIO (with examples).
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Re: Direct Memory Mapped GPIO driver

Mon Nov 16, 2015 5:14 pm

Aha! I suspected I was probably missing something. The instructions for these things are a bit disorganized and spread across myriad blogs and web sites. Anyway that id very helpful, thanks for posting that link.

I notice it said that if the Lightning driver is not available it is supposed to fall back to the default driver. That isn't happening on my system. As soon as I open any GPIO pin, I get an exception. So either the fall-back doesn't work as expected or I'm still not configuring things right. I'll keep tinkering with it...

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: Direct Memory Mapped GPIO driver

Mon Nov 16, 2015 5:34 pm

https://github.com/ms-iot/samples/tree/ ... ioTestTool

Build and run the above code to verify if the required GPIO pins are available.

The Lightning driver is supposed to be a one line replacement to the 'standard' driver.

Code: Select all

using Microsoft.IoT.Lightning.Providers;
using Windows.Devices;
if (LightningProvider.IsLightningEnabled)
{
    LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
}

gpioController = await GpioController.GetDefaultAsync();
should then work regardless of which driver is in use. It will the load the memory mapped driver if you have enabled it (or so I read in the comments). The default if you haven't.
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Re: Direct Memory Mapped GPIO driver

Fri Nov 20, 2015 7:53 pm

I'm still missing something. My problem is that namespace isn't available, I just get a compile error when I try to reference it. What exactly do I need to import, or install, or reference, in order to access the Microsoft.IoT.Lightning.Providers namespace? My project already has a reference to Windows IoT Extensions for the UWP.

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: Direct Memory Mapped GPIO driver

Fri Nov 20, 2015 7:58 pm

See 'Nuget Package Dependencies' under

https://ms-iot.github.io/content/en-US/ ... viders.htm

In order to install prerelease (current) version of Microsoft.IoT.Lightning Nuget package as well as receive prerelease updates to the Lightning package, make sure to set the “Include prerelease” option in the Nuget Package Manager.
1.Right click References in your project
2.Click “Manage Nuget Packages…”
3.Select package sources for Lightning nuget
4.Click “Include prerelease”.
5.Click “Install” to install the nuget package to your project


may solve your problem.
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Re: Direct Memory Mapped GPIO driver

Fri Nov 20, 2015 9:49 pm

Nice try, but no.

The NuGet package seems to be largely a red herring, since it does not appear to include the thing you need to reference. It appears to be the development dependencies for the CPP project.

I have finally got something that I can reference by downloading the source code for the Lightning Providers CPP project and including that in my project as part of the build.

<sarcasm>Nice clear instructions Microsoft, well done.</sarcasm>

NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Re: Direct Memory Mapped GPIO driver

Fri Nov 20, 2015 10:48 pm

I give up!! Any attempt to access the LightningProvider object at runtime causes the app to immediately crash and quit.

Code: Select all

            if (LightningProvider.IsLightningEnabled)
                {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                }
If I set a breakpoint on the if statement, then wait for it to be hit, then hover the mouse over the IsLightningEnabled field (just hover, no clicking or anything), the app crashes and quits -- WHILE PAUSED IN A BREAKPOINT!

This has been an exercise in utter frustration.

NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Re: Direct Memory Mapped GPIO driver

Tue Jan 05, 2016 9:33 am

I got a little bit further. I found yet another incomplete set of documentation and worked out that I needed to manually edit the Package.appxmanifest file. Now my code gets past the initial check to see if the Lightning Providers are enabled and setting them as the default, so I must be on the right lines.

My code now falls over when trying to get an I2C device. The same code works with the 'inbox' drivers. I get an exception that mentions "Failed to apply connection settings to the device".

There are basically only 3 settings: the bus speed; the slave address; and the sharing mode. I've tried both exclusive and shared access, everything else is dictated by the hardware so I have no leeway there.

Anyone got I2C working with the lightning providers?
--Tim

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: Direct Memory Mapped GPIO driver

Tue Jan 05, 2016 10:26 am

You almost certainly have failed to include the Lightning lib as a ref or your library is out of date. That will give the sort of errors you see.
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Re: Direct Memory Mapped GPIO driver

Tue Jan 05, 2016 1:41 pm

Don't you think the compiler might be upset if I'd forgotten to include the library? That is, after all, one of the benefits of using a statically typed language like C#.

Anyway, I'm pleased to report that I have, at long last, had a somewhat successful(*) run with the Lightning provider. The process was rather non-intuitive (and I say that as an experienced developer of >30 years and a C# developer of ~15 years, so please don't think I'm making noob mistakes here). So that others can avoid my pain, I have written up the steps required as a blog post:
http://tigra-astronomy.com/blog/the-wel ... -core-apps

The final step I was missing was the manual modification of the Package.appxmanifest file.

(*) And wouldn't you just know it, there is a showstopper bug in the I2C Provider!! Basically, if you set the bus speed to "Standard" it goes at 168KHz instead of the specified 100KHz, and standard mode devices (the one I'm using anyway) can't handle that and it produces garbage results :o Issue created on GitHub. https://github.com/ms-iot/BusProviders/issues/21

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: Direct Memory Mapped GPIO driver

Tue Jan 05, 2016 1:48 pm

"The final step I was missing was the manual modification of the Package.appxmanifest file."

That is all in the docs, FAQ here, or on GitHub. And no, if you have not included the library correctly, things will not work as expected. That is the UI driver addition to hook up to the hardware driver enabled in the OS via the Web.
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Re: Direct Memory Mapped GPIO driver

Tue Jan 05, 2016 1:53 pm

Of course, but my point is: if you haven't included the Lightning library then if you refer to anything in it the compiler will complain that it can't find it. How could it be otherwise?

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: Direct Memory Mapped GPIO driver

Tue Jan 05, 2016 2:24 pm

Because it is the linker that mostly does that step. Sometimes it creates stubs that are only tripped over later in execution. There is much more than just the compiler going on here.
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

NameOfTheDragon
Posts: 21
Joined: Mon Nov 16, 2015 12:49 am

Re: Direct Memory Mapped GPIO driver

Tue Jan 05, 2016 2:35 pm

The lack of specificity leads me to think that we are going down a hypothetical rabbit hole. The library is included as source code, which must be referenced as a project, which means it must be compiled, which means if you haven't done it correctly you will get a compiler error when you try to access the provider, because the namespace and types will not exist. Whatever the linker is doing later, I can't see how it is possible to get past the compilation step if things aren't correct. It's true there is a linker in the .NET Native build pipeline but you still have to get past the C# compiler and generate the MSIL first. Have you actually tried it or are you speculating?

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: Direct Memory Mapped GPIO driver

Tue Jan 05, 2016 3:01 pm

Been there, done that. Made mistakes which I sorted out. Did research, wrote an FAQ, try to help those who obviously didn't follow the precise path I did. I don't know where they fell off. I am here trying to guide you to where I am. Nothing more
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

ossandust
Posts: 11
Joined: Sun Jan 10, 2016 10:49 pm

Re: Direct Memory Mapped GPIO driver

Sun Jan 10, 2016 11:03 pm

Would it be possible to use the Lightning GPIO driver in a node.js application? I had no problem trying it out in a UWP app, but would like to know if there is a way to access the Microsoft.IoT.Lightning.Providers namespace within a nodejs javascript project - for instance in the "Webserver Blinky (Node.js)" sample on GitHub.

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: Direct Memory Mapped GPIO driver

Mon Jan 11, 2016 9:20 am

All the docs and examples for the Lightning driver are on GitHub. The languages it runs with are there. AFAIK it is all.
ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

Return to “Windows 10 for IoT”