-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCcmPinTests.cs
106 lines (91 loc) · 3.09 KB
/
CcmPinTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using Meadow;
using Meadow.Hardware;
using Meadow.Logging;
using Meadow.Units;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace CoreComputeBreakout;
public class CcmPinTests
{
private IMeadowDevice _device;
private Logger _logger;
public CcmPinTests(IMeadowDevice device, Logger logger)
{
_device = device;
_logger = logger;
}
public static void PulsePwm(IPwmPort pwm, Action? beforeUp = null, Action? beforeDown = null)
{
beforeUp?.Invoke();
for (var i = 0; i < 100; i += 5)
{
pwm.DutyCycle = i / 100f;
Thread.Sleep(100);
}
beforeDown?.Invoke();
for (var i = 100; i > 0; i -= 5)
{
pwm.DutyCycle = i / 100f;
Thread.Sleep(100);
}
}
public async Task TestPulsePWMs(IF7CoreComputeMeadowDevice device, int iterations)
{
for (var i = 0; i < iterations; i++)
{
foreach (var pin in device.Pins)
{
if (pin.Supports<IPwmChannelInfo>())
{
using (var pwm = device.CreatePwmPort(pin, new Frequency(500, Frequency.UnitType.Hertz), dutyCycle: 0f))
{
pwm.Start();
// do it twice to give the user the chance to probe
for (int c = 0; c < 2; c++)
{
PulsePwm(
pwm,
() => _logger.Info($"Pin {pin.Name} increasing"),
() => _logger.Info($"Pin {pin.Name} decreasing")
);
}
}
}
}
}
}
public async Task TestSPI5ControlPins(int iterations)
{
// this method is intended to allow testing the display control pins with a scope
var chipSelect = _device.CreateDigitalOutputPort(_device.GetPin("D17"));
var dc = _device.CreateDigitalOutputPort(_device.GetPin("D18"));
var reset = _device.CreateDigitalOutputPort(_device.GetPin("D19"));
await Task.Run(async () =>
{
while (iterations > 0)
{
var state = false;
for (int i = 0; i < 20; i++)
{
_logger.Info($"CS {state}");
chipSelect.State = state;
await Task.Delay(500);
}
for (int i = 0; i < 20; i++)
{
_logger.Info($"DC {state}");
chipSelect.State = state;
await Task.Delay(500);
}
for (int i = 0; i < 20; i++)
{
_logger.Info($"RES {state}");
chipSelect.State = state;
await Task.Delay(500);
}
iterations--;
}
});
}
}