Messages in this thread | | | Subject | Re: [PATCH v2 09/11] staging: pi433: Combine all rf69_set_amplifier_x() | From | Marcus Wolf <> | Date | Wed, 6 Dec 2017 11:43:30 +0200 |
| |
Am 06.12.2017 um 00:08 schrieb Simon Sandström: > Replaces the functions rf69_set_amplifier_1, _2, _3 with two > functions: rf69_enable_amplifier(dev, amp_mask) and > rf69_disable_amplifier(dev, amp_mask). > > Signed-off-by: Simon Sandström <simon@nikanor.nu> > --- > drivers/staging/pi433/pi433_if.c | 6 +++--- > drivers/staging/pi433/rf69.c | 46 ++++------------------------------------ > drivers/staging/pi433/rf69.h | 8 ++----- > 3 files changed, 9 insertions(+), 51 deletions(-) > > diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c > index 3b4170b9ba94..688d0cf00782 100644 > --- a/drivers/staging/pi433/pi433_if.c > +++ b/drivers/staging/pi433/pi433_if.c > @@ -1126,9 +1126,9 @@ static int pi433_probe(struct spi_device *spi) > /* setup the radio module */ > SET_CHECKED(rf69_set_mode (spi, standby)); > SET_CHECKED(rf69_set_data_mode (spi, DATAMODUL_MODE_PACKET)); > - SET_CHECKED(rf69_set_amplifier_0 (spi, OPTION_ON)); > - SET_CHECKED(rf69_set_amplifier_1 (spi, OPTION_OFF)); > - SET_CHECKED(rf69_set_amplifier_2 (spi, OPTION_OFF)); > + SET_CHECKED(rf69_enable_amplifier(spi, MASK_PALEVEL_PA0)); > + SET_CHECKED(rf69_disable_amplifier(spi, MASK_PALEVEL_PA1)); > + SET_CHECKED(rf69_disable_amplifier(spi, MASK_PALEVEL_PA2)); > SET_CHECKED(rf69_set_output_power_level (spi, 13)); > SET_CHECKED(rf69_set_antenna_impedance (spi, fiftyOhm)); > > diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c > index 4c9eb97978ef..c97c65ea8acd 100644 > --- a/drivers/staging/pi433/rf69.c > +++ b/drivers/staging/pi433/rf69.c > @@ -262,52 +262,14 @@ int rf69_set_frequency(struct spi_device *spi, u32 frequency) > return 0; > } > > -int rf69_set_amplifier_0(struct spi_device *spi, > - enum option_on_off option_on_off) > +int rf69_enable_amplifier(struct spi_device *spi, u8 amplifier_mask) > { > - #ifdef DEBUG > - dev_dbg(&spi->dev, "set: amp #0"); > - #endif > - > - switch (option_on_off) { > - case OPTION_ON: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) | MASK_PALEVEL_PA0)); > - case OPTION_OFF: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) & ~MASK_PALEVEL_PA0)); > - default: > - dev_dbg(&spi->dev, "set: illegal input param"); > - return -EINVAL; > - } > -} > - > -int rf69_set_amplifier_1(struct spi_device *spi, > - enum option_on_off option_on_off) > -{ > - #ifdef DEBUG > - dev_dbg(&spi->dev, "set: amp #1"); > - #endif > - > - switch (option_on_off) { > - case OPTION_ON: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) | MASK_PALEVEL_PA1)); > - case OPTION_OFF: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) & ~MASK_PALEVEL_PA1)); > - default: > - dev_dbg(&spi->dev, "set: illegal input param"); > - return -EINVAL; > - } > + return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) | amplifier_mask)); > } > > -int rf69_set_amplifier_2(struct spi_device *spi, > - enum option_on_off option_on_off) > +int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask) > { > - #ifdef DEBUG > - dev_dbg(&spi->dev, "set: amp #2"); > - #endif > - > - switch (option_on_off) { > - case OPTION_ON: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) | MASK_PALEVEL_PA2)); > - case OPTION_OFF: return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) & ~MASK_PALEVEL_PA2)); > - default: > - dev_dbg(&spi->dev, "set: illegal input param"); > - return -EINVAL; > - } > + return WRITE_REG(REG_PALEVEL, (READ_REG(REG_PALEVEL) & ~amplifier_mask)); > } > > int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel) > diff --git a/drivers/staging/pi433/rf69.h b/drivers/staging/pi433/rf69.h > index 18296b4502f3..ba25ab6aeae7 100644 > --- a/drivers/staging/pi433/rf69.h > +++ b/drivers/staging/pi433/rf69.h > @@ -33,12 +33,8 @@ int rf69_set_modulation_shaping(struct spi_device *spi, enum mod_shaping mod_sha > int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate); > int rf69_set_deviation(struct spi_device *spi, u32 deviation); > int rf69_set_frequency(struct spi_device *spi, u32 frequency); > -int rf69_set_amplifier_0(struct spi_device *spi, > - enum option_on_off option_on_off); > -int rf69_set_amplifier_1(struct spi_device *spi, > - enum option_on_off option_on_off); > -int rf69_set_amplifier_2(struct spi_device *spi, > - enum option_on_off option_on_off); > +int rf69_enable_amplifier(struct spi_device *spi, u8 amplifier_mask); > +int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask); > int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel); > int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp); > int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance antennaImpedance); >
Hi Simon,
I am sorry. I don't like that.
You expand to two functions, to get the luxury of having an enable and a disable function. On the other hand, you colapse from 3 function - one for each amp - to a single, taking the amp number as argument.
Although I don't see the big benefit, in programming theory this might be a better solution. But the old implementation reflects the hardware and the datasheet, since the chip does not have a register to enable and a register to disable, taking the amp number, but the chip has three bits, saying on or off. For someone, not reading the code as a "novel", but work with it, he for sure will read the datasheet. Then the new construction will be uncomfortable for him.
I tried to reflect the chip in every function I wrote. And the DEFINES in rf69.h are (almost) exactly named, as the you'll find the namings in the datasheet. That eases working with such a complex chip a lot.
Sorry,
Marcus
| |