data/full_repos/permissive/194847941/demo/15_ov5640_sdram/src/sccb/I2C_OV5640_Init_RGB565.v
1: b'%Warning-WIDTH: data/full_repos/permissive/194847941/demo/15_ov5640_sdram/src/sccb/I2C_OV5640_Init_RGB565.v:57: Operator LT expects 32 or 27 bits on the LHS, but LHS\'s VARREF \'i2c_clk_div\' generates 16 bits.\n                                                                                                              : ... In instance I2C_OV5640_Init_RGB565\n  if( i2c_clk_div < (CLK_Freq/I2C_Freq)/2)\n                  ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/194847941/demo/15_ov5640_sdram/src/sccb/I2C_OV5640_Init_RGB565.v:118: Operator LT expects 12 bits on the LHS, but LHS\'s VARREF \'lut_index\' generates 9 bits.\n                                                                                                               : ... In instance I2C_OV5640_Init_RGB565\n    if(lut_index < 12\'d2)\n                 ^\n%Error: data/full_repos/permissive/194847941/demo/15_ov5640_sdram/src/sccb/I2C_OV5640_Init_RGB565.v:164: Cannot find file containing module: \'I2C_Controller\'\n I2C_Controller  u_I2C_Controller \n ^~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/194847941/demo/15_ov5640_sdram/src/sccb,data/full_repos/permissive/194847941/I2C_Controller\n             data/full_repos/permissive/194847941/demo/15_ov5640_sdram/src/sccb,data/full_repos/permissive/194847941/I2C_Controller.v\n             data/full_repos/permissive/194847941/demo/15_ov5640_sdram/src/sccb,data/full_repos/permissive/194847941/I2C_Controller.sv\n             I2C_Controller\n             I2C_Controller.v\n             I2C_Controller.sv\n             obj_dir/I2C_Controller\n             obj_dir/I2C_Controller.v\n             obj_dir/I2C_Controller.sv\n%Error: data/full_repos/permissive/194847941/demo/15_ov5640_sdram/src/sccb/I2C_OV5640_Init_RGB565.v:185: Cannot find file containing module: \'I2C_OV5640_RGB565_Config\'\n I2C_OV5640_RGB565_Config u_I2C_OV5640_RGB565_Config\n ^~~~~~~~~~~~~~~~~~~~~~~~\n%Error: Exiting due to 2 error(s), 2 warning(s)\n'
module I2C_OV5640_Init_RGB565
(

	input		clk,
	input		rst_n,
	

	output		i2c_sclk,
	inout		i2c_sdat,
	
	output		config_done
);
reg   Config_done;




parameter	CLK_Freq	=	100_000000;
parameter	I2C_Freq	=	100_000;
reg	[15:0]	i2c_clk_div;
reg			i2c_ctrl_clk;
always@(posedge clk or negedge rst_n)
begin
	if(!rst_n) begin
		i2c_clk_div	<=	0;
		i2c_ctrl_clk	<=	0;
	end else begin
		if( i2c_clk_div	< (CLK_Freq/I2C_Freq)/2)
			 i2c_clk_div	<=	i2c_clk_div + 1'd1;
		else begin
			 i2c_clk_div	<=	0;
			i2c_ctrl_clk	<=	~i2c_ctrl_clk;
		end
	end
end



reg	i2c_en_r0, i2c_en_r1;
always@(posedge clk or negedge rst_n)
begin
	if(!rst_n)
		begin
		i2c_en_r0 <= 0;
		i2c_en_r1 <= 0;
		end
	else
		begin
		i2c_en_r0 <= i2c_ctrl_clk;
		i2c_en_r1 <= i2c_en_r0;
		end
end
wire	i2c_negclk = (i2c_en_r1 & ~i2c_en_r0) ? 1'b1 : 1'b0;



wire			i2c_end;
wire			i2c_ack;
reg		[8:0]	lut_index;
reg		[1:0]	setup_state;
reg				i2c_trans;
reg				i2c_wr;
wire	[23:0]	lut_data;
reg		[39:0]	i2c_data;

wire	[8:0]	LUT_SIZE;
always@(posedge clk or negedge rst_n)
begin
	if(!rst_n)
		begin
		Config_done <= 0;
		lut_index	<=	0;
		setup_state	<=	0;
		i2c_trans		<=	0;
		i2c_wr     <=	0;	
		end
	else if(i2c_negclk)
		begin
		if(lut_index < LUT_SIZE)
			begin
			Config_done <= 0;
			case(setup_state)
			0:	begin
				if(~i2c_end)
					setup_state	<=	1;		
				else
					setup_state	<=	0;				
					i2c_trans		<=	1;
				if(lut_index < 12'd2)
					begin
					i2c_wr <= 0;
					i2c_data<={8'h79,8'h78,lut_data};
					end
				else
				begin
					i2c_wr <= 1;
					i2c_data<={8'h00,8'h78,lut_data};
				end
				end
			1:	
				begin
				if(i2c_end)
					begin
					i2c_wr <= 0;
					i2c_trans <= 0;
					if(~i2c_ack)
						setup_state	<=	2;
					else
						setup_state	<=	0;
					end
				end
			2:	begin
				lut_index	<= lut_index + 1'd1;
				setup_state	<= 0;
				i2c_trans	<= 0;
				i2c_wr      <= 0;
				end
			endcase
			end
		else
			begin
			Config_done <= 1'b1;
			lut_index 	<= lut_index;
			setup_state	<= 0;
			i2c_trans	<= 0;
			i2c_wr      <= 0;
			end
	end
end

assign config_done=Config_done;



	I2C_Controller 	u_I2C_Controller	
	(	
		.clk			(clk),
		.rst_n			(rst_n),
								
		.i2c_clk		(i2c_ctrl_clk),
		.i2c_en			(i2c_negclk),
		.i2c_wdata		(i2c_data),
		.i2c_sclk		(i2c_sclk),
		.i2c_sdat		(i2c_sdat),
		
		.trans			(i2c_trans),
		.wr				(i2c_wr),
		.ack			(i2c_ack),
		.i2c_end		(i2c_end),
		.i2c_rdata		()
	);


			

	I2C_OV5640_RGB565_Config	u_I2C_OV5640_RGB565_Config
	(
		.LUT_INDEX		(lut_index	),
		.LUT_DATA		(lut_data	),
		.LUT_SIZE		(LUT_SIZE	)
	);



endmodule
module I2C_OV5640_Init_RGB565
(

	input		clk,
	input		rst_n,
	

	output		i2c_sclk,
	inout		i2c_sdat,
	
	output		config_done
);

reg   Config_done;




parameter	CLK_Freq	=	100_000000;
parameter	I2C_Freq	=	100_000;
reg	[15:0]	i2c_clk_div;
reg			i2c_ctrl_clk;
always@(posedge clk or negedge rst_n)
begin
	if(!rst_n) begin
		i2c_clk_div	<=	0;
		i2c_ctrl_clk	<=	0;
	end else begin
		if( i2c_clk_div	< (CLK_Freq/I2C_Freq)/2)
			 i2c_clk_div	<=	i2c_clk_div + 1'd1;
		else begin
			 i2c_clk_div	<=	0;
			i2c_ctrl_clk	<=	~i2c_ctrl_clk;
		end
	end
end



reg	i2c_en_r0, i2c_en_r1;
always@(posedge clk or negedge rst_n)
begin
	if(!rst_n)
		begin
		i2c_en_r0 <= 0;
		i2c_en_r1 <= 0;
		end
	else
		begin
		i2c_en_r0 <= i2c_ctrl_clk;
		i2c_en_r1 <= i2c_en_r0;
		end
end
wire	i2c_negclk = (i2c_en_r1 & ~i2c_en_r0) ? 1'b1 : 1'b0;



wire			i2c_end;
wire			i2c_ack;
reg		[8:0]	lut_index;
reg		[1:0]	setup_state;
reg				i2c_trans;
reg				i2c_wr;
wire	[23:0]	lut_data;
reg		[39:0]	i2c_data;

wire	[8:0]	LUT_SIZE;
always@(posedge clk or negedge rst_n)
begin
	if(!rst_n)
		begin
		Config_done <= 0;
		lut_index	<=	0;
		setup_state	<=	0;
		i2c_trans		<=	0;
		i2c_wr     <=	0;	
		end
	else if(i2c_negclk)
		begin
		if(lut_index < LUT_SIZE)
			begin
			Config_done <= 0;
			case(setup_state)
			0:	begin
				if(~i2c_end)
					setup_state	<=	1;		
				else
					setup_state	<=	0;				
					i2c_trans		<=	1;
				if(lut_index < 12'd2)
					begin
					i2c_wr <= 0;
					i2c_data<={8'h79,8'h78,lut_data};
					end
				else
				begin
					i2c_wr <= 1;
					i2c_data<={8'h00,8'h78,lut_data};
				end
				end
			1:	
				begin
				if(i2c_end)
					begin
					i2c_wr <= 0;
					i2c_trans <= 0;
					if(~i2c_ack)
						setup_state	<=	2;
					else
						setup_state	<=	0;
					end
				end
			2:	begin
				lut_index	<= lut_index + 1'd1;
				setup_state	<= 0;
				i2c_trans	<= 0;
				i2c_wr      <= 0;
				end
			endcase
			end
		else
			begin
			Config_done <= 1'b1;
			lut_index 	<= lut_index;
			setup_state	<= 0;
			i2c_trans	<= 0;
			i2c_wr      <= 0;
			end
	end
end

assign config_done=Config_done;



	I2C_Controller 	u_I2C_Controller	
	(	
		.clk			(clk),
		.rst_n			(rst_n),
								
		.i2c_clk		(i2c_ctrl_clk),
		.i2c_en			(i2c_negclk),
		.i2c_wdata		(i2c_data),
		.i2c_sclk		(i2c_sclk),
		.i2c_sdat		(i2c_sdat),
		
		.trans			(i2c_trans),
		.wr				(i2c_wr),
		.ack			(i2c_ack),
		.i2c_end		(i2c_end),
		.i2c_rdata		()
	);


			

	I2C_OV5640_RGB565_Config	u_I2C_OV5640_RGB565_Config
	(
		.LUT_INDEX		(lut_index	),
		.LUT_DATA		(lut_data	),
		.LUT_SIZE		(LUT_SIZE	)
	);



endmodule