Skip to content

Commit 03a7fce

Browse files
committed
Add call to initVariant in main move ble sense to variant.cpp
Added call to main.cpp to initVariant. Added a weak version in main.cpp. Then moved the code for initializing the enable sensor pin out of main.cpp into the initVariant that I added to variant.cpp for the specific board
1 parent aa0fca4 commit 03a7fce

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

Diff for: cores/arduino/main.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,24 @@
1313
void start_static_threads();
1414
#endif
1515

16-
#ifdef CONFIG_GPIO_NRFX
17-
#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>
18-
#endif
16+
17+
// This function will be overwriten by most variants.
18+
void __attribute__((weak))initVariant(void) {
19+
20+
}
21+
1922

2023
int main(void) {
2124
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM)
2225
Serial.begin(115200);
2326
#endif
2427

28+
initVariant();
29+
2530
#ifdef CONFIG_MULTITHREADING
2631
start_static_threads();
2732
#endif
2833

29-
#ifdef CONFIG_GPIO_NRFX
30-
static const struct gpio_dt_spec enable_sensors =
31-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), pin_enable_gpios);
32-
if (gpio_is_ready_dt(&enable_sensors)) {
33-
gpio_flags_t flags = enable_sensors.dt_flags | GPIO_OUTPUT_HIGH | GPIO_ACTIVE_HIGH | NRF_GPIO_DRIVE_H0H1;
34-
Serial.println((uint32_t)flags, HEX);
35-
36-
gpio_pin_configure(enable_sensors.port, enable_sensors.pin, flags);
37-
gpio_pin_set(enable_sensors.port, enable_sensors.pin, HIGH);
38-
//Serial.println("### Sensor pin enabled ###");
39-
40-
delay(500);
41-
}
42-
#endif
4334
setup();
4435

4536
for (;;) {

Diff for: variants/arduino_nano_33_ble_sense/variant.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
#include "Arduino.h"
12
#include <hal/nrf_power.h>
3+
#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>
24

35
void _on_1200_bps() {
46
nrf_power_gpregret_set(NRF_POWER, 0, 0xb0);
57
NVIC_SystemReset();
6-
}
8+
}
9+
10+
void initVariant(void) {
11+
static const struct gpio_dt_spec enable_sensors =
12+
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), pin_enable_gpios);
13+
if (gpio_is_ready_dt(&enable_sensors)) {
14+
gpio_flags_t flags = enable_sensors.dt_flags | GPIO_OUTPUT_HIGH | GPIO_ACTIVE_HIGH | NRF_GPIO_DRIVE_H0H1;
15+
Serial.println((uint32_t)flags, HEX);
16+
17+
gpio_pin_configure(enable_sensors.port, enable_sensors.pin, flags);
18+
gpio_pin_set(enable_sensors.port, enable_sensors.pin, HIGH);
19+
//Serial.println("### Sensor pin enabled ###");
20+
21+
delay(500);
22+
}
23+
}

0 commit comments

Comments
 (0)