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.
This commit is contained in:
Glenn Ruben Bakke 2018-11-11 21:37:05 +01:00 committed by Damien George
parent e5e0553224
commit 77b4cfcbc9
2 changed files with 36 additions and 1 deletions

View File

@ -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) },

View File

@ -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)