Skip to content

drivers: sensor: Add Atmel SAM QDEC (TC) Driver #1043

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

Closed
wants to merge 2 commits into from

Conversation

jpfaff
Copy link
Contributor

@jpfaff jpfaff commented Aug 8, 2017

Tested on Atmel SMART SAM E70 Xplained board
Origin: Original

@mnkp
Copy link
Member

mnkp commented Aug 14, 2017

From the point of view of the existing support for Atmel SAM Family in Zephyr the driver code looks good. The only open question is if SENSOR_POSITION parameter should have a unit. In case of QDEC we measure angular rotation.

@galak, @MaureenHelm could you please review this PR.

@jpfaff
Copy link
Contributor Author

jpfaff commented Aug 22, 2017

@bogdan-davidoaia could you please review this PR?

@galak galak added this to the v1.10 milestone Aug 30, 2017
@nashif nashif modified the milestones: v1.10, v1.10.0 Oct 3, 2017
@galak galak self-assigned this Nov 9, 2017
@galak galak force-pushed the arm branch 3 times, most recently from a053cce to 457699c Compare November 15, 2017 15:12
nagineni pushed a commit to nagineni/zephyr that referenced this pull request Nov 20, 2017
zephyrproject-rtos#1043)

 - Call k_sched_lock() and k_sched_unlock() in callbacks to prevent
   other tasks from accessing the callback map/ring buffer at the
   same time. This becomes important for network functionality as
   the zephyr network stack uses multiple tasks, which can still
   call add/signal/remove_callback().

Signed-off-by: James Prestwood <[email protected]>

* moved LOCK/UNLOCK to zjs_util.h

Signed-off-by: James Prestwood <[email protected]>
@nashif nashif modified the milestones: v1.10.0, v1.11.0 Nov 28, 2017
@jpfaff
Copy link
Contributor Author

jpfaff commented Dec 5, 2017

I have updated this PR to CMake and resolved merge conflicts.

@bogdan-davidoaia
Copy link
Contributor

@jpfaff sorry for the super late answer. Somehow the initial mails got lost in my inbox and only now did I see this PR since it got some updates.

For POSITION I'd change it to ANGULAR_ROTATION or ANGULAR_POSITION for clarity and express it in radians since we already have angular velocity expresses in radians/second for the gyro channels.

@jpfaff
Copy link
Contributor Author

jpfaff commented Dec 11, 2017

@bogdan-davidoaia no worries.
Different quadrature encoders have different number of steps per revolution, how would you implement that? Kconfig/DTS?
I always used rotary encorders, but it seems that there exist linear ones as well (some inkjet printers use them for example). We could stick to rotation anyway and with the steps per revolution config the linear movement can be extracted with some calculus, what do you think?

Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

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

  1. I don't think drivers/sensor is the correct place for this. (not sure what is)
  2. We need device tree support to get properties like sam_name & steps_per_unit.
  3. Can you split out the pinmap update into its own patch from the driver.

@mnkp
Copy link
Member

mnkp commented Dec 12, 2017

  1. I don't think drivers/sensor is the correct place for this. (not sure what is)

The quadrature decoder driver indeed doesn't fit too well anywhere in the API. There was a short discussion on the devel list in August regarding the issue and the proposal was to add it to the sensor API (the other possibility would be to extend counter API).
https://lists.zephyrproject.org/pipermail/zephyr-devel/2017-August/007917.html

  1. Can you split out the pinmap update into its own patch from the driver.

So far we've always kept pinmap in the same commit as the driver. It can be considered part of the SoC support. I just want to mention that having a separate commit for pinmap means change of style.

On a related note, should we provide pinmap also for sam4s, sam3x series?

Copy link
Member

@mnkp mnkp left a comment

Choose a reason for hiding this comment

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

I have some extra comments (assuming that we want to add this driver to the sensor API and not to the counter API).

default 24
help
Step per unit allows to set the sensor position granularity.
In case of a rotary encoder this equals to steps per revolution.
Copy link
Member

Choose a reason for hiding this comment

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

Steps per unit will likely be understood by the user as steps per radian. I think we need to explain this parameter better. Something among the lines of:

"For angular position this parameter tells the number of steps per revolution (one complete turn). For linear position number of steps per unit of length. Currently only angular position is supported."

This is assuming that in the future we may want to add 'linear position' channel and want this driver to be prepared for it.

degree -= 360;
}
}
sensor_degrees_to_rad(degree, val);
Copy link
Member

Choose a reason for hiding this comment

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

Calculating the value first in degrees and then converting it to radians means that we loose precision. We probably should make all the calculations in radians directly.

include/sensor.h Outdated
/** 1.0 micro-meters Particulate Matter, in ug/m^3 */
SENSOR_CHAN_PM_1_0,
/** 2.5 micro-meters Particulate Matter, in ug/m^3 */
SENSOR_CHAN_PM_2_5,
/** 10 micro-meters Particulate Matter, in ug/m^3 */
SENSOR_CHAN_PM_10,
/** Angular position in radians */
Copy link
Member

Choose a reason for hiding this comment

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

Is this parameter supposed to change in the range 0 to 2π, -π to π? Is the range unlimited? We probably should clarify this in comment.

@jpfaff
Copy link
Contributor Author

jpfaff commented Dec 19, 2017

@mnkp I agree with all your comments.
What can we do to find an agreement on the best place for this kind of drivers?

  • In sam e70 qdec is included in the counter module.
  • Other socs may have specialized modules for it.
  • Until now drivers/sensor is used for (soc)-external components.

@nashif
Copy link
Member

nashif commented Jan 7, 2018

Until now drivers/sensor is used for (soc)-external components.

not really, lots o the sensors in drivers/sensors are part of the SoC.

If you are using the sensor.h, then that belongs into sensors.

@galak galak force-pushed the arm branch 2 times, most recently from ee5b12f to f95e5fd Compare January 11, 2018 22:07
@galak galak added area: ARM ARM (32-bit) Architecture platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) labels Jan 13, 2018
@galak galak force-pushed the arm branch 2 times, most recently from 6b38c09 to ff730a4 Compare January 23, 2018 14:53
@galak galak removed this from the v1.11.0 milestone Feb 14, 2018
@galak galak force-pushed the arm branch 3 times, most recently from 23c2a89 to d3d7d54 Compare March 6, 2018 18:07
jpfaff added 2 commits March 6, 2018 12:15
Tested on Atmel SMART SAM E70 Xplained board

Origin: Original

Jira: ZEP-2478

Signed-off-by: Jonas Pfaff <[email protected]>
@galak galak changed the base branch from arm to master March 6, 2018 18:16
@codecov-io
Copy link

Codecov Report

Merging #1043 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1043   +/-   ##
======================================
  Coverage    53.2%   53.2%           
======================================
  Files         436     436           
  Lines       41353   41353           
  Branches     7937    7937           
======================================
  Hits        22002   22002           
  Misses      16127   16127           
  Partials     3224    3224
Impacted Files Coverage Δ
samples/philosophers/src/main.c 96.87% <0%> (-1.57%) ⬇️
kernel/posix/pthread.c 63% <0%> (+0.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cfc79d1...f434693. Read the comment docs.

@nashif
Copy link
Member

nashif commented Jul 3, 2018

what is the story with this PR? Is this going to be updated and is it still required? If nothing happens within the next week, it will be closed.

@pdunaj
Copy link
Collaborator

pdunaj commented Aug 7, 2018

Hi, will anything happen to this PR soon? We need to use other QDEC and I don't want to generate code conflicts or implement things already done?

@jpfaff
Copy link
Contributor Author

jpfaff commented Aug 7, 2018 via email

@pdunaj
Copy link
Collaborator

pdunaj commented Aug 7, 2018

Thanks, I will try to reuse the API since it was already discussed.

@pdunaj
Copy link
Collaborator

pdunaj commented Aug 9, 2018

Hi @jpfaff , you can delete the PR now to avoid any conflict in the future. I will create and issue and PR with our QDEC.

@jpfaff jpfaff closed this Aug 9, 2018
@jpfaff jpfaff deleted the qdec_sam branch August 9, 2018 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants