浏览代码

fw: adjustments/hacks to make the new asterix board bootable

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Gerard Marull-Paretas 6 月之前
父节点
当前提交
b7c502b6fd

+ 1 - 0
platform/platform_capabilities.py

@@ -274,6 +274,7 @@ board_capability_dicts = [
             'HAS_WEATHER',
             'HAS_WEATHER',
             'HAS_PUTBYTES_PREACKING',
             'HAS_PUTBYTES_PREACKING',
             # 'HAS_MAGNETOMETER',
             # 'HAS_MAGNETOMETER',
+            'HAS_PMIC',
         },
         },
     },
     },
 ]
 ]

+ 43 - 10
src/fw/board/boards/board_asterix.c

@@ -32,11 +32,11 @@ static QSPIPortState s_qspi_port_state;
 static QSPIPort QSPI_PORT = {
 static QSPIPort QSPI_PORT = {
   .state = &s_qspi_port_state,
   .state = &s_qspi_port_state,
   .auto_polling_interval = 16,
   .auto_polling_interval = 16,
-  .cs_gpio = NRF_GPIO_PIN_MAP(0, 14),
-  .clk_gpio = NRF_GPIO_PIN_MAP(0, 17),
+  .cs_gpio = NRF_GPIO_PIN_MAP(0, 17),
+  .clk_gpio = NRF_GPIO_PIN_MAP(0, 19),
   .data_gpio = {
   .data_gpio = {
     NRF_GPIO_PIN_MAP(0, 20),
     NRF_GPIO_PIN_MAP(0, 20),
-    NRF_GPIO_PIN_MAP(0, 24),
+    NRF_GPIO_PIN_MAP(0, 21),
     NRF_QSPI_PIN_NOT_CONNECTED,
     NRF_QSPI_PIN_NOT_CONNECTED,
     NRF_QSPI_PIN_NOT_CONNECTED,
     NRF_QSPI_PIN_NOT_CONNECTED,
   },
   },
@@ -57,8 +57,8 @@ IRQ_MAP_NRFX(QSPI, nrfx_qspi_irq_handler);
 static UARTDeviceState s_dbg_uart_state;
 static UARTDeviceState s_dbg_uart_state;
 static UARTDevice DBG_UART_DEVICE = {
 static UARTDevice DBG_UART_DEVICE = {
   .state = &s_dbg_uart_state,
   .state = &s_dbg_uart_state,
-  .tx_gpio = NRF_GPIO_PIN_MAP(0, 29),
-  .rx_gpio = NRF_GPIO_PIN_MAP(0, 28),
+  .tx_gpio = NRF_GPIO_PIN_MAP(0, 27),
+  .rx_gpio = NRF_GPIO_PIN_MAP(0, 5),
   .rts_gpio = NRF_UARTE_PSEL_DISCONNECTED,
   .rts_gpio = NRF_UARTE_PSEL_DISCONNECTED,
   .cts_gpio = NRF_UARTE_PSEL_DISCONNECTED,
   .cts_gpio = NRF_UARTE_PSEL_DISCONNECTED,
   .periph = NRFX_UARTE_INSTANCE(0),
   .periph = NRFX_UARTE_INSTANCE(0),
@@ -80,11 +80,42 @@ IRQ_MAP_NRFX(SPIM3, nrfx_spim_3_irq_handler);
 /* EXTI */
 /* EXTI */
 IRQ_MAP_NRFX(GPIOTE, nrfx_gpiote_irq_handler);
 IRQ_MAP_NRFX(GPIOTE, nrfx_gpiote_irq_handler);
 
 
+/* nPM1300 */
+static I2CBusState I2C_NPMC_IIC1_BUS_STATE = {};
+
+static const I2CBusHal I2C_NPMC_IIC1_BUS_HAL = {
+  .twim = NRFX_TWIM_INSTANCE(1),
+  .frequency = NRF_TWIM_FREQ_400K,
+};
+
+static const I2CBus I2C_NPMC_IIC1_BUS = {
+  .state = &I2C_NPMC_IIC1_BUS_STATE,
+  .hal = &I2C_NPMC_IIC1_BUS_HAL,
+  .scl_gpio = {
+    .gpio = NRF5_GPIO_RESOURCE_EXISTS,
+    .gpio_pin = NRF_GPIO_PIN_MAP(0, 14),
+  },
+  .sda_gpio = {
+    .gpio = NRF5_GPIO_RESOURCE_EXISTS,
+    .gpio_pin = NRF_GPIO_PIN_MAP(0, 15),
+  },
+  .name = "I2C_NPMC_IIC1"
+};
+IRQ_MAP_NRFX(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1, nrfx_twim_1_irq_handler);
+/* PERIPHERAL ID 9 */
+
+static const I2CSlavePort I2C_SLAVE_NPM1300 = {
+  .bus = &I2C_NPMC_IIC1_BUS,
+  .address = 0xD6,
+};
+
+I2CSlavePort * const I2C_NPM1300 = &I2C_SLAVE_NPM1300;
+
 /* peripheral I2C bus */
 /* peripheral I2C bus */
 static I2CBusState I2C_IIC2_BUS_STATE = {};
 static I2CBusState I2C_IIC2_BUS_STATE = {};
 
 
 static const I2CBusHal I2C_IIC2_BUS_HAL = {
 static const I2CBusHal I2C_IIC2_BUS_HAL = {
-  .twim = NRFX_TWIM_INSTANCE(1),
+  .twim = NRFX_TWIM_INSTANCE(0),
   .frequency = NRF_TWIM_FREQ_400K,
   .frequency = NRF_TWIM_FREQ_400K,
 };
 };
 
 
@@ -94,15 +125,16 @@ static const I2CBus I2C_IIC2_BUS = {
   .hal = &I2C_IIC2_BUS_HAL,
   .hal = &I2C_IIC2_BUS_HAL,
   .scl_gpio = {
   .scl_gpio = {
     .gpio = NRF5_GPIO_RESOURCE_EXISTS,
     .gpio = NRF5_GPIO_RESOURCE_EXISTS,
-    .gpio_pin = NRF_GPIO_PIN_MAP(1, 11),
+    .gpio_pin = NRF_GPIO_PIN_MAP(0, 25),
   },
   },
   .sda_gpio = {
   .sda_gpio = {
     .gpio = NRF5_GPIO_RESOURCE_EXISTS,
     .gpio = NRF5_GPIO_RESOURCE_EXISTS,
-    .gpio_pin = NRF_GPIO_PIN_MAP(1, 12),
+    .gpio_pin = NRF_GPIO_PIN_MAP(0, 11),
   },
   },
   .name = "I2C_IIC2"
   .name = "I2C_IIC2"
 };
 };
-IRQ_MAP_NRFX(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1, nrfx_twim_1_irq_handler);
+IRQ_MAP_NRFX(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0, nrfx_twim_0_irq_handler);
+
 /* PERIPHERAL ID 11 */
 /* PERIPHERAL ID 11 */
 
 
 /* sensor SPI bus */
 /* sensor SPI bus */
@@ -132,8 +164,9 @@ void board_early_init(void) {
 }
 }
 
 
 void board_init(void) {
 void board_init(void) {
+  i2c_init(&I2C_NPMC_IIC1_BUS);
   i2c_init(&I2C_IIC2_BUS);
   i2c_init(&I2C_IIC2_BUS);
-  
+
 #if 0
 #if 0
   i2c_init(&I2C_PMIC_HRM_BUS);
   i2c_init(&I2C_PMIC_HRM_BUS);
 
 

+ 14 - 12
src/fw/board/boards/board_asterix.h

@@ -24,7 +24,7 @@ static const BoardConfig BOARD_CONFIG = {
   .dbgserial_int = {
   .dbgserial_int = {
     .peripheral = NRFX_GPIOTE_INSTANCE(0), 
     .peripheral = NRFX_GPIOTE_INSTANCE(0), 
     .channel = 0,
     .channel = 0,
-    .gpio_pin = NRF_GPIO_PIN_MAP(0, 28),
+    .gpio_pin = NRF_GPIO_PIN_MAP(0, 5),
   },
   },
 
 
   .has_mic = true,
   .has_mic = true,
@@ -33,13 +33,13 @@ static const BoardConfig BOARD_CONFIG = {
 static const BoardConfigButton BOARD_CONFIG_BUTTON = {
 static const BoardConfigButton BOARD_CONFIG_BUTTON = {
   .buttons = {
   .buttons = {
     [BUTTON_ID_BACK] =
     [BUTTON_ID_BACK] =
-        { "Back",   { NRFX_GPIOTE_INSTANCE(0), 1, NRF_GPIO_PIN_MAP(0, 27) }, NRF_GPIO_PIN_PULLUP },
+        { "Back",   { NRFX_GPIOTE_INSTANCE(0), 1, NRF_GPIO_PIN_MAP(0, 28) }, NRF_GPIO_PIN_PULLUP },
     [BUTTON_ID_UP] =
     [BUTTON_ID_UP] =
-        { "Up",     { NRFX_GPIOTE_INSTANCE(0), 2, NRF_GPIO_PIN_MAP(0, 11) }, NRF_GPIO_PIN_PULLUP },
+        { "Up",     { NRFX_GPIOTE_INSTANCE(0), 2, NRF_GPIO_PIN_MAP(0, 29) }, NRF_GPIO_PIN_PULLUP },
     [BUTTON_ID_SELECT] =
     [BUTTON_ID_SELECT] =
-        { "Select", { NRFX_GPIOTE_INSTANCE(0), 3, NRF_GPIO_PIN_MAP(1, 0) }, NRF_GPIO_PIN_PULLUP },
+        { "Select", { NRFX_GPIOTE_INSTANCE(0), 3, NRF_GPIO_PIN_MAP(0, 30) }, NRF_GPIO_PIN_PULLUP },
     [BUTTON_ID_DOWN] =
     [BUTTON_ID_DOWN] =
-        { "Down",   { NRFX_GPIOTE_INSTANCE(0), 4, NRF_GPIO_PIN_MAP(1, 2) }, NRF_GPIO_PIN_PULLUP },
+        { "Down",   { NRFX_GPIOTE_INSTANCE(0), 4, NRF_GPIO_PIN_MAP(0, 31) }, NRF_GPIO_PIN_PULLUP },
   },
   },
   .button_com = { 0 },
   .button_com = { 0 },
   .active_high = false,
   .active_high = false,
@@ -106,12 +106,12 @@ static const BoardConfigMag BOARD_CONFIG_MAG = {
     .axes_inverts[AXIS_Z] = false,
     .axes_inverts[AXIS_Z] = false,
 #endif
 #endif
   },
   },
-  .mag_int_gpio = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 25) },
-  .mag_int = { .peripheral = NRFX_GPIOTE_INSTANCE(0), .channel = 5, .gpio_pin = NRF_GPIO_PIN_MAP(0, 25), },
+  .mag_int_gpio = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 3) },
+  .mag_int = { .peripheral = NRFX_GPIOTE_INSTANCE(0), .channel = 5, .gpio_pin = NRF_GPIO_PIN_MAP(0, 3), },
 };
 };
 
 
 static const BoardConfigActuator BOARD_CONFIG_VIBE = {
 static const BoardConfigActuator BOARD_CONFIG_VIBE = {
-  .ctl = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 25), true }, // LRA_EN
+  .ctl = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 2), true }, // LRA_EN
   .vsys_scale = 3300,
   .vsys_scale = 3300,
 };
 };
 
 
@@ -221,11 +221,11 @@ static const BoardConfigActuator BOARD_CONFIG_BACKLIGHT = {
 static const BoardConfigSharpDisplay BOARD_CONFIG_DISPLAY = {
 static const BoardConfigSharpDisplay BOARD_CONFIG_DISPLAY = {
   .spi = NRFX_SPIM_INSTANCE(3),
   .spi = NRFX_SPIM_INSTANCE(3),
 
 
-  .clk = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 8), true },
-  .mosi = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 6), true },
-  .cs = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 26), true },
+  .clk = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 6), true },
+  .mosi = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 8), true },
+  .cs = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(1, 3), true },
 
 
-  .on_ctrl = {GPIO_Port_NULL, },
+  .on_ctrl = { NRF5_GPIO_RESOURCE_EXISTS, NRF_GPIO_PIN_MAP(0, 9), true },
 };
 };
 
 
 extern const VoltageMonitorDevice * VOLTAGE_MONITOR_ALS;
 extern const VoltageMonitorDevice * VOLTAGE_MONITOR_ALS;
@@ -239,3 +239,5 @@ extern QSPIPort * const QSPI;
 extern QSPIFlash * const QSPI_FLASH;
 extern QSPIFlash * const QSPI_FLASH;
 
 
 extern MicDevice * const MIC;
 extern MicDevice * const MIC;
+
+extern I2CSlavePort * const I2C_NPM1300;

+ 6 - 7
src/fw/drivers/pmic/npm1300.c

@@ -71,17 +71,16 @@ bool pmic_init(void) {
   }
   }
   PBL_LOG(LOG_LEVEL_DEBUG, "found the nPM1300, BUCK1NORMVOUT = 0x%x", buck_out);
   PBL_LOG(LOG_LEVEL_DEBUG, "found the nPM1300, BUCK1NORMVOUT = 0x%x", buck_out);
   
   
-  /* XXX: LATER: only turn this on when the audio codec is being accessed */
   prv_read_register(PmicRegisters_LDSW_LDSWSTATUS, &buck_out);
   prv_read_register(PmicRegisters_LDSW_LDSWSTATUS, &buck_out);
-  PBL_LOG(LOG_LEVEL_DEBUG, "nPM1300 LDSW status before enabling LDSW1 0x%x", buck_out);
+  PBL_LOG(LOG_LEVEL_DEBUG, "nPM1300 LDSW status before enabling LDSW2 0x%x", buck_out);
   
   
-  prv_write_register(PmicRegisters_LDSW_TASKLDSW1CLR, 0x01);
-  prv_write_register(PmicRegisters_LDSW_LDSW1VOUTSEL, 8 /* 1.8V */);
-  prv_write_register(PmicRegisters_LDSW_LDSW1LDOSEL, 1 /* LDO */);
-  prv_write_register(PmicRegisters_LDSW_TASKLDSW1SET, 0x01);
+  prv_write_register(PmicRegisters_LDSW_TASKLDSW2CLR, 0x01);
+  prv_write_register(PmicRegisters_LDSW_LDSW2VOUTSEL, 8 /* 1.8V */);
+  prv_write_register(PmicRegisters_LDSW_LDSW2LDOSEL, 1 /* LDO */);
+  prv_write_register(PmicRegisters_LDSW_TASKLDSW2SET, 0x01);
 
 
   prv_read_register(PmicRegisters_LDSW_LDSWSTATUS, &buck_out);
   prv_read_register(PmicRegisters_LDSW_LDSWSTATUS, &buck_out);
-  PBL_LOG(LOG_LEVEL_DEBUG, "nPM1300 LDSW status after enabling LDSW1 0x%x", buck_out);
+  PBL_LOG(LOG_LEVEL_DEBUG, "nPM1300 LDSW status after enabling LDSW2 0x%x", buck_out);
 
 
   return true;
   return true;
 }
 }

+ 1 - 0
src/fw/drivers/wscript_build

@@ -1200,6 +1200,7 @@ if mcu_family == 'NRF52840':
             'nrf5/i2c_hal.c',
             'nrf5/i2c_hal.c',
             'nrf5/spi.c',
             'nrf5/spi.c',
             'nrf5/pwm.c',
             'nrf5/pwm.c',
+            'pmic/npm1300.c',
         ],
         ],
         use=[
         use=[
             'driver_clocksource',
             'driver_clocksource',