Configures LED
This commit is contained in:
parent
c15120178f
commit
ffeca36c27
5 changed files with 67 additions and 14 deletions
|
|
@ -4,6 +4,4 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
|||
|
||||
project(b_parasite)
|
||||
|
||||
# set(BOARD_ROOT .)
|
||||
|
||||
target_sources(app PRIVATE src/main.c src/prst/shtc3.c src/prst/adc.c)
|
||||
target_sources(app PRIVATE src/main.c src/prst/shtc3.c src/prst/adc.c src/prst/led.c)
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@
|
|||
compatible = "rbaron,bparasite_nrf52840";
|
||||
|
||||
chosen {
|
||||
// zephyr,console = &uart0;
|
||||
// zephyr,shell-uart = &uart0;
|
||||
// zephyr,uart-mcumgr = &uart0;
|
||||
// zephyr,bt-mon-uart = &uart0;
|
||||
// zephyr,bt-c2h-uart = &uart0;
|
||||
zephyr,sram = &sram0;
|
||||
zephyr,flash = &flash0;
|
||||
zephyr,code-partition = &slot0_partition;
|
||||
|
|
@ -21,6 +16,14 @@
|
|||
io-channels = <&adc 0>, <&adc 1>, <&adc 2>;
|
||||
};
|
||||
|
||||
leds {
|
||||
compatible = "gpio-leds";
|
||||
led0: led_0 {
|
||||
// P0.28.
|
||||
gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>;
|
||||
};
|
||||
};
|
||||
|
||||
soil_pwm: soil_pwm {
|
||||
compatible = "pwm-fixed";
|
||||
pwms = <&pwm0 0 PWM_MSEC(100) PWM_POLARITY_INVERTED>;
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
#include <zephyr/zephyr.h>
|
||||
|
||||
#include "prst/adc.h"
|
||||
#include "prst/led.h"
|
||||
#include "prst/macros.h"
|
||||
#include "prst/shtc3.h"
|
||||
|
||||
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
|
||||
|
||||
int main(void) {
|
||||
if (prst_adc_init() != 0) {
|
||||
LOG_ERR("Error initializing ADC.");
|
||||
}
|
||||
RET_IF_ERR(prst_adc_init());
|
||||
RET_IF_ERR(prst_led_init());
|
||||
|
||||
prst_adc_read_t batt;
|
||||
prst_adc_soil_moisture_t soil;
|
||||
|
|
@ -20,11 +20,13 @@ int main(void) {
|
|||
RET_IF_ERR(prst_adc_soil_read(batt.voltage, &soil));
|
||||
RET_IF_ERR(prst_adc_photo_read(batt.voltage, &photo));
|
||||
|
||||
// LOG_INF("Batt: %d mV", batt.millivolts);
|
||||
// LOG_INF("Soil: %.0f %% (%.3f mV)", 100 * soil.percentage,
|
||||
// soil.adc_read.voltage);
|
||||
LOG_INF("Batt: %d mV", batt.millivolts);
|
||||
LOG_INF("Soil: %.0f %% (%.3f mV)", 100 * soil.percentage,
|
||||
soil.adc_read.voltage);
|
||||
LOG_INF("Photo: %u lx (%.3f mV)", photo.brightness, soil.adc_read.voltage);
|
||||
|
||||
prst_led_flash(3);
|
||||
|
||||
k_msleep(500);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
code/nrf-connect/src/prst/led.c
Normal file
17
code/nrf-connect/src/prst/led.c
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include "led.h"
|
||||
|
||||
#include <drivers/gpio.h>
|
||||
|
||||
#include "macros.h"
|
||||
|
||||
LOG_MODULE_REGISTER(led, LOG_LEVEL_DBG);
|
||||
|
||||
struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_NODELABEL(led0), gpios);
|
||||
|
||||
int prst_led_init() {
|
||||
if (!device_is_ready(led.port)) {
|
||||
LOG_ERR("DEV NOT READY");
|
||||
return -1;
|
||||
}
|
||||
return gpio_pin_configure_dt(&led, GPIO_OUTPUT);
|
||||
}
|
||||
33
code/nrf-connect/src/prst/led.h
Normal file
33
code/nrf-connect/src/prst/led.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef _PRST_LED_H_
|
||||
#define _PRST_LED_H_
|
||||
|
||||
#include <drivers/gpio.h>
|
||||
#include <logging/log.h>
|
||||
|
||||
#include "macros.h"
|
||||
|
||||
#define PRST_LED_FLASH_PERIOD_MS 400
|
||||
|
||||
extern struct gpio_dt_spec led;
|
||||
|
||||
int prst_led_init();
|
||||
|
||||
static inline int prst_led_on() {
|
||||
return gpio_pin_set_dt(&led, 1);
|
||||
}
|
||||
|
||||
static inline int prst_led_off() {
|
||||
return gpio_pin_set_dt(&led, 0);
|
||||
}
|
||||
|
||||
static inline int prst_led_flash(int times) {
|
||||
LOG_MODULE_DECLARE(led, LOG_LEVEL_DBG);
|
||||
RET_IF_ERR(prst_led_off());
|
||||
for (int i = 0; i < 2 * times; i++) {
|
||||
RET_IF_ERR(gpio_pin_toggle_dt(&led));
|
||||
k_msleep(PRST_LED_FLASH_PERIOD_MS / 2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // _PRST_LED_H_
|
||||
Loading…
Add table
Reference in a new issue