samples: drivers: led: Add sample for Microchip XEC LED driver
Add a sample program demonstrating the LED driver for Microchip's XEC microcontrollers. The sample can be built for MEC152x and MEC172x. Signed-off-by: Jay Vasanth <jay.vasanth@microchip.com>
This commit is contained in:
parent
2128a3797b
commit
06fde72092
7 changed files with 288 additions and 0 deletions
9
samples/drivers/led_xec/CMakeLists.txt
Normal file
9
samples/drivers/led_xec/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
|
||||
project(led_xec)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
75
samples/drivers/led_xec/README.rst
Normal file
75
samples/drivers/led_xec/README.rst
Normal file
|
@ -0,0 +1,75 @@
|
|||
.. _led:
|
||||
|
||||
LED sample application
|
||||
##########################
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
This sample allows to test the Microchip led-xec driver which uses the
|
||||
breathing-blinking LED (BBLED) controllers. The SoC design is fixed
|
||||
allowing each BBLED control over one specific GPIO.
|
||||
MEC15xx and MEC172x:
|
||||
BBLED controller 0 uses GPIO 0156.
|
||||
BBLED controller 1 uses GPIO 0157.
|
||||
BBLED controller 2 uses GPIO 0153.
|
||||
MEC172x has a fourth instance of BBLED.
|
||||
BBLED controller 3 uses GPIO 0035
|
||||
|
||||
Test pattern
|
||||
============
|
||||
|
||||
For each LEDs (one after the other):
|
||||
|
||||
- Turning on
|
||||
- Turning off
|
||||
- Blinking on: 0.1 sec, off: 0.1 sec
|
||||
- Blinking on: 1 sec, off: 1 sec
|
||||
|
||||
Board Jumpers
|
||||
********************
|
||||
|
||||
EVB: mec172xevb_assy6906
|
||||
BBLED0 GPIO 0156.
|
||||
Connect GPIO 0156 to board LED4 by placing a wire from JP71-11 to J47-3.
|
||||
Make sure there are no jumpers on JP54 1-2 and JP21 4-5
|
||||
|
||||
BBLED1 GPIO 0157.
|
||||
Connect GPIO 0156 to board LED5 by placing a wire from JP71-12 to J48-3.
|
||||
Make sure there are no jumpers on JP54 3-4 and JP21 16-17
|
||||
|
||||
BBLED2 GPIO 0153.
|
||||
Connect GPIO 0153 to board LED7 by placing a wire from JP71-5 to JP146-5.
|
||||
JP146-5 is connected to MEC172x VCI_OUT1 without a jumper. Force VCI_OUT1
|
||||
high by forcing VCI_IN1 high: install jumper on J55 3-4 which pulls VCI_IN1
|
||||
to the VBAT rail via a 100K pull-up. Requires VBAT power rail is connected
|
||||
to VTR or some other power source.
|
||||
|
||||
BBLED3 GPIO 0035.
|
||||
Connect GPIO 0035 to board LED7 by placing a wire from JP67-19 to JP146-1.
|
||||
Make sure there is no jumper on JP79 17-18.
|
||||
JP146-1 is connected to MEC172x VCI_OUT2 without a jumper. Force VCI_OUT2
|
||||
high by forcing VCI_IN2 high: install a jumper on J55 5-6 which pulls VCI_IN2
|
||||
to the VBAT rail via a 100K pull-up. Requires VBAT power rail is connected
|
||||
to VTR or some other power source.
|
||||
|
||||
EVB: mec15xxevb_assy6853
|
||||
BBLED0 GPIO 0156.
|
||||
Add jumper on JP41 1-2 to connect GPIO 0156 to board LED2
|
||||
Remove jumper on JP31 13-14
|
||||
|
||||
BBLED1 GPIO 0157.
|
||||
Add jumper on JP41 3-4 to connect GPIO 0157 to board LED3
|
||||
Remove jumper on JP31 15-16
|
||||
|
||||
BBLED2 GPIO 0153.
|
||||
Add jumper on JP41 3-4 to connect GPIO 0153 to board LED4
|
||||
Remove jumper on JP31 17-18
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
This sample can be built and executed on all the boards with the LEDs connected.
|
||||
The LEDs must be correctly described in the DTS. Each breathing-blinking LED
|
||||
controller is fixed by chip design to connect to one GPIO. The bbled node must
|
||||
have its PINCTRL properties set to the correct GPIO.
|
26
samples/drivers/led_xec/boards/mec15xxevb_assy6853.overlay
Normal file
26
samples/drivers/led_xec/boards/mec15xxevb_assy6853.overlay
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Microchip Technology Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&bbled0 {
|
||||
compatible = "microchip,xec-bbled";
|
||||
pinctrl-0 = <&led0_gpio156>;
|
||||
pinctrl-names = "default";
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&bbled1 {
|
||||
compatible = "microchip,xec-bbled";
|
||||
pinctrl-0 = <&led1_gpio157>;
|
||||
pinctrl-names = "default";
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&bbled2 {
|
||||
compatible = "microchip,xec-bbled";
|
||||
pinctrl-0 = <&led2_gpio153>;
|
||||
pinctrl-names = "default";
|
||||
status = "okay";
|
||||
};
|
33
samples/drivers/led_xec/boards/mec172xevb_assy6906.overlay
Normal file
33
samples/drivers/led_xec/boards/mec172xevb_assy6906.overlay
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Microchip Technology Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&bbled0 {
|
||||
compatible = "microchip,xec-bbled";
|
||||
pinctrl-0 = <&led0_gpio156>;
|
||||
pinctrl-names = "default";
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&bbled1 {
|
||||
compatible = "microchip,xec-bbled";
|
||||
pinctrl-0 = <&led1_gpio157>;
|
||||
pinctrl-names = "default";
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&bbled2 {
|
||||
compatible = "microchip,xec-bbled";
|
||||
pinctrl-0 = <&led2_gpio153>;
|
||||
pinctrl-names = "default";
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&bbled3 {
|
||||
compatible = "microchip,xec-bbled";
|
||||
pinctrl-0 = <&led3_gpio035>;
|
||||
pinctrl-names = "default";
|
||||
status = "okay";
|
||||
};
|
4
samples/drivers/led_xec/prj.conf
Normal file
4
samples/drivers/led_xec/prj.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_LOG_MODE_MINIMAL=y
|
||||
|
||||
CONFIG_LED=y
|
8
samples/drivers/led_xec/sample.yaml
Normal file
8
samples/drivers/led_xec/sample.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
sample:
|
||||
description: Demonstration of the Microchip XEC LED driver
|
||||
name: XEC LED sample
|
||||
tests:
|
||||
sample.drivers.led.led_xec:
|
||||
build_only: true
|
||||
tags: LED
|
||||
platform_allow: mec172xevb_assy6906 mec15xxevb_assy6853
|
133
samples/drivers/led_xec/src/main.c
Normal file
133
samples/drivers/led_xec/src/main.c
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Microchip Technology Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <soc.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/led.h>
|
||||
#include <zephyr/logging/log_ctrl.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/sys/sys_io.h>
|
||||
LOG_MODULE_DECLARE(led, CONFIG_LED_LOG_LEVEL);
|
||||
|
||||
#define K_WAIT_DELAY 100u
|
||||
|
||||
struct dev_info {
|
||||
const struct device *dev;
|
||||
uint32_t base_addr;
|
||||
};
|
||||
|
||||
#define XEC_BBLED_DEV(node_id) \
|
||||
{ .dev = DEVICE_DT_GET(node_id), .base_addr = (uint32_t)DT_REG_ADDR(node_id) },
|
||||
|
||||
static const struct dev_info led_dev_table[] = {
|
||||
DT_FOREACH_STATUS_OKAY(microchip_xec_bbled, XEC_BBLED_DEV)
|
||||
};
|
||||
|
||||
static void print_bbled_regs(mem_addr_t bbled_base)
|
||||
{
|
||||
uint32_t r = 0;
|
||||
|
||||
if (!bbled_base) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INF("BBLED @ 0x%lx", bbled_base);
|
||||
|
||||
r = sys_read32(bbled_base);
|
||||
LOG_INF("config = 0x%x", r);
|
||||
r = sys_read32(bbled_base + 4U);
|
||||
LOG_INF("limits = 0x%x", r);
|
||||
r = sys_read32(bbled_base + 8U);
|
||||
LOG_INF("delay = 0x%x", r);
|
||||
r = sys_read32(bbled_base + 0xcU);
|
||||
LOG_INF("update_step_size = 0x%x", r);
|
||||
r = sys_read32(bbled_base + 0x10U);
|
||||
LOG_INF("update_interval = 0x%x", r);
|
||||
r = sys_read32(bbled_base + 0x14U);
|
||||
LOG_INF("output_delay = 0x%x", r);
|
||||
}
|
||||
|
||||
int led_test(void)
|
||||
{
|
||||
int ret = 0;
|
||||
size_t n = 0;
|
||||
uint32_t delay_on = 0, delay_off = 0;
|
||||
|
||||
/* Account for the time serial port is detected so log messages can
|
||||
* be seen
|
||||
*/
|
||||
k_sleep(K_SECONDS(1));
|
||||
|
||||
LOG_INF("Microchip XEC EVB BBLED Sample");
|
||||
|
||||
for (n = 0; n < ARRAY_SIZE(led_dev_table); n++) {
|
||||
const struct device *dev = led_dev_table[n].dev;
|
||||
uint32_t base = led_dev_table[n].base_addr;
|
||||
|
||||
LOG_INF("BBLED instance %d @ %x", n, base);
|
||||
print_bbled_regs(base);
|
||||
|
||||
if (!device_is_ready(dev)) {
|
||||
LOG_ERR("%s: device not ready", dev->name);
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG_INF("blink: T = 0.5 second, duty cycle = 0.5");
|
||||
delay_on = 250;
|
||||
delay_off = 250;
|
||||
ret = led_blink(dev, 0, delay_on, delay_off);
|
||||
if (ret) {
|
||||
LOG_ERR("LED blink API returned error %d", ret);
|
||||
}
|
||||
print_bbled_regs(base);
|
||||
|
||||
LOG_INF("Delay 5 seconds");
|
||||
k_sleep(K_SECONDS(5));
|
||||
|
||||
LOG_INF("blink: T = 3 seconds, duty cycle = 0.4");
|
||||
delay_on = 1200;
|
||||
delay_off = 1800;
|
||||
ret = led_blink(dev, 0, delay_on, delay_off);
|
||||
if (ret) {
|
||||
LOG_ERR("LED blink API returned error %d", ret);
|
||||
}
|
||||
print_bbled_regs(base);
|
||||
|
||||
LOG_INF("Delay 15 seconds");
|
||||
k_sleep(K_SECONDS(15));
|
||||
|
||||
LOG_INF("Set ON");
|
||||
ret = led_on(dev, 0);
|
||||
if (ret) {
|
||||
LOG_ERR("LED ON API returned error %d", ret);
|
||||
}
|
||||
print_bbled_regs(base);
|
||||
|
||||
LOG_INF("Delay 2 seconds");
|
||||
k_sleep(K_SECONDS(2));
|
||||
|
||||
LOG_INF("Set OFF");
|
||||
ret = led_off(dev, 0);
|
||||
if (ret) {
|
||||
LOG_ERR("LED OFF API returned error %d", ret);
|
||||
}
|
||||
print_bbled_regs(base);
|
||||
|
||||
LOG_INF("Delay 2 seconds");
|
||||
k_sleep(K_SECONDS(2));
|
||||
}
|
||||
|
||||
LOG_INF("LED test done");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
led_test();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue