qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Inès Varhol" <ines.varhol@telecom-paris.fr>, qemu-devel@nongnu.org
Cc: "Thomas Huth" <thuth@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Samuel Tardieu" <sam@rfc1149.net>,
	"Arnaud Minier" <arnaud.minier@telecom-paris.fr>,
	qemu-arm@nongnu.org,
	"Alistair Francis" <alistair.francis@wdc.com>
Subject: Re: [PATCH v5 1/5] hw/display : Add device DM163
Date: Tue, 23 Apr 2024 23:18:49 +0200	[thread overview]
Message-ID: <169a6afc-2dde-414e-a88b-04587722a530@linaro.org> (raw)
In-Reply-To: <20240421140604.111262-2-ines.varhol@telecom-paris.fr>

Hi Inès,

On 21/4/24 16:02, Inès Varhol wrote:
> This device implements the IM120417002 colors shield v1.1 for Arduino
> (which relies on the DM163 8x3-channel led driving logic) and features
> a simple display of an 8x8 RGB matrix. The columns of the matrix are
> driven by the DM163 and the rows are driven externally.
> 
> Acked-by: Alistair Francis <alistair.francis@wdc.com>
> Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr>
> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
> ---
>   docs/system/arm/b-l475e-iot01a.rst |   3 +-
>   include/hw/display/dm163.h         |  59 +++++
>   hw/display/dm163.c                 | 334 +++++++++++++++++++++++++++++
>   hw/display/Kconfig                 |   3 +
>   hw/display/meson.build             |   1 +
>   hw/display/trace-events            |  14 ++
>   6 files changed, 413 insertions(+), 1 deletion(-)
>   create mode 100644 include/hw/display/dm163.h
>   create mode 100644 hw/display/dm163.c


> +static void dm163_propagate_outputs(DM163State *s)
> +{
> +    s->last_buffer_idx = (s->last_buffer_idx + 1) % RGB_MATRIX_NUM_ROWS;
> +    /* Values are output when reset is high and enable is low. */
> +    if (s->rst_b && !s->en_b) {
> +        memcpy(s->outputs, s->latched_outputs, sizeof(s->outputs));
> +    } else {
> +        memset(s->outputs, 0, sizeof(s->outputs));
> +    }
> +    for (unsigned x = 0; x < RGB_MATRIX_NUM_COLS; x++) {
> +        trace_dm163_channels(3 * x, (uint8_t)(s->outputs[3 * x] >> 6));
> +        trace_dm163_channels(3 * x + 1, (uint8_t)(s->outputs[3 * x + 1] >> 6));
> +        trace_dm163_channels(3 * x + 2, (uint8_t)(s->outputs[3 * x + 2] >> 6));
> +        s->buffer[s->last_buffer_idx][x] =
> +            (s->outputs[3 * x + 2] >> 6) |
> +            ((s->outputs[3 * x + 1] << 2) & 0xFF00) |
> +            (((uint32_t)s->outputs[3 * x] << 10) & 0xFF0000);

Alternatively easier to review as:

           uint16_t x0 = extract16(s->outputs[3 * x + 0], 6, 8);
           uint16_t x1 = extract16(s->outputs[3 * x + 1], 6, 8);
           uint16_t x2 = extract16(s->outputs[3 * x + 2], 6, 8);
           uint32_t val = 0;

           trace_dm163_channels(3 * x + 0, x0);
           trace_dm163_channels(3 * x + 1, x1);
           trace_dm163_channels(3 * x + 2, x2);

           val = deposit32(val,  0, 8, x2);
           val = deposit32(val,  8, 8, x1);
           val = deposit32(val, 16, 8, x0);

           s->buffer[s->last_buffer_idx][x] = val;

> +    }
> +    for (unsigned row = 0; row < RGB_MATRIX_NUM_ROWS; row++) {
> +        if (s->activated_rows & (1 << row)) {
> +            s->buffer_idx_of_row[row] = s->last_buffer_idx;
> +            s->redraw |= (1 << row);
> +            trace_dm163_redraw(s->redraw);
> +        }
> +    }
> +}

> +static uint8_t dm163_bank0(const DM163State *s, uint8_t led)
> +{
> +    /*
> +     * Bank 1 uses 6 bits per led, so a value may be stored accross
> +     * two uint64_t entries.
> +     */
> +    const uint8_t low_bit = 6 * led;
> +    const uint8_t low_word = low_bit / 64;
> +    const uint8_t high_word = (low_bit + 5) / 64;
> +    const uint8_t low_shift = low_bit % 64;

FYI note the BIT* macros in "qemu/bitops.h" (but you'd need to
use arrays of unsigned long instead of uint64_t).

> +
> +    if (low_word == high_word) {
> +        /* Simple case: the value belongs to one entry. */
> +        return (s->bank0_shift_register[low_word] &
> +                MAKE_64BIT_MASK(low_shift, 6)) >> low_shift;
> +    }
> +
> +    const uint8_t bits_in_low_word = 64 - low_shift;
> +    const uint8_t bits_in_high_word = 6 - bits_in_low_word;
> +    return ((s->bank0_shift_register[low_word] &
> +             MAKE_64BIT_MASK(low_shift, bits_in_low_word)) >>
> +            low_shift) |
> +           ((s->bank0_shift_register[high_word] &
> +             MAKE_64BIT_MASK(0, bits_in_high_word))
> +         << bits_in_low_word);

Splitting this (assigning intermediate variables) could benefit
code review (see earlier suggestion).

> +}
> +
> +static uint8_t dm163_bank1(const DM163State *s, uint8_t led)
> +{
> +    const uint64_t entry = s->bank1_shift_register[led / RGB_MATRIX_NUM_COLS];
> +    const unsigned shift = 8 * (led % RGB_MATRIX_NUM_COLS);
> +    return (entry & MAKE_64BIT_MASK(shift, 8)) >> shift;

Or simply:

       return extract64(entry, 8 * (led % RGB_MATRIX_NUM_COLS), 8);

> +}

Anyhow, I only gave nitpicking comments to improve readability,
model LGTM! :)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Regards,

Phil.


  reply	other threads:[~2024-04-23 21:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-21 14:02 [PATCH v5 0/5] Add device DM163 (led driver, matrix colors shield & display) Inès Varhol
2024-04-21 14:02 ` [PATCH v5 1/5] hw/display : Add device DM163 Inès Varhol
2024-04-23 21:18   ` Philippe Mathieu-Daudé [this message]
2024-04-21 14:02 ` [PATCH v5 2/5] hw/arm : Pass STM32L4x5 SYSCFG gpios to STM32L4x5 SoC Inès Varhol
2024-04-21 14:02 ` [PATCH v5 3/5] hw/arm : Create Bl475eMachineState Inès Varhol
2024-04-21 14:02 ` [PATCH v5 4/5] hw/arm : Connect DM163 to B-L475E-IOT01A Inès Varhol
2024-04-21 14:02 ` [PATCH v5 5/5] tests/qtest : Add testcase for DM163 Inès Varhol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=169a6afc-2dde-414e-a88b-04587722a530@linaro.org \
    --to=philmd@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=arnaud.minier@telecom-paris.fr \
    --cc=ines.varhol@telecom-paris.fr \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sam@rfc1149.net \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).