Skip to content

Commit

Permalink
workaround for npm1300
Browse files Browse the repository at this point in the history
  • Loading branch information
maxd-nordic committed Aug 21, 2023
1 parent 0b77adb commit 9342371
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
7 changes: 7 additions & 0 deletions boards/arm/nrf9131ek_nrf9131/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2023 Nordic Semiconductor ASA.
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

if (CONFIG_BOARD_NRF9131EK_NRF9131 OR CONFIG_BOARD_NRF9131EK_NRF9131_NS)
zephyr_library()
zephyr_library_sources(npm1300.c)
endif()
18 changes: 18 additions & 0 deletions boards/arm/nrf9131ek_nrf9131/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Thingy:91 nRF9161 board configuration
#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

if BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS

config BOARD_INIT_PRIORITY
int "Initialization priority for board configuration"
default 80

endif # BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS

module=BOARD
module-dep=LOG
module-str=Log level for board
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
53 changes: 53 additions & 0 deletions boards/arm/nrf9131ek_nrf9131/npm1300.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include <zephyr/logging/log.h>
#include <zephyr/device.h>
#include <zephyr/drivers/i2c.h>

LOG_MODULE_REGISTER(board_secure, CONFIG_BOARD_LOG_LEVEL);

#define CHECKERR if (err) {LOG_ERR("I2C error: %d", err); return err;}

Check failure on line 15 in boards/arm/nrf9131ek_nrf9131/npm1300.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

boards/arm/nrf9131ek_nrf9131/npm1300.c:15 space required after that ';' (ctx:VxV)

static const struct i2c_dt_spec pmic = I2C_DT_SPEC_GET(DT_NODELABEL(pmic_main));

static int pmic_write_reg(uint16_t address, uint8_t value)
{
uint8_t buf[] = {
address >> 8,
address & 0xFF,
value,
};

return i2c_write_dt(&pmic, buf, ARRAY_SIZE(buf));
}

static int thingy91x_board_init(void)
{
int err = 0;

if (!device_is_ready(pmic.bus)) {
LOG_ERR("cannot reach PMIC!");
return -ENODEV;
}

// disable charger for config

Check failure on line 39 in boards/arm/nrf9131ek_nrf9131/npm1300.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

boards/arm/nrf9131ek_nrf9131/npm1300.c:39 do not use C99 // comments
err = pmic_write_reg(0x0305, 0x03); CHECKERR;

// set VBUS current limit 500mA

Check failure on line 42 in boards/arm/nrf9131ek_nrf9131/npm1300.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

boards/arm/nrf9131ek_nrf9131/npm1300.c:42 trailing whitespace

Check failure on line 42 in boards/arm/nrf9131ek_nrf9131/npm1300.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

boards/arm/nrf9131ek_nrf9131/npm1300.c:42 do not use C99 // comments
err = pmic_write_reg(0x0201, 0x00); CHECKERR;
err = pmic_write_reg(0x0202, 0x00); CHECKERR;
err = pmic_write_reg(0x0200, 0x01); CHECKERR;

// enable charger

Check failure on line 47 in boards/arm/nrf9131ek_nrf9131/npm1300.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

C99_COMMENTS

boards/arm/nrf9131ek_nrf9131/npm1300.c:47 do not use C99 // comments
err = pmic_write_reg(0x0304, 0x03); CHECKERR;

return err;
}

SYS_INIT(thingy91x_board_init, POST_KERNEL, CONFIG_BOARD_INIT_PRIORITY);

0 comments on commit 9342371

Please sign in to comment.