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

Initial progress dump for Mcp25xxx binding #306

Merged
merged 46 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fd0fc96
Initial progress dump for Mcp25xxx binding
shaggygi Mar 3, 2019
4d8c903
Added another dev board
shaggygi Mar 3, 2019
75d7d64
Set projects to latest language version
shaggygi Mar 3, 2019
1123222
Small format update
shaggygi Mar 3, 2019
9d3098e
Updated approach to pin read and writes
shaggygi Mar 3, 2019
b6ccd1b
Added IRegister
shaggygi Mar 6, 2019
26db479
Changed Register to Address
shaggygi Mar 6, 2019
539cdd0
Added initial AcceptanceFilter Register tests
shaggygi Mar 6, 2019
8be6fe2
Too many tests
shaggygi Mar 6, 2019
ec18f94
Added initial BitTimeConfiguration Register tests
shaggygi Mar 6, 2019
f5df482
Added initial CanControl Register tests
shaggygi Mar 7, 2019
54a6553
Added initial ErrorDetection Register tests
shaggygi Mar 7, 2019
afdd36c
Added initial Interrupt Register tests
shaggygi Mar 7, 2019
288d665
Added initial MessageReceive Register tests
shaggygi Mar 8, 2019
1e9173b
Added initial MessageTransmit Register tests
shaggygi Mar 9, 2019
d83c07a
Changed GetAddress() to Address
shaggygi Mar 9, 2019
f75c628
Added initial instruction tests
shaggygi Mar 10, 2019
859b523
Removed register setters
shaggygi Mar 10, 2019
42b8dfe
Simplified bit numbers and added range exception tests
shaggygi Mar 10, 2019
9e62919
Added registers from bytes
shaggygi Mar 10, 2019
7a3f833
Fixed summaries
shaggygi Mar 10, 2019
60bade9
Added registers from byte tests
shaggygi Mar 11, 2019
b3d7a79
Fixed wrong test
shaggygi Mar 11, 2019
82bdaf2
Simplify GpioController name
shaggygi Mar 13, 2019
9b1bfc0
Added comment about Read Rx Buffer instruction format base value
shaggygi Mar 13, 2019
194e3a7
Added needed stackalloc
shaggygi Mar 13, 2019
b533d1a
Updated bit shift and check
shaggygi Mar 13, 2019
ccabae9
Converted ReadStatusResponse to enum
shaggygi Mar 13, 2019
f2dfc17
Changed RxFilterNumber enum to byte
shaggygi Mar 13, 2019
781d1a8
Changed RxMaskFilter enum to byte
shaggygi Mar 13, 2019
184ce4c
Changed RxBufferFilter enum to byte
shaggygi Mar 13, 2019
e1ffc20
Changed TxBufferNumber enum to byte
shaggygi Mar 13, 2019
6017f9d
Made wording consistent
shaggygi Mar 13, 2019
66656df
Updated invalid argument tests
shaggygi Mar 14, 2019
0712738
Updated StandbyPin setter
shaggygi Mar 14, 2019
bf34a54
Simplified sample reading all registers
shaggygi Mar 15, 2019
7de8c22
Updated summaries to match datasheet
shaggygi Mar 15, 2019
f2b0ae2
Added comment for flag alias
shaggygi Mar 16, 2019
2cac593
Removed VerifyPinConfigured
shaggygi Apr 27, 2019
5a936c8
Decreased StackThreshold
shaggygi Apr 27, 2019
89a2728
Added comment about instruction format for Load Tx Buffer instruction
shaggygi Apr 27, 2019
79b36dd
Added new InstructionFormat enum
shaggygi Apr 27, 2019
85b227d
Updated package version
shaggygi Apr 27, 2019
b1f5780
Moved back to specific version for now
shaggygi Apr 27, 2019
429237a
Updated GetRxBufferNumber check
shaggygi Apr 27, 2019
e8a2bf8
Updated register properties to extended names
shaggygi Apr 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/devices/Mcp25xxx/Mcp2515.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Device.Gpio;
using System.Device.Spi;

namespace Iot.Device.Mcp25xxx
{
/// <summary>
/// Driver for the Microchip MCP2515 CAN controller.
/// </summary>
public class Mcp2515 : Mcp25xxx
{
/// <summary>
/// Initializes a new instance of the Mcp2515 class.
/// </summary>
/// <param name="spiDevice">The SPI device used for communication.</param>
/// <param name="reset">The output pin number that is connected to Reset.</param>
/// <param name="tx0rts">The output pin number that is connected to Tx0RTS.</param>
/// <param name="tx1rts">The output pin number that is connected to Tx1RTS.</param>
/// <param name="tx2rts">The output pin number that is connected to Tx2RTS.</param>
/// <param name="interrupt">The input pin number that is connected to INT.</param>
/// <param name="rx0bf">The input pin number that is connected to Rx0BF.</param>
/// <param name="rx1bf">The input pin number that is connected to Rx1BF.</param>
/// <param name="clkout">The input pin number that is connected to CLKOUT.</param>
/// <param name="masterGpioController">
/// The GPIO controller for defined external pins. If not specified, the default controller will be used.
/// </param>
public Mcp2515(
SpiDevice spiDevice,
int reset = -1,
int tx0rts = -1,
int tx1rts = -1,
int tx2rts = -1,
int interrupt = -1,
int rx0bf = -1,
int rx1bf = -1,
int clkout = -1,
IGpioController masterGpioController = null)
: base(
spiDevice,
reset,
tx0rts,
tx1rts,
tx2rts,
interrupt,
rx0bf,
rx1bf,
clkout,
masterGpioController)
{
}
}
}
81 changes: 81 additions & 0 deletions src/devices/Mcp25xxx/Mcp25625.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Device.Gpio;
using System.Device.Spi;

namespace Iot.Device.Mcp25xxx
{
/// <summary>
/// Driver for the Microchip MCP25625 CAN controller.
/// </summary>
public class Mcp25625 : Mcp25xxx
{
private readonly int _standby;

/// <summary>
/// Initializes a new instance of the Mcp25625 class.
/// </summary>
/// <param name="spiDevice">The SPI device used for communication.</param>
/// <param name="reset">The output pin number that is connected to Reset.</param>
/// <param name="tx0rts">The output pin number that is connected to Tx0RTS.</param>
/// <param name="tx1rts">The output pin number that is connected to Tx1RTS.</param>
/// <param name="tx2rts">The output pin number that is connected to Tx2RTS.</param>
/// <param name="standby">The output pin number that is connected to STBY.</param>
/// <param name="interrupt">The input pin number that is connected to INT.</param>
/// <param name="rx0bf">The input pin number that is connected to Rx0BF.</param>
/// <param name="rx1bf">The input pin number that is connected to Rx1BF.</param>
/// <param name="clkout">The input pin number that is connected to CLKOUT.</param>
/// <param name="masterGpioController">
/// The GPIO controller for defined external pins. If not specified, the default controller will be used.
/// </param>
public Mcp25625(
SpiDevice spiDevice,
int reset = -1,
int tx0rts = -1,
int tx1rts = -1,
int tx2rts = -1,
int standby = -1,
int interrupt = -1,
int rx0bf = -1,
int rx1bf = -1,
int clkout = -1,
IGpioController masterGpioController = null)
: base(
spiDevice,
reset,
tx0rts,
tx1rts,
tx2rts,
interrupt,
rx0bf,
rx1bf,
clkout,
masterGpioController)
{
_standby = standby;

if (_standby != -1)
{
// Master controller should already be configured if other pins are used.
_masterGpioController = _masterGpioController ?? new GpioController();
_masterGpioController.OpenPin(_standby, PinMode.Output);
}
}

/// <summary>
/// Writes a value to STBY pin.
/// </summary>
public void WriteStandbyPin(PinValue value)
{
if (_standby == -1)
{
throw new InvalidOperationException("No Standby pin configured.");
}

_masterGpioController.Write(_standby, value);
}
}
}
Loading