[riot-notifications] [RIOT-OS/RIOT] drivers/mrf24j40: add external PA/LNA control on MC/MD/ME devices (#11410)

Peter Kietzmann notifications at github.com
Tue May 21 16:40:10 CEST 2019


PeterKietzmann commented on this pull request.



> +#else
+    (void) dev;
+#endif
+}
+
+void mrf24j40_enable_lna(mrf24j40_t *dev)
+{
+#if MRF24J40_USE_EXT_PA_LNA
+    /* Disable automatic switch on PA/LNA */
+    mrf24j40_reg_write_long(dev, MRF24J40_REG_TESTMODE, MRF24J40_TESTMODE_RSSIWAIT0);
+
+    /* Configure all GPIOs as Output */
+    mrf24j40_reg_write_short(dev, MRF24J40_REG_TRISGPIO, 0xF);
+
+    /* Enable LNA */
+    mrf24j40_reg_write_short(dev, MRF24J40_REG_GPIO, 0xC);

When you write `0xC` (`0b00001100`) to the register, it sets GPIO1 to zero, and GPIO2/GPIO3 to one. 1.3.1 says:

"*Set GPIO2 (0x33<2>) = 1 and GPIO1 (0x32<1>) = 0. This enables the LNA and disables the PA"*

So why do you set GPIO3 here? I think it would be clearer to use preprocessor constants 

> +#else
+    (void) dev;
+#endif
+}
+
+void mrf24j40_disable_pa_lna(mrf24j40_t *dev)
+{
+#if MRF24J40_USE_EXT_PA_LNA
+    /* Disable automatic switch on PA/LNA */
+    mrf24j40_reg_write_long(dev, MRF24J40_REG_TESTMODE, MRF24J40_TESTMODE_RSSIWAIT0);
+
+    /* Configure all GPIOs as Output */
+    mrf24j40_reg_write_short(dev, MRF24J40_REG_TRISGPIO, 0xF);
+
+    /* Disable all GPIO outputs */
+    mrf24j40_reg_write_short(dev, MRF24J40_REG_GPIO, 0);

Mhm, I see. But nevertheless, it seems cleaner if we only implement what the function name indicates: configure/disable pa and lna and nothing else. Mind to change?

> @@ -36,6 +36,56 @@ static inline void getbus(mrf24j40_t *dev)
     spi_acquire(SPIDEV, CSPIN, SPI_MODE_0, dev->params.spi_clk);
 }
 
+void mrf24j40_enable_pa_lna(mrf24j40_t *dev)

If `mrf24j40_enable_lna` is a subset up `mrf24j40_enable_pa_lna` I would have expected it to be called from here.

> @@ -81,6 +81,7 @@ bool mrf24j40_cca(mrf24j40_t *dev)
     uint8_t tmp_rssi;
 
     mrf24j40_assert_awake(dev);
+    mrf24j40_enable_lna(dev);

I'm unsure what I like better: `#ifdef` around the function call or inside (as you did). I tend to prefer outside because it wouldn't call the function if `MRF24J40_USE_EXT_PA_LNA` is zero  and it makes it directly visible, although the code might get uglier. What was you motivation to implement it inside? 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11410#pullrequestreview-240082547
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190521/8667666e/attachment.html>


More information about the notifications mailing list