Re: [PATCH 16/17] auxdisplay: ht16k33: Add support for segment displays

From: Geert Uytterhoeven
Date: Mon Mar 29 2021 - 03:16:20 EST


Hoi Robin,

On Mon, Mar 29, 2021 at 9:09 AM Robin van der Gracht <robin@xxxxxxxxxxx> wrote:
> On 2021-03-22 15:48, Geert Uytterhoeven wrote:
> > The Holtek HT16K33 LED controller is not only used for driving
> > dot-matrix displays, but also for driving segment displays.
> >
> > Add support for 4-digit 7-segment and quad 14-segment alphanumeric
> > displays, like the Adafruit 7-segment and 14-segment display backpack
> > and FeatherWing expansion boards. Use the character line display core
> > support to display a message, which will be scrolled if it doesn't fit.
> >
> > Signed-off-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> > ---
> > The 7-segment support is based on schematics, and untested on actual
> > hardware.
> > ---
> > drivers/auxdisplay/ht16k33.c | 198 +++++++++++++++++++++++++++++++++--
> > 1 file changed, 191 insertions(+), 7 deletions(-)
> >
> ...
> >
> > +static int ht16k33_seg_probe(struct i2c_client *client,
> > + struct ht16k33_priv *priv, uint32_t brightness)
> > +{
> > + struct ht16k33_seg *seg = &priv->seg;
> > + struct device *dev = &client->dev;
> > + int err;
> > +
> > + err = ht16k33_brightness_set(priv, MAX_BRIGHTNESS);
> > + if (err)
> > + return err;
> > +
> > + switch (priv->type) {
> > + case DISP_MATRIX:
> > + /* not handled here */
> > + break;
>
> This 'case' shouldn't happen. Having said that, the break here will
> still
> cause the linedisp_register() function to be called for the DISP_MATRIX
> type.
> If you'd like to handle this case, a return (or setting 'err') should
> prevent this.

This function is never called if priv->type == DISP_MATRIX, so this
cannot happen. However, gcc complains if not all enum values are
handled in a switch() statement, hence the dummy case.

Is there a better way to handle this?

> > + case DISP_QUAD_7SEG:
> > + INIT_DELAYED_WORK(&priv->work, ht16k33_seg7_update);
> > + seg->map.seg7 = initial_map_seg7;
> > + seg->map_size = sizeof(seg->map.seg7);
> > + err = device_create_file(dev, &dev_attr_map_seg7);
> > + break;
> > +
> > + case DISP_QUAD_14SEG:
> > + INIT_DELAYED_WORK(&priv->work, ht16k33_seg14_update);
> > + seg->map.seg14 = initial_map_seg14;
> > + seg->map_size = sizeof(seg->map.seg14);
> > + err = device_create_file(dev, &dev_attr_map_seg14);
> > + break;
> > + }
> > + if (err)
> > + return err;
> > +
> > + err = linedisp_register(&seg->linedisp, dev, 4, seg->curr,
> > + ht16k33_linedisp_update);
> > + if (err)
> > + goto err_remove_map_file;
> > +
> > + return 0;

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds