data/full_repos/permissive/117026779/src/AmbientLightSensor.v
1: b'%Warning-WIDTH: data/full_repos/permissive/117026779/src/AmbientLightSensor.v:128: Operator ASSIGN expects 16 bits on the Assign RHS, but Assign RHS\'s REPLICATE generates 15 bits.\n                                                                                 : ... In instance AmbientLightSensorDemo.U0\n           shift_in  = { shift_in[14:1], sdata };\n                     ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/117026779/src/AmbientLightSensor.v:121: Operator EQ expects 32 or 5 bits on the LHS, but LHS\'s VARREF \'counter\' generates 4 bits.\n                                                                                 : ... In instance AmbientLightSensorDemo.U0\n          if(counter == 16)\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/117026779/src/AmbientLightSensor.v:138: Operator GTE expects 32 or 9 bits on the LHS, but LHS\'s VARREF \'clk_counter\' generates 4 bits.\n                                                                                 : ... In instance AmbientLightSensorDemo.U0\n          else if(clk_counter >= CLOCK_DIVIDER)\n                              ^~\n%Warning-WIDTH: data/full_repos/permissive/117026779/src/AmbientLightSensor.v:134: Operator GTE expects 32 or 9 bits on the LHS, but LHS\'s VARREF \'clk_counter\' generates 4 bits.\n                                                                                 : ... In instance AmbientLightSensorDemo.U0\n          if(clk_counter >= CLOCK_DIVIDER*2)\n                         ^~\n%Error: data/full_repos/permissive/117026779/src/AmbientLightSensor.v:49: Unsupported: Inout port connection \'data\' to inout signal requires 8 bits, but connection\'s VARREF \'data\' generates 32 bits.\n                                                                        : ... In instance AmbientLightSensorDemo\n    .data(data)\n     ^~~~\n%Warning-WIDTH: data/full_repos/permissive/117026779/src/AmbientLightSensor.v:49: Inout port connection \'data\' expects 8 bits on the pin connection, but pin connection\'s VARREF \'data\' generates 32 bits.\n                                                                                : ... In instance AmbientLightSensorDemo\n    .data(data)\n     ^~~~\n%Error: Exiting due to 1 error(s), 5 warning(s)\n'
module AmbientLightSensor(
    input wire clk,
    input wire rst,
    input wire oe,
    input wire trigger,
    input wire sdata,
    output reg sclk,
    output reg cs,
    output reg done,
    inout wire [7:0] data
);



parameter IDLE 			= 0;
parameter ACQUIRE_DATA 	= 1;
parameter CLOCK_WAIT 	= 2;
parameter LATCH_DATA 	= 3;
parameter CLOCK_DIVIDER	= 500;



reg [15:0] out;
reg [15:0] shift_in;
reg [ 3:0] counter;
reg [ 3:0] clk_counter;
reg [ 1:0] state;






assign data       = oe ? out[7:0] : 8'bz;






always @(posedge clk or posedge rst)
begin
    if (rst)
    begin
    	out 		= 0;
        counter 	= 0;
        state 		= IDLE;
        clk_counter = 0;
        done 		= 0;
        sclk        = 0;
        shift_in    = 0;
    end
    else
    begin
        case(state)
        	IDLE:
        	begin
        		if(trigger)
        		begin
        			counter = 0;
			        done    = 0;
			        cs 		= 0;
			        state   = ACQUIRE_DATA;
        		end
        	end
        	ACQUIRE_DATA:
        	begin
        		if(counter == 16)
        		begin
        			state 		= LATCH_DATA;
        		end
        		else begin
        		    counter = counter + 1;
	        		clk_counter = 0;
	        		shift_in 	= { shift_in[14:1], sdata };
	        		state 		= CLOCK_WAIT;
        		end
        	end
        	CLOCK_WAIT:
        	begin
        		if(clk_counter >= CLOCK_DIVIDER*2)
        		begin
        			state = ACQUIRE_DATA;
        		end
        		else if(clk_counter >= CLOCK_DIVIDER)
        		begin
        			sclk = 1;
        		end
        		else begin
        			sclk = 0;
        		end
        		clk_counter = clk_counter + 1;
        	end
        	LATCH_DATA:
    		begin
		        cs 		= 0;
		        done 	= 1;
		        out 	= shift_in;
		        state 	= IDLE;
    		end
        endcase
    end
end
endmodule
module AmbientLightSensor(
    input wire clk,
    input wire rst,
    input wire oe,
    input wire trigger,
    input wire sdata,
    output reg sclk,
    output reg cs,
    output reg done,
    inout wire [7:0] data
);




parameter IDLE 			= 0;
parameter ACQUIRE_DATA 	= 1;
parameter CLOCK_WAIT 	= 2;
parameter LATCH_DATA 	= 3;
parameter CLOCK_DIVIDER	= 500;



reg [15:0] out;
reg [15:0] shift_in;
reg [ 3:0] counter;
reg [ 3:0] clk_counter;
reg [ 1:0] state;






assign data       = oe ? out[7:0] : 8'bz;






always @(posedge clk or posedge rst)
begin
    if (rst)
    begin
    	out 		= 0;
        counter 	= 0;
        state 		= IDLE;
        clk_counter = 0;
        done 		= 0;
        sclk        = 0;
        shift_in    = 0;
    end
    else
    begin
        case(state)
        	IDLE:
        	begin
        		if(trigger)
        		begin
        			counter = 0;
			        done    = 0;
			        cs 		= 0;
			        state   = ACQUIRE_DATA;
        		end
        	end
        	ACQUIRE_DATA:
        	begin
        		if(counter == 16)
        		begin
        			state 		= LATCH_DATA;
        		end
        		else begin
        		    counter = counter + 1;
	        		clk_counter = 0;
	        		shift_in 	= { shift_in[14:1], sdata };
	        		state 		= CLOCK_WAIT;
        		end
        	end
        	CLOCK_WAIT:
        	begin
        		if(clk_counter >= CLOCK_DIVIDER*2)
        		begin
        			state = ACQUIRE_DATA;
        		end
        		else if(clk_counter >= CLOCK_DIVIDER)
        		begin
        			sclk = 1;
        		end
        		else begin
        			sclk = 0;
        		end
        		clk_counter = clk_counter + 1;
        	end
        	LATCH_DATA:
    		begin
		        cs 		= 0;
		        done 	= 1;
		        out 	= shift_in;
		        state 	= IDLE;
    		end
        endcase
    end
end
endmodule