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: auxdisplay: Add driver for common 7-segment display #68501

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xingrz
Copy link
Member

@xingrz xingrz commented Feb 3, 2024

This PR introduces a new driver for a common GPIO-driven 7-segment display. supporting both common anode and common cathode configurations.

It also includes a new sample demonstrates counting from 0 to 1000, with an interval of 100ms between each increment.

506611706963670_ pic

@xingrz xingrz marked this pull request as ready for review February 3, 2024 12:49
@xingrz xingrz requested a review from thedjnK as a code owner February 3, 2024 12:49
@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding area: Samples Samples area: Aux display labels Feb 3, 2024
dts/bindings/auxdisplay/gpio-7-segment.yaml Outdated Show resolved Hide resolved
struct auxdisplay_gpio_7seg_data *data = dev->data;
uint32_t ib, ic;

for (ib = 0, ic = 0; ib < cfg->digit_count && ic < len; ic++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the other drivers, this always writes from the last position, whilst for a 7-segment display you might want (or expect) that, it deviates from the API:

 * @brief	Write data to auxiliary display screen at current position

What are your thoughts on adding position get/set and having write update the current character and advancing the position (also thinking this can be used on hex segment displays also)?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a consideration for handling decimal points. For example, if you want to display 10.3, the decimal point is the third character in the data. However, on a 7-segment display, it is part of the second digit (0). Therefore, I need to do some processing in the write function, so that when the current character is identified as '.', the decimal point of the previous digit is lit.

return -ENODEV;
}

snprintk(data, sizeof(data), "8.8.8.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good if this sample adapted to the number of characters in the display

for (ib = 0, ic = 0; ib < cfg->digit_count && ic < len; ic++) {
if (ch[ic] >= '0' && ch[ic] <= '9') {
cfg->buffer[ib++] = DIGITS[ch[ic] - '0'];
} else if (ch[ic] == '.') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does not check that a dot segment is present

Copy link
Member Author

Choose a reason for hiding this comment

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

It's okay here since it's just setting the buffer bits and not actually updating the GPIOs directly. The DP bit will be ignored if only 7 GPIOs are present, as handled in the auxdisplay_gpio_7seg_timer_expiry_fn function below.

@xingrz
Copy link
Member Author

xingrz commented Mar 19, 2024

Oh, wow! I have a new idea. Maybe I should separate this into an LED strip (or LED controller) driver, probably named "common-electrode-leds", and build the segment display driver on top of it. So, in theory, we could then drive any any-segment display with any form of multi-channel LED controller.

@thedjnK
Copy link
Collaborator

thedjnK commented Apr 9, 2024

Oh, wow! I have a new idea. Maybe I should separate this into an LED strip (or LED controller) driver, probably named "common-electrode-leds", and build the segment display driver on top of it. So, in theory, we could then drive any any-segment display with any form of multi-channel LED controller.

It's an option. For LED displays they are usually numeric, alphanumeric or hex, so auxdisplay can work with all of those.

Copy link

github-actions bot commented Jun 9, 2024

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jun 9, 2024
@github-actions github-actions bot closed this Jun 24, 2024
@cfriedt
Copy link
Member

cfriedt commented Aug 12, 2024

@xingrz - is there any chance that this could be reopened? I guess that this fell off the radar during the last release cycle.

I would be happy to re-review 😄

@xingrz
Copy link
Member Author

xingrz commented Aug 13, 2024

@cfriedt Well, I’m not sure. I’m uncertain if this idea is fully developed. I’ve noticed that in actual projects, people often use dedicated LED driver ICs or GPIO expanders instead of the MCU’s GPIOs to drive the 7-segment displays. This approach provides enough driving power and minimizes IO usage. I think we should consider these scenarios, but I don’t have any concrete ideas yet. Let’s keep this PR closed for now. Perhaps in the future, someone interested might discover it and offer some new insights.

@simonguinot simonguinot self-requested a review August 13, 2024 08:45
@thedjnK
Copy link
Collaborator

thedjnK commented Aug 13, 2024

Port expanders are natively supported in zephyr through the GPIO interface so should be fine

@cfriedt
Copy link
Member

cfriedt commented Aug 13, 2024

I have a board in front of me that just uses GPIO as well without a driver. Depending on the brightness level required, I think it's reasonable in some circumstances.

@xingrz xingrz reopened this Aug 14, 2024
@github-actions github-actions bot removed the Stale label Aug 15, 2024
Copy link
Collaborator

@thedjnK thedjnK left a comment

Choose a reason for hiding this comment

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

Wasn't aware this got updated, minor change request for the binding compatible then looks good to go!

* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT gpio_7_segment
Copy link
Collaborator

Choose a reason for hiding this comment

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

should have zephyr prefix

};
};

compatible: "gpio-7-segment"
Copy link
Collaborator

Choose a reason for hiding this comment

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

needs zephyr, prefix

Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Nov 11, 2024
@cfriedt cfriedt removed the Stale label Nov 12, 2024
@cfriedt
Copy link
Member

cfriedt commented Nov 12, 2024

This is so close to being done @xingrz

@xingrz
Copy link
Member Author

xingrz commented Nov 12, 2024

@kartben Thanks for you suggestions.

Also rebased to include the build_all/auxdisplay changes.

};
};

compatible: "zephyr,gpio-7-segment"
Copy link
Member

Choose a reason for hiding this comment

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

why put a zephyr, prefix if this binding is already based on linux ? why not just keep the linux compatible ?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it’s not based on Linux, and they are not compatible. This driver was introduced a few months before a similar one was added to the Linux kernel. It’s a completely different implementation, with additional features such as multi-digit support.

@thedjnK
Copy link
Collaborator

thedjnK commented Nov 28, 2024

@xingrz would you be able to come back to this?

thedjnK
thedjnK previously approved these changes Nov 28, 2024
@xingrz
Copy link
Member Author

xingrz commented Nov 28, 2024

Rebased to align with #82121.

Additionally, I added a native_sim target to the sample, ensuring it gets included in CI builds going forward.

thedjnK
thedjnK previously approved these changes Nov 28, 2024
kartben
kartben previously approved these changes Nov 28, 2024
drivers/auxdisplay/auxdisplay_gpio_7seg.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@kartben kartben left a comment

Choose a reason for hiding this comment

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

Pending request for change re: README has actually not been addressed, sorry that I missed it earlier today

@xingrz
Copy link
Member Author

xingrz commented Nov 29, 2024

Pending request for change re: README has actually not been addressed, sorry that I missed it earlier today

Apologies for missing that as well. I'll address it as soon as possible.

@xingrz xingrz force-pushed the auxdisplay-7seg/pr branch 2 times, most recently from 14a5702 to 6992fec Compare November 29, 2024 06:10
@pdgendt pdgendt dismissed their stale review November 29, 2024 07:08

Request addressed

This commit introduces a new driver for a common GPIO-driven 7-segment
display. supporting both common anode and common cathode configurations.

Signed-off-by: Chen Xingyu <[email protected]>
This commit introduces a new sample for the Auxiliary display driver.

The sample demonstrates counting from 0 to 1000, with an interval of 100ms
between each increment.

This sample primarily serves to demonstrate the capabilities of segment
displays.

Signed-off-by: Chen Xingyu <[email protected]>
@xingrz
Copy link
Member Author

xingrz commented Nov 29, 2024

Rebased to include the recently merged DEVICE_API changes.

This PR is now ready for review.

@thedjnK
Copy link
Collaborator

thedjnK commented Dec 1, 2024

@xingrz for future, when people should look at a review again they need to be requested, use the refresh icon next to each name in the reviewers list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants