-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpint.v
65 lines (53 loc) · 1.2 KB
/
rpint.v
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
/*
* Zucker SOC
* Copyright (c) 2021 Lone Dynamics Corporation. All rights reserved.
*
* SPI slave controller
*
* This receives 16 byte gamepad/joystick reports from Keks firmware as
* makes them available as 120-bit registers.
*
*/
module rpint #()
(
input clk,
input resetn,
output reg [127:0] ldata,
output reg [127:0] rdata,
input sclk,
input mosi,
);
reg [127:0] xfer_buffer;
reg [7:0] xfer_bits = 0;
reg xfer_done = 0;
reg xfer_done_r1;
reg xfer_done_r2;
reg xfer_done_r3;
always @(posedge clk) begin
xfer_done_r1 <= xfer_done;
xfer_done_r2 <= xfer_done_r1;
xfer_done_r3 <= xfer_done_r2;
if (!resetn) begin
xfer_done_r1 <= 0;
xfer_done_r2 <= 0;
xfer_done_r3 <= 0;
end else if (xfer_done_r3 == 1'b0 && xfer_done_r2 == 1'b1) begin
if (xfer_buffer[7:0] == 8'h00) begin
ldata <= xfer_buffer[127:0];
end else if (xfer_buffer[7:0] == 8'h01) begin
rdata <= xfer_buffer[127:0];
end
end
end
always @(posedge sclk) begin
if (xfer_bits == 127) begin
xfer_buffer <= { xfer_buffer, mosi };
xfer_bits <= 0;
xfer_done <= 1;
end else begin
xfer_buffer <= { xfer_buffer, mosi };
xfer_bits <= xfer_bits + 1;
xfer_done <= 0;
end
end
endmodule