ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_nrf5_sdk15_power.c
Go to the documentation of this file.
1 
13 #include "ruuvi_interface_power.h"
14 #if RUUVI_NRF5_SDK15_POWER_ENABLED
15 #include <stdint.h>
16 #include "nrf_bootloader_info.h"
17 #include "nrfx_power.h"
18 #include "nrf_soc.h"
19 #include "nrf_sdh.h"
20 #include "ruuvi_driver_error.h"
21 #include "ruuvi_nrf5_sdk15_error.h"
22 #include "sdk_errors.h"
23 
24 
25 static bool m_is_init = false;
26 
28 {
29  ret_code_t err_code = NRF_SUCCESS;
30  nrfx_power_config_t config = {0};
31 
32  if (regulators.DCDC_INTERNAL)
33  {
34  config.dcdcen = true;
35  }
36 
37  if (regulators.DCDC_HV)
38  {
39 #if NRF_POWER_HAS_VDDH
40  config.dcdcenhv = true;
41 #else
42  err_code |= RD_ERROR_NOT_SUPPORTED;
43 #endif
44  }
45 
46  if (m_is_init)
47  {
48  nrfx_power_uninit();
49  m_is_init = false;
50  }
51 
52  err_code |= nrfx_power_init (&config);
53  m_is_init = true;
54  return ruuvi_nrf5_sdk15_to_ruuvi_error (err_code);
55 }
56 
57 void ri_power_reset (void)
58 {
59  if (nrf_sdh_is_enabled())
60  {
61  sd_nvic_SystemReset();
62  }
63  else
64  {
65  NVIC_SystemReset();
66  }
67 }
68 
69 void ri_power_enter_bootloader (void)
70 {
71  if (nrf_sdh_is_enabled())
72  {
73  sd_power_gpregret_clr (0, 0xffffffff);
74  sd_power_gpregret_set (0, BOOTLOADER_DFU_START);
75  sd_nvic_SystemReset();
76  }
77  else
78  {
79  NRF_POWER->GPREGRET = BOOTLOADER_DFU_START;
80  NVIC_SystemReset();
81  }
82 }
83 
84 #endif
uint32_t rd_status_t
bitfield for representing errors
rd_status_t ruuvi_nrf5_sdk15_to_ruuvi_error(const ret_code_t error)
convert nrf5 sdk15 error code into Ruuvi error code.
#define RD_ERROR_NOT_SUPPORTED
Not supported.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
rd_status_t ri_power_regulators_enable(const ri_power_regulators_t regulators)
Enable given regulators.
void ri_power_enter_bootloader(void)
Enter bootloader.
void ri_power_reset(void)
Reset IC.
Enable implementation selected by application.
unsigned int DCDC_HV
DC/DC for high voltage, i.e. nRF52840 USB.
unsigned int DCDC_INTERNAL
DC/DC for internal circuitry, i.e. nRF52832 radio.