8000 nrf/modules/nrf: Add function to enable/disable DCDC. · codemee/micropython@77b4cfc · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 77b4cfc

Browse files
glennrubdpgeorge
authored andcommitted
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.
1 parent e5e0553 commit 77b4cfc

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

ports/nrf/modules/nrf/modnrf.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,40 @@
2929

3030
#if MICROPY_PY_NRF
3131

32-
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
3332
#include "flashbdev.h"
3433
#include "flash.h"
34+
#include "nrf_power.h"
35+
36+
#if BLUETOOTH_SD
37+
#include "nrf_soc.h"
38+
#include "ble_drv.h"
39+
#define BLUETOOTH_STACK_ENABLED() (ble_drv_stack_enabled())
40+
#endif
3541

3642
#define FLASH_PAGE_ALIGN_UP(addr) (((addr) - 1) + (FLASH_PAGESIZE)-(((addr) - 1) % (FLASH_PAGESIZE)))
3743

3844
extern uint32_t _unused_flash_start;
3945
extern uint32_t _unused_flash_len;
4046

47+
#if NRF_POWER_HAS_DCDCEN
48+
STATIC mp_obj_t dcdc(size_t n_args, const mp_obj_t *args) {
49+
if (n_args > 0) {
50+
bool dcdc_state = mp_obj_is_true(args[0]);
51+
#if BLUETOOTH_SD
52+
if (BLUETOOTH_STACK_ENABLED()) {
53+
sd_power_dcdc_mode_set(dcdc_state);
54+
} else
55+
#endif
56+
{
57+
nrf_power_dcdcen_set(NRF_POWER, dcdc_state);
58+
}
59+
}
60+
return mp_obj_new_bool(nrf_power_dcdcen_get(NRF_POWER));
61+
}
62+
STATIC MP_ 8000 DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dcdc_obj, 0, 1, dcdc);
63+
#endif
64+
65+
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
4166
mp_obj_t nrf_modnrf_freeflash_start_aligned(void) {
4267
return mp_obj_new_int_from_uint(FLASH_PAGE_ALIGN_UP((uint32_t)&_unused_flash_start));
4368
}
@@ -54,6 +79,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_length_aligned_obj, nrf_mo
5479

5580
STATIC const mp_rom_map_elem_t nrf_module_globals_table[] = {
5681
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_nrf) },
82+
#if NRF_POWER_HAS_DCDCEN
83+
{ MP_ROM_QSTR(MP_QSTR_dcdc), MP_ROM_PTR(&dcdc_obj) },
84+
#endif
5785
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
5886
{ MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&nrf_flashbdev_type) },
5987
{ MP_ROM_QSTR(MP_QSTR_unused_flash_start), MP_ROM_PTR(&nrf_modnrf_freeflash_start_aligned_obj) },

ports/nrf/nrfx_glue.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@
2727
#ifndef NRFX_GLUE_H
2828
#define NRFX_GLUE_H
2929

30+
#include "py/mpconfig.h"
31+
#include "py/misc.h"
32+
3033
#include <soc/nrfx_irqs.h>
3134

35+
#ifndef ARRAY_SIZE
36+
#define ARRAY_SIZE MP_ARRAY_SIZE
37+
#endif
38+
3239
#define NRFX_STATIC_ASSERT(expression)
3340

3441
#define NRFX_ASSERT(expression) do { bool res = expression; (void)res; } while (0)

0 commit comments

Comments
 (0)
0