// Board configuration: tang_nano_9k_lcd_480_272_tm1638_hackathon
// This module uses few parameterization and relaxed typing rules

// Exercise M10 in the hackathon setup of Basics-Graphics-Music (BGM):
// https://github.com/yuri-panchul/basics-graphics-music
//
// Copy a directory such as hackathon/problems/5_shift_register, replace its
// hackathon_top.sv with this file and add johnson_counter.sv.
//
// The counter runs from slow_clock.  The LEDs show Q5-Q1, and the screen
// five lamps, Q1 on the left, like the LED module on the breadboard.

module hackathon_top
(
    input  logic       clock,
    input  logic       slow_clock,
    input  logic       reset,

    input  logic [7:0] key,
    output logic [7:0] led,

    // A dynamic seven-segment display

    output logic [7:0] abcdefgh,
    output logic [7:0] digit,

    // LCD screen interface

    input  logic [8:0] x,
    input  logic [8:0] y,

    output logic [4:0] red,
    output logic [5:0] green,
    output logic [4:0] blue,

    inout  logic [3:0] gpio
);

    //------------------------------------------------------------------------

    logic [4:0] q;

    johnson_counter i_johnson_counter
    (
        .clk ( slow_clock ),
        .rst ( reset      ),
        .q   ( q          )
    );

    assign led      = { 3'b0, q };

    assign abcdefgh = '0;
    assign digit    = '0;

    //------------------------------------------------------------------------
    // Five square lamps on the 480 x 272 screen, 40 pixels wide, 64 apart,
    // stage 1 on the left.  Bright green when 1, dim when 0.

    always_comb
    begin
        red   = 0;
        green = 0;
        blue  = 0;

        for (int i = 0; i < 5; i ++)
            if (x >= 9' (92 + i * 64) & x < 9' (132 + i * 64) & y >= 116 & y < 156)
                green = q [i] ? 63 : 12;
    end

endmodule
