-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_arduino_style.c
52 lines (41 loc) · 1.65 KB
/
init_arduino_style.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (c) 2020 Jefferson Lee.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <init.h>
#include <arduino_nano_33_ble.h>
/*
* this method roughly follows the steps here:
* https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/6216632cc70271619ad43547c804dabb4afa4a00/variants/ARDUINO_NANO33BLE/variant.cpp#L136
*/
/* note: IDK how but all the nordic headers got automagically imported. Cool. */
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_LEDPWR, GPIO_OUTPUT);
arduino_gpio_digitalWrite(&gpios, ARDUINO_LEDPWR, 1);
CoreDebug->DEMCR = 0;
NRF_CLOCK->TRACECONFIG = 0;
/* Arduino uses software to disable RTC1, but I disabled it using DeviceTree */
/* nrf_rtc_event_disable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK); */
/* nrf_rtc_int_disable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK); */
NRF_PWM_Type * PWM[] = {
NRF_PWM0, NRF_PWM1, NRF_PWM2, NRF_PWM3
};
for (unsigned int i = 0; i < (ARRAY_SIZE(PWM)); i++) {
PWM[i]->ENABLE = 0;
PWM[i]->PSEL.OUT[0] = 0xFFFFFFFFUL;
}
/* the PCB designers decided to use GPIO's as power pins for the internal sensors */
arduino_gpio_pinMode(&gpios, ARDUINO_INTERNAL_VDD_ENV_ENABLE, GPIO_OUTPUT);
arduino_gpio_pinMode(&gpios, ARDUINO_INTERNAL_I2C_PULLUP, GPIO_OUTPUT);
arduino_gpio_digitalWrite(&gpios, ARDUINO_INTERNAL_VDD_ENV_ENABLE, 1);
arduino_gpio_digitalWrite(&gpios, ARDUINO_INTERNAL_I2C_PULLUP, 1);
/* add a busy wait because the internal sensors need time to boot up */
k_busy_wait(500 * 1000);
return 0;
}
SYS_INIT(board_internal_sensors_init, PRE_KERNEL_1, 0);