[PATCH 6/8 v3] staging: pi433: use defines for shifting register values

From: Valentin Vidic
Date: Wed Dec 13 2017 - 12:45:14 EST


Avoid shifting by magic numbers and use defines instead.

Signed-off-by: Valentin Vidic <Valentin.Vidic@xxxxxxxxx>
---
v2: - drop change for SHIFT_DATAMODUL_MODULATION_TYPE
- move shifting to the header file
v3: - drop auto case
- use CURRENT suffix
- precompute define values

drivers/staging/pi433/rf69.c | 15 +++++++--------
drivers/staging/pi433/rf69_registers.h | 6 ++++++
2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index f77ecd60f43a..0889c65d5a31 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -340,14 +340,13 @@ enum lnaGain rf69_get_lna_gain(struct spi_device *spi)

currentValue = rf69_read_reg(spi, REG_LNA);

- switch (currentValue & MASK_LNA_CURRENT_GAIN >> 3) { // improvement: change 3 to define
- case LNA_GAIN_AUTO: return automatic;
- case LNA_GAIN_MAX: return max;
- case LNA_GAIN_MAX_MINUS_6: return maxMinus6;
- case LNA_GAIN_MAX_MINUS_12: return maxMinus12;
- case LNA_GAIN_MAX_MINUS_24: return maxMinus24;
- case LNA_GAIN_MAX_MINUS_36: return maxMinus36;
- case LNA_GAIN_MAX_MINUS_48: return maxMinus48;
+ switch (currentValue & MASK_LNA_CURRENT_GAIN) {
+ case LNA_GAIN_MAX_CURRENT: return max;
+ case LNA_GAIN_MAX_MINUS_6_CURRENT: return maxMinus6;
+ case LNA_GAIN_MAX_MINUS_12_CURRENT: return maxMinus12;
+ case LNA_GAIN_MAX_MINUS_24_CURRENT: return maxMinus24;
+ case LNA_GAIN_MAX_MINUS_36_CURRENT: return maxMinus36;
+ case LNA_GAIN_MAX_MINUS_48_CURRENT: return maxMinus48;
default: return undefined;
}
}
diff --git a/drivers/staging/pi433/rf69_registers.h b/drivers/staging/pi433/rf69_registers.h
index d23b8b668ef5..4a189c6a4ab3 100644
--- a/drivers/staging/pi433/rf69_registers.h
+++ b/drivers/staging/pi433/rf69_registers.h
@@ -246,6 +246,12 @@
#define LNA_GAIN_MAX_MINUS_36 0x05
#define LNA_GAIN_MAX_MINUS_48 0x06

+#define LNA_GAIN_MAX_CURRENT 0x08
+#define LNA_GAIN_MAX_MINUS_6_CURRENT 0x10
+#define LNA_GAIN_MAX_MINUS_12_CURRENT 0x18
+#define LNA_GAIN_MAX_MINUS_24_CURRENT 0x20
+#define LNA_GAIN_MAX_MINUS_36_CURRENT 0x28
+#define LNA_GAIN_MAX_MINUS_48_CURRENT 0x30

/* RegRxBw (0x19) and RegAfcBw (0x1A) */
#define MASK_BW_DCC_FREQ 0xE0
--
2.15.0