import os
import re
common_words = set([
'about', 'after', 'all', 'also', 'an', 'and',
'any', 'are', 'as', 'at',
'be', 'because', 'but', 'by', 'can', 'come',
'could', 'day', 'do', 'even',
'first', 'for', 'get', 'give', 'go', 'has',
'have', 'he', 'her',
'him', 'his', 'how', 'I', 'in', 'into', 'it',
'its', 'just',
'know', 'like', 'look', 'make', 'man', 'many',
'me', 'more', 'my', 'new',
'no', 'not', 'now', 'of', 'one', 'only', 'or',
'other', 'our', 'out',
'over', 'people', 'say', 'see', 'she', 'so',
'some', 'take', 'tell', 'than',
'their', 'them', 'then', 'there', 'these',
'they', 'think',
'this', 'time', 'two', 'up', 'use', 'very',
'want', 'was', 'way',
'we', 'well', 'what', 'when', 'which', 'who',
'will', 'with', 'would',
'year', 'you', 'your'
])
valid_extensions = set([
'c', 'h', 'yaml', 'cmake', 'conf', 'txt', 'overlay',
'rst', 'dtsi',
'Kconfig', 'dts', 'defconfig', 'yml', 'ld', 'sh', 'py',
'soc', 'cfg'
])
def filter_repeated_words(text):
# Split the text into lines
lines = text.split('\n')
# Combine lines into a single string with unique separator
combined_text = '/*sep*/'.join(lines)
# Replace repeated words within a line
def replace_within_line(match):
return match.group(1)
# Regex for matching repeated words within a line
within_line_pattern =
re.compile(r'\b(' +
'|'.join(map(re.escape, common_words)) +
r')\b\s+\b\1\b')
combined_text = within_line_pattern.
sub(replace_within_line, combined_text)
# Replace repeated words across line boundaries
def replace_across_lines(match):
return match.group(1) + match.group(2)
# Regex for matching repeated words across line boundaries
across_lines_pattern = re.
compile(r'\b(' + '|'.join(
map(re.escape, common_words)) +
r')\b(\s*[*\/\n\s]*)\b\1\b')
combined_text = across_lines_pattern.
sub(replace_across_lines, combined_text)
# Split the text back into lines
filtered_text = combined_text.split('/*sep*/')
return '\n'.join(filtered_text)
def process_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
text = file.read()
new_text = filter_repeated_words(text)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(new_text)
def process_directory(directory_path):
for root, dirs, files in os.walk(directory_path):
dirs[:] = [d for d in dirs if not d.startswith('.')]
for file in files:
# Filter out hidden files
if file.startswith('.'):
continue
file_extension = file.split('.')[-1]
if
file_extension in valid_extensions: # 只处理指定后缀的文件
file_path = os.path.join(root, file)
print(f"Processed file: {file_path}")
process_file(file_path)
directory_to_process = "/home/mi/works/github/zephyrproject/zephyr"
process_directory(directory_to_process)
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
49 lines
1.8 KiB
YAML
49 lines
1.8 KiB
YAML
# Copyright (c) 2019, Linaro Limited
|
|
# Copyright (c) 2019, Nordic Semiconductor ASA
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
description: |
|
|
Worldsemi WS2812 (and compatible) LED controller
|
|
|
|
Driver bindings for daisy chains of WS2812 (and compatible devices
|
|
like SK6812, or Everlight B1414) LED controllers.
|
|
|
|
The PWM protocol is described here:
|
|
https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
|
|
|
|
A 0 bit's pulse width is between 200 and 500 ns. A 1 bit's is
|
|
at least 550 ns, with 700 ns or so typical. Pixel order is GRB.
|
|
|
|
You can connect the device to either a GPIO on your SoC, or a SPI
|
|
MOSI line. Use the worldsemi,ws2812-spi.yaml or
|
|
worldsemi,ws2812-gpio.yaml bindings instead of this file after
|
|
making your choice.
|
|
|
|
Everlight B1414:
|
|
|
|
The specification of the Everlight B1414 LED controller is slightly different.
|
|
For the control signal (waveform) each bit is described with a 1.2 us pulse:
|
|
|
|
0 bit: 300 ns high and 900 ns low.
|
|
1 bit: 900 ns high and 300 ns low.
|
|
|
|
There is a +/- 80 ns tolerance for each timing.
|
|
|
|
The latch/reset delay is 250 us and it must be set using the reset-delay
|
|
property. The pixel order depends on the model and it can be configured
|
|
using the color-mapping property.
|
|
|
|
include: led-strip.yaml
|
|
|
|
properties:
|
|
reset-delay:
|
|
type: int
|
|
default: 8
|
|
description: |
|
|
Minimum delay to wait (in microseconds) to make sure that the strip has
|
|
latched the signal. If omitted, a default value of 8 microseconds is used.
|
|
This default is good for the WS2812 controllers. Note that despite the
|
|
WS2812 datasheet states that a 50 microseconds delay is required, it seems
|
|
6 microseconds is enough. The default is set to 8 microseconds just to be
|
|
safe.
|