You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2020/08/10 00:00:36 UTC

[mynewt-core] 02/02: hw/bsp/pinetime: Use bus driver for flash and display

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

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

commit 9360debc22b961ca7abbdbab697c61480f8ae15d
Author: Casper Meijn <ca...@meijn.net>
AuthorDate: Sat Aug 8 10:48:09 2020 +0200

    hw/bsp/pinetime: Use bus driver for flash and display
    
    Use the bus driver for the SPI flash, so that the SPI display can be
    operated in parallel.
---
 hw/bsp/pinetime/src/hal_bsp.c | 48 +++++++++++++++++++++++++++++++++++++++++++
 hw/bsp/pinetime/syscfg.yml    |  8 ++++++++
 2 files changed, 56 insertions(+)

diff --git a/hw/bsp/pinetime/src/hal_bsp.c b/hw/bsp/pinetime/src/hal_bsp.c
index 307282d..d7dcb46 100644
--- a/hw/bsp/pinetime/src/hal_bsp.c
+++ b/hw/bsp/pinetime/src/hal_bsp.c
@@ -56,6 +56,18 @@ hal_bsp_core_dump(int *area_cnt)
     return dump_cfg;
 }
 
+#if MYNEWT_VAL(SPIFLASH)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+struct bus_spi_node_cfg flash_spi_cfg = {
+    .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS),
+    .pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN),
+    .mode = BUS_SPI_MODE_3,
+    .data_order = HAL_SPI_MSB_FIRST,
+    .freq = MYNEWT_VAL(SPIFLASH_BAUDRATE),
+};
+#endif
+#endif
+
 static const struct hal_flash *flash_devs[] = {
     /* MCU internal flash. */
     [0] = &nrf52k_flash_dev,
@@ -169,15 +181,51 @@ hal_bsp_charger_init(void)
 }
 #endif
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+static struct bus_spi_node hal_bsp_display_spi;
+struct bus_spi_node_cfg hal_bsp_display_spi_cfg = {
+    .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS),
+    .pin_cs = LCD_CHIP_SELECT_PIN,
+    .mode = BUS_SPI_MODE_3,
+    .data_order = HAL_SPI_MSB_FIRST,
+    .freq = 8000,
+};
+
+static void
+hal_bsp_display_spi_init(void)
+{
+    int rc;
+
+    rc = bus_spi_node_create("spidisplay", &hal_bsp_display_spi, &hal_bsp_display_spi_cfg, NULL);
+    assert(rc == 0);
+}
+#endif
+
 void
 hal_bsp_init(void)
 {
+    int rc;
+
+    (void)rc;
+
     /* Make sure system clocks have started. */
     hal_system_clock_start();
 
     /* Create all available nRF52840 peripherals */
     nrf52_periph_create();
 
+    #if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    /* Create display spi node */
+    hal_bsp_display_spi_init();
+
+    #if MYNEWT_VAL(SPIFLASH)
+    /* Create external flash dev */
+    rc = spiflash_create_spi_dev(&spiflash_dev.dev,
+                                 MYNEWT_VAL(BSP_FLASH_SPI_NAME), &flash_spi_cfg);
+    assert(rc == 0);
+    #endif
+    #endif
+
     #if MYNEWT_VAL(BSP_CHARGER)
     /* Create charge controller */
     hal_bsp_charger_init();
diff --git a/hw/bsp/pinetime/syscfg.yml b/hw/bsp/pinetime/syscfg.yml
index bcb6e8d..97edf0e 100644
--- a/hw/bsp/pinetime/syscfg.yml
+++ b/hw/bsp/pinetime/syscfg.yml
@@ -29,6 +29,14 @@ syscfg.defs:
         description: 'Setup charger driver in the BSP'
         value: 1
 
+syscfg.defs.BUS_DRIVER_PRESENT:
+    BSP_FLASH_SPI_NAME:
+        description: 'SPIFLASH device name'
+        value: '"spiflash0"'
+    BSP_FLASH_SPI_BUS:
+        description: 'bus name SPIFLASH is connected to'
+        value: '"spi0"'
+
 syscfg.vals.BOOT_LOADER:
     BSP_BATTERY: 0
     BSP_CHARGER: 0