diff --git a/code/nrf-connect/boards/arm/bparasite_nrf52840/Kconfig b/code/nrf-connect/boards/arm/bparasite_nrf52840/Kconfig index dce0746..aa0eeee 100644 --- a/code/nrf-connect/boards/arm/bparasite_nrf52840/Kconfig +++ b/code/nrf-connect/boards/arm/bparasite_nrf52840/Kconfig @@ -6,4 +6,9 @@ config BOARD_ENABLE_DCDC select SOC_DCDC_NRF52X default y +config BOARD_ENABLE_DCDC_HV + bool "High Voltage DCDC converter" + select SOC_DCDC_NRF52X_HV + default y + endif # BOARD_BPARASITE_NRF52840 \ No newline at end of file diff --git a/code/nrf-connect/boards/arm/bparasite_nrf52840/bparasite_nrf52840.dts b/code/nrf-connect/boards/arm/bparasite_nrf52840/bparasite_nrf52840.dts index 8f27267..da5d29a 100644 --- a/code/nrf-connect/boards/arm/bparasite_nrf52840/bparasite_nrf52840.dts +++ b/code/nrf-connect/boards/arm/bparasite_nrf52840/bparasite_nrf52840.dts @@ -27,6 +27,7 @@ buttons { compatible = "gpio-keys"; button0: button_0 { + // P0.12. gpios = <&gpio0 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; label = "Push button switch 0"; }; @@ -34,9 +35,18 @@ soil_pwm: soil_pwm { compatible = "pwm-fixed"; - pwms = <&pwm0 0 PWM_MSEC(100) PWM_POLARITY_INVERTED>; + pwms = <&pwm0 0 PWM_MSEC(100) PWM_POLARITY_NORMAL>; pulse = ; }; + + ctrl { + compatible = "gpio-keys"; + fast_disch: fast_disch { + // P1.10. + gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>; + label = "Fast discharge circuitry"; + }; + }; }; &gpiote { @@ -53,7 +63,7 @@ &uart0 { compatible = "nordic,nrf-uart"; - status = "okay"; + status = "disabled"; current-speed = <115200>; pinctrl-0 = <&uart0_default>; pinctrl-1 = <&uart0_sleep>; diff --git a/code/nrf-connect/prj.conf b/code/nrf-connect/prj.conf index 07aba1a..ce9324f 100644 --- a/code/nrf-connect/prj.conf +++ b/code/nrf-connect/prj.conf @@ -1,13 +1,28 @@ CONFIG_LOG=y CONFIG_PWM=y +CONFIG_PWM_LOG_LEVEL_DBG=y CONFIG_CBPRINTF_FP_SUPPORT=y CONFIG_I2C=y CONFIG_ADC=y +CONFIG_GPIO=y CONFIG_BT=y CONFIG_BT_PERIPHERAL=y -CONFIG_BT_DEBUG_LOG=y +CONFIG_BT_DEBUG_LOG=n CONFIG_BT_DEVICE_NAME="para" -# CONFIG_BT_SETTINGS=n -# CONFIG_SETTINGS=n -CONFIG_BT_CTLR_TX_PWR_PLUS_8=y \ No newline at end of file +CONFIG_BT_SETTINGS=n +CONFIG_SETTINGS=n +CONFIG_BT_CTLR_TX_PWR_PLUS_8=y + +CONFIG_CONSOLE=n +CONFIG_SERIAL=n +CONFIG_PM=y +CONFIG_PM_DEVICE=y + +CONFIG_USE_SEGGER_RTT=y + +CONFIG_CONSOLE=n +CONFIG_RTT_CONSOLE=n + +CONFIG_PINCTRL=y + diff --git a/code/nrf-connect/src/main.c b/code/nrf-connect/src/main.c index 1777755..3b18230 100644 --- a/code/nrf-connect/src/main.c +++ b/code/nrf-connect/src/main.c @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include "prst/adc.h" @@ -38,8 +41,16 @@ int main(void) { RET_IF_ERR(prst_ble_adv_set_data(&sensors)); RET_IF_ERR(prst_ble_adv_start()); - k_msleep(5000); + k_sleep(K_SECONDS(2)); RET_IF_ERR(prst_ble_adv_stop()); + + k_sleep(K_SECONDS(2)); + + prst_led_flash(1); + + // Example: go to deep sleep. + pm_state_force(0u, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); + k_sleep(K_SECONDS(2)); } } diff --git a/code/nrf-connect/src/prst/adc.c b/code/nrf-connect/src/prst/adc.c index 7d8ae99..fb875bc 100644 --- a/code/nrf-connect/src/prst/adc.c +++ b/code/nrf-connect/src/prst/adc.c @@ -74,14 +74,14 @@ int prst_adc_batt_read(prst_adc_read_t* out) { int prst_adc_soil_read(float battery_voltage, prst_adc_soil_moisture_t* out) { // Start PWM. - RET_IF_ERR(pwm_set_pulse_dt(&soil_pwm_dt, pulse)); + RET_IF_ERR(pwm_set_dt(&soil_pwm_dt, soil_pwm_dt.period, pulse)); k_msleep(30); RET_IF_ERR(read_adc_spec(&adc_soil_spec, &out->adc_read)); // Stop PWM. - RET_IF_ERR(pwm_set_pulse_dt(&soil_pwm_dt, 0)); + RET_IF_ERR(pwm_set_dt(&soil_pwm_dt, 0, 0)); out->percentage = get_soil_moisture_percent(battery_voltage, buf); return 0; diff --git a/code/nrf-connect/src/prst/button.c b/code/nrf-connect/src/prst/button.c index 04596ad..84c2a05 100644 --- a/code/nrf-connect/src/prst/button.c +++ b/code/nrf-connect/src/prst/button.c @@ -22,7 +22,8 @@ static void button_pressed(const struct device *dev, struct gpio_callback *cb, int prst_button_init() { RET_IF_ERR(!device_is_ready(button.port)); RET_IF_ERR(gpio_pin_configure_dt(&button, GPIO_INPUT)); - RET_IF_ERR(gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE)); + // EDGE interrupts consume more power! Just use a LEVEL one. + RET_IF_ERR(gpio_pin_interrupt_configure_dt(&button, GPIO_INT_LEVEL_ACTIVE)); gpio_init_callback(&cb_data, button_pressed, BIT(button.pin)); RET_IF_ERR(gpio_add_callback(button.port, &cb_data)); return 0;