Skip to content

Commit a2b76ab

Browse files
committed
samples: driver: lin: add ncv7430 sample for lin master mode
Introduce new sample for lin driver act as a master node to control the ncv7430 led controller IC as a slave node Signed-off-by: The Nguyen <[email protected]>
1 parent 5f267b0 commit a2b76ab

File tree

9 files changed

+584
-0
lines changed

9 files changed

+584
-0
lines changed

samples/drivers/lin/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. zephyr:code-sample-category:: lin
2+
:name: Local Interconnect Network (LIN)
3+
:show-listing:
4+
5+
These samples demonstrate how to use the :ref:`lin` driver API.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(lin_ncv7430)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.. zephyr:code-sample:: lin-ncv7430
2+
:name: NCV7430 LED Controller over LIN
3+
:relevant-api: lin_controller
4+
5+
Sample application for using the NCV7430 LED Controller with Zephyr's LIN API.
6+
7+
Overview
8+
********
9+
10+
This sample demonstrates how to use the Local Interconnect Network (LIN) API to control a RGB LED
11+
using NCV7430 LED Controller. You could find more details about NCV7430 in the
12+
`NCV7430 Datasheet`_.
13+
14+
The LIN controller acts as a LIN master node that sends commands to the NCV7430 LED controller
15+
to change the LED colors. The application cycles through a set of predefined colors, sending the
16+
appropriate LIN messages to the NCV7430 to update the LED color accordingly.
17+
18+
Requirements
19+
************
20+
21+
* A board with LIN controller support (e.g., ek_ra8m1/r7fa8m1ahecbd).
22+
* An NCV7430 evaluation board connected to the LIN controller pins (e.g. `skpang NCV7430 Breakout Board`_).
23+
24+
Building and Running
25+
********************
26+
27+
Building and Running for EK-RA8M1
28+
=================================
29+
The :zephyr:board:`ek_ra8m1` board does not come with an onboard LIN transceiver. In order to use
30+
the LIN bus on the EK-RA8M1 board, an external LIN bus transceiver `mikroe LIN Click`_ must be
31+
connected to this board:
32+
33+
- P609 EK-RA8M1 (TXD) <-> RXD mikroe LIN Click
34+
- P610 EK-RA8M1 (RXD) <-> TXD mikroe LIN Click
35+
- GND EK-RA8M1 <--------> GND mikroe LIN Click
36+
- 3.3V EK-RA8M1 <-------> 3V3 mikroe LIN Click
37+
- P601 EK-RA8M1 <--------> EN mikroe LIN Click
38+
- P602 EK-RA8M1 <--------> WK mikroe LIN Click
39+
40+
.. note::
41+
42+
An additional pull-up resistor (10k Ohm) is required between EK-RA8M1 P609 (TXD) and 3.3V to
43+
ensure proper idle state on the LIN bus.
44+
45+
The sample can be built and executed for the EK-RA8M1 as follows:
46+
47+
.. zephyr-app-commands::
48+
:zephyr-app: samples/drivers/lin/ncv7430
49+
:board: ek_ra8m1
50+
:goals: build flash
51+
:compact:
52+
53+
Observe the LED color changes on the NCV7430 evaluation board as the application cycles through
54+
the predefined colors.
55+
56+
Sample Output
57+
=============
58+
59+
.. code-block:: console
60+
61+
NCV7430 sample started
62+
Set LED color: Red - read back actual color code: 0xFF0000
63+
Set LED color: Green - read back actual color code: 0x00FF00
64+
Set LED color: Blue - read back actual color code: 0x0000FF
65+
66+
.. _skpang NCV7430 Breakout Board:
67+
https://www.skpang.co.uk/ncv7430-led-controller-breakout-board-p-5187.html
68+
69+
.. _NCV7430 Datasheet:
70+
https://www.onsemi.com/pdf/datasheet/ncv7430-d.pdf
71+
72+
.. _mikroe LIN Click:
73+
https://www.mikroe.com/lin-click
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
lin_click0: tle72593ge {
9+
compatible = "infineon,tle72593ge", "lin-transceiver-gpio";
10+
wakeup-gpios = <&ioport6 1 GPIO_ACTIVE_HIGH>;
11+
enable-gpios = <&ioport6 2 GPIO_ACTIVE_HIGH>;
12+
max-bitrate = <20000>;
13+
#phy-cells = <0>;
14+
};
15+
};
16+
17+
&ioport6 {
18+
status = "okay";
19+
};
20+
21+
&pinctrl {
22+
sci0_default: sci0_default {
23+
group1 {
24+
/* TXD */
25+
psels = <RA_PSEL(RA_PSEL_SCI_0, 6, 9)>;
26+
drive-strength = "high";
27+
};
28+
29+
group2 {
30+
/* RXD */
31+
psels = <RA_PSEL(RA_PSEL_SCI_0, 6, 10)>;
32+
};
33+
};
34+
};
35+
36+
&sci0 {
37+
pinctrl-0 = <&sci0_default>;
38+
pinctrl-names = "default";
39+
interrupts = <95 1>, <94 1>, <93 1>, <92 1>;
40+
interrupt-names = "rxi", "txi", "tei", "eri";
41+
status = "okay";
42+
43+
uart {
44+
status = "disabled";
45+
};
46+
47+
i2c {
48+
status = "disabled";
49+
};
50+
51+
dut: lin {
52+
phys = <&lin_click0>;
53+
status = "okay";
54+
};
55+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_LIN=y
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sample:
2+
name: LIN driver NCV7430 sample
3+
tests:
4+
sample.drivers.lin.ncv7430:
5+
tags: lin
6+
depends_on: lin
7+
integration_platforms:
8+
- ek_ra8m1/r7fa8m1ahecbd
9+
harness: console
10+
harness_config:
11+
type: one_line
12+
regex:
13+
- "NCV7430 sample started"
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/sys/printk.h>
9+
#include <zephyr/device.h>
10+
#include <zephyr/drivers/lin.h>
11+
#include <zephyr/sys/byteorder.h>
12+
13+
#include "ncv7430.h"
14+
15+
#define LIN_BUS_BAUDRATE 19200U
16+
#define LIN_BUS_BREAK_LEN 13U
17+
#define LIN_BUS_BREAK_DELIMITER_LEN 1U
18+
19+
#define LED_CHANGE_INTERVAL_MS 1000
20+
21+
/* RGB LED test sequence (RGB888 format, separate channels) */
22+
static const struct rgb_led_color rgb_led_test_colors[8] = {
23+
{255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 0},
24+
{0, 255, 255}, {255, 0, 255}, {255, 255, 255}, {0, 0, 0},
25+
};
26+
27+
/* RGB LED color names in string */
28+
static const unsigned char rgb_test_color_name[][8] = {
29+
"Red", "Green", "Blue", "Yellow", "Cyan", "Magenta", "White", "Black",
30+
};
31+
32+
static const struct lin_config dut_config = {
33+
.mode = LIN_MODE_COMMANDER,
34+
.baudrate = LIN_BUS_BAUDRATE,
35+
.break_len = LIN_BUS_BREAK_LEN,
36+
.break_delimiter_len = LIN_BUS_BREAK_DELIMITER_LEN,
37+
.flags = 0,
38+
};
39+
40+
static unsigned int current_led_idx;
41+
42+
int main(void)
43+
{
44+
const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(dut));
45+
int ret;
46+
47+
ret = device_is_ready(dev);
48+
if (!ret) {
49+
printk("NCV7430 device not found\n");
50+
return 0;
51+
}
52+
53+
ret = lin_configure(dev, &dut_config);
54+
if (ret) {
55+
printk("LIN configure failed: %d\n", ret);
56+
return 0;
57+
}
58+
59+
ret = lin_start(dev);
60+
if (ret) {
61+
printk("LIN start failed: %d\n", ret);
62+
return 0;
63+
}
64+
65+
ret = ncv7430_init(dev, NCV7430_NODE_ADDRESS);
66+
if (ret) {
67+
printk("NCV7430 initialization failed: %d\n", ret);
68+
return 0;
69+
}
70+
71+
printk("NCV7430 sample started\n");
72+
current_led_idx = 0;
73+
74+
while (true) {
75+
struct rgb_led_color color = rgb_led_test_colors[current_led_idx];
76+
struct rgb_led_color read_color;
77+
uint32_t color_code;
78+
79+
ret = ncv7430_set_led_color(dev, NCV7430_NODE_ADDRESS, &color);
80+
if (ret != 0) {
81+
printk("Failed to set LED color: %d\n", ret);
82+
return 0;
83+
}
84+
85+
ret = ncv7430_get_led_color(dev, NCV7430_NODE_ADDRESS, &read_color);
86+
if (ret != 0) {
87+
printk("Failed to get LED color: %d\n", ret);
88+
return 0;
89+
}
90+
91+
color_code = sys_get_be24((uint8_t *)&read_color);
92+
printk("Set LED color: %s - read back actual color code: 0x%06X\n",
93+
rgb_test_color_name[current_led_idx], color_code);
94+
95+
if ((read_color.red != color.red) || (read_color.green != color.green) ||
96+
(read_color.blue != color.blue)) {
97+
printk("Warning: Mismatch in set and read back color "
98+
"values!\n");
99+
}
100+
101+
current_led_idx++;
102+
if (current_led_idx == ARRAY_SIZE(rgb_led_test_colors)) {
103+
current_led_idx = 0;
104+
}
105+
106+
k_msleep(LED_CHANGE_INTERVAL_MS);
107+
}
108+
109+
return 0;
110+
}

0 commit comments

Comments
 (0)