]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/tests/mbed/bus_out/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / tests / mbed / bus_out / main.cpp
1 #include "mbed.h"
2 #include "test_env.h"
3
4 namespace {
5 BusOut bus_out(LED1, LED2, LED3, LED4);
6 PinName led_pins[4] = {LED1, LED2, LED3, LED4}; // Temp, used to map pins in bus_out
7 }
8
9 int main()
10 {
11     notify_start();
12
13     bool result = false;
14
15     for (;;) {
16         const int mask = bus_out.mask();
17         int led_mask = 0x00;
18         if (LED1 != NC) led_mask |= 0x01;
19         if (LED2 != NC) led_mask |= 0x02;
20         if (LED3 != NC) led_mask |= 0x04;
21         if (LED4 != NC) led_mask |= 0x08;
22
23         printf("MBED: BusIn mask: 0x%X\r\n", mask);
24         printf("MBED: BusIn LED mask: 0x%X\r\n", led_mask);
25
26         // Let's check bus's connected pins mask
27         if (mask != led_mask) {
28             break;
29         }
30
31         // Checking if DigitalOut is correctly set as connected
32         for (int i=0; i < 4; i++) {
33             printf("MBED: BusOut.bit[%d] is %s\r\n",
34                 i,
35                 (led_pins[i] != NC && bus_out[i].is_connected())
36                     ? "connected"
37                     : "not connected");
38         }
39
40         for (int i=0; i < 4; i++) {
41             if (led_pins[i] != NC && bus_out[0].is_connected() == 0) {
42                 break;
43             }
44         }
45
46         // Write mask all LEDs
47         bus_out.write(mask);    // Set all LED's pins in high state
48         if (bus_out.read() != mask) {
49             break;
50         }
51         // Zero all LEDs and see if mask is correctly cleared on all bits
52         bus_out.write(~mask);
53         if (bus_out.read() != 0x00) {
54             break;
55         }
56
57         result = true;
58         break;
59     }
60
61     printf("MBED: Blinking LEDs: \r\n");
62
63     // Just a quick LED blinking...
64     for (int i=0; i<4; i++) {
65         if (led_pins[i] != NC && bus_out[i].is_connected()) {
66             bus_out[i] = 1;
67             printf("%c", 'A' + i);
68         } else {
69             printf(".");
70         }
71         wait(0.2);
72         if (led_pins[i] != NC && bus_out[i].is_connected()) {
73             bus_out[i] = 0;
74             printf("%c", 'a' + i);
75         } else {
76             printf(".");
77         }
78     }
79     printf("\r\n");
80
81     notify_completion(result);
82 }