lkml.org 
[lkml]   [2017]   [Dec]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH 6/8 v2] staging: pi433: use defines for shifting register values
Avoid shifting by magic numbers and use defines instead.

Signed-off-by: Valentin Vidic <Valentin.Vidic@CARNet.hr>
---
v2: - drop change for SHIFT_DATAMODUL_MODULATION_TYPE
- move shifting to the header file

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

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index f77ecd60f43a..ce259b4f0b0e 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -340,14 +340,14 @@ 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_AUTO_SHIFTED: return automatic;
+ case LNA_GAIN_MAX_SHIFTED: return max;
+ case LNA_GAIN_MAX_MINUS_6_SHIFTED: return maxMinus6;
+ case LNA_GAIN_MAX_MINUS_12_SHIFTED: return maxMinus12;
+ case LNA_GAIN_MAX_MINUS_24_SHIFTED: return maxMinus24;
+ case LNA_GAIN_MAX_MINUS_36_SHIFTED: return maxMinus36;
+ case LNA_GAIN_MAX_MINUS_48_SHIFTED: return maxMinus48;
default: return undefined;
}
}
diff --git a/drivers/staging/pi433/rf69_registers.h b/drivers/staging/pi433/rf69_registers.h
index d23b8b668ef5..6329bbf9e499 100644
--- a/drivers/staging/pi433/rf69_registers.h
+++ b/drivers/staging/pi433/rf69_registers.h
@@ -237,6 +237,7 @@
#define MASK_LNA_ZIN 0x80
#define MASK_LNA_CURRENT_GAIN 0x38
#define MASK_LNA_GAIN 0x07
+#define SHIFT_LNA_CURRENT_GAIN 3

#define LNA_GAIN_AUTO 0x00 /* default */
#define LNA_GAIN_MAX 0x01
@@ -246,6 +247,13 @@
#define LNA_GAIN_MAX_MINUS_36 0x05
#define LNA_GAIN_MAX_MINUS_48 0x06

+#define LNA_GAIN_AUTO_SHIFTED (LNA_GAIN_AUTO << SHIFT_LNA_CURRENT_GAIN)
+#define LNA_GAIN_MAX_SHIFTED (LNA_GAIN_MAX << SHIFT_LNA_CURRENT_GAIN)
+#define LNA_GAIN_MAX_MINUS_6_SHIFTED (LNA_GAIN_MAX_MINUS_6 << SHIFT_LNA_CURRENT_GAIN)
+#define LNA_GAIN_MAX_MINUS_12_SHIFTED (LNA_GAIN_MAX_MINUS_12 << SHIFT_LNA_CURRENT_GAIN)
+#define LNA_GAIN_MAX_MINUS_24_SHIFTED (LNA_GAIN_MAX_MINUS_24 << SHIFT_LNA_CURRENT_GAIN)
+#define LNA_GAIN_MAX_MINUS_36_SHIFTED (LNA_GAIN_MAX_MINUS_36 << SHIFT_LNA_CURRENT_GAIN)
+#define LNA_GAIN_MAX_MINUS_48_SHIFTED (LNA_GAIN_MAX_MINUS_48 << SHIFT_LNA_CURRENT_GAIN)

/* RegRxBw (0x19) and RegAfcBw (0x1A) */
#define MASK_BW_DCC_FREQ 0xE0
--
2.15.0
\
 
 \ /
  Last update: 2017-12-13 17:56    [W:0.053 / U:1.548 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site