Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full shutdown and powerup sequences for MiniscopeV4 Python480 sensor #333

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
12 changes: 12 additions & 0 deletions .bonsai/Bonsai.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Packages>
<Package id="AForge" version="2.2.5" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aacuevas this was probably because you were messing around with the Video package in your bonsai installation, right? I don't think we need these dependencies in our local bonsai used to test this package.

<Package id="AForge.Video" version="2.2.5" />
<Package id="AForge.Video.DirectShow" version="2.2.5" />
<Package id="Bonsai" version="2.8.5" />
<Package id="Bonsai.Core" version="2.8.5" />
<Package id="Bonsai.Design" version="2.8.5" />
Expand All @@ -12,6 +15,8 @@
<Package id="Bonsai.Scripting.Expressions.Design" version="2.8.0" />
<Package id="Bonsai.System" version="2.8.1" />
<Package id="Bonsai.System.Design" version="2.8.0" />
<Package id="Bonsai.Video" version="2.4.0" />
<Package id="Bonsai.Video.Design" version="2.4.0" />
<Package id="Bonsai.Vision" version="2.8.1" />
<Package id="Bonsai.Vision.Design" version="2.8.1" />
<Package id="jacobslusser.ScintillaNET" version="3.6.3" />
Expand Down Expand Up @@ -46,10 +51,15 @@
<AssemblyReference assemblyName="Bonsai.Scripting.Expressions.Design" />
<AssemblyReference assemblyName="Bonsai.System" />
<AssemblyReference assemblyName="Bonsai.System.Design" />
<AssemblyReference assemblyName="Bonsai.Video" />
<AssemblyReference assemblyName="Bonsai.Video.Design" />
<AssemblyReference assemblyName="Bonsai.Vision" />
<AssemblyReference assemblyName="Bonsai.Vision.Design" />
</AssemblyReferences>
<AssemblyLocations>
<AssemblyLocation assemblyName="AForge" processorArchitecture="MSIL" location="Packages/AForge.2.2.5/lib/AForge.dll" />
<AssemblyLocation assemblyName="AForge.Video" processorArchitecture="MSIL" location="Packages/AForge.Video.2.2.5/lib/AForge.Video.dll" />
<AssemblyLocation assemblyName="AForge.Video.DirectShow" processorArchitecture="MSIL" location="Packages/AForge.Video.DirectShow.2.2.5/lib/AForge.Video.DirectShow.dll" />
<AssemblyLocation assemblyName="Bonsai" processorArchitecture="MSIL" location="Packages/Bonsai.2.8.5/lib/net48/Bonsai.exe" />
<AssemblyLocation assemblyName="Bonsai.Core" processorArchitecture="MSIL" location="Packages/Bonsai.Core.2.8.5/lib/net462/Bonsai.Core.dll" />
<AssemblyLocation assemblyName="Bonsai.Design" processorArchitecture="MSIL" location="Packages/Bonsai.Design.2.8.5/lib/net462/Bonsai.Design.dll" />
Expand All @@ -61,6 +71,8 @@
<AssemblyLocation assemblyName="Bonsai.Scripting.Expressions.Design" processorArchitecture="MSIL" location="Packages/Bonsai.Scripting.Expressions.Design.2.8.0/lib/net462/Bonsai.Scripting.Expressions.Design.dll" />
<AssemblyLocation assemblyName="Bonsai.System" processorArchitecture="MSIL" location="Packages/Bonsai.System.2.8.1/lib/net462/Bonsai.System.dll" />
<AssemblyLocation assemblyName="Bonsai.System.Design" processorArchitecture="MSIL" location="Packages/Bonsai.System.Design.2.8.0/lib/net462/Bonsai.System.Design.dll" />
<AssemblyLocation assemblyName="Bonsai.Video" processorArchitecture="MSIL" location="Packages/Bonsai.Video.2.4.0/lib/net462/Bonsai.Video.dll" />
<AssemblyLocation assemblyName="Bonsai.Video.Design" processorArchitecture="MSIL" location="Packages/Bonsai.Video.Design.2.4.0/lib/net462/Bonsai.Video.Design.dll" />
<AssemblyLocation assemblyName="Bonsai.Vision" processorArchitecture="MSIL" location="Packages/Bonsai.Vision.2.8.1/lib/net462/Bonsai.Vision.dll" />
<AssemblyLocation assemblyName="Bonsai.Vision.Design" processorArchitecture="MSIL" location="Packages/Bonsai.Vision.Design.2.8.1/lib/net462/Bonsai.Vision.Design.dll" />
<AssemblyLocation assemblyName="Markdig" processorArchitecture="MSIL" location="Packages/Markdig.0.18.1/lib/net40/Markdig.dll" />
Expand Down
17 changes: 8 additions & 9 deletions OpenEphys.Onix1/ConfigureNeuropixelsV1e.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var serializer = new I2CRegisterContext(device, DS90UB9x.SER_ADDR);

// set I2C clock rate to ~400 kHz
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.SCLHIGH, 20);
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.SCLLOW, 20);
DS90UB9x.Set933I2CRate(device, 400e3);

// read probe metadata
var probeMetadata = new NeuropixelsV1eMetadata(serializer);
Expand All @@ -167,8 +166,8 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var deviceInfo = new NeuropixelsV1eDeviceInfo(context, DeviceType, deviceAddress, probeControl);
var shutdown = Disposable.Create(() =>
{
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, NeuropixelsV1e.DefaultGPO10Config);
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO32, NeuropixelsV1e.DefaultGPO32Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, NeuropixelsV1e.DefaultGPO10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio32, NeuropixelsV1e.DefaultGPO32Config);
});
return new CompositeDisposable(
DeviceManager.RegisterDevice(deviceName, deviceInfo),
Expand All @@ -194,10 +193,10 @@ static void ConfigureDeserializer(DeviceContext device)
device.WriteRegister(DS90UB9x.DATALINES0, 0x3245106B); // Sync, psb[0], psb[1], psb[2], psb[3], psb[4], psb[5], psb[6],
device.WriteRegister(DS90UB9x.DATALINES1, 0xFFFFFFFF);

DS90UB9x.Initialize933SerDesLink(device, DS90UB9xMode.Raw12BitHighFrequency);

// configure deserializer I2C aliases
var deserializer = new I2CRegisterContext(device, DS90UB9x.DES_ADDR);
uint coaxMode = 0x4 + (uint)DS90UB9xMode.Raw12BitHighFrequency; // 0x4 maintains coax mode
deserializer.WriteByte((uint)DS90UB9xDeserializerI2CRegister.PortMode, coaxMode);

uint alias = NeuropixelsV1e.ProbeAddress << 1;
deserializer.WriteByte((uint)DS90UB9xDeserializerI2CRegister.SlaveID1, alias);
Expand All @@ -211,16 +210,16 @@ static void ConfigureDeserializer(DeviceContext device)
static void ResetProbe(I2CRegisterContext serializer, uint gpo10Config)
{
gpo10Config &= ~NeuropixelsV1e.Gpo10ResetMask;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);
Thread.Sleep(1);
gpo10Config |= NeuropixelsV1e.Gpo10ResetMask;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);
}

static uint TurnOnLed(I2CRegisterContext serializer, uint gpo23Config)
{
gpo23Config &= ~NeuropixelsV1e.Gpo32LedMask;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO32, gpo23Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio32, gpo23Config);

return gpo23Config;
}
Expand Down
19 changes: 9 additions & 10 deletions OpenEphys.Onix1/ConfigureNeuropixelsV2e.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var gpo10Config = EnableProbeSupply(serializer);

// set I2C clock rate to ~400 kHz
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.SCLHIGH, 20);
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.SCLLOW, 20);

DS90UB9x.Set933I2CRate(device, 400e3);

// read probe metadata
var probeAMetadata = ReadProbeMetadata(serializer, NeuropixelsV2e.ProbeASelected);
var probeBMetadata = ReadProbeMetadata(serializer, NeuropixelsV2e.ProbeBSelected);
Expand Down Expand Up @@ -210,7 +209,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var deviceInfo = new NeuropixelsV2eDeviceInfo(context, DeviceType, deviceAddress, gainCorrectionA, gainCorrectionB);
var shutdown = Disposable.Create(() =>
{
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, NeuropixelsV2e.DefaultGPO10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, NeuropixelsV2e.DefaultGPO10Config);
SelectProbe(serializer, NeuropixelsV2e.NoProbeSelected);
});
return new CompositeDisposable(
Expand All @@ -237,10 +236,10 @@ static void ConfigureDeserializer(DeviceContext device)
device.WriteRegister(DS90UB9x.DATALINES0, 0xFFFFF8A6); // NP A
device.WriteRegister(DS90UB9x.DATALINES1, 0xFFFFF97B); // NP B

DS90UB9x.Initialize933SerDesLink(device, DS90UB9xMode.Raw12BitHighFrequency);

// configure deserializer I2C aliases
var deserializer = new I2CRegisterContext(device, DS90UB9x.DES_ADDR);
uint coaxMode = 0x4 + (uint)DS90UB9xMode.Raw12BitHighFrequency; // 0x4 maintains coax mode
deserializer.WriteByte((uint)DS90UB9xDeserializerI2CRegister.PortMode, coaxMode);

uint alias = NeuropixelsV2e.ProbeAddress << 1;
deserializer.WriteByte((uint)DS90UB9xDeserializerI2CRegister.SlaveID1, alias);
Expand All @@ -257,7 +256,7 @@ static uint EnableProbeSupply(I2CRegisterContext serializer)
SelectProbe(serializer, NeuropixelsV2e.NoProbeSelected);

// turn on analog supply and wait for boot
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);
System.Threading.Thread.Sleep(20);
return gpo10Config;
}
Expand All @@ -269,16 +268,16 @@ static NeuropixelsV2eMetadata ReadProbeMetadata(I2CRegisterContext serializer, b
}
static void SelectProbe(I2CRegisterContext serializer, byte probeSelect)
{
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO32, probeSelect);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio32, probeSelect);
System.Threading.Thread.Sleep(20);
}

static void ResetProbes(I2CRegisterContext serializer, uint gpo10Config)
{
gpo10Config &= ~NeuropixelsV2e.GPO10ResetMask;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);
gpo10Config |= NeuropixelsV2e.GPO10ResetMask;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);
}

static void ConfigureProbeStreaming(I2CRegisterContext i2cNP)
Expand Down
25 changes: 12 additions & 13 deletions OpenEphys.Onix1/ConfigureNeuropixelsV2eBeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,11 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var serializer = new I2CRegisterContext(device, DS90UB9x.SER_ADDR);
var gpo10Config = NeuropixelsV2eBeta.DefaultGPO10Config;
var gpo32Config = NeuropixelsV2eBeta.DefaultGPO32Config;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO32, gpo32Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio32, gpo32Config);

// set I2C clock rate to ~400 kHz
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.SCLHIGH, 20);
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.SCLLOW, 20);
DS90UB9x.Set933I2CRate(device, 400e3);

// read probe metadata
var probeAMetadata = ReadProbeMetadata(serializer, ref gpo32Config, NeuropixelsV2eBeta.SelectProbeA);
Expand All @@ -170,7 +169,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
// REC_NRESET and NRESET go high on both probes to take the ASIC out of reset
// TODO: not sure if REC_NRESET and NRESET are tied together on flex
gpo10Config |= NeuropixelsV2eBeta.GPO10ResetMask | NeuropixelsV2eBeta.GPO10NResetMask;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);
System.Threading.Thread.Sleep(20);

// configure probe streaming
Expand Down Expand Up @@ -227,7 +226,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source

// toggle probe LED
gpo32Config = (gpo32Config & ~NeuropixelsV2eBeta.GPO32LedMask) | (EnableLed ? 0 : NeuropixelsV2eBeta.GPO32LedMask);
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO32, gpo32Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio32, gpo32Config);

// Both probes are now streaming, hit them with a mux reset to (roughly) sync.
// NB: We have found that this gives PCLK-level synchronization MOST of the time.
Expand All @@ -238,8 +237,8 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var deviceInfo = new NeuropixelsV2eDeviceInfo(context, DeviceType, deviceAddress, gainCorrectionA, gainCorrectionB);
var shutdown = Disposable.Create(() =>
{
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, NeuropixelsV2eBeta.DefaultGPO10Config);
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO32, NeuropixelsV2eBeta.DefaultGPO32Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, NeuropixelsV2eBeta.DefaultGPO10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio32, NeuropixelsV2eBeta.DefaultGPO32Config);
});
return new CompositeDisposable(
DeviceManager.RegisterDevice(deviceName, deviceInfo),
Expand All @@ -265,10 +264,10 @@ static void ConfigureDeserializer(DeviceContext device)
device.WriteRegister(DS90UB9x.DATALINES0, 0x00007654); // NP A
device.WriteRegister(DS90UB9x.DATALINES1, 0x00000123); // NP B

DS90UB9x.Initialize933SerDesLink(device, DS90UB9xMode.Raw12BitHighFrequency);

// configure deserializer I2C aliases
var deserializer = new I2CRegisterContext(device, DS90UB9x.DES_ADDR);
uint coaxMode = 0x4 + (uint)DS90UB9xMode.Raw12BitHighFrequency; // 0x4 maintains coax mode
deserializer.WriteByte((uint)DS90UB9xDeserializerI2CRegister.PortMode, coaxMode);

uint alias = NeuropixelsV2eBeta.ProbeAddress << 1;
deserializer.WriteByte((uint)DS90UB9xDeserializerI2CRegister.SlaveID1, alias);
Expand All @@ -293,17 +292,17 @@ static void SelectProbe(I2CRegisterContext serializer, ref uint gpo32Config, byt
NeuropixelsV2eBeta.SelectProbeB => gpo32Config & ~NeuropixelsV2eBeta.ProbeSelectMask,
_ => gpo32Config
};
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO32, gpo32Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio32, gpo32Config);
System.Threading.Thread.Sleep(20);
}

static void SyncProbes(I2CRegisterContext serializer, uint gpo10Config)
{
gpo10Config &= ~NeuropixelsV2eBeta.GPO10NResetMask;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);

gpo10Config |= NeuropixelsV2eBeta.GPO10NResetMask;
serializer.WriteByte((uint)DS90UB9xSerializerI2CRegister.GPIO10, gpo10Config);
serializer.WriteByte((uint)DS90UB933SerializerI2CRegister.Gpio10, gpo10Config);
}

static void ConfigureProbeStreaming(I2CRegisterContext i2cNP)
Expand Down
2 changes: 2 additions & 0 deletions OpenEphys.Onix1/ConfigureUclaMiniscopeV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ override protected bool CheckLinkState(DeviceContext device)
const int FailureToWriteRegister = -6;
try
{
ConfigureUclaMiniscopeV4Camera.ConfigureSerializer(ds90ub9x);
ConfigureUclaMiniscopeV4Camera.ConfigureCameraSystem(ds90ub9x, Camera.FrameRate, Camera.InterleaveLed);
}
catch (ONIException ex) when (ex.Number == FailureToWriteRegister)
{
return false;
}

Thread.Sleep(150);
var linkState = device.ReadRegister(PortController.LINKSTATE);
return (linkState & PortController.LINKSTATE_SL) != 0;
}
Expand Down
Loading
Loading