r2axz / bluepill-serial-monster

USB to 3 Port Serial (UART) adapter firmware for STM32 Blue Pill.
MIT License
329 stars 78 forks source link

Dynamic control #63

Open ein-shved opened 1 year ago

ein-shved commented 1 year ago

I needed a device with two two-pinned uarts and several gpio and with control via usb. This project was close to my needs, but lucks of gpio controls and had extra functionality which blocks almost all pins.

I suggest the basic version of dynamic controlling the gpio pins via shell to allow user use extra pins as gpio. Current version of this PR is not suitable to release, because it was not properly tested, definitely will brake some generic functionality and not optimal and pretty in some places.

Additionally I used here some language features like macro-metaprogramming and format output which was not used previously for some reason. It may be found not suitable by maintainers.

But from now I can use it for my purpose and I do not know when I will make it perfect. So I made this PR to bring maintainers' attention so they may find something useful from it.

This PR adds new control to shell: gpio.

This command accepts the gpio name as first argument in view [gpio_][pin_][p]<P><N> where gpio_, pin_ and p are optional prefixes, <P> is the name of port like a, b or c. <N> is the number of pin.

Examples: pa1, gpio_pin_pa10, b3

More on this, it accepts massive aliases:

The pin may be in one of 3 states:

The second argument may be:

There are defaults for first two arguments:

So command gpio, gpio all and gpio all show are equal.

r2axz commented 1 year ago

Hi Yuri,

Thanks for your PR. I had a quick look at the code and yes, some things definitely seem useful right away. For instance, the preprocessor macros.

I will review the PR thoroughly and let you know my thoughts. Please don't expect a quick review, I'm going to a vacation for two weeks and after that I'm going to be pretty busy with work for another week or two at least. My apologies for not being able to review faster.

Best, Kirill.

kzyapkov commented 1 year ago

Excellent. I abandoned my PR for an alternative approach, but would love to see this polished and merged.

ein-shved commented 1 year ago

@r2axz no problem. As I wrote, there is already well known problems, which should be fixed first. For some of them I have no much knowledge to resolve quick (need to longread manuals first). Another problems I will fix soon - for example duplication code with withing cdc_shell.c. And there more minor ideas for improvement the code (starting from applying clang-format, till adding the functionality like gpio-notiffications). I will go through patches by myself and left my thoughts withing comments.

I got used to gerrit-review with per-commit discussion and tried to split commits on complete functionality blocks, some of them are not really needed here (like nix build) but it is up to you.

BTW Im going to one week vocation right after you =)

ein-shved commented 1 year ago

@kzyapkov it's a pity you abandoned it. Fill free to participate in discussions here.