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
|
#include "mbed.h"
#include "test_env.h"
namespace {
BusOut bus_out(LED1, LED2, LED3, LED4);
PinName led_pins[4] = {LED1, LED2, LED3, LED4}; // Temp, used to map pins in bus_out
}
int main()
{
notify_start();
bool result = false;
for (;;) {
const int mask = bus_out.mask();
int led_mask = 0x00;
if (LED1 != NC) led_mask |= 0x01;
if (LED2 != NC) led_mask |= 0x02;
if (LED3 != NC) led_mask |= 0x04;
if (LED4 != NC) led_mask |= 0x08;
printf("MBED: BusIn mask: 0x%X\r\n", mask);
printf("MBED: BusIn LED mask: 0x%X\r\n", led_mask);
// Let's check bus's connected pins mask
if (mask != led_mask) {
break;
}
// Checking if DigitalOut is correctly set as connected
for (int i=0; i < 4; i++) {
printf("MBED: BusOut.bit[%d] is %s\r\n",
i,
(led_pins[i] != NC && bus_out[i].is_connected())
? "connected"
: "not connected");
}
for (int i=0; i < 4; i++) {
if (led_pins[i] != NC && bus_out[0].is_connected() == 0) {
break;
}
}
// Write mask all LEDs
bus_out.write(mask); // Set all LED's pins in high state
if (bus_out.read() != mask) {
break;
}
// Zero all LEDs and see if mask is correctly cleared on all bits
bus_out.write(~mask);
if (bus_out.read() != 0x00) {
break;
}
result = true;
break;
}
printf("MBED: Blinking LEDs: \r\n");
// Just a quick LED blinking...
for (int i=0; i<4; i++) {
if (led_pins[i] != NC && bus_out[i].is_connected()) {
bus_out[i] = 1;
printf("%c", 'A' + i);
} else {
printf(".");
}
wait(0.2);
if (led_pins[i] != NC && bus_out[i].is_connected()) {
bus_out[i] = 0;
printf("%c", 'a' + i);
} else {
printf(".");
}
}
printf("\r\n");
notify_completion(result);
}
|