From 6fc21458717a2ac6d14acdf9b665f993893f50a2 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 2 Dec 2020 10:55:00 +0100 Subject: [PATCH] Allow for power supply configuration --- src/boards/boards.c | 25 +++++++++++++++++++++++++ src/boards/boards.h | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/src/boards/boards.c b/src/boards/boards.c index e1ab96d3..bcf7b9ab 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -82,6 +82,31 @@ void board_init(void) neopixel_init(); #endif +#if ENABLE_DCDC_0 == 1 + NRF_POWER->DCDCEN0 = 1; +#endif +#if ENABLE_DCDC_1 == 1 + NRF_POWER->DCDCEN = 1; +#endif + +// When board is supplied on VDDH (and not VDD), this specifies what voltage the GPIO should run at +// and what voltage is output at VDD. The default (0xffffffff) is 1.8V; typically you'll want +// #define UICR_REGOUT0_VALUE UICR_REGOUT0_VOUT_3V3 +// in board.h when using that power configuration. +#ifdef UICR_REGOUT0_VALUE + if (NRF_UICR->REGOUT0 != UICR_REGOUT0_VALUE) + { + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} + NRF_UICR->REGOUT0 = UICR_REGOUT0_VALUE; + + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} + + NVIC_SystemReset(); + } +#endif + // Init scheduler APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); diff --git a/src/boards/boards.h b/src/boards/boards.h index edc7666e..8aa0ece6 100644 --- a/src/boards/boards.h +++ b/src/boards/boards.h @@ -61,6 +61,14 @@ #define BOARD_RGB_BRIGHTNESS 0x101010 #endif +// Power configuration - should we enable DC/DC converters? (requires inductors on board) +#ifndef ENABLE_DCDC_0 +#define ENABLE_DCDC_0 0 +#endif +#ifndef ENABLE_DCDC_1 +#define ENABLE_DCDC_1 0 +#endif + // Helper function #define memclr(buffer, size) memset(buffer, 0, size) #define varclr(_var) memclr(_var, sizeof(*(_var)))