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

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


The following commit(s) were added to refs/heads/master by this push:
     new 42f1790a nimble/drivers/fem: Add support for SKY66403-11
42f1790a is described below

commit 42f1790a6ccdb401fa8bfb90f79cf83a7443db44
Author: Szymon Janc <szymon.j...@codecoup.pl>
AuthorDate: Fri Jun 9 17:28:47 2023 +0200

    nimble/drivers/fem: Add support for SKY66403-11
    
    This adds driver for SKY66403-11. It is very similar to SKY66112-11
    but PINs configuration has different meaning in transmit mode.
---
 .../fem/sky66403/include/sky66403/sky66403.h       |  42 +++++
 nimble/drivers/fem/sky66403/pkg.yml                |  32 ++++
 nimble/drivers/fem/sky66403/src/sky66403.c         | 201 +++++++++++++++++++++
 nimble/drivers/fem/sky66403/syscfg.yml             |  76 ++++++++
 4 files changed, 351 insertions(+)

diff --git a/nimble/drivers/fem/sky66403/include/sky66403/sky66403.h 
b/nimble/drivers/fem/sky66403/include/sky66403/sky66403.h
new file mode 100644
index 00000000..a9dc99ba
--- /dev/null
+++ b/nimble/drivers/fem/sky66403/include/sky66403/sky66403.h
@@ -0,0 +1,42 @@
+/*
+ * 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 _SKY66403_H
+#define _SKY66403_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void sky66403_tx_linear_mode(uint8_t enabled);
+void sky66403_rx_bypass(uint8_t enabled);
+void sky66403_tx_bypass(uint8_t enabled);
+
+#if MYNEWT_VAL_CHOICE(SKY66403_ANTENNA_PORT, runtime)
+uint8_t sky66403_default_antenna_get(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SKY66403_H */
diff --git a/nimble/drivers/fem/sky66403/pkg.yml 
b/nimble/drivers/fem/sky66403/pkg.yml
new file mode 100644
index 00000000..d119cf12
--- /dev/null
+++ b/nimble/drivers/fem/sky66403/pkg.yml
@@ -0,0 +1,32 @@
+#
+# 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/sky66403
+pkg.description: Driver for SKY66403 front-end module
+pkg.author: "Apache Mynewt <d...@mynewt.apache.org>"
+pkg.homepage: "https://mynewt.apache.org/";
+pkg.apis:
+    - ble_fem_pa
+    - ble_fem_lna
+    - ble_fem_antenna
+pkg.deps:
+    - nimble/controller
+
+pkg.init:
+    sky66403_init: 999
diff --git a/nimble/drivers/fem/sky66403/src/sky66403.c 
b/nimble/drivers/fem/sky66403/src/sky66403.c
new file mode 100644
index 00000000..1aa87d14
--- /dev/null
+++ b/nimble/drivers/fem/sky66403/src/sky66403.c
@@ -0,0 +1,201 @@
+/*
+ * 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 <sky66403/sky66403.h>
+#include <syscfg/syscfg.h>
+#include <hal/hal_gpio.h>
+#include <controller/ble_fem.h>
+
+static struct {
+    uint8_t rx_bypass : 1;
+    uint8_t tx_bypass : 1;
+} sky66403_config = {
+    .rx_bypass = MYNEWT_VAL(SKY66403_RX_BYPASS),
+    .tx_bypass = MYNEWT_VAL(SKY66403_TX_BYPASS),
+};
+
+#if !MYNEWT_VAL_CHOICE(SKY66403_ANTENNA_PORT, runtime)
+static uint8_t
+sky66403_default_antenna_get(void)
+{
+    if (MYNEWT_VAL_CHOICE(SKY66403_ANTENNA_PORT, ANT2)) {
+        return 2;
+    } else {
+        return 1;
+    }
+}
+#endif
+
+static void
+sky66403_bypass(uint8_t enabled)
+{
+    /* this is called only if bypass is enabled which means CPS PIN is
+     * correctly set and there is no need to check it here.
+     */
+    hal_gpio_write(MYNEWT_VAL(SKY66403_PIN_CPS), enabled);
+}
+
+void
+ble_fem_pa_init(void)
+{
+    sky66403_tx_linear_mode(MYNEWT_VAL(SKY66403_TX_LINEAR_MODE));
+    sky66403_tx_bypass(0);
+#if MYNEWT_VAL(BLE_FEM_ANTENNA)
+    ble_fem_antenna(0);
+#endif
+}
+
+void
+ble_fem_pa_enable(void)
+{
+    if (sky66403_config.tx_bypass) {
+        sky66403_bypass(1);
+    }
+}
+
+void
+ble_fem_pa_disable(void)
+{
+    if (sky66403_config.tx_bypass) {
+        sky66403_bypass(0);
+    }
+}
+
+void
+ble_fem_lna_init(void)
+{
+    sky66403_rx_bypass(0);
+#if MYNEWT_VAL(BLE_FEM_ANTENNA)
+    ble_fem_antenna(0);
+#endif
+}
+
+void
+ble_fem_lna_enable(void)
+{
+    if (sky66403_config.rx_bypass) {
+        sky66403_bypass(1);
+    }
+}
+
+void
+ble_fem_lna_disable(void)
+{
+    if (sky66403_config.rx_bypass) {
+        sky66403_bypass(0);
+    }
+}
+
+void
+sky66403_tx_linear_mode(uint8_t enabled)
+{
+    int pin = MYNEWT_VAL(SKY66403_PIN_CHL);
+
+    if (pin >= 0) {
+        hal_gpio_write(pin, enabled);
+    }
+}
+
+int
+ble_fem_antenna(uint8_t port)
+{
+    int pin = MYNEWT_VAL(SKY66403_PIN_SEL);
+    uint8_t ant;
+
+    if (pin >= 0) {
+        switch (port) {
+        case 0:
+            ant = sky66403_default_antenna_get();
+            assert(ant == 1 || ant == 2);
+            return ble_fem_antenna(ant);
+        case 1:
+            hal_gpio_write(pin, 0);
+            break;
+        case 2:
+            hal_gpio_write(pin, 1);
+            break;
+        default:
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+void
+sky66403_rx_bypass(uint8_t enabled)
+{
+    int pin = MYNEWT_VAL(SKY66403_PIN_CPS);
+
+    if (pin >= 0) {
+        sky66403_config.rx_bypass = enabled;
+        sky66403_bypass(enabled);
+    }
+}
+
+void
+sky66403_tx_bypass(uint8_t enabled)
+{
+    int pin = MYNEWT_VAL(SKY66403_PIN_CPS);
+
+    if (pin >= 0) {
+        sky66403_config.tx_bypass = enabled;
+        sky66403_bypass(enabled);
+    }
+}
+
+void
+sky66403_init(void)
+{
+    int pin;
+
+    /* Use CRX and CTX to enable sleep mode */
+    pin = MYNEWT_VAL(SKY66403_PIN_CSD);
+    if (pin >= 0) {
+        hal_gpio_init_out(pin, 1);
+    }
+
+    /* Set default tx power mode */
+    pin = MYNEWT_VAL(SKY66403_PIN_CHL);
+    if (pin >= 0) {
+        hal_gpio_init_out(pin, MYNEWT_VAL(SKY66403_TX_LINEAR_MODE));
+    }
+
+    /* Disable bypass, we'll enable it when needed */
+    pin = MYNEWT_VAL(SKY66403_PIN_CPS);
+    if (pin >= 0) {
+        hal_gpio_init_out(pin, 0);
+    }
+
+    /* configure default antenna */
+    pin = MYNEWT_VAL(SKY66403_PIN_SEL);
+    if (pin >= 0) {
+        switch (sky66403_default_antenna_get()) {
+        case 1:
+            hal_gpio_init_out(pin, 0);
+            break;
+        case 2:
+            hal_gpio_init_out(pin, 1);
+            break;
+        default:
+            assert(0);
+        }
+    }
+}
diff --git a/nimble/drivers/fem/sky66403/syscfg.yml 
b/nimble/drivers/fem/sky66403/syscfg.yml
new file mode 100644
index 00000000..def2da51
--- /dev/null
+++ b/nimble/drivers/fem/sky66403/syscfg.yml
@@ -0,0 +1,76 @@
+# 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:
+    SKY66403_PIN_CSD:
+        description: >
+            GPIO pin number to control CSD signal.
+            When set to '-1', pin state will not be changed and it should be
+            driven externally.
+        value: -1
+    SKY66403_PIN_CPS:
+        description: >
+            GPIO pin number to control CPS signal.
+            When set to '-1', pin state will not be changed and it should be
+            driven externally.
+        value: -1
+    SKY66403_PIN_CHL:
+        description: >
+            GPIO pin number to control CHL signal.
+            When set to '-1', pin state will not be changed and it should be
+            driven externally.
+        value: -1
+    SKY66403_PIN_SEL:
+        description: >
+            GPIO pin number to control SEL signal.
+            When set to '-1', pin state will not be changed and it should be
+            driven externally.
+        value: -1
+    SKY66403_TX_LINEAR_MODE:
+        description: >
+            Enables linear mode for TX.
+            Only valid if CHL signal is controller by driver.
+        value: 0
+    SKY66403_TX_BYPASS:
+        description: >
+            Enables bypass for TX which effectively disables operation as PA.
+            Only valid if CPS signal is controller by driver.
+        value: 0
+    SKY66403_RX_BYPASS:
+        description: >
+            Enables bypass for RX which effectively disables operation as PA.
+            Only valid if CPS signal is controller by driver.
+        value: 0
+    SKY66403_ANTENNA_PORT:
+        description: >
+            Selects which antenna port should be enabled. If 'runtime' is
+            selected SKY66403_default_antenna_get() (see SKY66403/SKY66403.h)
+            shall be implemeneted by application.
+        choices:
+            - ANT1
+            - ANT2
+            - runtime
+        value: ANT1
+
+syscfg.vals.!BLE_FEM_PA:
+    # Enable TX bypass by default if PA is disabled
+    SKY66403_TX_BYPASS: 1
+
+syscfg.vals.!BLE_FEM_LNA:
+    # Enable RX bypass by default if LNA is disabled
+    SKY66403_RX_BYPASS: 1

Reply via email to