boards: arduino_nano_33_ble: refactor init code

- Specify in DT the pin to enable I2C pull-up connection
- Always build board.c, so that the I2C bus is always pulled-up

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-03-21 12:27:06 +01:00 committed by Carles Cufí
parent f266b286b7
commit 1b479d6a8a
7 changed files with 35 additions and 44 deletions

View file

@ -2,12 +2,9 @@
# SPDX-License-Identifier: Apache-2.0
add_library(arduino_nano_33_ble_pins INTERFACE)
target_include_directories(arduino_nano_33_ble_pins
target_include_directories(arduino_nano_33_ble_pins
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/inc/")
if(CONFIG_BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS)
zephyr_library()
zephyr_library_sources("${CMAKE_CURRENT_SOURCE_DIR}/src/init_sensors.c")
target_link_libraries(${ZEPHYR_CURRENT_LIBRARY} PRIVATE arduino_nano_33_ble_pins)
endif()
zephyr_library()
zephyr_library_sources(board.c)

View file

@ -4,7 +4,3 @@
config BOARD_ARDUINO_NANO_33_BLE
bool "Arduino Nano 33 BLE board"
depends on SOC_NRF52840_QIAA
config BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS
bool "Initializes the internal I2C sensors on the board"
depends on BOARD_ARDUINO_NANO_33_BLE

View file

@ -16,8 +16,6 @@ config I2C_NRFX
default y
config NRFX_TWIM
default y
config BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS
default y
endif #I2C
if SPI

View file

@ -50,6 +50,11 @@
regulator-boot-on;
};
zephyr,user {
/* I2C pull-ups are connected to VDD via pin voltage level */
pull-up-gpios = <&gpio1 0 GPIO_ACTIVE_HIGH>;
};
/* These aliases are provided for compatibility with samples */
aliases {
led0 = &led0;

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2020 Jefferson Lee.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <init.h>
#include <drivers/gpio.h>
static int board_init(const struct device *dev)
{
const struct gpio_dt_spec pull_up =
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), pull_up_gpios);
ARG_UNUSED(dev);
if (!device_is_ready(pull_up.port)) {
return -ENODEV;
}
return gpio_pin_configure_dt(&pull_up, GPIO_OUTPUT_INIT_HIGH);
}
SYS_INIT(board_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

View file

@ -75,10 +75,9 @@ A convenience header mapping the Arduino pin names to their
Zephyr pin numbers can be found in :code:`arduino_nano_33_ble_pins.h`,
if you link against the :code:`arduino_nano_33_ble_pins` CMake library.
For your convenience, one Kconfig option is added:
#. :code:`BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS`:
This configuration option enables the internal I2C sensors.
The I2C pull-ups are enabled by setting pin P1.00 high. This is automatically
done at system init. The pin is specified in the ``zephyr,user`` Devicetree node
as ``pull-up-gpios``.
Programming and Debugging
*************************

View file

@ -1,28 +0,0 @@
/*
* Copyright (c) 2020 Jefferson Lee.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <init.h>
#include <arduino_nano_33_ble.h>
#define ARDUINO_SENSOR_INIT_PRIORITY 50
/*
* this method roughly follows the steps here:
* https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/6216632cc70271619ad43547c804dabb4afa4a00/variants/ARDUINO_NANO33BLE/variant.cpp#L136
*/
static int board_internal_sensors_init(const struct device *dev)
{
ARG_UNUSED(dev);
struct arduino_gpio_t gpios;
arduino_gpio_init(&gpios);
arduino_gpio_pinMode(&gpios, ARDUINO_INTERNAL_I2C_PULLUP, GPIO_OUTPUT);
arduino_gpio_digitalWrite(&gpios, ARDUINO_INTERNAL_I2C_PULLUP, 1);
return 0;
}
SYS_INIT(board_internal_sensors_init, POST_KERNEL, ARDUINO_SENSOR_INIT_PRIORITY);