Vehicle-mounted equipment RGB light control system and method based on SPI protocol

By adopting an SPI-based method for controlling RGB lighting in automotive devices, a timing mapping code table and a state lighting effect descriptor are generated. This solves the problems of timing accuracy and resource consumption in automotive RGB lighting control, achieving efficient and accurate lighting display and system stability, while reducing hardware costs.

CN121751432APending Publication Date: 2026-03-27SHENZHEN SHUNMENG TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-06
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

Traditional RGB lighting control suffers from insufficient timing accuracy, excessive system resource consumption, and difficulty in balancing hardware cost and complexity in automotive environments, resulting in unstable lighting display and strained system resources.

Method used

An RGB lighting control method for vehicle-mounted devices based on the SPI protocol is adopted. This method achieves high-precision timing control and reduces system complexity and hardware cost by generating a timing mapping code table, receiving and converting RGB color values ​​into GRB order, calculating brightness gradient curves and generating state light effect descriptors, constructing SPI transmission sequences, and monitoring system performance.

Benefits of technology

It achieves high-precision RGB lighting control in the automotive environment, reduces CPU usage to less than 2%, ensures timing accuracy, improves the consistency of lighting display and system stability, and is suitable for long-term automotive application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121751432A_ABST
    Figure CN121751432A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of light control of vehicle-mounted electronic equipment, in particular to a vehicle-mounted equipment RGB light control system and method based on an SPI protocol. The method comprises the following steps: acquiring SPI clock frequency parameters, and generating a time sequence mapping code table based on the SPI clock frequency parameters; receiving and converting the RGB color values into a GRB sequence, and generating an SPI transmission frame sequence according to the time sequence mapping code table; calculating a brightness gradient curve of the light brightness of the vehicle-mounted equipment to obtain a gamma correction brightness table; generating a state lighting effect descriptor according to the gamma correction brightness table; rGB values are extracted from the state lighting effect descriptors, a complete SPI transmission sequence is constructed for the RGB values according to the SPI transmission frame sequence, transmission is executed through configured SPI hardware, and RGB lamp driving signals are generated. According to the invention, the system complexity and the hardware cost are greatly reduced through the light control technology of the vehicle-mounted electronic equipment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of lighting control technology for vehicle electronic devices, and more particularly to an RGB lighting control system and method for vehicle devices based on the SPI protocol. Background Technology

[0002] Traditional WS2812-type RGB LED control relies on nanosecond-level precise timing (0 code ≈ 0.35μs high + 0.8μs low), requiring extremely high timing accuracy. Ordinary MCUs struggle to accurately achieve this timing control under interruption and system load fluctuations, leading to visual defects such as color deviation, flickering instability, and inconsistent brightness in the light display, severely impacting user experience and product quality. Traditional direct GPIO driving methods, which simulate timing through software, consume significant CPU resources (approximately 10%). In automotive environments, this high resource consumption severely affects the real-time performance of critical devices like dashcams, such as video processing and event recording, and can even cause main functions to freeze or crash during peak system load periods. To address these issues, the industry has proposed using dedicated driver ICs or DMA+GPIO solutions. However, dedicated driver ICs not only increase material costs but also occupy valuable PCB space, increasing product size. While DMA+GPIO solutions reduce CPU usage, they still pose a risk of timing jitter under frequent system interrupts and have high implementation complexity, hindering cross-platform portability.

[0003] In summary, existing technologies suffer from insufficient timing accuracy, excessive system resource consumption, and an inability to balance hardware cost and complexity, all of which urgently need to be addressed. Summary of the Invention

[0004] Therefore, it is necessary to provide an RGB lighting control system and method for vehicle-mounted devices based on the SPI protocol to solve at least one of the above-mentioned technical problems.

[0005] To achieve the above objectives, a method for controlling RGB lighting in an in-vehicle device based on the SPI protocol includes the following steps: Step S1: Obtain and generate a timing mapping code table based on the SPI clock frequency parameters; Step S2: Receive and convert RGB color values ​​into GRB order, and generate an SPI transmission frame sequence according to the timing mapping code table; Step S3: Calculate the brightness gradient curve of the vehicle-mounted equipment's headlight brightness to obtain a gamma-corrected brightness table; generate a state light effect descriptor based on the gamma-corrected brightness table; Step S4: Extract RGB values ​​from the status light effect descriptor, construct a complete SPI transmission sequence for the RGB values ​​according to the SPI transmission frame sequence, and execute the transmission through the configured SPI hardware to generate RGB lamp drive signals; Step S5: When a change in the status of the vehicle equipment is detected, the status light effect descriptor is updated and a new round of light effect update is executed through the RGB light drive signal; Step S6: Monitor and optimize resource usage based on the system performance data of the vehicle equipment to obtain lighting control commands; use the lighting control commands to control RGB lighting, and trigger and judge the error recovery process during RGB lighting control to generate an RGB light fault report.

[0006] This invention achieves seamless conversion between the standard SPI interface and the WS2812 single-wire protocol by acquiring the SPI clock frequency and generating a precise timing mapping code table. This allows ordinary automotive SPI controllers to drive WS2812 RGB LEDs without additional hardware. This method maintains high-precision timing control at different SPI clock frequencies. Pre-generating multiple mapping code tables ensures system adaptability under clock frequency adjustments, effectively reducing system integration complexity and hardware costs, while guaranteeing signal timing stability and reliability. It is particularly suitable for the variable operating conditions in automotive environments. By receiving RGB color values ​​and converting them to the GRB sequence required by the WS2812 protocol, and then generating the SPI transmission frame sequence according to the timing mapping code table, the key issue of protocol format conversion is solved. This method achieves efficient encoding and transmission of color data, supports cascaded control of multiple RGB LEDs, and each binary bit is precisely expanded to the corresponding SPI transmission data, ensuring data transmission accuracy. Furthermore, the transmission sequence generated according to the physical connection order of the LEDs simplifies the application layer control logic, freeing developers from concern themselves with the underlying protocol details, significantly improving the development efficiency and flexibility of automotive RGB lighting control. By applying gamma correction to calculate the brightness gradient curve and generate a state light effect descriptor, the nonlinearity of human eye's brightness perception is solved, making the change in light brightness appear linear and improving the user experience. This method automatically adjusts the gamma value according to ambient temperature, reducing the output brightness in the middle brightness area under high-temperature conditions, effectively reducing LED power consumption and heat generation, and extending the lifespan of the LED chips. Specific gamma correction curves set for different lighting effect types make effects such as breathing lights and flashing lights more natural and smooth. Combined with the state light effect descriptor generated by the device status, intelligent association between lighting effects and device status is achieved, enhancing the human-machine interaction experience of in-vehicle devices. By extracting RGB values ​​from the state light effect descriptor and constructing a complete SPI transmission sequence, a highly efficient and reliable data transmission mechanism is achieved. This method enhances transmission stability and fault tolerance by adding a reset code, preamble, and end code, making it particularly suitable for application scenarios with complex automotive electromagnetic environments. Precise configuration of SPI hardware parameters and the introduction of a CRC check mechanism effectively reduce the transmission error rate, and the automatic retransmission mechanism ensures the reliability of data transmission even in harsh environments. The dual-buffered transmission design improves system throughput, making continuous lighting effect updates smoother and enhancing the overall robustness and user experience of the automotive RGB lighting control system. By establishing a mapping relationship between state and lighting effects and monitoring state changes in real time, intuitive and visual feedback on the status of automotive devices is achieved. The priority mechanism introduced by this method ensures that important status information (such as error warnings) is displayed in a timely manner, and state buffering avoids light flickering caused by frequent state switching, improving the user experience. The smooth and gradual transition of lighting effects reduces the visual impact of abrupt changes, and the synergistic application of color and effect gradients makes state transitions more natural.The multi-LED collaborative gradient effect creates a flowing visual effect, significantly improving the human-machine interaction quality of the in-vehicle equipment. Users can intuitively understand the equipment status through the lighting, enhancing operational safety and convenience. By monitoring system performance data and optimizing resource usage, the RGB lighting control system achieves adaptive adjustment and fault recovery. This method dynamically adjusts the update frequency and clock parameters based on CPU load and power fluctuations, ensuring stable system operation under various working conditions. Differentiated update strategies and optimal transmission time slot selection effectively reduce system resource consumption and improve overall efficiency. Multi-level error detection and recovery mechanisms significantly improve system reliability, and automatic identification, isolation, and self-healing testing of faulty LEDs enhance the system's fault tolerance and maintainability. The generation and recording of fault reports provide detailed diagnostic information for equipment maintenance, comprehensively improving the stability, reliability, and maintainability of the in-vehicle RGB lighting control system, making it particularly suitable for long-term in-vehicle applications.

[0007] Therefore, this invention successfully solves the three major technical challenges mentioned above by utilizing the SPI hardware clock characteristics to simulate the timing of the WS2812 single-wire protocol, establishing a mapping relationship between logic values ​​and specific SPI data frames (e.g., logic 0 is mapped to "1100 0000b"). Combined with a gamma-corrected brightness gradation algorithm and a dynamic resource optimization mechanism, this method requires no additional hardware, using only the existing SPI peripheral on the SoC, reducing CPU utilization to less than 2%, ensuring timing accuracy with jitter of less than 15ns at an 8MHz clock, achieving over 95% color consistency, and significantly reducing system complexity and hardware costs. This provides a highly efficient, accurate, and economical new solution for automotive RGB lighting control.

[0008] Preferably, the present invention also provides an SPI-based in-vehicle device RGB lighting control system for executing the SPI-based in-vehicle device RGB lighting control method described above. The SPI-based in-vehicle device RGB lighting control system includes: The timing map generation module is used to obtain and generate a timing map code table based on the SPI clock frequency parameters; The data frame conversion module is used to receive and convert RGB color values ​​into GRB order, and generate SPI transmission frame sequence according to the timing mapping code table; The luminous efficacy calculation and state analysis module is used to calculate the luminance gradient curve of the on-board equipment's headlight brightness and obtain a gamma-corrected luminance table; and generate a state luminous efficacy descriptor based on the gamma-corrected luminance table. The SPI transmission execution module is used to extract RGB values ​​from the status light effect descriptor, construct a complete SPI transmission sequence for the RGB values ​​according to the SPI transmission frame sequence, and execute the transmission through the configured SPI hardware to generate RGB lamp drive signals. The status monitoring and update module is used to trigger the update of the status light effect descriptor and execute a new round of light effect update through the RGB light drive signal when a status change of the vehicle equipment is detected. The performance optimization and fault handling module is used to monitor and optimize resource usage based on the system performance data of the vehicle equipment, and obtain lighting control commands; it uses the lighting control commands to control RGB lighting, and triggers and judges the error recovery process during RGB lighting control, and generates RGB light fault reports.

[0009] This SPI-based RGB lighting control system for in-vehicle devices achieves precise conversion between the standard SPI interface and the WS2812 single-wire protocol through a timing mapping generation module, driving RGB LEDs without additional hardware and reducing system costs. The data frame conversion module efficiently processes color data and supports multi-LED cascading, simplifying the development process. The luminous efficacy calculation and status analysis module applies gamma correction and temperature adaptive technology to improve visual effects and extend LED lifespan. The SPI transmission execution module ensures reliable data transmission through complete transmission sequence construction and error detection mechanisms. The status monitoring and update module provides intelligent visual feedback on device status, and priority mechanisms and smooth transitions enhance the user experience. The performance optimization and fault handling module ensures stable operation and self-healing capabilities in complex in-vehicle environments through dynamic resource allocation and multi-level error recovery mechanisms. Overall, this system achieves efficient, reliable, and intelligent in-vehicle RGB lighting control, improving the human-machine interaction quality and system robustness of in-vehicle devices, making it particularly suitable for long-term in-vehicle applications. Attached Figure Description

[0010] Fig. 1 This is a flowchart illustrating the steps of a method for controlling RGB lighting in an in-vehicle device based on the SPI protocol. Fig. 2 This is a schematic diagram illustrating the process of achieving the breathing light effect in this invention.

[0011] The objectives, features, and advantages of this invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0012] The technical method of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.

[0013] Furthermore, the accompanying drawings are merely illustrative of the invention and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor methods and / or microcontroller methods.

[0014] It should be understood that although the terms "first," "second," etc., may be used herein to describe various units, these units should not be limited by these terms. These terms are used merely to distinguish one unit from another. For example, without departing from the scope of the exemplary embodiments, a first unit may be referred to as a second unit, and similarly, a second unit may be referred to as a first unit. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.

[0015] To achieve the above objectives, please refer to Figs. 1-2 This invention provides a method for controlling RGB lighting in an in-vehicle device based on the SPI protocol, comprising the following steps: Step S1: Obtain and generate a timing mapping code table based on the SPI clock frequency parameters; In this embodiment of the invention, the clock frequency parameters of the SPI controller are obtained, and the target SPI clock is set to 8MHz. A mapping relationship is established according to the timing requirements of the WS2812 protocol (logic 0 requires a high level of 400ns and a low level of 850ns; logic 1 requires a high level of 800ns and a low level of 450ns). At an 8MHz clock, the system maps logic 0 to 0xC0 (11000000b), generating a combined waveform of a high level of 250ns and a low level of 750ns; and maps logic 1 to 0xFC (11111100b), generating a combined waveform of a high level of 750ns and a low level of 250ns. The system verifies the error rate of the mapping code table, ensuring it is less than 20ns, and pre-generates multiple sets of mapping code tables for different clock frequencies within the 6-10MHz range to achieve clock frequency adaptation.

[0016] Step S2: Receive and convert RGB color values ​​into GRB order, and generate an SPI transmission frame sequence according to the timing mapping code table; In this embodiment of the invention, a 24-bit RGB color value is received and converted into the GRB sequence required by the WS2812 protocol (e.g., 0xFF0080 is converted to 0x00FF80). The system splits the 24-bit GRB value into 24 binary bits, and maps each binary bit "0" to 0xC0 and each binary bit "1" to 0xFC by querying the timing mapping code table, generating 24 bytes of SPI transmission data. For the case of multiple cascaded RGB LEDs, the system generates and merges the SPI transmission frame sequence for each LED according to the physical connection order of the LEDs, ensuring that the data is transmitted sequentially from the first LED to the last LED according to the requirements of WS2812 LED cascading.

[0017] Step S3: Calculate the brightness gradient curve of the vehicle-mounted equipment's headlight brightness to obtain a gamma-corrected brightness table; generate a state light effect descriptor based on the gamma-corrected brightness table; In this embodiment of the invention, the number of gradation steps is determined based on the target brightness value and the gradation period, and the gamma correction formula is applied: Corrected brightness = ×255, calculate the brightness value for each gradient step. The system monitors the ambient temperature; when it exceeds 45°C, it automatically adjusts the gamma value from 2.2 to 2.4, reducing the output brightness in the intermediate brightness range. Different gamma correction curves are set for different lighting effects: a sine function is applied for the breathing light effect, and a rectangular wave function with a transition interval is applied for the flashing effect. The system obtains the current device status, queries the preset status-lighting effect mapping table, retrieves the basic lighting parameters for the corresponding status, calculates the actual RGB value at the current moment using the gamma correction brightness table, and generates a 32-bit status lighting effect descriptor containing color, brightness, and mode.

[0018] Step S4: Extract RGB values ​​from the status light effect descriptor, construct a complete SPI transmission sequence for the RGB values ​​according to the SPI transmission frame sequence, and execute the transmission through the configured SPI hardware to generate RGB lamp drive signals; In this embodiment of the invention, 24-bit RGB values ​​are extracted from the status light effect descriptor, rearranged into GRB order according to the WS2812 protocol requirements, and then split into 24 binary bits and mapped to SPI transmission data. The system generates at least 50 bytes of 0x00 as a reset code, generates a low-level reset signal for more than 50 microseconds, and constructs a complete SPI transmission sequence, including the reset code, preamble (8 bytes 0xAA), data frame, and end code (8 bytes 0x55). The system configures the SPI hardware parameters, including an 8MHz clock frequency, MSB priority, and simplex mode, loads the complete SPI transmission sequence into the SPI transmit buffer, and starts transmission. The system calculates an 8-bit CRC checksum and adds it to the end of the sequence. When a transmission error is detected, the current frame is automatically retransmitted to ensure reliable transmission of the RGB light control signal.

[0019] Step S5: When a change in the status of the vehicle equipment is detected, the status light effect descriptor is updated and a new round of light effect update is executed through the RGB light drive signal; In this embodiment of the invention, a state-lighting effect mapping table is established in non-volatile memory, defining corresponding RGB color values, lighting modes, frequencies, and priorities for different device states (such as power on, power off, recording, SD card error, firmware upgrade, etc.). The system monitors the status changes of the vehicle-mounted device in real time through multiple interfaces, integrates all status information into a status word, and maintains two variables: the current display state and the desired state. The system determines the highest priority state according to predefined priority rules, compares it with the current display state, and triggers an update of the state lighting effect descriptor when they are inconsistent and the new state has a higher priority. The system buffers states that switch frequently in a short period of time, implementing a delayed update and state merging strategy, and adds color gradient and effect gradient mechanisms during state transitions to achieve a smooth transition of lighting effects.

[0020] Step S6: Monitor and optimize resource usage based on the system performance data of the vehicle equipment to obtain lighting control commands; use the lighting control commands to control RGB lighting, and trigger and judge the error recovery process during RGB lighting control to generate an RGB light fault report; In this embodiment of the invention, CPU utilization and SPI bus load are monitored in real time. When the CPU load exceeds a preset threshold, the lighting effect update frequency is automatically reduced. The system monitors power supply voltage fluctuations. When the voltage exceeds a safety threshold, the SPI clock frequency is adjusted and the timing mapping code table is recalculated. The system implements differentiated update strategies for critical and non-critical states, analyzes the SPI bus traffic history, selects the optimal transmission time slot to execute lighting control commands, and detects transmission anomalies through the SPI status register and feedback signal mechanism. When a problem is detected, an error recovery process is triggered: sending a reset code, reducing the SPI clock frequency, selecting a conservative bit mode, and retransmitting data. If recovery fails three times consecutively, the system marks the RGB lights as faulty, generates a fault report, and implements partial functional degradation and fault isolation measures. Simultaneously, self-healing tests are performed periodically to achieve automatic recovery of faulty LEDs.

[0021] Preferably, step S1 includes the following steps: Step S11: Obtain the clock frequency parameters of the SPI controller and set the target SPI clock to 8MHz; Step S12: Calculate the duration of high and low levels required by the WS2812 protocol and determine the timing requirements of the logic values ​​for 0 and 1 codes; Step S13: Establish the mapping relationship between logic values ​​and SPI data frames according to the logic value timing requirements. Logic 0 corresponds to SPI 8-bit data frame 11000000b, which generates a combination waveform of a high level for 250ns and a low level for 750ns under an 8MHz clock. Logic 1 corresponds to SPI 8-bit data frame 11111100b, which generates a combination waveform of a high level for 750ns and a low level for 250ns under an 8MHz clock. This yields the mapping code table. Step S14: Verify the error rate of the mapping code table under the target SPI clock. When the error rate is less than 20ns, generate a complete timing mapping code table. Step S15: Based on different SPI clock frequency parameters, and considering the case where the SPI clock frequency parameters are adjusted within the range of 6-10MHz, multiple sets of timing mapping code tables are generated in advance.

[0022] In this embodiment of the invention, the clock frequency parameters of the SPI controller are obtained, the current clock frequency value is obtained by reading the configuration register of the SPI controller, and the target SPI clock is set to 8MHz. The system adjusts the clock frequency by setting the BR[2:0] bits in the SPI_CR1 register.

[0023] According to the timing requirements specified in the WS2812 protocol, the following calculations are performed: 1. Logic 0 requires a high-level duration of 400ns and a low-level duration of 850ns; 2. Logic 1 requires a high-level duration of 800ns and a low-level duration of 450ns; Establish the mapping relationship between logic values ​​and SPI data frames at an 8MHz SPI clock (125ns per clock cycle): 1. Logic 0 corresponds to SPI 8-bit data frame 11000000b (0xC0), generating a combined waveform of a high level of 250ns and a low level of 750ns; 2. Logic 1 corresponds to SPI 8-bit data frame 11111100b (0xFC), generating a combined waveform of a high level for 750ns and a low level for 250ns; Through this mapping relationship, the system can accurately simulate the timing required by the WS2812 protocol using the standard SPI interface.

[0024] The duration of the high and low levels of the actual output waveform is measured using a high-precision oscilloscope and compared with the requirements of the WS2812 protocol to calculate the error rate. When the maximum error is less than 20ns, the mapping code table is confirmed to be valid and generation is complete.

[0025] For different scenarios with SPI clock frequencies in the range of 6-10MHz, corresponding mapping code tables are pre-calculated and generated. For example: At a clock speed of 1.6MHz: logic 0 corresponds to 0xC0, and logic 1 corresponds to 0xF0; At a clock speed of 2.7MHz: logic 0 corresponds to 0xC0, and logic 1 corresponds to 0xF8; At a clock speed of 3.8MHz: logic 0 corresponds to 0xC0, and logic 1 corresponds to 0xFC; At a clock speed of 4.9MHz: logic 0 corresponds to 0xE0, and logic 1 corresponds to 0xFE; At a clock speed of 5.10MHz: logic 0 corresponds to 0xE0, and logic 1 corresponds to 0xFE; The system automatically selects the most suitable mapping code table based on the actual detected SPI clock frequency to ensure accurate simulation of the WS2812 protocol timing at different clock frequencies.

[0026] Preferably, step S2 includes the following steps: Step S21: Receive 24-bit RGB color values ​​and rearrange the RGB color channels of the RGB color values ​​into GRB conforming to the requirements of the WS2812 protocol; Step S22: Query the timing mapping code table, and expand each 1 bit of the 24-bit RGB color value into 8 bits of SPI transmission data according to GRB, generating an initial SPI transmission frame sequence containing 192 bits of transmission data. Step S23: For the case of multiple RGB LEDs cascaded, generate the initial SPI transmission frame sequence for each LED in sequence according to the physical connection order of the LEDs and merge them into an SPI transmission frame sequence.

[0027] In this embodiment of the invention, a 24-bit RGB color value transmitted from the vehicle control unit is received and converted into the GRB order required by the WS2812 protocol. The WS2812 protocol specifies that the data transmission order is GRB, not RGB; therefore, the system needs to rearrange the color channels. Specifically, the original 24-bit RGB value 0xRRGGBB is rearranged into 0xGGRRBB format. For example, for the RGB color value 0xFF0080 (red 255, green 0, blue 128), the system rearranges it into the GRB order 0x00FF80 (green 0, red 255, blue 128). The rearrangement algorithm is implemented as follows: 1. Extract the red component (R): (RGB>>16)&0xFF; 2. Extract the green component (G): (RGB>>8)&0xFF; 3. Extract the blue component (B): RGB & 0xFF; 4. Recombine in GRB order: GRB = (G << 16) | (R << 8) | B; The 24-bit GRB color value is split into 24 individual binary bits. Then, a timing mapping table is consulted to expand each binary bit into a corresponding 8-bit SPI transmission data: binary bit "0" is mapped to 0xC0 (11000000b); binary bit "1" is mapped to 0xFC (11111100b). The system processes each bit of the GRB value in descending order of importance, generating a total of 24 × 8 = 192 bits of SPI transmission data, or 24 bytes. For example, for the GRB color value 0x00FF80, its binary representation is 00000000 11111111 10000000. The system expands this into a 24-byte SPI transmission frame sequence, realizing the conversion from a single RGB color value to a WS2812 protocol-compatible SPI data frame.

[0028] The WS2812 LEDs support cascading, with data signals passing sequentially through each LED. The system generates a corresponding SPI transmission frame sequence for each LED based on the physical connection order of the RGB LEDs in the vehicle-mounted device, and then merges these sequences according to the data flow direction (from the first LED to the last). During the merging process, the system first determines the total number of LEDs N, and then processes the color value of each LED in the order of index 0 to N-1. For each LED, the system repeats steps S21 and S22 to generate a 24-byte SPI transmission frame sequence corresponding to that LED, and adds it to the final SPI transmission frame sequence. The final SPI transmission frame sequence contains all the data needed to control all LEDs, and according to the WS2812 protocol, the data is transmitted sequentially from the first LED to the last.

[0029] Preferably, the generation of the gamma-corrected luminance table in step S3 includes: Acquire and determine the number of gradient steps based on the target brightness value and gradient period; The luminance value of each gradient step in the gradient step is calculated using the gamma correction formula, where the gamma value is 2.2. It acquires the ambient temperature and automatically adjusts the gamma value to 2.4 when the ambient temperature exceeds a preset threshold of 45°C. Different gamma correction curves are set according to the different lighting effect types of the lighting effect parameters. For the breathing light effect, a sine function is used to calculate the brightness change curve, and for the flashing effect, a rectangular wave function is used to calculate the brightness change curve. A brief transition interval is added at the high-low level transition.

[0030] In this embodiment of the invention, the system receives the target brightness value (range 0-255) and the transition period (in milliseconds) from the vehicle control unit. Based on the SPI communication rate and the WS2812 refresh rate limitations, the system calculates the number of transition steps by dividing the transition period by the minimum refresh interval (typically 20 milliseconds). For example, when the target brightness value is 200 and the transition period is 2000 milliseconds, the number of transition steps is 2000 ÷ 20 = 100 steps. The system ensures that the number of transition steps is at least 2 and at most 256, and calculates the brightness increment for each step to achieve a smooth transition.

[0031] The human eye's perception of brightness is non-linear. The system uses a gamma correction formula to make brightness changes appear linear visually: Corrected brightness = ×255; The default gamma value is 2.2, suitable for brightness correction under normal ambient temperature. The system calculates the corrected brightness value for all gradient steps and stores the results in the gamma-corrected brightness table.

[0032] The system obtains the current ambient temperature through an onboard temperature sensor and compares it with a preset threshold of 45°C. 1. When the ambient temperature does not exceed 45°C, the system maintains the default gamma value of 2.2; 2. When the ambient temperature exceeds 45°C, the system will adjust the gamma value to 2.4; An increase in gamma value means a decrease in output brightness in the mid-brightness range, which helps reduce LED power consumption and heat generation in high-temperature environments. For example, the same linear brightness of 100 is corrected to 187 at a gamma value of 2.2 and to 179 at a gamma value of 2.4, a brightness reduction of approximately 4.3%. The system recalculates the entire gamma-corrected brightness table when it detects an ambient temperature change exceeding ±5°C, ensuring that brightness control adapts to the current temperature environment.

[0033] The system sets different gamma correction curves according to different lighting effects: 1. Breathing Light Effect: The brightness change curve is calculated using a sine function to achieve a smooth transition between the minimum and maximum brightness values. Brightness = Minimum Brightness + (Maximum Brightness - Minimum Brightness) × (sin(2π × Current Steps ÷ Total Steps - π / 2) + 1) ÷ 2.

[0034] 2. Flickering effect: The brightness change curve is calculated using a rectangular wave function, and a brief transition interval is added at the high-low level transition.

[0035] The system divides the total number of steps into several complete cycles, each cycle containing four stages: a high-level state, a high-to-low transition, a low-level state, and a low-to-high transition. During the transition interval, the system uses a cubic Bézier curve to calculate the transition brightness, ensuring a smooth and natural brightness change and avoiding visual discomfort caused by abrupt changes.

[0036] Preferably, the step S3 of generating the state luminous effect descriptor based on the gamma-corrected luminance table includes: Get the current device status; Query the preset state-lighting effect mapping table to obtain the basic lighting parameters for the corresponding state, including color, mode, and frequency; Calculate the actual RGB value at the current moment using the gamma-corrected luminance table; Generate a state light effect descriptor that includes color, brightness, and mode.

[0037] In this embodiment of the invention, device status information sent by the vehicle control unit is received via the CAN bus, or the current device status is obtained by reading the device's internal status register. Device status includes, but is not limited to: normal operation, standby, fault, low battery, charging, charging complete, and upgrading. The obtained status information is parsed into predefined status codes, represented by 8-bit unsigned integers, supporting up to 256 different statuses. The system polls the device status every 100 milliseconds to ensure timely reflection of device status changes.

[0038] Query the preset state-lighting effect mapping table to obtain the basic lighting parameters for the corresponding state. The mapping table is stored in non-volatile memory using a key-value pair structure. The key is the device status code, and the values ​​are the corresponding set of basic lighting parameters, including: 1. RGB color values ​​(24 bits, 8 bits per channel); 2. Lighting modes (8-bit, such as constant, flashing, breathing, etc.); 3. Frequency (16-bit, in millihertz); For example, when the status is "Charging", the query result might be: RGB color value = 0x00FF00 (pure green), lighting mode = 0x02 (breathing mode), frequency = 500 (0.5Hz, i.e., the breathing cycle is 2 seconds). Dynamic updates to the mapping table are supported, and the lighting effects corresponding to specific states can be modified through configuration commands, achieving customization of the lighting effects.

[0039] The system uses a gamma-corrected luminance table to calculate the actual RGB value at the current moment: 1. Determine the relative position of the current moment within the light cycle based on the light mode and frequency parameters. 2. Query the gamma-corrected brightness table to obtain the brightness percentage corresponding to the current moment. 3. Apply this brightness percentage to the base RGB color values ​​to calculate the actual RGB values. For example, in the "charging" state, the basic RGB color value is 0x00FF00, the lighting mode is breathing mode, and the cycle is 2 seconds. Assuming that the current position is 84% ​​of the cycle, and the queried brightness percentage is 30%, then the actual RGB value is 0x00FF00 × 30% = 0x004D00.

[0040] The system generates a status light effect descriptor containing color, brightness, and mode. The status light effect descriptor is a 32-bit data structure containing the following fields: RGB color value (24 bits); brightness adjustment flag (1 bit); reserved bits (3 bits); and light mode (4 bits). The system fills the calculated actual RGB value into the color field of the descriptor; if gamma correction is applied, the brightness adjustment flag is set to 1; the light mode field is directly obtained from the basic light parameters. For example, for the calculated actual RGB value 0x004D00 for the "charging" state, the generated status light effect descriptor is 0x004D0012 (color = 0x004D00, brightness adjustment flag = 1, reserved bits = 000, light mode = 0010). In multi-LED scenarios, the system generates a status light effect descriptor independently for each LED, supporting different LEDs displaying different status information. For example, in an in-vehicle device, the first LED displays the charging status, the second LED displays the network connection status, and the third LED displays fault information.

[0041] Preferably, step S4 includes the following steps: Step S41: Extract the RGB value to be displayed from the status light effect descriptor, convert the RGB value into an SPI transmission frame, generate a reset code, generate a low-level reset signal for more than 50 microseconds, and construct a complete SPI transmission sequence, which includes a preamble, a data frame, and an end code. Step S42: Configure SPI hardware parameters, including 8MHz clock frequency, MSB priority, and simplex mode; Step S43: Load the complete SPI transmission sequence into the SPI transmit buffer and start the transmission; Step S44: Calculate and add a check field to the complete SPI transmission sequence, and automatically retransmit the current frame when a transmission error is detected.

[0042] In this embodiment of the invention, a 24-bit RGB color value is extracted from the status light effect descriptor and converted into the GRB sequence required by the WS2812 protocol. For example, for descriptor 0x004D0012, the RGB value 0x004D00 is extracted and converted into the GRB sequence 0x4D0000. The 24-bit GRB value is split into 24 binary bits, and each binary bit is mapped to 8 bits of SPI transmission data by querying the timing mapping code table (binary bit "0" is mapped to 0xC0, and binary bit "1" is mapped to 0xFC). At least 50 bytes of 0x00 are generated as a reset code, and a low-level reset signal of more than 50 microseconds is generated under an 8MHz SPI clock to meet the reset requirements of the WS2812 protocol.

[0043] The complete SPI transmission sequence structure is: [Reset code (50 bytes 0x00)][Preamble (8 bytes 0xAA)][LED 1 data frame (24 bytes)][LED 2 data frame (24 bytes)]...[LED N data frame (24 bytes)][End code (8 bytes 0x55)].

[0044] In the case of multiple LEDs, the system adds the SPI transmission frame of each LED to the data frame part in sequence according to the physical connection order of the LEDs.

[0045] Configure the following hardware parameters by setting the SPI control register: 1. Clock frequency: 8MHz (achieved by setting the frequency division factor); 2. Clock polarity and phase: CPOL=0, CPHA=0 (SPI mode 0); 3. Data transmission order: MSB first (LSBFIRST=0); 4. Transmission mode: Simplex mode (data is transmitted using only the MOSI lines); The system also configures the relevant GPIO pins to high-speed push-pull output mode to ensure signal integrity.

[0046] Allocate a sufficiently large memory buffer to store the complete SPI transmission sequence. For a case containing N LEDs, the buffer size should be at least 50 + 8 + 24 × N + 8 bytes. To improve transmission efficiency, a double-buffering mechanism is employed: while one buffer is being transferred via DMA, the other buffer is used to prepare the next frame of data. Data is transferred from memory to the SPI peripheral via the DMA controller, a transmission completion interrupt is configured, and a timeout detection mechanism is implemented to ensure transmission reliability.

[0047] When constructing the SPI transmission sequence, an 8-bit CRC checksum is calculated and added to the end of the sequence to verify the integrity of the transmission. An automatic retransmission mechanism is implemented. 1. When a CRC checksum error is detected, the system marks it as a transmission error; 2. The system records the number of errors. If the number of consecutive errors exceeds a preset threshold (e.g., 3 times), a system warning will be generated. 3. The system resets the SPI peripheral and clears the transmit buffer; 4. The system reloads the current frame data into the send buffer and restarts transmission; It also implements adaptive clock adjustment: when the error rate exceeds a preset threshold (e.g., 5%), the system reduces the SPI clock frequency (e.g., from 8MHz to 6MHz) to improve transmission reliability; when the system has 100 consecutive error-free transmissions, it restores the original clock frequency.

[0048] Preferably, step S5 includes the following steps: Step S51: Establish the mapping relationship between the vehicle equipment status and the lighting effect, define the specific color and effect corresponding to the specific status, and obtain the desired status of the vehicle equipment; Step S52: Monitor the status changes of the vehicle-mounted equipment in real time, including power-on, power-off, recording, SD card status, and firmware upgrade status; Step S53: Detect whether the current lighting display is consistent with the expected state of the vehicle equipment; Step S54: Establish a state priority mechanism. When a state change is detected and the new state has a higher priority than the current displayed state, the state light effect descriptor is immediately updated. Step S55: When the vehicle-mounted equipment frequently switches states within a preset short-term threshold, the state changes are buffered. Step S56: During the state transition of the vehicle-mounted equipment, add a gradient effect to achieve a smooth transition.

[0049] In this embodiment of the invention, a status-lighting effect mapping table is established in non-volatile memory and stored using a key-value pair structure. This mapping table contains the following fields: status code (8 bits); RGB color value (24 bits); lighting mode (8 bits); frequency (16 bits); priority (8 bits).

[0050] The following example states are predefined as mappings to lighting effects: 1. Power-on status: Solid blue light, priority 5; 2. Power off state: No lights, priority 10; 3. Recording status: Red flashing (1Hz), priority 8; 4. SD card error status: Yellow flashing rapidly (2Hz), priority 9; 5. Firmware upgrade status: Purple breathing (0.5Hz), priority 7; 6. Low battery status: slow orange flash (0.5Hz), priority 6; The system supports dynamic updating of mapping relationships via CAN bus or I2C interface, enabling flexible configuration of lighting effects.

[0051] Real-time status information of vehicle-mounted equipment can be obtained through multiple interfaces: 1. Power Status: Monitor the POWER_GOOD signal of the power management chip; 2. Recording Status: Read the status register of the camera controller; 3. SD Card Status: Monitor the interrupt signals and status register of the SD card controller; 4. Firmware upgrade status: Receives upgrade commands and progress information through a dedicated communication channel; All monitored status information is integrated into a 32-bit status word, with each status occupying a unique bit, thus achieving unified status management.

[0052] Maintain two state variables: the current display state and the desired state. By comparing these two state variables, determine whether the lighting display needs to be updated.

[0053] The specific comparison process is as follows: 1. Extract the status information of each functional module from the status word; 2. Based on predefined state priority rules, determine the current highest priority state as the desired state; 3. Compare the desired state with the current displayed state; 4. If the two are inconsistent, the lighting effects update process will be triggered; The system performs a status comparison every 500 milliseconds to ensure that the lighting display is synchronized with the device status.

[0054] The system defines a priority value (0-15) for each state in the state-lighting effect mapping table, with a larger value indicating a higher priority.

[0055] When a state change is detected, the system executes the following priority processing flow: 1. Extract the status codes of all active states from the status word; 2. Query the status-lighting effect mapping table to obtain the priority value of each active status; 3. Identify the state with the highest priority value as the desired state; 4. Compare the priority of the desired state with the current displayed state; If the desired state has a higher priority than the current display state, the state light effect descriptor will be updated immediately; if the desired state has a lower priority than or equal to the current display state, the current display will remain unchanged.

[0056] The system implements a priority overriding mechanism: when a high-priority state disappears, the next highest priority state is automatically displayed without additional instructions.

[0057] The system implements a state anti-jitter mechanism to avoid flickering and instability in the lighting effects caused by frequent state changes in a short period of time.

[0058] The specific implementation methods include two strategies: 1. Delayed update strategy: When frequent changes in state are detected, the system does not immediately update the lighting effects, but starts a timer to delay for 300 milliseconds before performing the update operation; 2. State merging strategy: The system collects all state changes within an observation window (e.g., 500 milliseconds), counts the frequency of occurrence of each state, and selects the state with the highest frequency and highest priority as the target state. The system also implements a state stability assessment mechanism, which temporarily reduces the priority of frequently changing unstable states until the state becomes stable.

[0059] The system implements two mechanisms: color gradient and effect gradient. 1. Color gradient mechanism: When a state switch causes a color change, the system calculates the intermediate color through linear interpolation within 500 milliseconds to achieve a smooth transition.

[0060] Specific implementation method: The starting RGB color value and the target RGB color value are decomposed into three components: R, G, and B. Calculate the difference for each component; The transition time is divided into 20 equally spaced time points; For each time point t, calculate the current color component value = starting component value + (target component value - starting component value) × t; The calculated R, G, and B components are recombined into RGB color values ​​to update the lighting display; 2. Effect transition mechanism: When the state switch causes the lighting mode to change, the system implements a smooth transition between modes.

[0061] The transition time is adjusted according to the urgency of the state transition. The transition time is shortened for high-priority states and lengthened for low-priority states, thus achieving a balance between state importance and visual smoothness.

[0062] Preferably, the resource consumption optimization in step S6 includes: The CPU resource utilization and SPI bus load of the in-vehicle equipment are acquired and tested to obtain the system performance test results. Based on the system performance test results, a CPU load threshold is set. When the CPU load of the vehicle equipment exceeds the CPU load threshold, the lighting effect update frequency is automatically reduced to half of the original. The system acquires power supply voltage fluctuation values ​​and automatically adjusts the SPI clock frequency parameters when the power supply voltage fluctuation values ​​exceed the preset voltage safety threshold. Based on the adjustment of the SPI clock frequency parameters, the timing mapping code table is recalculated; When the lighting effect update frequency is reduced, update the lighting effects for critical states. Analyze the SPI bus traffic history, identify communication low points, and select the optimal transmission time slot to execute the lighting control command.

[0063] In this embodiment of the invention, the system collects CPU utilization and SPI bus load data in real time through a built-in performance monitoring module: 1. CPU utilization calculation: Calculated by comparing the time difference between an empty loop and the actual running time. 2. SPI bus load rate calculation: Calculate the ratio of the total number of bytes transmitted via SPI to the theoretical maximum transmission capacity within 1 second. The system collects performance data for 30 consecutive seconds, calculates the average, maximum and standard deviation, and forms the system performance test results, providing a basis for subsequent optimization decisions.

[0064] The system sets the CPU load threshold based on the performance test results: CPU load threshold = maximum CPU utilization - 2 × standard deviation; The system samples the current CPU utilization rate every 500 milliseconds and compares it with the CPU load threshold. When the CPU utilization rate exceeds the threshold three times consecutively, the system implements automatic frequency reduction, lowering the lighting effect update frequency from the default 50Hz to 25Hz.

[0065] The system implements a dynamic frequency reduction mechanism, calculating a frequency reduction factor based on the degree to which CPU utilization exceeds a threshold. K = min(2, current CPU utilization / CPU load threshold); New update frequency = original update frequency / K; When the CPU utilization returns to normal (below 80% of the threshold for 10 consecutive samples), the system gradually restores the lighting effect update frequency, increasing it by 10% each time, until it returns to the default frequency.

[0066] The system monitors the power supply voltage of the on-board equipment through an ADC sampling circuit and calculates the voltage fluctuation value. Voltage fluctuation value = |current voltage - nominal voltage| / nominal voltage × 100%; When the voltage fluctuation exceeds the voltage safety threshold (default 5%), the system triggers SPI clock frequency adjustment: 1. When the voltage is lower than the nominal value, reduce the SPI clock frequency by 25%; 2. When the voltage is higher than the nominal value, reduce the SPI clock frequency by 15%; The system implements a voltage stability assessment mechanism, dynamically adjusts the voltage safety threshold based on the standard deviation of voltage fluctuations, and gradually restores the SPI clock frequency after the voltage stabilizes.

[0067] When the SPI clock frequency changes, the system recalculates the timing mapping code table: 1. Calculate the unit time at the new clock frequency; 2. Based on the timing requirements of the WS2812 protocol, calculate the number of clock cycles required for logic 0 and logic 1 at the new clock frequency; 3. Determine the new mapping relationship and verify the error rate; 4. Fine-tune the mapping relationship if necessary to ensure that the actual waveform conforms to the WS2812 protocol requirements; The system pre-calculates and stores the corresponding mapping code table for commonly used SPI clock frequencies. When adjusting the frequency, it directly loads the closest mapping code table and then fine-tunes it according to the actual frequency, reducing computational overhead.

[0068] The system categorizes states into critical states (priority ≥ 8) and non-critical states (priority < 8) based on their priority. When the lighting effect update frequency is reduced, the system executes a differentiated update strategy: 1. The update frequency for critical states remains unchanged; 2. Reduce the update frequency of non-critical applications; The system implements a state switching optimization mechanism to ensure that important state changes can be reflected in a timely manner. At the same time, under extreme CPU load conditions, the system burden is further reduced by simplifying the complexity of lighting effects.

[0069] The system analyzes the SPI bus traffic history to identify communication troughs: The SPI bus status is sampled every 10 milliseconds to form an activity history record. Statistical analysis of the most recent 10 seconds of historical records is performed to identify periodic patterns; Time periods with a busy rate below 20% are marked as low communication times; The system establishes a lighting control command queue to implement a priority scheduling mechanism: Emergency lighting instructions (such as error status indications) should be sent immediately; Regular light update commands wait for the optimal time slot, but the waiting time does not exceed 100 milliseconds; Low-priority lighting effects (such as gradient transitions) are executed in strict optimal time slots; Preferably, the triggering judgment of the error recovery process in step S6 includes: The SPI transmission completion flag is detected by the SPI status register, and the RGB light response status is detected by a preset feedback signal mechanism. When the SPI transmission completion flag is not completed or the RGB light response status is no response, the error recovery process is triggered. The error recovery process includes: sending a reset code to all RGB LEDs to obtain the initial state of the LEDs; reducing the SPI clock frequency parameter and selecting a conservative bit mode with greater timing margin from the timing mapping code table; and retransmitting the complete SPI transmission sequence. If the error recovery process fails three times in a row, the RGB light will be marked as faulty and an RGB light fault report will be generated.

[0070] The system employs a two-level error detection mechanism to ensure the reliability of lighting control: 1. SPI transmission completion flag detection: After each SPI data transmission, the system reads the transmission completion flag bit from the SPI status register; Set a transmission timeout timer with a timeout period equal to the data length × 1.5 × the transmission time per byte. If the transmission completion flag is not detected within the timeout period, it is marked as an "SPI transmission not completed" error. 2. RGB LED response status detection: The system detects the response status of the RGB lights through a feedback circuit connected to the data output terminal of the RGB lights. The feedback circuit consists of pull-up resistors and a comparator. The comparator output is connected to the GPIO pin of the microcontroller. The system delays for 50 microseconds after sending the data frame, and then reads the GPIO status. If a low level is read, mark it as a "no response" error. The system records the response status of each RGB LED individually, constructs an LED health mapping table, and achieves accurate fault location.

[0071] When the system detects an incomplete SPI transmission or a no-response error from the LED, it immediately initiates the error recovery process: 1. Reset operation: The system sends a reset code (60 consecutive bytes of 0x00) to all RGB lights. It generates a low-level signal for at least 60 microseconds, exceeding the 50-microsecond reset time specified in the WS2812 protocol; Before sending the reset code, first reset the SPI controller, clear the buffer, and reconfigure the registers; 2. Reduce the SPI clock frequency: The first error recovery will reduce the frequency by 25% (e.g., from 8MHz to 6MHz); The second error recovery will reduce the frequency by 50% (e.g., from 8MHz to 4MHz); The third error recovery will reduce the frequency by 75% (e.g., from 8MHz to 2MHz); 3. Select conservative position mode: Standard bit mode: Logic 0 corresponds to 11000000b, and logic 1 corresponds to 11111100b; Conservative bit mode: Logic 0 corresponds to 11100000b (high level time increased by 50%), and logic 1 corresponds to 11111000b (low level time increased by 50%). The system recalculates timing parameters based on the reduced SPI clock frequency to ensure that the signal meets the WS2812 protocol requirements; 4. Resend data: The system regenerates the complete SPI transmission sequence using a conservative bit mode; Resend data via the SPI interface; After sending is complete, perform a double-level error check again to verify the recovery effect; If the recovery is successful, the system records the recovery event and attempts to restore the original SPI clock frequency after 60 seconds; if the recovery fails, the system proceeds to the next recovery attempt.

[0072] The system sets a counter for each error recovery attempt, recording the number of consecutive failures. If the RGB LED still fails to respond normally after three consecutive executions of the error recovery process, the system executes the following fault handling procedure: 1. Fault marking: The system marks the RGB lights as faulty; Update the status bit of the corresponding LED in the LED health mapping table to 0; 2. Fault report generation: Generate a fault report that includes the fault time, fault LED index, last successful color value, recovery attempt information, etc. The fault report is stored in non-volatile memory and sent to the main control unit via the communication interface; 3. Functionality degradation mechanism: When some LED chips are detected to be faulty, the lighting control strategy is automatically adjusted. The information originally intended to be displayed on the faulty LED is redirected to the adjacent normal LED; Generate all-black (0x000000) color data for faulty LEDs, but preserve the data structure to ensure that the data can be correctly passed to the normal LEDs after the faulty LEDs; 4. Self-healing attempt mechanism: After marking the LED bead as faulty, the system automatically performs a recovery test every 30 minutes. Send a simple color sequence to the fault LED and detect the response. If the LED bead is detected to have resumed normal operation, the system will automatically remove it from the fault state and restore normal control.

[0073] Please see Fig. 2 This diagram illustrates the implementation process of a breathing light effect in an in-vehicle device RGB lighting control system based on the SPI protocol. A breathing light effect is a lighting effect where the brightness gradually changes to simulate a breathing rhythm, typically used to indicate device status or increase visual appeal.

[0074] Fig. 2 Starting with "Start: Target Color RGB", the RGB color values ​​are first converted to the HSV (Hue, Saturation, Value) color space. The HSV color space is more suitable for handling color changes, especially changes in brightness (V component).

[0075] Next, the V component, i.e., the brightness value, is extracted. The decision node "Breathing mode enabled?" in the flowchart determines whether to enable the breathing light effect. If enabled, the calculation process for the breathing light effect begins; if not enabled, the V value remains unchanged.

[0076] In breathing light mode, the system calculates a sinusoidal brightness modulation. The formula for calculating the brightness value is: ; in It's the brightness value. This is the base brightness value. This is a parameter that varies with time, usually linearly related to time, and is used to control the period and phase of a sine wave. This formula generates a periodically changing brightness value using a sine function, simulating the fluctuations of breathing.

[0077] After the calculation is completed, the V value in the HSV is updated, that is, the brightness value is updated. Then the process returns to the HSV to RGB conversion step to convert the updated HSV value back to RGB format for use in SPI transmission.

[0078] Next, SPI control signals are generated, which are used to control the RGB lights. Another decision node in the flowchart, "Cascade Control?", determines whether cascading control of multiple RGB lights is needed. If it's single-light control, one LED data entry (24 bytes of SPI data) is sent; if it's multi-light control, all light data are sent in a loop.

[0079] Finally, a reset signal is sent to ensure all LEDs are ready to receive new data, and then the lighting effect is output, completing the breathing light effect. The entire process terminates at the "End" node.

[0080] Fig. 2 It clearly demonstrates how to achieve a breathing light effect by adjusting the brightness value, and explains how to control RGB lights via the SPI protocol to achieve this effect.

[0081] Therefore, the embodiments should be considered as exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of the equivalents of the application are intended to be included within the invention.

[0082] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features of the invention herein.

Claims

1. A method for controlling RGB lighting in an in-vehicle device based on the SPI protocol, characterized in that, Applied to automotive equipment, the automotive equipment including an SPI controller, the method includes the following steps: Step S1: Obtain and generate a timing mapping code table based on the SPI clock frequency parameters; Step S2: Receive and convert RGB color values ​​into GRB order, and generate an SPI transmission frame sequence according to the timing mapping code table; Step S3: Calculate the brightness gradient curve of the vehicle-mounted equipment's headlight brightness to obtain a gamma-corrected brightness table; generate a state light effect descriptor based on the gamma-corrected brightness table; Step S4: Extract RGB values ​​from the status light effect descriptor, construct a complete SPI transmission sequence for the RGB values ​​according to the SPI transmission frame sequence, and execute the transmission through the configured SPI hardware to generate RGB lamp drive signals; Step S5: When a change in the status of the vehicle equipment is detected, the status light effect descriptor is updated and a new round of light effect update is executed through the RGB light drive signal; Step S6: Monitor and optimize resource usage based on the system performance data of the vehicle equipment to obtain lighting control commands; use the lighting control commands to control RGB lighting, and trigger and judge the error recovery process during RGB lighting control to generate an RGB light fault report.

2. The RGB lighting control method for vehicle-mounted devices based on the SPI protocol according to claim 1, characterized in that, Step S1 includes the following steps: Step S11: Obtain the clock frequency parameters of the SPI controller and set the target SPI clock to 8MHz; Step S12: Calculate the duration of high and low levels required by the WS2812 protocol and determine the timing requirements of the logic values ​​for 0 and 1 codes; Step S13: Establish the mapping relationship between logic values ​​and SPI data frames according to the logic value timing requirements. Logic 0 corresponds to SPI 8-bit data frame 11000000b, which generates a combination waveform of a high level for 250ns and a low level for 750ns under an 8MHz clock. Logic 1 corresponds to SPI 8-bit data frame 11111100b, which generates a combination waveform of a high level for 750ns and a low level for 250ns under an 8MHz clock. This yields the mapping code table. Step S14: Verify the error rate of the mapping code table under the target SPI clock. When the error rate is less than 20ns, generate a complete timing mapping code table. Step S15: Based on different SPI clock frequency parameters, and considering the case where the SPI clock frequency parameters are adjusted within the range of 6-10MHz, multiple sets of timing mapping code tables are generated in advance.

3. The RGB lighting control method for vehicle-mounted devices based on the SPI protocol according to claim 1, characterized in that, Step S2 includes the following steps: Step S21: Receive 24-bit RGB color values ​​and rearrange the RGB color channels of the RGB color values ​​into GRB conforming to the requirements of the WS2812 protocol; Step S22: Query the timing mapping code table, and expand each 1 bit of the 24-bit RGB color value into 8 bits of SPI transmission data according to GRB, generating an initial SPI transmission frame sequence containing 192 bits of transmission data. Step S23: For the case of multiple RGB LEDs cascaded, generate the initial SPI transmission frame sequence for each LED in sequence according to the physical connection order of the LEDs and merge them into an SPI transmission frame sequence.

4. The RGB lighting control method for vehicle-mounted devices based on the SPI protocol according to claim 1, characterized in that, The generation of the gamma-corrected luminance table in step S3 includes: Acquire and determine the number of gradient steps based on the target brightness value and gradient period; The luminance value of each gradient step in the gradient step is calculated using the gamma correction formula, where the gamma value is 2.

2. It acquires the ambient temperature and automatically adjusts the gamma value to 2.4 when the ambient temperature exceeds a preset threshold of 45°C. Different gamma correction curves are set according to different lighting effect types based on preset lighting effect parameters. For the breathing light effect, a sine function is used to calculate the brightness change curve, and for the flashing effect, a rectangular wave function is used to calculate the brightness change curve. A brief transition interval is added at the high-low level transition.

5. The RGB lighting control method for vehicle-mounted devices based on the SPI protocol according to claim 1, characterized in that, Step S3, which generates a state luminous effect descriptor based on the gamma-corrected luminance table, includes: Get the current device status; Query the preset state-lighting effect mapping table to obtain the basic lighting parameters for the corresponding state, including color, mode, and frequency; Calculate the actual RGB value at the current moment using the gamma-corrected luminance table; Generate a state light effect descriptor that includes color, brightness, and mode.

6. The RGB lighting control method for vehicle-mounted devices based on the SPI protocol according to claim 1, characterized in that, Step S4 includes the following steps: Step S41: Extract the RGB value to be displayed from the status light effect descriptor, convert the RGB value into an SPI transmission frame, generate a reset code, generate a low-level reset signal for more than 50 microseconds, and construct a complete SPI transmission sequence, which includes a preamble, a data frame, and an end code. Step S42: Configure SPI hardware parameters, including 8MHz clock frequency, MSB priority, and simplex mode; Step S43: Load the complete SPI transmission sequence into the SPI transmit buffer and start the transmission; Step S44: Calculate and add a check field to the complete SPI transmission sequence, and automatically retransmit the current frame when a transmission error is detected.

7. The RGB lighting control method for vehicle-mounted devices based on the SPI protocol according to claim 1, characterized in that, Step S5 includes the following steps: Step S51: Establish the mapping relationship between the vehicle equipment status and the lighting effect, define the specific color and effect corresponding to the specific status, and obtain the desired status of the vehicle equipment; Step S52: Monitor the status changes of the vehicle-mounted equipment in real time, including power-on, power-off, recording, SD card status, and firmware upgrade status; Step S53: Detect whether the current lighting display is consistent with the expected state of the vehicle equipment; Step S54: Establish a state priority mechanism. When a state change is detected and the new state has a higher priority than the current displayed state, the state light effect descriptor is immediately updated. Step S55: When the vehicle-mounted equipment frequently switches states within a preset short-term threshold, the state changes are buffered. Step S56: During the state transition of the vehicle-mounted equipment, add a gradient effect to achieve a smooth transition.

8. The RGB lighting control method for vehicle-mounted devices based on the SPI protocol according to claim 1, characterized in that, Step S6 involves optimizing resource usage, including: The CPU resource utilization and SPI bus load of the in-vehicle equipment are acquired and tested to obtain the system performance test results. Based on the system performance test results, a CPU load threshold is set. When the CPU load of the vehicle equipment exceeds the CPU load threshold, the lighting effect update frequency is automatically reduced to half of the original. The system acquires power supply voltage fluctuation values ​​and automatically adjusts the SPI clock frequency parameters when the power supply voltage fluctuation values ​​exceed the preset voltage safety threshold. Based on the adjustment of the SPI clock frequency parameters, the timing mapping code table is recalculated; When the lighting effect update frequency is reduced, update the lighting effects for critical states. Analyze the SPI bus traffic history, identify communication low points, and select the optimal transmission time slot to execute the lighting control command.

9. The RGB lighting control method for vehicle-mounted devices based on the SPI protocol according to claim 1, characterized in that, The triggering criteria for the error recovery process in step S6 include: The SPI transmission completion flag is detected by the SPI status register, and the RGB light response status is detected by a preset feedback signal mechanism. When the SPI transmission completion flag is not completed or the RGB light response status is no response, the error recovery process is triggered. The error recovery process includes: sending a reset code to all RGB LEDs to obtain the initial state of the LEDs; reducing the SPI clock frequency parameter and selecting a conservative bit mode with greater timing margin from the timing mapping code table; and retransmitting the complete SPI transmission sequence. If the error recovery process fails three times in a row, the RGB light will be marked as faulty and an RGB light fault report will be generated.

10. A vehicle-mounted RGB lighting control system based on the SPI protocol, characterized in that, For executing the SPI protocol-based RGB lighting control method for in-vehicle devices as described in claim 1, the SPI protocol-based RGB lighting control system for in-vehicle devices includes: The timing map generation module is used to obtain and generate a timing map code table based on the SPI clock frequency parameters; The data frame conversion module is used to receive and convert RGB color values ​​into GRB order, and generate SPI transmission frame sequence according to the timing mapping code table; The luminous efficacy calculation and state analysis module is used to calculate the luminance gradient curve of the on-board equipment's headlight brightness and obtain a gamma-corrected luminance table; and generate a state luminous efficacy descriptor based on the gamma-corrected luminance table. The SPI transmission execution module is used to extract RGB values ​​from the status light effect descriptor, construct a complete SPI transmission sequence for the RGB values ​​according to the SPI transmission frame sequence, and execute the transmission through the configured SPI hardware to generate RGB lamp drive signals. The status monitoring and update module is used to trigger the update of the status light effect descriptor and execute a new round of light effect update through the RGB light drive signal when a status change of the vehicle equipment is detected. The performance optimization and fault handling module is used to monitor and optimize resource usage based on the system performance data of the vehicle equipment, and obtain lighting control commands; it uses the lighting control commands to control RGB lighting, and triggers and judges the error recovery process during RGB lighting control, and generates RGB light fault reports.