mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
iio: adc: hx711: localize loop iterators in hx711_read
Tighten the scope of the loop variables in hx711_read() now that trailing-pulse selection is already handled by the callers. Also replace the 24-bit loop bound with a named constant while touching the same code. Suggested-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
b74def999f
commit
fc737af158
|
|
@ -23,6 +23,8 @@
|
|||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
|
||||
#define HX711_DATA_BITS 24
|
||||
|
||||
/* gain to pulse and scale conversion */
|
||||
#define HX711_GAIN_MAX 3
|
||||
#define HX711_RESET_GAIN 128
|
||||
|
|
@ -157,16 +159,16 @@ static int hx711_cycle(struct hx711_data *hx711_data)
|
|||
|
||||
static int hx711_read(struct hx711_data *hx711_data, int trailing_pulses)
|
||||
{
|
||||
int i, ret;
|
||||
int value = 0;
|
||||
int val;
|
||||
int ret;
|
||||
|
||||
/* we double check if it's really down */
|
||||
val = gpiod_get_value(hx711_data->gpiod_dout);
|
||||
if (val)
|
||||
return -EIO;
|
||||
|
||||
for (i = 0; i < 24; i++) {
|
||||
for (int i = 0; i < HX711_DATA_BITS; i++) {
|
||||
value <<= 1;
|
||||
ret = hx711_cycle(hx711_data);
|
||||
if (ret)
|
||||
|
|
@ -175,7 +177,7 @@ static int hx711_read(struct hx711_data *hx711_data, int trailing_pulses)
|
|||
|
||||
value ^= 0x800000;
|
||||
|
||||
for (i = 0; i < trailing_pulses; i++)
|
||||
for (int i = 0; i < trailing_pulses; i++)
|
||||
hx711_cycle(hx711_data);
|
||||
|
||||
return value;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user