summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Ruben Bakke <glennbakke@gmail.com>2018-11-11 21:37:05 +0100
committerDamien George <damien@micropython.org>2021-08-09 14:55:59 +1000
commit77b4cfcbc9d2f46cb275fb6027999a1bfc0feb77 (patch)
treea665ecdc332ccb4ff9b370fd72080438c262b05d
parente5e05532240e464da90b7b941542a06b36baa766 (diff)
nrf/modules/nrf: Add function to enable/disable DCDC.
This function can be used to enable and disable the DC/DC converter with or without the Bluetooth stack enabled. It can also be used to query the current state of the DC/DC. This commit also adds a definition of ARRAY_SIZE needed by nrfx HAL-layer.
-rw-r--r--ports/nrf/modules/nrf/modnrf.c30
-rw-r--r--ports/nrf/nrfx_glue.h7
2 files changed, 36 insertions, 1 deletions
diff --git a/ports/nrf/modules/nrf/modnrf.c b/ports/nrf/modules/nrf/modnrf.c
index fd955dc62..fc217b1d7 100644
--- a/ports/nrf/modules/nrf/modnrf.c
+++ b/ports/nrf/modules/nrf/modnrf.c
@@ -29,15 +29,40 @@
#if MICROPY_PY_NRF
-#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
#include "flashbdev.h"
#include "flash.h"
+#include "nrf_power.h"
+
+#if BLUETOOTH_SD
+#include "nrf_soc.h"
+#include "ble_drv.h"
+#define BLUETOOTH_STACK_ENABLED() (ble_drv_stack_enabled())
+#endif
#define FLASH_PAGE_ALIGN_UP(addr) (((addr) - 1) + (FLASH_PAGESIZE)-(((addr) - 1) % (FLASH_PAGESIZE)))
extern uint32_t _unused_flash_start;
extern uint32_t _unused_flash_len;
+#if NRF_POWER_HAS_DCDCEN
+STATIC mp_obj_t dcdc(size_t n_args, const mp_obj_t *args) {
+ if (n_args > 0) {
+ bool dcdc_state = mp_obj_is_true(args[0]);
+ #if BLUETOOTH_SD
+ if (BLUETOOTH_STACK_ENABLED()) {
+ sd_power_dcdc_mode_set(dcdc_state);
+ } else
+ #endif
+ {
+ nrf_power_dcdcen_set(NRF_POWER, dcdc_state);
+ }
+ }
+ return mp_obj_new_bool(nrf_power_dcdcen_get(NRF_POWER));
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dcdc_obj, 0, 1, dcdc);
+#endif
+
+#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
mp_obj_t nrf_modnrf_freeflash_start_aligned(void) {
return mp_obj_new_int_from_uint(FLASH_PAGE_ALIGN_UP((uint32_t)&_unused_flash_start));
}
@@ -54,6 +79,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_length_aligned_obj, nrf_mo
STATIC const mp_rom_map_elem_t nrf_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_nrf) },
+ #if NRF_POWER_HAS_DCDCEN
+ { MP_ROM_QSTR(MP_QSTR_dcdc), MP_ROM_PTR(&dcdc_obj) },
+ #endif
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
{ MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&nrf_flashbdev_type) },
{ MP_ROM_QSTR(MP_QSTR_unused_flash_start), MP_ROM_PTR(&nrf_modnrf_freeflash_start_aligned_obj) },
diff --git a/ports/nrf/nrfx_glue.h b/ports/nrf/nrfx_glue.h
index b4a60257a..56e1f719d 100644
--- a/ports/nrf/nrfx_glue.h
+++ b/ports/nrf/nrfx_glue.h
@@ -27,8 +27,15 @@
#ifndef NRFX_GLUE_H
#define NRFX_GLUE_H
+#include "py/mpconfig.h"
+#include "py/misc.h"
+
#include <soc/nrfx_irqs.h>
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE MP_ARRAY_SIZE
+#endif
+
#define NRFX_STATIC_ASSERT(expression)
#define NRFX_ASSERT(expression) do { bool res = expression; (void)res; } while (0)