PWM kinda works
This commit is contained in:
parent
bae06952fb
commit
9c9492567f
6 changed files with 78 additions and 14 deletions
18
code/nrf-connect/dts/bindings/pwm-fixed.yaml
Normal file
18
code/nrf-connect/dts/bindings/pwm-fixed.yaml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Hello
|
||||
|
||||
description: A fixed frequency & pulse PWM.
|
||||
|
||||
compatible: pwm-fixed
|
||||
|
||||
include: base.yaml
|
||||
|
||||
properties:
|
||||
pwms:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: the PWM spec.
|
||||
|
||||
pulse:
|
||||
required: true
|
||||
type: int
|
||||
description: The period of the PWM pulse.
|
||||
|
|
@ -1,17 +1,5 @@
|
|||
// To get started, press Ctrl+Space (or Option+Esc) to bring up the completion menu and view the available nodes.
|
||||
|
||||
// You can also use the buttons in the sidebar to perform actions on nodes.
|
||||
// Actions currently available include:
|
||||
|
||||
// * Enabling / disabling the node
|
||||
// * Adding the bus to a bus
|
||||
// * Removing the node
|
||||
// * Connecting ADC channels
|
||||
|
||||
// For more help, browse the DeviceTree documentation at https: //docs.zephyrproject.org/latest/guides/dts/index.html
|
||||
// You can also visit the nRF DeviceTree extension documentation at https: //nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html
|
||||
|
||||
&pinctrl {
|
||||
/* Configure pwm0 instance to use pin 5. */
|
||||
pwm0_default: pwm0_default {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(PWM_OUT0, 0, 5)>;
|
||||
|
|
@ -26,6 +14,7 @@
|
|||
};
|
||||
};
|
||||
|
||||
/* Configure i2c0 instance to use pins 24 (SDA) & 13 (SCL). */
|
||||
i2c0_default: i2c0_default {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(TWIM_SDA, 0, 24)>,
|
||||
|
|
@ -49,3 +38,11 @@
|
|||
label = "SHTC3";
|
||||
};
|
||||
};
|
||||
|
||||
/ {
|
||||
soil_pwm: soil_pwm {
|
||||
compatible = "pwm-fixed";
|
||||
pwms = <&pwm0 0 PWM_MSEC(100) PWM_POLARITY_INVERTED>;
|
||||
pulse = <PWM_MSEC(50)>;
|
||||
};
|
||||
};
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||
CONFIG_I2C=y
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#include <drivers/i2c.h>
|
||||
#include <drivers/pwm.h>
|
||||
#include <logging/log.h>
|
||||
#include <zephyr/zephyr.h>
|
||||
|
||||
|
|
@ -6,6 +7,16 @@
|
|||
|
||||
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
|
||||
|
||||
// PWM_DT_SPEC_GET(DT_LABEL(pwm0));
|
||||
static const struct pwm_dt_spec soil_pwm_dt =
|
||||
PWM_DT_SPEC_GET(DT_NODELABEL(soil_pwm));
|
||||
static const uint32_t pulse = DT_PROP(DT_NODELABEL(soil_pwm), pulse);
|
||||
|
||||
void main(void) {
|
||||
prst_shtc3_read_t shtc3_read = prst_shtc3_read();
|
||||
// prst_shtc3_read_t shtc3_read = prst_shtc3_read();
|
||||
pwm_set_pulse_dt(&soil_pwm_dt, pulse);
|
||||
|
||||
while (true) {
|
||||
k_msleep(500);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
code/nrf-connect/src/prst/adc.c
Normal file
3
code/nrf-connect/src/prst/adc.c
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#include "adc.h"
|
||||
|
||||
prst_adc_photo_sensor_t prst_adc_photo_read(double battery_voltage) {}
|
||||
34
code/nrf-connect/src/prst/adc.h
Normal file
34
code/nrf-connect/src/prst/adc.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef _PRST_ADC_H_
|
||||
#define _PRST_ADC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct prst_adc_batt_val {
|
||||
int16_t raw;
|
||||
uint16_t millivolts;
|
||||
double voltage;
|
||||
} prst_adc_batt_read_t;
|
||||
|
||||
typedef struct prst_adc_soil_moisture {
|
||||
int16_t raw;
|
||||
// A value from 0 (completely dry) to 2^10 (completely wet).
|
||||
uint16_t relative;
|
||||
double percentage;
|
||||
} prst_adc_soil_moisture_t;
|
||||
|
||||
typedef struct prst_adc_photo_sensor {
|
||||
int16_t raw;
|
||||
double voltage;
|
||||
// Value in lux.
|
||||
uint16_t brightness;
|
||||
} prst_adc_photo_sensor_t;
|
||||
|
||||
void prst_adc_init();
|
||||
|
||||
prst_adc_batt_read_t prst_adc_batt_read();
|
||||
|
||||
prst_adc_soil_moisture_t prst_adc_soil_read(double battery_voltage);
|
||||
|
||||
prst_adc_photo_sensor_t prst_adc_photo_read(double battery_voltage);
|
||||
|
||||
#endif // _PRST_ADC_H_
|
||||
Loading…
Add table
Reference in a new issue