Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/digit7seg: add 4-digit 7-segment display driver #20981

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

plmorange
Copy link
Contributor

Contribution description

Added riot/drivers/sha5461as to control a 4-digit 7-segment display (plus decimal point).

Testing procedure

A test is available in tests/drivers/sha5461as, designed for the Arduino Nano 33 BLE. The test will display "8" segment by segment on each digit, followed by "RIOT," and then it will stop.

Issues/PRs references

@github-actions github-actions bot added Area: doc Area: Documentation Area: tests Area: tests and testing framework Area: drivers Area: Device drivers labels Nov 13, 2024
@plmorange
Copy link
Contributor Author

Hi @Enoch247, I’ve finished my PR! I'm sure it can be improved, especially the sha5461as_display function. Could you please review it when you have a moment?

@mguetschow mguetschow changed the title Driver sha5461as drivers/sha5461as: add 4-digit 7-segment display driver Nov 13, 2024
@plmorange plmorange marked this pull request as draft November 13, 2024 13:51
@Enoch247
Copy link
Contributor

Thanks for the contribution. I'll try to review this tonight.

@Enoch247 Enoch247 self-assigned this Nov 13, 2024
Copy link
Contributor

@Enoch247 Enoch247 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the level of abstraction provided by the driver is too low. I expected to be able to pass it a number or array of digits to display. Currently the driver requires applications to manually set a bitfield with each bit corresponding to the display's segments. The application must also know the mapping of the bits to segments.

drivers/include/sha5461as.h Outdated Show resolved Hide resolved
drivers/include/sha5461as.h Outdated Show resolved Hide resolved
drivers/include/sha5461as.h Outdated Show resolved Hide resolved
drivers/include/sha5461as.h Outdated Show resolved Hide resolved
drivers/include/sha5461as.h Outdated Show resolved Hide resolved
drivers/include/sha5461as.h Outdated Show resolved Hide resolved
tests/drivers/sha5461as/main.c Outdated Show resolved Hide resolved
tests/drivers/sha5461as/main.c Outdated Show resolved Hide resolved
tests/drivers/sha5461as/main.c Outdated Show resolved Hide resolved
drivers/include/sha5461as.h Outdated Show resolved Hide resolved
@plmorange plmorange changed the title drivers/sha5461as: add 4-digit 7-segment display driver drivers/digit7seg: add 4-digit 7-segment display driver Nov 14, 2024
@plmorange
Copy link
Contributor Author

I think the level of abstraction provided by the driver is too low. I expected to be able to pass it a number or array of digits to display. Currently the driver requires applications to manually set a bitfield with each bit corresponding to the display's segments. The application must also know the mapping of the bits to segments.

Thank you for reviewing my PR.
Is it a solution to leave the low level abstraction as it is now and create another high-level module?

@plmorange plmorange marked this pull request as ready for review November 14, 2024 14:24
@Enoch247
Copy link
Contributor

I think the level of abstraction provided by the driver is too low. I expected to be able to pass it a number or array of digits to display. Currently the driver requires applications to manually set a bitfield with each bit corresponding to the display's segments. The application must also know the mapping of the bits to segments.

Is it a solution to leave the low level abstraction as it is now and create another high-level module?

It is not my preference, but if you have a reason to do it this way, can you please describe it so that I better understand.

@Enoch247
Copy link
Contributor

BTW, in the future, please hold off to squash/force push until requested once a PR is submitted. It makes the process a bit easier. See here for some helpful tips.

@Enoch247
Copy link
Contributor

Great work adding the documentation for the driver! Its not always the fun part of writing code, but it will really help users of your driver in the future.

drivers/include/digit7seg.h Outdated Show resolved Hide resolved
drivers/include/digit7seg.h Show resolved Hide resolved
drivers/include/digit7seg.h Outdated Show resolved Hide resolved
drivers/include/digit7seg.h Outdated Show resolved Hide resolved
drivers/include/digit7seg.h Outdated Show resolved Hide resolved
drivers/include/digit7seg.h Show resolved Hide resolved
drivers/include/digit7seg.h Outdated Show resolved Hide resolved
@plmorange
Copy link
Contributor Author

plmorange commented Nov 22, 2024

Add to force push cause the fixup commit message was more than 50 char.

drivers/digit7seg: add return value doc in header and remove unused params in digit7seg_t

drivers/digit7seg: add return value doc in header

drivers/digit7seg: add return value doc in header
@plmorange
Copy link
Contributor Author

The PR is ready for review! :D

@Enoch247
Copy link
Contributor

Thanks. Sorry for the delay. I will set aside some time this weekend to look it over, if not sooner.

@Enoch247
Copy link
Contributor

As state before, I think that there needs to be a way for applications to send numbers to the display. As far as I see, the driver's API allows to manually set the display's segments, but that is the exception rather than the normal way an application would want to interact with a numeric display driver. Something like:

int digit7seg_set(digit7seg_t *dev, int val, int scale);
int digit7seg_set_digit(digit7seg_t *dev, unsigned digit, unsigned val);

val and scale could be similar to that used by phaydat_t

@plmorange
Copy link
Contributor Author

As state before, I think that there needs to be a way for applications to send numbers to the display. As far as I see, the driver's API allows to manually set the display's segments, but that is the exception rather than the normal way an application would want to interact with a numeric display driver. Something like:

int digit7seg_set(digit7seg_t *dev, int val, int scale);
int digit7seg_set_digit(digit7seg_t *dev, unsigned digit, unsigned val);

val and scale could be similar to that used by phaydat_t

OK, I'll do it as soon as I can!

@RIOT-OS RIOT-OS deleted a comment from Outman9900 Dec 16, 2024
@RIOT-OS RIOT-OS deleted a comment from Outman9900 Dec 16, 2024
Copy link
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this! Some first comments from my side below.

/**
* @ingroup drivers_digit7seg
* @file
* @brief Device driver for less than 5 digits of 7 segments without IC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @brief Device driver for less than 5 digits of 7 segments without IC
* @brief Device driver for up to 4 digits of 7 segments without IC

do we really want such restriction?

Comment on lines +116 to +117
* @param[in] value the value as an uint8_t, a is equal to the first bit
* b the second.... dp the 8th bit.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a user, I would expect the driver to do the number to 7-segment-bit conversion for me.

* b the second.... dp the 8th bit.
*
* @return 0 on success
* @return -1 when an incorrect digit is passed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return -1 when an incorrect digit is passed
* @return -1 when an invalid index is passed

?


## About

This driver was developed to works with [5461AS](http://www.topliteusa.com/uploadfile/2014/0825/A-5461AS.pdf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This driver was developed to works with [5461AS](http://www.topliteusa.com/uploadfile/2014/0825/A-5461AS.pdf)
This driver was developed to work with [5461AS](http://www.topliteusa.com/uploadfile/2014/0825/A-5461AS.pdf)

## About

This driver was developed to works with [5461AS](http://www.topliteusa.com/uploadfile/2014/0825/A-5461AS.pdf)
in a way that all 4 digits (and less) with 7 segments without integrated controller
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
in a way that all 4 digits (and less) with 7 segments without integrated controller
in a way that up to 4 digits with 7 segments without integrated controller


static void _shift_display(void *arg, int chan)
{
(void)chan;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why having the variable in this private function if it is unused?

Comment on lines +122 to +125
uint32_t temp_value = value << (index * BYTE_BITS);
uint32_t up_value = dev->value >> ((index + 1) * BYTE_BITS);
up_value <<= ((index + 1) * BYTE_BITS);
uint32_t down_value = ((0b00000001 << (index * BYTE_BITS)) - 1) & dev->value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's worth adding some explaining comments to what this code does.


#define DIGIT7SEG_MAX_DIGITS (4) /**< Max pin number, can be below or equal */
#ifndef DIGIT7SEG_TIMER_HZ
# define DIGIT7SEG_TIMER_HZ MHZ(1) /**< default timer hz */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# define DIGIT7SEG_TIMER_HZ MHZ(1) /**< default timer hz */
# define DIGIT7SEG_TIMER_HZ MHZ(1) /**< default timer hz */

as per the Coding Convention. please also check other places

#ifndef DIGIT7SEG_TIMER_HZ
# define DIGIT7SEG_TIMER_HZ MHZ(1) /**< default timer hz */
#endif
#ifndef DIGIT7SEG_DELAY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to prefix all those "over-writeable" parameters with CONFIG_.

This driver was developed to works with [5461AS](http://www.topliteusa.com/uploadfile/2014/0825/A-5461AS.pdf)
in a way that all 4 digits (and less) with 7 segments without integrated controller
can be controlled into [RIOT-OS](https://github.com/RIOT-OS/RIOT).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth mentioning one free HW timer as a prerequisites for using this driver here.

@RIOT-OS RIOT-OS deleted a comment from Outman9900 Dec 16, 2024
@RIOT-OS RIOT-OS deleted a comment from Outman9900 Dec 16, 2024
@RIOT-OS RIOT-OS deleted a comment from Outman9900 Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: doc Area: Documentation Area: drivers Area: Device drivers Area: tests Area: tests and testing framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants