You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/12/13 19:02:31 UTC

[mynewt-nimble] 01/02: nimble/drivers/fem: Add support for nRF21540

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 9f99d55e64d492057425b455810b465dca8efd5b
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Nov 25 13:56:23 2022 +0100

    nimble/drivers/fem: Add support for nRF21540
    
    This adds support for nRF21540 FEM.
    FEM is controlled via GPIOs, there's no support for SPI.
---
 .../fem/nrf21540/include/nrf21540/nrf21540.h       |  36 ++++++
 nimble/drivers/fem/nrf21540/pkg.yml                |  30 +++++
 nimble/drivers/fem/nrf21540/src/nrf21540.c         | 143 +++++++++++++++++++++
 nimble/drivers/fem/nrf21540/syscfg.yml             |  45 +++++++
 4 files changed, 254 insertions(+)

diff --git a/nimble/drivers/fem/nrf21540/include/nrf21540/nrf21540.h b/nimble/drivers/fem/nrf21540/include/nrf21540/nrf21540.h
new file mode 100644
index 00000000..54efc854
--- /dev/null
+++ b/nimble/drivers/fem/nrf21540/include/nrf21540/nrf21540.h
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#ifndef _NRF21540_H
+#define _NRF21540_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int nrf21540_mode_set(uint8_t mode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _NRF21540_H */
diff --git a/nimble/drivers/fem/nrf21540/pkg.yml b/nimble/drivers/fem/nrf21540/pkg.yml
new file mode 100644
index 00000000..c6dd5f55
--- /dev/null
+++ b/nimble/drivers/fem/nrf21540/pkg.yml
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: nimble/drivers/fem/nrf21540
+pkg.description: Driver for nRF21540 front-end module
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "https://mynewt.apache.org/"
+pkg.apis:
+    - ble_fem_pa
+    - ble_fem_lna
+    - ble_fem_antenna
+
+pkg.init:
+    nrf21540_init: 999
diff --git a/nimble/drivers/fem/nrf21540/src/nrf21540.c b/nimble/drivers/fem/nrf21540/src/nrf21540.c
new file mode 100644
index 00000000..b70a66e7
--- /dev/null
+++ b/nimble/drivers/fem/nrf21540/src/nrf21540.c
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <syscfg/syscfg.h>
+#include <nrf21540/nrf21540.h>
+#include <hal/hal_gpio.h>
+#include <controller/ble_fem.h>
+
+static void
+nrf21540_pdn_set(int state)
+{
+    int pin;
+
+    pin = MYNEWT_VAL(NRF21540_PIN_PDN);
+    hal_gpio_write(pin, state);
+}
+
+int
+nrf21540_mode_set(uint8_t mode)
+{
+#ifdef MYNEWT_VAL_NRF21540_PIN_MODE
+    int pin;
+
+    pin = MYNEWT_VAL(NRF21540_PIN_MODE);
+    hal_gpio_init_out(pin, mode);
+
+    return 0;
+#else
+    return -1;
+#endif
+}
+
+void
+ble_fem_pa_init(void)
+{
+    nrf21540_pdn_set(0);
+}
+
+void
+ble_fem_pa_enable(void)
+{
+    nrf21540_pdn_set(1);
+}
+
+void
+ble_fem_pa_disable(void)
+{
+    nrf21540_pdn_set(0);
+}
+
+void
+ble_fem_lna_init(void)
+{
+}
+
+void
+ble_fem_lna_enable(void)
+{
+    nrf21540_pdn_set(1);
+}
+
+void
+ble_fem_lna_disable(void)
+{
+    nrf21540_pdn_set(0);
+}
+
+int
+ble_fem_antenna(uint8_t port)
+{
+#ifdef MYNEWT_VAL_NRF21540_PIN_ANT_SEL
+    int pin;
+
+    pin = MYNEWT_VAL(NRF21540_PIN_ANT_SEL);
+    switch (port) {
+    case 0:
+    case 1:
+        hal_gpio_write(pin, 0);
+        break;
+    case 2:
+        hal_gpio_write(pin, 1);
+        break;
+    default:
+        return -1;
+    }
+
+    return 0;
+#else
+    return -1;
+#endif
+}
+
+void
+nrf21540_init(void)
+{
+    int pin;
+
+    pin = MYNEWT_VAL(NRF21540_PIN_PDN);
+    assert(pin >= 0);
+    hal_gpio_init_out(pin, 0);
+
+#ifdef MYNEWT_VAL_NRF21540_PIN_ANT_SEL
+    pin = MYNEWT_VAL(NRF21540_PIN_ANT_SEL);
+    assert(pin >= 0);
+    switch (MYNEWT_VAL(NRF21540_ANTENNA_PORT)) {
+    case 1:
+        hal_gpio_init_out(pin, 0);
+        break;
+    case 2:
+        hal_gpio_init_out(pin, 1);
+        break;
+    default:
+        assert(0);
+    }
+#endif
+
+#ifdef MYNEWT_VAL_NRF21540_PIN_MODE
+    pin = MYNEWT_VAL(NRF21540_PIN_MODE);
+    assert(pin >= 0);
+    if (MYNEWT_VAL_CHOICE(NRF21540_TX_GAIN_PRESET, POUTB)) {
+        hal_gpio_init_out(pin, 1);
+    } else {
+        hal_gpio_init_out(pin, 0);
+    }
+#endif
+}
diff --git a/nimble/drivers/fem/nrf21540/syscfg.yml b/nimble/drivers/fem/nrf21540/syscfg.yml
new file mode 100644
index 00000000..13e5f17a
--- /dev/null
+++ b/nimble/drivers/fem/nrf21540/syscfg.yml
@@ -0,0 +1,45 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+    NRF21540_PIN_PDN:
+        description: >
+            GPIO pin number to control PDN signal.
+        value:
+        restrictions: $notnull
+    NRF21540_PIN_ANT_SEL:
+        description: >
+            GPIO pin number to control ANT_SEL signal.
+        value:
+    NRF21540_PIN_MODE:
+        description: >
+            GPIO pin number to control MODE signal.
+        value:
+    NRF21540_ANTENNA_PORT:
+        description: >
+            Selects antenna port, valid only if ANT_SEL pin is configured.
+        range: 1, 2
+        value: 1
+    NRF21540_TX_GAIN_PRESET:
+        description: >
+            Selects TX gain preset, valid only if MODE pin is configured.
+        choices:
+            - none
+            - POUTA
+            - POUTB
+        value: none