lkml.org 
[lkml]   [2010]   [Feb]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PWM PATCH 2/5] Emulates PWM hardware using a high-resolution timer and a GPIO pin
> 
> 11.02.2010, ? 23:58, Pavel Machek ???????(?):
>
> > On Thu 2010-02-11 14:35:14, Bill Gatliff wrote:
> >> Pavel Machek wrote:
> >>>> +static void
> >>>> +gpio_pwm_work (struct work_struct *work)
> >>>> +{
> >>>> + struct gpio_pwm *gp = container_of(work, struct gpio_pwm, work);
> >>>> +
> >>>> + if (gp->active)
> >>>> + gpio_direction_output(gp->gpio, gp->polarity ? 1 : 0);
> >>>> + else
> >>>> + gpio_direction_output(gp->gpio, gp->polarity ? 0 : 1);
> >>>> +}
> >>>>
> >>>
> >>> ...polarity ^ active ?
> >>>
> >>
> >> ... except that if polarity and/or active are >1, I don't send the
> >> values 1 or 0 to gpio_direction_output. I don't know if the API is
> >> specifically intended to accept nonzero values that are greater than 1.
> >
> > !polarity ^ !active ? :-).
>
>
> One the one hand that wouldn't be 100% right because according to
> ANSI C !(0) is just != 0 but no one says it is 1.

I believe you are wrong here.

!!x is common idiom using to turn anything into 0/1, used all over kernel.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


\
 
 \ /
  Last update: 2010-02-12 14:43    [W:0.054 / U:1.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site