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

feature: shift register #458

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

JaimeAlbq
Copy link

shift_reg: add shift_reg component

The feature is a driver to interface the microcontroller with shift
registers just using 3 pins: Clock, Data and Latch.

For further information, please, take a look at the component
README.md.

Feature requested by issue #457.

@UncleRus UncleRus added area:ci enhancement New feature or request labels Oct 9, 2022
@trombik trombik marked this pull request as draft October 9, 2022 22:38
@trombik
Copy link
Collaborator

trombik commented Oct 9, 2022

i made the PR draft. when the PR passes the tests, please remove Draft. when you are ready for review, ask a review. if you need help to pass tests, ask here.

please consolidate commits, especially when you reverted commits, by git rebase -i. see A Guide to Git Interactive Rebase, with Practical Examples. in general, too small commits is better than too big commits.

(so far, looks good)

@trombik trombik changed the title Feature shift register feature: shift register Oct 9, 2022
@JaimeAlbq JaimeAlbq force-pushed the feature-shift-reg branch 2 times, most recently from 01ae8f9 to 39471fb Compare October 11, 2022 15:57
@JaimeAlbq JaimeAlbq marked this pull request as ready for review October 11, 2022 16:35
@trombik
Copy link
Collaborator

trombik commented Oct 11, 2022

here is my first review. the biggest one is the order of arguments.

all in all, a good PR.

@JaimeAlbq
Copy link
Author

here is my first review. the biggest one is the order of arguments.

all in all, a good PR.

No problem. If you need anything from my side or a hand, I'll be there.

Copy link
Collaborator

@trombik trombik left a comment

Choose a reason for hiding this comment

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

please see my comments. for starters, change the order of arguments. thanks

components/shift_reg/shift_reg.c Outdated Show resolved Hide resolved
components/shift_reg/shift_reg.c Outdated Show resolved Hide resolved
components/shift_reg/shift_reg.c Outdated Show resolved Hide resolved
components/shift_reg/shift_reg.c Outdated Show resolved Hide resolved
components/shift_reg/shift_reg.h Outdated Show resolved Hide resolved
components/shift_reg/shift_reg.h Outdated Show resolved Hide resolved
components/shift_reg/shift_reg.h Outdated Show resolved Hide resolved
components/shift_reg/shift_reg.h Outdated Show resolved Hide resolved
components/shift_reg/shift_reg.h Outdated Show resolved Hide resolved
examples/shift_reg/default/main/main.c Outdated Show resolved Hide resolved
The feature is a driver to interface the microcontroller with shift
registers just using 3 pins: Clock, Data and Latch.

For further information, please, take a look at the component
[README.md](components/shift_reg/README.md).

Feature requested by issue UncleRus#457.
@JaimeAlbq
Copy link
Author

Hello @trombik,

Could you please perform the review one more time. I did the required changes.

@trombik
Copy link
Collaborator

trombik commented Oct 20, 2022

@JaimeAlbq will do after the weekend (I work on weekends)

@trombik trombik self-assigned this Oct 23, 2022
// MSB Mode
for (int8_t i = 7; i >= 0; i--)
{
if ((data >> i) & 1)
Copy link
Owner

Choose a reason for hiding this comment

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

This condition can be replaced by a single expression:

gpio_set_level(dev->pin.data, (data >> i) & 1);


esp_err_t shift_reg_latch(shift_reg_config_t *dev)
{
gpio_set_level(dev->pin.latch, true);
Copy link
Owner

Choose a reason for hiding this comment

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

Here we need to check if dev is NULL

#include <driver/gpio.h>
#include <ets_sys.h>

typedef enum {
Copy link
Owner

Choose a reason for hiding this comment

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

All structs and enums must be commented in doxy-style, like this:

/**
 * This structure is intended to store the device handle and its state.
 */
typedef struct {
    int foo;  //< Special field
} some_device_t;

...

/**
 * Device operational modes
 */
typedef enum {
    MODE_FOO = 0; //< Mode Foo
    MODE_BAR;     //< Mode Bar
} some_mode_t;

@@ -0,0 +1 @@
# add required non-default option for the example if any
Copy link
Owner

Choose a reason for hiding this comment

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

Please delete this file if the example does not require special ESP-IDF settings.

ESP_ERROR_CHECK(shift_reg_send(&shifter, value, 2));
ESP_ERROR_CHECK(shift_reg_latch(&shifter));
ESP_LOGI(__func__, "reg_value: 0x%02X 0x%02X", shifter.reg_value[0], shifter.reg_value[1]);
vTaskDelay(2 / portTICK_PERIOD_MS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use pdMS_TO_TICKS instead of portTICK_PERIOD_MS which is deprecated.

To initialize the shift register it is going to need to call the `esp_err_t shift_reg_init(shift_reg_config_t *dev)`, by passing the created shift register configurations.

### De-initialization
Since the `uint8_t *reg_value` is created accordingly of the number of registers, the vector allocate the necessary size in the heap memory, so `esp_err_t shift_reg_deinit(shift_reg_config_t *dev)` can be used to free this memory.
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should go to the header file so that users can see this in the official documentation. see other documentation pages under docs/source/groups.

@UncleRus UncleRus marked this pull request as draft November 7, 2022 03:44
@trombik
Copy link
Collaborator

trombik commented Nov 14, 2022

@JaimeAlbq please read the review comments, and modify the code, or justify. after that, I'll test the code on real hardware.

JaimeAlbq and others added 7 commits February 7, 2024 10:57
- `examples/shift_reg/default/sdkconfig.defaults`: removed
- `README.md`: moved and renamed to `docs/source/groups/shift_reg.rst`
- `examples/shift_reg/default/main/main.c`: updated the `portTICK_PERIOD_MS` to `pdMS_TO_TICKS`
- `components/shift_reg/shift_reg.h`: added comment in doxygen-style for structures and enums
- `components/shift_reg/shift_reg.c`:
  - `shift_reg_latch()`: added argument checker for `NULL` pointer
  - `shift_reg_send8bits()`: improved the GPIO set
`.eil.yml`: updated
`.eil.yml`: updated
@JaimeAlbq
Copy link
Author

@UncleRus or @trombik, could one of you support me to pass the CI?

@mmarkwort
Copy link
Contributor

mmarkwort commented May 10, 2024

Call devtools.py from devtools directory with arguments check. If check is okay then call with argument render.

There are some doc files are missing and the tool should help you to generate them.

@mmarkwort
Copy link
Contributor

I did a small check on your branch. You should update the branch to the current master version. Then first you have to add your name to the devtools/persons.yml. Then you have to remove 'name:' from depends section in your .eil.yml

After you have made the changes run devtooly.py check and devtooly.py render again.

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

Successfully merging this pull request may close these issues.

None yet

4 participants