-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_spi.ts
50 lines (29 loc) · 951 Bytes
/
test_spi.ts
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
import { Console} from "as-wasi";
import { buff, cmp } from "../assembly";
import { Spi } from '../assembly/spi';
Console.log("Initialising SPI");
let device = Spi.init(0, 4000000, -1, -1, -1, -1);
Console.log("SPI Write");
let a: u8[] = [0xaa, 0xbb, 0xcc];
device.write(buff(a));
Console.log("SPI Read");
let b: u8[] = [0x00, 0x00, 0x00, 0x00, 0x00];
let b1 = buff(b);
device.read(b1);
assert(cmp(b1, buff([0xab, 0xab, 0xab, 0xab, 0xab])));
Console.log("SPI Transfer In Place");
let c: u8[] = [0xaa, 0xbb, 0xcc, 0xdd];
let c1 = buff(c);
device.transfer_inplace(c1);
Console.log(`RX: ${c}`);
assert(cmp(c1, buff([0x11, 0x22, 0x33, 0x44])));
Console.log("SPI Transfer");
let w: u8[] = [0xaa, 0xbb, 0xcc, 0xdd];
let w1 = buff(w);
let r: u8[] = [0x00, 0x00, 0x00, 0x00];
let r1 = buff(r);
device.transfer(r1, w1);
Console.log(`RX: ${r1}`);
assert(cmp(r1, buff([0x11, 0x22, 0x33, 0x44])));
Console.log("SPI Deinit");
device.deinit();