mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] sterlinghughes closed pull request #931: Adding support for SPI_2 for nrf52
Date Thu, 22 Mar 2018 15:38:34 GMT
sterlinghughes closed pull request #931: Adding support for SPI_2 for nrf52
URL: https://github.com/apache/mynewt-core/pull/931
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_spi.c b/hw/mcu/nordic/nrf52xxx/src/hal_spi.c
index 9e46e1b48..a72c5907a 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_spi.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_spi.c
@@ -40,7 +40,7 @@ typedef void (*nrf52_spi_irq_handler_t)(void);
  */
 
 /* The maximum number of SPI interfaces we will allow */
-#define NRF52_HAL_SPI_MAX (2)
+#define NRF52_HAL_SPI_MAX (3)
 
 /* Used to disable all interrupts */
 #define NRF_SPI_IRQ_DISABLE_ALL 0xFFFFFFFF
@@ -92,6 +92,9 @@ struct nrf52_hal_spi nrf52_hal_spi0;
 #if MYNEWT_VAL(SPI_1_MASTER)  || MYNEWT_VAL(SPI_1_SLAVE)
 struct nrf52_hal_spi nrf52_hal_spi1;
 #endif
+#if MYNEWT_VAL(SPI_2_MASTER)  || MYNEWT_VAL(SPI_2_SLAVE)
+struct nrf52_hal_spi nrf52_hal_spi2;
+#endif
 
 static const struct nrf52_hal_spi *nrf52_hal_spis[NRF52_HAL_SPI_MAX] = {
 #if MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_0_SLAVE)
@@ -100,9 +103,14 @@ static const struct nrf52_hal_spi *nrf52_hal_spis[NRF52_HAL_SPI_MAX]
= {
     NULL,
 #endif
 #if MYNEWT_VAL(SPI_1_MASTER)  || MYNEWT_VAL(SPI_1_SLAVE)
-    &nrf52_hal_spi1
+    &nrf52_hal_spi1,
 #else
-    NULL
+    NULL,
+#endif
+#if MYNEWT_VAL(SPI_2_MASTER)  || MYNEWT_VAL(SPI_2_SLAVE)
+    &nrf52_hal_spi2,
+#else
+    NULL,
 #endif
 };
 
@@ -117,7 +125,7 @@ static const struct nrf52_hal_spi *nrf52_hal_spis[NRF52_HAL_SPI_MAX] =
{
         goto err;                                           \
     }
 
-#if (MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_1_MASTER) )
+#if (MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_1_MASTER) || MYNEWT_VAL(SPI_2_MASTER))
 static void
 nrf52_irqm_handler(struct nrf52_hal_spi *spi)
 {
@@ -163,7 +171,7 @@ nrf52_irqm_handler(struct nrf52_hal_spi *spi)
 }
 #endif
 
-#if (MYNEWT_VAL(SPI_0_SLAVE)  || MYNEWT_VAL(SPI_1_SLAVE) )
+#if (MYNEWT_VAL(SPI_0_SLAVE)  || MYNEWT_VAL(SPI_1_SLAVE) || MYNEWT_VAL(SPI_2_SLAVE))
 static void
 nrf52_irqs_handler(struct nrf52_hal_spi *spi)
 {
@@ -254,6 +262,24 @@ nrf52_spi1_irq_handler(void)
 }
 #endif
 
+#if MYNEWT_VAL(SPI_2_MASTER)  || MYNEWT_VAL(SPI_2_SLAVE)
+void
+nrf52_spi2_irq_handler(void)
+{
+    os_trace_enter_isr();
+    if (nrf52_hal_spi2.spi_type == HAL_SPI_TYPE_MASTER) {
+#if MYNEWT_VAL(SPI_2_MASTER)
+        nrf52_irqm_handler(&nrf52_hal_spi2);
+#endif
+    } else {
+#if MYNEWT_VAL(SPI_2_SLAVE)
+        nrf52_irqs_handler(&nrf52_hal_spi2);
+#endif
+    }
+    os_trace_exit_isr();
+}
+#endif
+
 static void
 hal_spi_stop_transfer(NRF_SPIM_Type *spim)
 {
@@ -575,6 +601,26 @@ hal_spi_init(int spi_num, void *cfg, uint8_t spi_type)
         }
 #else
         goto err;
+#endif
+    } else if (spi_num == 2) {
+#if MYNEWT_VAL(SPI_2_MASTER)  || MYNEWT_VAL(SPI_2_SLAVE)
+        spi->irq_num = SPIM2_SPIS2_SPI2_IRQn;
+        irq_handler = nrf52_spi2_irq_handler;
+        if (spi_type == HAL_SPI_TYPE_MASTER) {
+#if MYNEWT_VAL(SPI_2_MASTER)
+            spi->nhs_spi.spim = NRF_SPIM2;
+#else
+            assert(0);
+#endif
+        } else {
+#if MYNEWT_VAL(SPI_2_SLAVE)
+            spi->nhs_spi.spis = NRF_SPIS2;
+#else
+            assert(0);
+#endif
+        }
+#else
+        goto err;
 #endif
     } else {
         goto err;
diff --git a/hw/mcu/nordic/nrf52xxx/syscfg.yml b/hw/mcu/nordic/nrf52xxx/syscfg.yml
index e24ccc1af..e2a761f87 100644
--- a/hw/mcu/nordic/nrf52xxx/syscfg.yml
+++ b/hw/mcu/nordic/nrf52xxx/syscfg.yml
@@ -71,6 +71,17 @@ syscfg.defs:
             - "!SPI_1_MASTER"
             - "!I2C_1"
 
+    SPI_2_MASTER:
+        description: 'SPI 2 master'
+        value: 0
+        restrictions:
+            - "!SPI_2_SLAVE"
+    SPI_2_SLAVE:
+        description: 'SPI 2 slave'
+        value: 0
+        restrictions:
+            - "!SPI_2_MASTER"
+
     ADC_0:
         description: 'NRF52 ADC 0'
         value:  0


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message