Thib ob HDMI saib rau Raspberry Pi3 ntawm DPI interface thiab FPGA board


Cov yeeb yaj kiab no qhia tau hais tias: lub rooj tsav xwm Raspberry Pi3, txuas nrog nws ntawm GPIO connector yog FPGA board Mars Rover2rpi (Cyclone IV), uas lub HDMI saib txuas nrog. Qhov thib ob saib yog txuas ntawm tus qauv HDMI connector ntawm Raspberry Pi3. Txhua yam ua haujlwm ua ke zoo li ob lub monitor system.

Tom ntej no kuv yuav qhia koj seb qhov no siv tau li cas.

Qhov nrov Raspberry Pi3 pawg thawj coj saib muaj GPIO txuas uas koj tuaj yeem txuas ntau daim npav nthuav dav: sensors, LEDs, stepper tsav tsav thiab ntau ntxiv. Qhov tseeb muaj nuj nqi ntawm txhua tus pin ntawm ib lub connector nyob ntawm qhov chaw nres nkoj configuration. GPIO ALT2 configuration tso cai rau koj hloov lub connector rau DPI interface hom, Display Parallel Interface. Muaj cov npav nthuav dav rau txuas VGA saib ntawm DPI. Txawm li cas los xij, thawj zaug, VGA saib tsis muaj ntau dua li HDMI, thiab qhov thib ob, cov kev sib txuas lus digital tau nce zoo dua li cov analogue. Ntxiv mus, DAC ntawm xws li VGA expansion boards feem ntau yog ua nyob rau hauv daim ntawv ntawm R-2-R chains thiab feem ntau tsis ntau tshaj 6 khoom ib xim.

Hauv ALT2 hom, GPIO connector pins muaj cov ntsiab lus hauv qab no:

Thib ob HDMI saib rau Raspberry Pi3 ntawm DPI interface thiab FPGA board

Ntawm no kuv tau xim RGB pins ntawm connector liab, ntsuab thiab xiav feem. Lwm cov cim tseem ceeb yog V-SYNC thiab H-SYNC cov cim, nrog rau CLK. Lub CLK moos zaus yog qhov zaus ntawm qhov pixel qhov tseem ceeb yog tso tawm rau lub connector; nws nyob ntawm qhov xaiv video hom.

Txhawm rau txuas lub digital HDMI saib, koj yuav tsum tau ntes DPI cov cim ntawm lub interface thiab hloov mus rau HDMI cov teeb liab. Qhov no tuaj yeem ua tau, piv txwv li, siv qee yam ntawm FPGA pawg thawj coj saib. Raws li nws hloov tawm, Mars Rover2rpi board yog tsim rau cov hom phiaj no. Qhov tseeb, qhov kev xaiv tseem ceeb rau kev txuas lub rooj tsavxwm no los ntawm lub adapter tshwj xeeb zoo li no:

Thib ob HDMI saib rau Raspberry Pi3 ntawm DPI interface thiab FPGA board

Lub rooj tsavxwm no yog siv los ua kom cov GPIO cov chaw nres nkoj thiab txuas ntxiv cov khoom siv peripheral mus rau raspberry. Nyob rau tib lub sijhawm, 4 GPIO cov cim nrog qhov kev sib txuas no yog siv rau JTAG cov cim, kom cov kev pab cuam los ntawm Raspberry tuaj yeem thauj cov FPGA firmware rau hauv FPGA. Vim li no, qhov kev sib txuas tus qauv no tsis haum rau kuv; 4 DPI cov teeb liab poob tawm. Luckily, cov combs ntxiv ntawm lub rooj tsavxwm muaj Raspberry-tshaj pinout. Yog li kuv tuaj yeem tig lub rooj tsavxwm 90 degrees thiab tseem txuas rau kuv lub raspberry:

Thib ob HDMI saib rau Raspberry Pi3 ntawm DPI interface thiab FPGA board

Tau kawg, koj yuav tau siv tus programmer sab nraud JTAG, tab sis qhov no tsis yog teeb meem.

Tseem muaj teeb meem me me. Tsis yog txhua tus FPGA tus pin tuaj yeem siv los ua lub moos nkag. Tsuas muaj qee tus pins tshwj xeeb uas tuaj yeem siv rau lub hom phiaj no. Yog li nws tau muab tawm ntawm no tias GPIO_0 CLK teeb liab tsis ncav cuag FPGA cov tswv yim, uas tuaj yeem siv los ua FPGA moos input. Yog li kuv tseem yuav tsum tau muab ib txoj hlua khi rau ntawm txoj phuam. Kuv txuas GPIO_0 thiab lub rooj tsavxwm KEY[1] teeb liab:

Thib ob HDMI saib rau Raspberry Pi3 ntawm DPI interface thiab FPGA board

Tam sim no kuv yuav qhia koj me ntsis txog qhov project FPGA. Qhov teeb meem tseem ceeb hauv kev tsim cov teeb liab HDMI yog qhov siab heev. Yog tias koj saib ntawm HDMI connector pinout, koj tuaj yeem pom tias cov teeb liab RGB tam sim no yog cov cim sib txawv:

Thib ob HDMI saib rau Raspberry Pi3 ntawm DPI interface thiab FPGA board

Kev siv lub teeb liab sib txawv tso cai rau koj los tawm tsam hom kev cuam tshuam ntawm cov kab sib kis. Hauv qhov no, thawj yim-ntsis code ntawm txhua lub teeb liab xim yog hloov mus rau 10-ntsis TMDS (Transition-minimized differential signaling). Qhov no yog ib txoj kev tshwj xeeb coding kom tshem tawm DC tivthaiv ntawm lub teeb liab thiab txo cov teeb liab hloov mus rau hauv ib txoj kab sib txawv. Txij li thaum 10 cov khoom tam sim no yuav tsum tau xa mus hla cov kab sib txuas rau ib byte ntawm cov xim, nws hloov tawm tias serializer moos ceev yuav tsum yog 10 npaug siab dua li pixel moos ceev. Yog tias peb ua piv txwv hom video 1280x720 60Hz, ces pixel zaus ntawm hom no yog 74,25 MHz. Lub serializer yuav tsum yog 742,5 MHz.

Tsis tu ncua FPGAs, hmoov tsis, tsis muaj peev xwm ntawm qhov no. Txawm li cas los xij, hmoov zoo rau peb, FPGA tau tsim-hauv DDIO pins. Cov no yog cov lus xaus uas twb muaj lawm, raws li nws yog, 2-rau-1 serializers. Ntawd yog, lawv tuaj yeem tso tawm ob qhov sib txuas ntawm qhov nce thiab poob ntawm lub moos zaus. Qhov no txhais tau hais tias hauv qhov project FPGA koj tuaj yeem siv tsis yog 740 MHz, tab sis 370 MHz, tab sis koj yuav tsum siv DDIO cov khoom tso tawm hauv FPGA. Tam sim no 370 MHz twb yog ib qho kev ua tiav tiav. Hmoov tsis zoo, 1280x720 hom yog qhov txwv. Kev daws teeb meem siab dua tsis tuaj yeem ua tiav hauv peb Cyclone IV FPGA ntsia ntawm Mars Rover2rpi board.

Yog li, nyob rau hauv tus tsim, input pixel zaus CLK mus rau lub PLL, qhov twg nws yog multiplied los ntawm 5. Ntawm no zaus, lub R, G, B bytes yog hloov dua siab tshiab rau hauv me ntsis khub. Qhov no yog qhov TMDS encoder ua. Qhov chaws hauv Verilog HDL zoo li no:

module hdmi(
	input wire pixclk,		// 74MHz
	input wire clk_TMDS2,	// 370MHz
	input wire hsync,
	input wire vsync,
	input wire active,
	input wire [7:0]red,
	input wire [7:0]green,
	input wire [7:0]blue,
	output wire TMDS_bh,
	output wire TMDS_bl,
	output wire TMDS_gh,
	output wire TMDS_gl,
	output wire TMDS_rh,
	output wire TMDS_rl
);

wire [9:0] TMDS_red, TMDS_green, TMDS_blue;
TMDS_encoder encode_R(.clk(pixclk), .VD(red  ), .CD({vsync,hsync}), .VDE(active), .TMDS(TMDS_red));
TMDS_encoder encode_G(.clk(pixclk), .VD(green), .CD({vsync,hsync}), .VDE(active), .TMDS(TMDS_green));
TMDS_encoder encode_B(.clk(pixclk), .VD(blue ), .CD({vsync,hsync}), .VDE(active), .TMDS(TMDS_blue));

reg [2:0] TMDS_mod5=0;  // modulus 5 counter
reg [4:0] TMDS_shift_bh=0, TMDS_shift_bl=0;
reg [4:0] TMDS_shift_gh=0, TMDS_shift_gl=0;
reg [4:0] TMDS_shift_rh=0, TMDS_shift_rl=0;

wire [4:0] TMDS_blue_l  = {TMDS_blue[9],TMDS_blue[7],TMDS_blue[5],TMDS_blue[3],TMDS_blue[1]};
wire [4:0] TMDS_blue_h  = {TMDS_blue[8],TMDS_blue[6],TMDS_blue[4],TMDS_blue[2],TMDS_blue[0]};
wire [4:0] TMDS_green_l = {TMDS_green[9],TMDS_green[7],TMDS_green[5],TMDS_green[3],TMDS_green[1]};
wire [4:0] TMDS_green_h = {TMDS_green[8],TMDS_green[6],TMDS_green[4],TMDS_green[2],TMDS_green[0]};
wire [4:0] TMDS_red_l   = {TMDS_red[9],TMDS_red[7],TMDS_red[5],TMDS_red[3],TMDS_red[1]};
wire [4:0] TMDS_red_h   = {TMDS_red[8],TMDS_red[6],TMDS_red[4],TMDS_red[2],TMDS_red[0]};

always @(posedge clk_TMDS2)
begin
	TMDS_shift_bh <= TMDS_mod5[2] ? TMDS_blue_h  : TMDS_shift_bh  [4:1];
	TMDS_shift_bl <= TMDS_mod5[2] ? TMDS_blue_l  : TMDS_shift_bl  [4:1];
	TMDS_shift_gh <= TMDS_mod5[2] ? TMDS_green_h : TMDS_shift_gh  [4:1];
	TMDS_shift_gl <= TMDS_mod5[2] ? TMDS_green_l : TMDS_shift_gl  [4:1];
	TMDS_shift_rh <= TMDS_mod5[2] ? TMDS_red_h   : TMDS_shift_rh  [4:1];
	TMDS_shift_rl <= TMDS_mod5[2] ? TMDS_red_l   : TMDS_shift_rl  [4:1];
	TMDS_mod5 <= (TMDS_mod5[2]) ? 3'd0 : TMDS_mod5+3'd1;
end

assign TMDS_bh = TMDS_shift_bh[0];
assign TMDS_bl = TMDS_shift_bl[0];
assign TMDS_gh = TMDS_shift_gh[0];
assign TMDS_gl = TMDS_shift_gl[0];
assign TMDS_rh = TMDS_shift_rh[0];
assign TMDS_rl = TMDS_shift_rl[0];

endmodule

module TMDS_encoder(
	input clk,
	input [7:0] VD,	// video data (red, green or blue)
	input [1:0] CD,	// control data
	input VDE,  	// video data enable, to choose between CD (when VDE=0) and VD (when VDE=1)
	output reg [9:0] TMDS = 0
);

wire [3:0] Nb1s = VD[0] + VD[1] + VD[2] + VD[3] + VD[4] + VD[5] + VD[6] + VD[7];
wire XNOR = (Nb1s>4'd4) || (Nb1s==4'd4 && VD[0]==1'b0);
wire [8:0] q_m = {~XNOR, q_m[6:0] ^ VD[7:1] ^ {7{XNOR}}, VD[0]};

reg [3:0] balance_acc = 0;
wire [3:0] balance = q_m[0] + q_m[1] + q_m[2] + q_m[3] + q_m[4] + q_m[5] + q_m[6] + q_m[7] - 4'd4;
wire balance_sign_eq = (balance[3] == balance_acc[3]);
wire invert_q_m = (balance==0 || balance_acc==0) ? ~q_m[8] : balance_sign_eq;
wire [3:0] balance_acc_inc = balance - ({q_m[8] ^ ~balance_sign_eq} & ~(balance==0 || balance_acc==0));
wire [3:0] balance_acc_new = invert_q_m ? balance_acc-balance_acc_inc : balance_acc+balance_acc_inc;
wire [9:0] TMDS_data = {invert_q_m, q_m[8], q_m[7:0] ^ {8{invert_q_m}}};
wire [9:0] TMDS_code = CD[1] ? (CD[0] ? 10'b1010101011 : 10'b0101010100) : (CD[0] ? 10'b0010101011 : 10'b1101010100);

always @(posedge clk) TMDS <= VDE ? TMDS_data : TMDS_code;
always @(posedge clk) balance_acc <= VDE ? balance_acc_new : 4'h0;

endmodule

Tom qab ntawd cov khoom tso tawm tau muab pub rau DDIO cov zis, uas ua raws cov teeb liab ib-ntsis ntawm qhov nce thiab poob.

DDIO nws tus kheej tuaj yeem piav qhia nrog Verilog code hauv qab no:

module ddio(
	input wire d0,
	input wire d1,
	input wire clk,
	output wire out
	);

reg r_d0;
reg r_d1;
always @(posedge clk)
begin
	r_d0 <= d0;
	r_d1 <= d1;
end
assign out = clk ? r_d0 : r_d1;
endmodule

Tab sis feem ntau nws yuav tsis ua haujlwm li ntawd. Koj yuav tsum siv Alter's megafunction ALTDDIO_OUT los ua kom cov DDIO tso zis cov ntsiab lus. Kuv qhov project siv lub tsev qiv ntawv ALTDDIO_OUT.

Qhov no tej zaum yuav zoo li me ntsis nyuaj, tab sis nws ua haujlwm.

Koj tuaj yeem saib tag nrho cov cai sau hauv Verilog HDL ntawm no github.

Cov firmware muab tso ua ke rau FPGA yog flashed rau hauv EPCS nti ntsia ntawm Mars Rover2rpi board. Yog li, thaum lub zog siv rau FPGA lub rooj tsavxwm, FPGA yuav pib pib ntawm lub cim xeeb flash thiab pib.

Tam sim no peb yuav tsum tham me ntsis txog kev teeb tsa ntawm Raspberry nws tus kheej.

Kuv tab tom ua kev sim ntawm Raspberry PI OS (32 ntsis) raws li Debian Buster, Version: Lub Yim Hli 2020,
Hnub tim: 2020-08-20, Kernel version: 5.4.

Koj yuav tsum ua ob yam:

  • kho cov ntaub ntawv config.txt;
  • tsim ib qho X server configuration los ua haujlwm nrog ob tus saib.

Thaum kho cov ntaub ntawv /boot/config.txt koj xav tau:

  1. lov tes taw kev siv i2c, i2s, spi;
  2. pab kom DPI hom siv overlay dtoverlay = dpi24;
  3. configure video hom 1280 Γ— 720 60Hz, 24 ntsis ib pixel ntawm DPI;
  4. qhia tus lej yuav tsum tau ntawm framebuffers 2 (max_framebuffers = 2, tsuas yog tom qab ntawd yuav cov khoom thib ob /dev/fb1 tshwm)

Cov ntawv tag nrho ntawm cov ntaub ntawv config.txt zoo li no.

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

dtparam=i2c_arm=off
dtparam=spi=off
dtparam=i2s=off

dtoverlay=dpi24
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0
framebuffer_width=1280
framebuffer_height=720
display_default_lcd=0
enable_dpi_lcd=1
dpi_group=2
dpi_mode=87
#dpi_group=1
#dpi_mode=4
dpi_output_format=0x6f027
dpi_timings=1280 1 110 40 220 720 1 5 5 20 0 0 0 60 0 74000000 3

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
#dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
#dtoverlay=vc4-fkms-v3d
max_framebuffers=2

Tom qab ntawd, koj yuav tsum tsim cov ntaub ntawv teeb tsa rau X server siv ob lub saib ntawm ob lub framebuffers /dev/fb0 thiab /dev/fb1:

Kuv configuration file /usr/share/x11/xorg.conf.d/60-dualscreen.conf zoo li no

Section "Device"
        Identifier      "LCD"
        Driver          "fbturbo"
        Option          "fbdev" "/dev/fb0"
        Option          "ShadowFB" "off"
        Option          "SwapbuffersWait" "true"
EndSection

Section "Device"
        Identifier      "HDMI"
        Driver          "fbturbo"
        Option          "fbdev" "/dev/fb1"
        Option          "ShadowFB" "off"
        Option          "SwapbuffersWait" "true"
EndSection

Section "Monitor"
        Identifier      "LCD-monitor"
        Option          "Primary" "true"
EndSection

Section "Monitor"
        Identifier      "HDMI-monitor"
        Option          "RightOf" "LCD-monitor"
EndSection

Section "Screen"
        Identifier      "screen0"
        Device          "LCD"
        Monitor         "LCD-monitor"
EndSection

Section "Screen"
        Identifier      "screen1"
        Device          "HDMI" 
	Monitor         "HDMI-monitor"
EndSection

Section "ServerLayout"
        Identifier      "default"
        Option          "Xinerama" "on"
        Option          "Clone" "off"
        Screen 0        "screen0"
        Screen 1        "screen1" RightOf "screen0"
EndSection

Zoo, yog tias nws tsis tau teeb tsa, ces koj yuav tsum nruab Xinerama. Tom qab ntawd qhov chaw desktop yuav nthuav dav rau ob lub saib, raws li pom hauv cov yeeb yaj kiab demo saum toj no.

Qhov ntawd yog txhua yam. Tam sim no, Raspberry Pi3 cov tswv yuav tuaj yeem siv ob lub saib.

Cov lus piav qhia thiab daim duab kos duab ntawm Mars Rover2rpi board tuaj yeem pom saib ntawm no.

Tau qhov twg los: www.hab.com