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/rotary_encoder : WIP #5168
Conversation
(this is a follow-up of the "Encoder drivers" mail on riot-devel@ ) |
For reference I provided a link to devel's archive: https://lists.riot-os.org/pipermail/devel/2016-March/003725.html |
Any progress? |
it works more or less, but i'm willing to merge other changes before. This PR was here because some ppl wanted to have a look and test it... It still work, I'm using it on a daily basis... |
Thanks |
WIP and new feature -> next release. |
Postponed due to Feature Freeze. |
Did you, can you give a quick update? |
Other changes are not merged and will probably never be merged because nobody can test (except me obviously) them (even if the board is "maintained"...). As stated before, I was willing to contribute as much as possible, but it looks like RIOT team can't handle these kind of minor contributions (affecting only a handfull of isolated ppl), which is understandable given the size of the team and all the works in progress in more useful part :) Quick update: nothing has changed since last time and work is currently stalled. |
This is not a denial of your work, I'm just curious, but may I ask why, if it only affects a handful of people (and are not able to provide the hardware for us to test) you want to contribute the code for it to RIOT? You always can publish the code for the driver on your own terms: CPUs can be integrated by changing the |
@dkm I appretiate your effort of trying to get the code merged here! |
Don't get me wrong, me too! Just wondering if you were aware about the external integration. |
@miri64 because you have partial support for this board, it is free software, you have a nice community working with PR and I wanted to make the existing support better. I like the idea of having my changes getting merged and being useful to other (even if only a few) (which is harder if I publish changes elsewhere). Initially, I thought these changes could be a start for contributing to RIOT. I guess my mistake is thinking that if the code is not yet removed (obsoleted), it is still active and possible to contribute. [I know that everything is ready for having part of RIOT out of the tree, I've been using this on my side.] Back to this PR. I did a quick and dirty hack and someone on the mailing list was interested by it. I was instructed to open this PR, but I don't think I'll take the time needed to clean it: it can be closed with no regret :) |
Maybe @astralien3000 could be interested by a rotary encoder driver in RIOT. I took a quick look at your code and there are quite some things missing, requiring changes before getting it merged. See this page for coding guidelines commonly used in RIOT. I won't comment inline and just summarize some of the problems I saw here:
int my_func(void* arg)
{
/* some code */
}
It can be a bit of work, but I think this PR is nice addition in general for RIOT and I would be happy to press the green button one day. |
@aabadie I'm still using this piece of code but didn't bother polishing it as I was already struggling with other changes. I would be happy to make the necessary effort for getting it merged in RIOT. Expect some rebase in the coming days :) |
@aabadie actually, you can be interested as well ^^ |
The original code can handle different kind of encoder. To simplify the porting, I've constrained it to the kind I'm using (cheap aliexpress device). I'm still not clear exactly what kind it is. I've tested with some other encoder (ripped from a logitech kbd) and it was clearly not a good match. |
I'm not really sure, I should check what I'm using :) Also, I was in the process of cleaning the code, and started by having correct copyright. The original code is released under the GPL v3. RIOT is (mainly?) licensed under LGPL v2.1. I'm not sure that it is a good idea to mix these (the result, if using this code, would have to be distributed under GPL clauses, not LGPL), even if I don't really see how the Lesser version is used in RIOT as i thought resulting executables were always static. Do you have more insight on this ? A solution would be to rewrite the drivers from scratch, but I'm not sure I'll find the time... |
I guess you are talking of this project : https://github.com/buxtronix/arduino/tree/master/libraries/Rotary The GPLv3 is indeed a problem if one copy-pastes it as is in RIOT code. Looking at the code in your PR, except the state tables that remains very similar, the code is already kind of a rewrite of the initial library : the GPIO API is different, you are using interrupts instead of polling, etc @emmanuelsearch, @OlegHahm any thoughts ? |
Yes, that's the code I'm referring to... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preliminary code review. Please add documentation in header files. Remove commented out code and use /* */
comment style.
drivers/include/rotary.h
Outdated
*/ | ||
|
||
/** | ||
* @ingroup drivers_rotary_encoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@defgroup
drivers/include/rotary.h
Outdated
*/ | ||
|
||
#ifndef __ROTARY_ENC_H | ||
#define __ROTARY_ENC_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ROTARY_ENC_H
drivers/include/rotary.h
Outdated
#include <periph/gpio.h> | ||
|
||
typedef struct { | ||
gpio_t pin1, pin2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 spaces instead of 4. Did you run uncrustify?
drivers/rotary_encoder/rotary.c
Outdated
} | ||
|
||
int | ||
rotary_init(rotary_t *dev, gpio_t pin1, gpio_t pin2){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no new line between type and function definition. Space between arguments and {
drivers/rotary_encoder/rotary.c
Outdated
rotary_t *dev = (rotary_t*) rot_dev; | ||
unsigned int b1_v = gpio_read(dev->pin1) ? 1 : 0; | ||
unsigned int b2_v = gpio_read(dev->pin2) ? 1 : 0; | ||
unsigned char pinstate = ( b1_v? 2 : 0) | (b2_v ? 1 : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b1_v
and b2_v
don't need to be set to 0 or 1. Simply use
int b1_v = gpio_read(dev->pin1);
int b2_v = gpio_read(dev->pin2);
or get rid of them :-)
Additionally, I would also make pinstate
an int
since it's only a support variable. If you remove the other 2 variables there's no size impact (and sometimes avoids extra casting introduced by the compiler).
int pinstate = (gpio_read(dev->pin1) ? 2 : 0) | (gpio_read(dev->pin2) ? 1 : 0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. I'll keep the 2 var as the compiler is able to remove them when asked and also he keeps them when debuging with -O0
:)
drivers/include/rotary.h
Outdated
// Clockwise step. | ||
#define DIR_CW 0x10 | ||
// Anti-clockwise step. | ||
#define DIR_CCW 0x20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's meant to be used by some other module please make an enum of it
drivers/include/rotary.h
Outdated
void rotary_register(rotary_t *dev, unsigned int pid); | ||
|
||
|
||
#define ROTARY_EVT 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename to ROTARY_MSG_TYPE
or similar
drivers/rotary_encoder/rotary.c
Outdated
} | ||
|
||
void | ||
rotary_register(rotary_t *dev, unsigned int pid){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use kernel_pid_t
drivers/include/rotary.h
Outdated
|
||
typedef struct { | ||
gpio_t pin1, pin2; | ||
unsigned int listener; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use kernel_pid_t
drivers/rotary_encoder/rotary.c
Outdated
|
||
dev->state = ttable[dev->state & 0xf][pinstate]; | ||
|
||
switch(dev->state & 0x30){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current state tables has values from 1 to 5 or from 1 to 6. So masking with 0x30 will always return 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mask is used to test upper bits for values stored in the table (ie. if the value has DIR_CW or DIR_CCW bit set). dev->state
equals one line of the table, it is not an index of the table.
I'll add doc in header later. But as I'm still not convinced that this GPL3 code can be used easily in RIOT... |
If I understand well, the fact that your code is under GPL implies that any user app or driver using your code ( After that it is a matter of policy, which seems to be no GPL in the repos. @dkm From your side, you seems to consider that your code is not different enough from this lib to have an other license. The only way to publish it as LGPL is to ask the author of the lib if he considers what you wrote as a derived work of his and if he agrees to publish it under an other license. |
@astralien3000 There is no «being different enough». I've based the code from a copy of his code, so it's clearly a derived work and must comply with its license. Best move would be to reject this PR and simply make it live outside with a clear statement in the README. I can do that if you think it's worth the effort :) |
Well, what is the point of starting from scratch in your case ? The algorithm is like 70 lines long. If you start from scratch and implement the same idea, you will end up with the same algorithm, maybe with slightly different names. Does the fact that you have seen the other code before writing yours makes yours a derived work ? For me it's yes because patents concern ideas, not only lines of code. If you think you would have done something different by starting from scratch, why didn't you do that in the first place ? Well I guess this PR will be rejected if there is no solution with the license. |
In theory, I should not be the one re-implementing it. But in this case, for a 70 lines long code, I guess nobody would complain :) As for 'why didn't you do it in the first place', easy answer: I tend to not rewrite existing code when possible :) |
No significant progress for half a year. Closing as memo for now. |
This is a WIP for handling rotary encoders. Tested on lm4f120, so basic feature should be mostly OK.
There are still lots of things to take care, in particular how to handle the different hw you can find.