samples: rgb_led: Add support for hexiwear_k64
The hexiwear_k64 board can drive the leds with a pwm, so update the rgb_led sample to work with this board. Jira: ZEP-2025 Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
This commit is contained in:
parent
3b5577d102
commit
a580bc5b2e
@ -32,6 +32,11 @@ resistor for each of the single color LEDs.
|
||||
The sample app requires three PWM ports. So, it can not work
|
||||
on Quark D2000 platform.
|
||||
|
||||
Hexiwear K64
|
||||
============
|
||||
No special board setup is necessary because there is an on-board RGB LED
|
||||
connected to the K64 PWM.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
|
||||
@ -2,3 +2,5 @@ CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_PWM_QMSI_NUM_PORTS=3
|
||||
CONFIG_SYS_LOG=y
|
||||
CONFIG_SYS_LOG_PWM_LEVEL=4
|
||||
|
||||
@ -4,5 +4,5 @@ sample:
|
||||
tests:
|
||||
- test:
|
||||
build_only: true
|
||||
platform_whitelist: arduino_101
|
||||
platform_whitelist: arduino_101 hexiwear_k64
|
||||
tags: apps
|
||||
|
||||
@ -14,9 +14,22 @@
|
||||
#include <misc/printk.h>
|
||||
#include <device.h>
|
||||
#include <pwm.h>
|
||||
#include <board.h>
|
||||
|
||||
#if defined(CONFIG_SOC_QUARK_SE_C1000)
|
||||
#define PWM_DEV CONFIG_PWM_QMSI_DEV_NAME
|
||||
#define PWM_DEV0 CONFIG_PWM_QMSI_DEV_NAME
|
||||
#define PWM_CH0 0
|
||||
#define PWM_DEV1 CONFIG_PWM_QMSI_DEV_NAME
|
||||
#define PWM_CH1 1
|
||||
#define PWM_DEV2 CONFIG_PWM_QMSI_DEV_NAME
|
||||
#define PWM_CH2 2
|
||||
#elif defined(CONFIG_BOARD_HEXIWEAR_K64)
|
||||
#define PWM_DEV0 RED_PWM_NAME
|
||||
#define PWM_CH0 RED_PWM_CHANNEL
|
||||
#define PWM_DEV1 GREEN_PWM_NAME
|
||||
#define PWM_CH1 GREEN_PWM_CHANNEL
|
||||
#define PWM_DEV2 BLUE_PWM_NAME
|
||||
#define PWM_CH2 BLUE_PWM_CHANNEL
|
||||
#else
|
||||
#error "Choose supported board or add new board for the application"
|
||||
#endif
|
||||
@ -38,13 +51,15 @@ static int write_pin(struct device *pwm_dev, u32_t pwm_pin,
|
||||
|
||||
void main(void)
|
||||
{
|
||||
struct device *pwm_dev;
|
||||
struct device *pwm_dev[3];
|
||||
u32_t pulse_width0, pulse_width1, pulse_width2;
|
||||
|
||||
printk("PWM demo app-RGB LED\n");
|
||||
|
||||
pwm_dev = device_get_binding(PWM_DEV);
|
||||
if (!pwm_dev) {
|
||||
pwm_dev[0] = device_get_binding(PWM_DEV0);
|
||||
pwm_dev[1] = device_get_binding(PWM_DEV1);
|
||||
pwm_dev[2] = device_get_binding(PWM_DEV2);
|
||||
if (!pwm_dev[0] || !pwm_dev[1] || !pwm_dev[2]) {
|
||||
printk("Cannot find PWM device!\n");
|
||||
return;
|
||||
}
|
||||
@ -52,22 +67,24 @@ void main(void)
|
||||
while (1) {
|
||||
for (pulse_width0 = 0; pulse_width0 <= PERIOD;
|
||||
pulse_width0 += STEPSIZE) {
|
||||
if (write_pin(pwm_dev, 0, pulse_width0) != 0) {
|
||||
if (write_pin(pwm_dev[0], PWM_CH0,
|
||||
pulse_width0) != 0) {
|
||||
printk("pin 0 write fails!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (pulse_width1 = 0; pulse_width1 <= PERIOD;
|
||||
pulse_width1 += STEPSIZE) {
|
||||
if (write_pin(pwm_dev, 1, pulse_width1) != 0) {
|
||||
if (write_pin(pwm_dev[1], PWM_CH1,
|
||||
pulse_width1) != 0) {
|
||||
printk("pin 1 write fails!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (pulse_width2 = 0; pulse_width2 <= PERIOD;
|
||||
pulse_width2 += STEPSIZE) {
|
||||
if (write_pin(pwm_dev, 2, pulse_width2)
|
||||
!= 0) {
|
||||
if (write_pin(pwm_dev[2], PWM_CH2,
|
||||
pulse_width2) != 0) {
|
||||
printk("pin 2 write fails!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user