samples: basic: Convert to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access to the pwm controller device. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
a4b78f5755
commit
1ca6828db9
3 changed files with 35 additions and 25 deletions
|
@ -17,12 +17,12 @@
|
|||
#define PWM_LED0_NODE DT_ALIAS(pwm_led0)
|
||||
|
||||
#if DT_NODE_HAS_STATUS(PWM_LED0_NODE, okay)
|
||||
#define PWM_LABEL DT_PWMS_LABEL(PWM_LED0_NODE)
|
||||
#define PWM_CTLR DT_PWMS_CTLR(PWM_LED0_NODE)
|
||||
#define PWM_CHANNEL DT_PWMS_CHANNEL(PWM_LED0_NODE)
|
||||
#define PWM_FLAGS DT_PWMS_FLAGS(PWM_LED0_NODE)
|
||||
#else
|
||||
#error "Unsupported board: pwm-led0 devicetree alias is not defined"
|
||||
#define PWM_LABEL ""
|
||||
#define PWM_CTLR DT_INVALID_NODE
|
||||
#define PWM_CHANNEL 0
|
||||
#define PWM_FLAGS 0
|
||||
#endif
|
||||
|
@ -40,9 +40,9 @@ void main(void)
|
|||
|
||||
printk("PWM-based blinky\n");
|
||||
|
||||
pwm = device_get_binding(PWM_LABEL);
|
||||
if (!pwm) {
|
||||
printk("Error: didn't find %s device\n", PWM_LABEL);
|
||||
pwm = DEVICE_DT_GET(PWM_CTLR);
|
||||
if (!device_is_ready(pwm)) {
|
||||
printk("Error: PWM device %s is not ready\n", pwm->name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -53,16 +53,15 @@ void main(void)
|
|||
* Keep its value at least MIN_PERIOD_USEC * 4 to make sure
|
||||
* the sample changes frequency at least once.
|
||||
*/
|
||||
printk("Calibrating for device %s channel %d...\n",
|
||||
PWM_LABEL, PWM_CHANNEL);
|
||||
printk("Calibrating for channel %d...\n", PWM_CHANNEL);
|
||||
max_period = MAX_PERIOD_USEC;
|
||||
while (pwm_pin_set_usec(pwm, PWM_CHANNEL,
|
||||
max_period, max_period / 2U, PWM_FLAGS)) {
|
||||
max_period /= 2U;
|
||||
if (max_period < (4U * MIN_PERIOD_USEC)) {
|
||||
printk("Error: PWM device %s "
|
||||
printk("Error: PWM device "
|
||||
"does not support a period at least %u\n",
|
||||
PWM_LABEL, 4U * MIN_PERIOD_USEC);
|
||||
4U * MIN_PERIOD_USEC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
#define PWM_LED0_NODE DT_ALIAS(pwm_led0)
|
||||
|
||||
#if DT_NODE_HAS_STATUS(PWM_LED0_NODE, okay)
|
||||
#define PWM_LABEL DT_PWMS_LABEL(PWM_LED0_NODE)
|
||||
#define PWM_CTLR DT_PWMS_CTLR(PWM_LED0_NODE)
|
||||
#define PWM_CHANNEL DT_PWMS_CHANNEL(PWM_LED0_NODE)
|
||||
#define PWM_FLAGS DT_PWMS_FLAGS(PWM_LED0_NODE)
|
||||
#else
|
||||
#error "Unsupported board: pwm-led0 devicetree alias is not defined"
|
||||
#define PWM_LABEL ""
|
||||
#define PWM_CTLR DT_INVALID_NODE
|
||||
#define PWM_CHANNEL 0
|
||||
#define PWM_FLAGS 0
|
||||
#endif
|
||||
|
@ -46,9 +46,9 @@ void main(void)
|
|||
|
||||
printk("PWM-based LED fade\n");
|
||||
|
||||
pwm = device_get_binding(PWM_LABEL);
|
||||
if (!pwm) {
|
||||
printk("Error: didn't find %s device\n", PWM_LABEL);
|
||||
pwm = DEVICE_DT_GET(PWM_CTLR);
|
||||
if (!device_is_ready(pwm)) {
|
||||
printk("Error: PWM device %s is not ready\n", pwm->name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,34 +22,34 @@
|
|||
#define BLUE_NODE DT_ALIAS(blue_pwm_led)
|
||||
|
||||
#if DT_NODE_HAS_STATUS(RED_NODE, okay)
|
||||
#define RED_LABEL DT_PWMS_LABEL(RED_NODE)
|
||||
#define RED_CTLR_NODE DT_PWMS_CTLR(RED_NODE)
|
||||
#define RED_CHANNEL DT_PWMS_CHANNEL(RED_NODE)
|
||||
#define RED_FLAGS DT_PWMS_FLAGS(RED_NODE)
|
||||
#else
|
||||
#error "Unsupported board: red-pwm-led devicetree alias is not defined"
|
||||
#define RED_LABEL ""
|
||||
#define RED_CTLR_NODE DT_INVALID_NODE
|
||||
#define RED_CHANNEL 0
|
||||
#define RED_FLAGS 0
|
||||
#endif
|
||||
|
||||
#if DT_NODE_HAS_STATUS(GREEN_NODE, okay)
|
||||
#define GREEN_LABEL DT_PWMS_LABEL(GREEN_NODE)
|
||||
#define GREEN_CTLR_NODE DT_PWMS_CTLR(GREEN_NODE)
|
||||
#define GREEN_CHANNEL DT_PWMS_CHANNEL(GREEN_NODE)
|
||||
#define GREEN_FLAGS DT_PWMS_FLAGS(GREEN_NODE)
|
||||
#else
|
||||
#error "Unsupported board: green-pwm-led devicetree alias is not defined"
|
||||
#define GREEN_LABEL ""
|
||||
#define GREEN_CTLR_NODE DT_INVALID_NODE
|
||||
#define GREEN_CHANNEL 0
|
||||
#define GREEN_FLAGS 0
|
||||
#endif
|
||||
|
||||
#if DT_NODE_HAS_STATUS(BLUE_NODE, okay)
|
||||
#define BLUE_LABEL DT_PWMS_LABEL(BLUE_NODE)
|
||||
#define BLUE_CTLR_NODE DT_PWMS_CTLR(BLUE_NODE)
|
||||
#define BLUE_CHANNEL DT_PWMS_CHANNEL(BLUE_NODE)
|
||||
#define BLUE_FLAGS DT_PWMS_FLAGS(BLUE_NODE)
|
||||
#else
|
||||
#error "Unsupported board: blue-pwm-led devicetree alias is not defined"
|
||||
#define BLUE_LABEL ""
|
||||
#define BLUE_CTLR_NODE DT_INVALID_NODE
|
||||
#define BLUE_CHANNEL 0
|
||||
#define BLUE_FLAGS 0
|
||||
#endif
|
||||
|
@ -78,11 +78,22 @@ void main(void)
|
|||
|
||||
printk("PWM-based RGB LED control\n");
|
||||
|
||||
pwm_dev[RED] = device_get_binding(RED_LABEL);
|
||||
pwm_dev[GREEN] = device_get_binding(GREEN_LABEL);
|
||||
pwm_dev[BLUE] = device_get_binding(BLUE_LABEL);
|
||||
if (!pwm_dev[RED] || !pwm_dev[GREEN] || !pwm_dev[BLUE]) {
|
||||
printk("Error: cannot find one or more PWM devices\n");
|
||||
pwm_dev[RED] = DEVICE_DT_GET(RED_CTLR_NODE);
|
||||
pwm_dev[GREEN] = DEVICE_DT_GET(GREEN_CTLR_NODE);
|
||||
pwm_dev[BLUE] = DEVICE_DT_GET(BLUE_CTLR_NODE);
|
||||
|
||||
if (!device_is_ready(pwm_dev[RED])) {
|
||||
printk("Error: red PWM device %s is not ready\n", pwm_dev[RED]->name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!device_is_ready(pwm_dev[GREEN])) {
|
||||
printk("Error: green PWM device %s is not ready\n", pwm_dev[GREEN]->name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!device_is_ready(pwm_dev[BLUE])) {
|
||||
printk("Error: blue PWM device %s is not ready\n", pwm_dev[BLUE]->name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue