Skip to content

Commit

Permalink
fixes hdl-util#43: enforce hdmi 12px minimum control period during vi…
Browse files Browse the repository at this point in the history
…deo and data-island preambles; fixed off-by-one errors on VG, VP, and VSync
  • Loading branch information
krisd committed Aug 20, 2023
1 parent b5bc3d7 commit a3f0739
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/hdmi.sv
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ always_comb begin
hsync <= invert ^ (cx >= screen_width + hsync_pulse_start && cx < screen_width + hsync_pulse_start + hsync_pulse_size);
// vsync pulses should begin and end at the start of hsync, so special
// handling is required for the lines on which vsync starts and ends
if (cy == screen_height + vsync_pulse_start)
if (cy == screen_height + vsync_pulse_start - 1)
vsync <= invert ^ (cx >= screen_width + hsync_pulse_start);
else if (cy == screen_height + vsync_pulse_start + vsync_pulse_size)
else if (cy == screen_height + vsync_pulse_start + vsync_pulse_size - 1)
vsync <= invert ^ (cx < screen_width + hsync_pulse_start);
else
vsync <= invert ^ (cy >= screen_height + vsync_pulse_start && cy < screen_height + vsync_pulse_start + vsync_pulse_size);
Expand Down Expand Up @@ -254,8 +254,8 @@ generate
end
else
begin
video_guard <= cx >= frame_width - 2 && cx < frame_width && (cy == frame_height - 1 || cy < screen_height);
video_preamble <= cx >= frame_width - 10 && cx < frame_width - 2 && (cy == frame_height - 1 || cy < screen_height);
video_guard <= cx >= frame_width - 2 && cx < frame_width && (cy == frame_height - 1 || cy < screen_height - 1 /* no VG at end of last line */);
video_preamble <= cx >= frame_width - 10 && cx < frame_width - 2 && (cy == frame_height - 1 || cy < screen_height - 1 /* no VP at end of last line */);
end
end

Expand All @@ -264,17 +264,17 @@ generate
logic [4:0] num_packets_alongside;
always_comb
begin
max_num_packets_alongside = ((frame_width - screen_width) /* VD period */ - 2 /* V guard */ - 8 /* V preamble */ - 12 /* 12px control period */ - 2 /* DI guard */ - 2 /* DI start guard */ - 8 /* DI premable */) / 32;
max_num_packets_alongside = (frame_width - screen_width /* VD period */ - 2 /* V guard */ - 8 /* V preamble */ - 4 /* Min V control period */ - 2 /* DI trailing guard */ - 2 /* DI leading guard */ - 8 /* DI premable */ - 4 /* Min DI control period */) / 32;
if (max_num_packets_alongside > 18)
num_packets_alongside = 5'd18;
else
num_packets_alongside = 5'(max_num_packets_alongside);
end

logic data_island_period_instantaneous;
assign data_island_period_instantaneous = num_packets_alongside > 0 && cx >= screen_width + 10 && cx < screen_width + 10 + num_packets_alongside * 32;
assign data_island_period_instantaneous = num_packets_alongside > 0 && cx >= screen_width + 14 && cx < screen_width + 14 + num_packets_alongside * 32;
logic packet_enable;
assign packet_enable = data_island_period_instantaneous && 5'(cx + screen_width + 22) == 5'd0;
assign packet_enable = data_island_period_instantaneous && 5'(cx + screen_width + 18) == 5'd0;

logic data_island_guard = 0;
logic data_island_preamble = 0;
Expand All @@ -289,8 +289,11 @@ generate
end
else
begin
data_island_guard <= num_packets_alongside > 0 && ((cx >= screen_width + 8 && cx < screen_width + 10) || (cx >= screen_width + 10 + num_packets_alongside * 32 && cx < screen_width + 10 + num_packets_alongside * 32 + 2));
data_island_preamble <= num_packets_alongside > 0 && cx >= screen_width && cx < screen_width + 8;
data_island_guard <= num_packets_alongside > 0 && (
(cx >= screen_width + 12 && cx < screen_width + 14) /* leading guard */ ||
(cx >= screen_width + 14 + num_packets_alongside * 32 && cx < screen_width + 14 + num_packets_alongside * 32 + 2) /* trailing guard */
);
data_island_preamble <= num_packets_alongside > 0 && cx >= screen_width + 4 && cx < screen_width + 12;
data_island_period <= data_island_period_instantaneous;
end
end
Expand Down

0 comments on commit a3f0739

Please sign in to comment.