- Fully open toolchain: arm-none-eabi-gcc inside Podman/Docker container - Platform-agnostic build via justfile (auto-detects podman vs docker) - CMake + Ninja build system with arm-none-eabi toolchain file - nRF52840 linker script and startup with full 64-entry vector table - Register access via typed bitfield unions (include/regs.h) - FHSS channel sequencer: AES-128-ECB PRNG over 40 channels (2402-2480 MHz) - Low-power sleep via SYSTEM_ON WFI + GPIOTE wakeup on button press - Vendor deps as shallow git submodules: nrfx, CMSIS_5, tiny-AES-c
38 lines
781 B
C
38 lines
781 B
C
#include "power.h"
|
|
#include "regs.h"
|
|
#include <nrf52840.h>
|
|
#include <cmsis_gcc.h>
|
|
|
|
/* P0.02 on XIAO BLE — adjust to match your schematic */
|
|
#define BUTTON_PIN 2u
|
|
|
|
void power_init(void)
|
|
{
|
|
/* DC/DC converter has lower quiescent current than the LDO */
|
|
NRF_POWER->DCDCEN = 1u;
|
|
|
|
NRF_GPIOTE->CONFIG[0] = (gpiote_config_t){
|
|
.bit = {
|
|
.MODE = GPIOTE_MODE_EVENT,
|
|
.PSEL = BUTTON_PIN,
|
|
.PORT = 0u,
|
|
.POLARITY = GPIOTE_POL_LOTOHI,
|
|
}
|
|
}.reg;
|
|
|
|
NRF_GPIOTE->INTENSET = (gpiote_inten_t){ .bit.IN0 = 1u }.reg;
|
|
|
|
NVIC_EnableIRQ(GPIOTE_IRQn);
|
|
}
|
|
|
|
void power_sleep_until_button(void)
|
|
{
|
|
NRF_POWER->TASKS_LOWPWR = 1u;
|
|
__WFI();
|
|
}
|
|
|
|
void GPIOTE_IRQHandler(void)
|
|
{
|
|
NRF_GPIOTE->EVENTS_IN[0] = 0u;
|
|
}
|