Community, I’d appreciate your input on my proposed design of the driver for this module. I expect the modules to arrive by Monday and I’d like to start coding by then. My anniversary is this weekend so there’s no chance it’s happening before then Please let me know what you think about the approach I’m taking and if there’s anything else you would like to see included that I haven’t yet considered.
The basic approach that I’m taking is that the IO60P16 module should appear as an extension of the IO that we’re normally used to using through standard NETMF. Unfortunately, NETMF still does not have common interfaces for IO ports. So, I will be creating new classes that mimic the below mentioned classes as they are in v4.2. Where possible, all methods, events, & properties of the NETMF class will also be implemented in it’s IO60P16 counterpart. This approach also makes it easy to build arrays of ports which is important in many applications (ex. LED cubes).
Let’s try and hash this out by Monday, if possible. Thanks for you input!
Port (base class for all other [italic]x[/italic]Port classes)
Based on: Port Members | Microsoft Learn
InputPort
Based on: InputPort Class | Microsoft Learn
[italic]Example Usage:[/italic]
IO60P16.InputPort pin1 = io60p16.CreateInputPort(Pins.IO.Port0_Pin1);
IO60P16.InputPort pin1 = io60p16.CreateInputPort(Pins.IO.Port0_Pin1, Port.ResistorMode.PullDown);
IO60P16.InputPort pin1 = io60p16.CreateInputPort(Pins.IO.Port0_Pin1, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
IO60P16.InputPort pin1 = io60p16.CreateInputPort(0, 1, resistorMode=pullDown);
OutputPort
Based on: OutputPort Class | Microsoft Learn
[italic]Example Usage:[/italic]
IO60P16.OutputPort pin1 = io60p16.CreateOutputPort(Pins.IO.Port0_Pin1, true /* state */);
IO60P16.OutputPort pin1 = io60p16.CreateOutputPort(Pins.IO.Port0_Pin1, true /* state */, Port.ResistorMode.PullDown);
IO60P16.OutputPort pin1 = io60p16.CreateOutputPort(0, 1, Port.ResistorMode.PullDown);
InterruptPort
Based on: InterruptPort Class | Microsoft Learn
[italic]Example Usage:[/italic]
IO60P16.InterruptPort pin1 = io60p16.CreateOutputPort(Pins.IO.Port0_Pin1, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
IO60P16.InterruptPort pin1 = io60p16.CreateOutputPort(0, 1, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
PWM
Based on: http://msdn.microsoft.com/en-us/library/hh401130.aspx
[italic]Example Usage:[/italic]
IO60P16.PWM pin1 = io60p16.CreatePWM(Pins.Pwm.Pwm15, 2800*1000, 2000*1000, false /* invert */ );
IO60P16.PWM pin2 = io60p16.CreatePWM(15, 2800, 2000, PWM.ScaleFactor.Milliseconds, false /* invert */);
pin1.Start();
pin1.Stop();
PWM.Start(new [] { pin1, pin2 });
TristatePort
Based on: TristatePort Class | Microsoft Learn
[italic]Example Usage:[/italic]
IO60P16.TristatePort pin1 = io60p16.CreateTristatePort(Pins.IO.Port0_Pin1, false /* initial state */, Port.ResistorMode.PullDown);
IO60P16.TristatePort pin1 = io60p16.CreateTristatePort(0, 1, Port.ResistorMode.PullDown, false /* initial state */, Port.ResistorMode.PullDown);
Module Chaining (Module collection)
Up to eight modules can be chained together using Extender modules. During bootup, chained modules will be auto-detected and an array of IO60P16 objects built.
[italic]Example Usage:[/italic]
int cnt = io60p16.Modules.Count;
IO60P16.OutputPort pin1 = io60p16.Modules[1].CreateOutputPort(Pins.IO.Port0_Pin1, true /* state */);
EDIT: Added per Mikes suggestion.
IO60P16.Write() - sets the state of multiple ports simultaneously.
[italic]Example Usage:[/italic]
IO60P16.OutputPort pin1 = io60p16.CreateOutputPort(Pins.IO.Port0_Pin0, true /* state */);
IO60P16.OutputPort pin2 = io60p16.CreateOutputPort(Pins.IO.Port0_Pin1, true /* state */);
IO60P16.OutputPort pin3 = io60p16.CreateOutputPort(Pins.IO.Port0_Pin2, true /* state */);
IO60P16.OutputPort pin4 = io60p16.CreateOutputPort(Pins.IO.Port0_Pin3, true /* state */);
var halfByte = new [] {pin1, pin2, pin3, pin4};
IO60P16.Write(halfByte, 11 /* 1011 */);
Because all of this is controlled via I2C, there’s probably going to be a limit as to how many could be changed simultaneously. I’ll learn more about this limitation once I can play with the boards.
IO60P16.Read() - reads the state of multiple ports simultaneously.
[italic]Example Usage:[/italic]
IO60P16.InputPort pin1 = io60p16.CreateInputPort(Pins.IO.Port0_Pin0, true /* state */);
IO60P16.InputPort pin2 = io60p16.CreateInputPort(Pins.IO.Port0_Pin1, true /* state */);
IO60P16.InputPort pin3 = io60p16.CreateInputPort(Pins.IO.Port0_Pin2, true /* state */);
IO60P16.InputPort pin4 = io60p16.CreateInputPort(Pins.IO.Port0_Pin3, true /* state */);
var halfByte = new [] {pin1, pin2, pin3, pin4};
int val = IO60P16.Read(halfByte);