-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from WildernessLabs/can-bus-wing
Added CAN wing
- Loading branch information
Showing
5 changed files
with
162 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Meadow.Foundation.ICs.CAN; | ||
using Meadow.Hardware; | ||
using Meadow.Units; | ||
|
||
namespace Meadow.Foundation.FeatherWings | ||
{ | ||
/// <summary> | ||
/// Represents an Adafruit CAN Bus featherwing | ||
/// </summary> | ||
public class CanBusWing : Mcp2515 | ||
{ | ||
/// <summary> | ||
/// Creates a CanBusWing driver | ||
/// </summary> | ||
public CanBusWing(IF7FeatherMeadowDevice feather) | ||
: base( | ||
bus: feather.CreateSpiBus(3, 1_000_000.Hertz()), | ||
chipSelect: feather.Pins.D09.CreateDigitalOutputPort(true), | ||
interruptPort: feather.Pins.D10.CreateDigitalInterruptPort(InterruptMode.EdgeFalling), | ||
oscillator: CanOscillator.Osc_16MHz) | ||
{ } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Meadow.Sdk/1.1.0"> | ||
<PropertyGroup> | ||
<Version>1.11.0</Version> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>10.0</LangVersion> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<Authors>Wilderness Labs, Inc</Authors> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<OutputType>Library</OutputType> | ||
<AssemblyName>CanBusWing</AssemblyName> | ||
<Company>Wilderness Labs, Inc</Company> | ||
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/</PackageProjectUrl> | ||
<PackageId>Meadow.Foundation.FeatherWings.GPSWing</PackageId> | ||
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.Foundation.FeatherWings</RepositoryUrl> | ||
<PackageTags>Meadow.Foundation, CanBusWing, CAN</PackageTags> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Description>AdaFruit CAN Bus FeatherWing</Description> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="..\..\icon.png" Pack="true" PackagePath="" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\Meadow.Core\Source\implementations\f7\Meadow.F7\Meadow.F7.csproj" /> | ||
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\ICs.CAN.Mcp2515\Driver\ICs.CAN.Mcp2515.csproj" /> | ||
</ItemGroup> | ||
</Project> |
12 changes: 12 additions & 0 deletions
12
Source/CanBusWing/Samples/CanBusWing_Sample/CanBusWing_Sample.csproj
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Meadow.Sdk/1.1.0"> | ||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
<OutputType>Library</OutputType> | ||
<AssemblyName>App</AssemblyName> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\..\Meadow.Core\Source\implementations\f7\Meadow.F7\Meadow.F7.csproj" /> | ||
<ProjectReference Include="..\..\Driver\CanBusWing.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Meadow; | ||
using Meadow.Devices; | ||
using Meadow.Foundation.FeatherWings; | ||
using Meadow.Hardware; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace MeadowApp | ||
{ | ||
public class MeadowApp : App<F7FeatherV2> | ||
{ | ||
//<!=SNIP=> | ||
|
||
private CanBusWing wing; | ||
|
||
public override Task Initialize() | ||
{ | ||
Console.WriteLine("Initialize..."); | ||
|
||
wing = new CanBusWing(Device); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public override async Task Run() | ||
{ | ||
var bus = wing.CreateCanBus(CanBitrate.Can_250kbps); | ||
|
||
Console.WriteLine($"Listening for CAN data..."); | ||
|
||
var tick = 0; | ||
|
||
while (true) | ||
{ | ||
var frame = bus.ReadFrame(); | ||
if (frame != null) | ||
{ | ||
if (frame is StandardDataFrame sdf) | ||
{ | ||
Console.WriteLine($"Standard Frame: {sdf.ID:X3} {BitConverter.ToString(sdf.Payload)}"); | ||
} | ||
else if (frame is ExtendedDataFrame edf) | ||
{ | ||
Console.WriteLine($"Extended Frame: {edf.ID:X8} {BitConverter.ToString(edf.Payload)}"); | ||
} | ||
} | ||
else | ||
{ | ||
await Task.Delay(100); | ||
} | ||
|
||
if (tick++ % 50 == 0) | ||
{ | ||
Console.WriteLine($"Sending Standard Frame..."); | ||
|
||
bus.WriteFrame(new StandardDataFrame | ||
{ | ||
ID = 0x700, | ||
Payload = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, (byte)(tick & 0xff) } | ||
}); | ||
} | ||
} | ||
} | ||
|
||
//<!=SNOP=> | ||
} | ||
} |
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