-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
260 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,47 @@ | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace WPIHal; | ||
|
||
public struct CANStreamMessage; | ||
[StructLayout(LayoutKind.Sequential)] | ||
public struct CANStreamMessage | ||
{ | ||
public uint MessageID; | ||
public uint TimeStamp; | ||
public DataBuffer Data; | ||
public byte DataSize; | ||
|
||
[System.Runtime.CompilerServices.InlineArray(8)] | ||
public struct DataBuffer | ||
{ | ||
private byte _element0; | ||
} | ||
} | ||
|
||
public readonly struct CANMessage | ||
{ | ||
private readonly ulong timestamp; | ||
private readonly DataBuffer data; | ||
private readonly int dataSize; | ||
|
||
public CANMessage(ReadOnlySpan<byte> buffer, ulong timestamp) | ||
{ | ||
Debug.Assert(buffer.Length <= 8); | ||
buffer.CopyTo(data); | ||
this.timestamp = timestamp; | ||
this.dataSize = buffer.Length; | ||
} | ||
|
||
[UnscopedRef] | ||
public ReadOnlySpan<byte> Data => data[..dataSize]; | ||
|
||
public ulong Timestamp => timestamp; | ||
|
||
[InlineArray(8)] | ||
public struct DataBuffer | ||
{ | ||
private byte _element0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace WPIHal; | ||
|
||
public enum HalStatus : int | ||
{ | ||
Ok = 0, | ||
} | ||
|
||
public static class HalStatusExtensions | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void ThrowIfFailed(this HalStatus status) | ||
{ | ||
if (status == HalStatus.Ok) | ||
{ | ||
return; | ||
} | ||
// TODO Throw Exception | ||
throw new InvalidOperationException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,67 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using WPIHal.Handles; | ||
using WPIUtil; | ||
|
||
namespace WPIHal.Natives; | ||
|
||
public static partial class HalAddressableLED | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
public struct LedData | ||
{ | ||
public byte B; | ||
public byte G; | ||
public byte R; | ||
public byte Padding; | ||
} | ||
|
||
[LibraryImport("wpiHal", EntryPoint = "HAL_FreeAddressableLED")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void FreeAddressableLED(HalAddressableLEDHandle handle); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_InitializeAddressableLED")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial HalAddressableLEDHandle InitializeAddressableLED(HalDigitalHandle outputPort, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_SetAddressableLEDBitTiming")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void SetAddressableLEDBitTiming(HalAddressableLEDHandle handle, int highTime0NanoSeconds, int lowTime0NanoSeconds, int highTime1NanoSeconds, int lowTime1NanoSeconds, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_SetAddressableLEDLength")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void SetAddressableLEDLength(HalAddressableLEDHandle handle, int length, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_SetAddressableLEDOutputPort")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void SetAddressableLEDOutputPort(HalAddressableLEDHandle handle, HalDigitalHandle outputPort, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_SetAddressableLEDSyncTime")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void SetAddressableLEDSyncTime(HalAddressableLEDHandle handle, int syncTimeMicroSeconds, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_StartAddressableLEDOutput")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void StartAddressableLEDOutput(HalAddressableLEDHandle handle, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_StopAddressableLEDOutput")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void StopAddressableLEDOutput(HalAddressableLEDHandle handle, out HalStatus status); | ||
|
||
[LibraryImport("wpiHal", EntryPoint = "HAL_WriteAddressableLEDData")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void WriteAddressableLEDData(HalAddressableLEDHandle handle, ReadOnlySpan<AddressableLEDData> data, int length, out HalStatus status); | ||
public static partial void WriteAddressableLEDData(HalAddressableLEDHandle handle, ReadOnlySpan<LedData> data, int length, out HalStatus status); | ||
|
||
public static void WriteAddressableLEDData(HalAddressableLEDHandle handle, ReadOnlySpan<AddressableLEDData> data, out HalStatus status) | ||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
public static void WriteAddressableLEDData(HalAddressableLEDHandle handle, ReadOnlySpan<LedData> data, out HalStatus status) | ||
{ | ||
WriteAddressableLEDData(handle, data, data.Length, out status); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,49 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using WPIHal.Handles; | ||
using WPIUtil; | ||
|
||
namespace WPIHal.Natives; | ||
|
||
public static partial class HalAnalogAccumulator | ||
{ | ||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_GetAccumulatorCount")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial long GetAccumulatorCount(HalAnalogInputHandle analogPortHandle, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_GetAccumulatorOutput")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void GetAccumulatorOutput(HalAnalogInputHandle analogPortHandle, out long value, out long count, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_GetAccumulatorValue")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial long GetAccumulatorValue(HalAnalogInputHandle analogPortHandle, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_InitAccumulator")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void InitAccumulator(HalAnalogInputHandle analogPortHandle, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_IsAccumulatorChannel")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial int IsAccumulatorChannel(HalAnalogInputHandle analogPortHandle, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_ResetAccumulator")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void ResetAccumulator(HalAnalogInputHandle analogPortHandle, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_SetAccumulatorCenter")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void SetAccumulatorCenter(HalAnalogInputHandle analogPortHandle, int center, out HalStatus status); | ||
|
||
[AutomateStatusCheck(StatusCheckMethod = HalBase.StatusCheckCall)] | ||
[LibraryImport("wpiHal", EntryPoint = "HAL_SetAccumulatorDeadband")] | ||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] | ||
public static partial void SetAccumulatorDeadband(HalAnalogInputHandle analogPortHandle, int deadband, out HalStatus status); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.