current_usec() returns a uint64_t, but it used TICK2USEC(timebase)
to convert scheduler ticks to microseconds. On 32-bit clock_t builds,
TICK2USEC() performs the multiplication in 32-bit arithmetic before the
result is widened.
With CONFIG_USEC_PER_TICK=10000, this wraps after about 71.6 minutes:
UINT32_MAX / 1000000 ~= 4294 seconds
After the wrap, up_timer_gettick() can report time near zero again. This
can leave absolute watchdog timeouts, such as those used by usleep() /
clock_nanosleep(), waiting for a tick value that will not be reached until
the 32-bit scheduler counter wraps.
Cast timebase to uint64_t before multiplying by USEC_PER_TICK so
current_usec() remains monotonic across the 32-bit microsecond boundary.
Signed-off-by: Max Kriegleder <max.kriegleder@gmail.com>
Converted USB Host CDC-ECM to a lower half driver.
Removed existing full network driver callbacks and replaced with lower
half.
Signed-off-by: daniellizewski <daniellizewski@geotab.com>
Added support for USB host to use an USB CDC-ECM device.
This class is used for usb-ethernet adapters as well as many modems.
Signed-off-by: daniellizewski <daniellizewski@geotab.com>
Added support for selecting a different USB configuration.
Certain USB devices offer different classes using different
configurations. This allows a board file to provide a callback
to select the proper configuration for a given USB device.
Signed-off-by: daniellizewski <daniellizewski@geotab.com>
BREAKING: In an effort to simplify NuttX initialization, NSH_ARCHINIT is
removed. board_app_initialize is also removed. BOARD_LATE_INITIALIZE now
performs all board initialization logic, and is by default enabled. All
references to these symbols are removed. BOARDIOC_INIT remains, but will
result in -ENOTTY when called. It is to be removed in a later commit.
Quick fix: Boards relying on NSH_ARCHINIT should now enable
CONFIG_BOARD_LATE_INITIALIZE instead. If the application needs
fine-grained control over board initialization from userspace, the logic
performed by BOARDIOC_INIT may be copied to the board_finalinitialize
function and used instead via BOARDIOC_FINALINIT. All
board_app_initialize logic provided by NuttX is now moved to
board_late_initialize, and the same should be done for out-of-tree
boards.
Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
DShot is a packet based serial protocol, used for controlling motor controllers
(ESCs), typically for drones.
This adds an upper-half driver for dshot protocol, along with common
configuration options and definitions definitions.
Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
Always allocate per-file can_reader on open so write-only descriptors get msgalign / ioctl state; free that context on close when it was never linked into cd_readers (fixes leak).
Cap each drain loop (20×500 ms) so close() cannot block forever when bxCAN retries without ACK or dev_txempty never clears.
Fix stm32can_vputreg debug log to print the written value (correct parameter name).
Signed-off-by: Alexey Matveev <tippet@yandex.ru>
This driver adds support to MPR121 Capacitive Keypad usually found
at Aliexpress. The MPR121 is a touch sensor chip from Freescale/NXP
that supports up to 12 sensor electrodes and 1 proximity electrode.
Signed-off-by: Alan C. Assis <acassis@gmail.com>
- Replace syslog() with finfo()/fwarn() to follow the NuttX subsystem
debug convention.
- Merge adjacent early-continue `if` branches in w25n_pick_free_spare
and w25n_scan_factory_bad.
- Add Input Parameters / Returned Value sections to the BBM helper
headers.
- Clarify why only -EIO triggers a remap retry in w25n_erase and
w25n_bwrite (block-level E-FAIL/P-FAIL vs. transient bus faults).
Signed-off-by: Julian Oes <julian@oes.ch>
Use the chip's built-in 20-entry non-volatile Bad Block Management
Look-Up Table (datasheet section 8.2.7) to transparently route around
bad blocks.
Init:
- Reserve the top 24 blocks of the array as a spare pool
- Clamp the MTD geometry to W25N_USER_BLOCKS = 1000 so upper layers
never see the spare area (125 MB usable instead of 128 MB)
- Force BUF=1 alongside enabling ECC. The W25N01GVxxIT variant
power-ups with BUF=0 (Continuous Read mode), in which Read Data
ignores the column address and always starts at byte 0 - which
silently broke any read targeting a non-zero column (OOB markers,
sub-page reads in w25n_read).
- Scan all 1024 blocks for factory bad markers (non-FFh at byte 0 of
the spare area of page 0) and remap any user-area bad blocks via the
A1h BBM command. Idempotent across reboots: blocks already present
in the LUT are skipped, so repeated scans don't consume LUT slots.
Runtime:
- On E-FAIL from w25n_block_erase or P-FAIL from w25n_program_execute,
allocate a spare and issue A1h, then retry the operation once. The
chip routes the retry to the spare PBA transparently. Data buffer is
reloaded on program retry.
- Uncorrectable read ECC is left as -EIO (soft errors shouldn't trigger
permanent remap, and remapping discards data we may still recover).
Safeguards against burning LUT slots on bogus bad blocks:
- w25n_pick_free_spare erases each candidate spare as an active proof
of life before returning it - the factory OOB marker alone isn't
trusted.
- w25n_bbm_swap rejects A1h with LBA outside the user area or PBA
outside the spare pool.
Stack discipline for the logger-thread hot path:
- The 20-entry cached LUT lives in the device struct, not on the stack.
- w25n_read_bbm_lut decodes 4 bytes at a time instead of reading the
full 80-byte LUT dump into a local buffer.
Boot diagnostics are emitted via syslog so they appear unconditionally:
- [w25n] BBM scan summary (new/remapped/unremapped/previously-remapped/
LUT slots used)
- [w25n] W25N01GV ready line with user blocks, spare count, geometry,
and actual SPI frequency
- [w25n] per-remap info and warnings on runtime E-FAIL/P-FAIL paths
Note: existing littlefs filesystems become unmountable because the
block count shrinks from 1024 to 1000; both PX4 board init.c paths
already mount with autoformat so they reformat on first boot after
this change.
Signed-off-by: Julian Oes <julian@oes.ch>
This sensor was not present in the Make.defs file
AMG88xx Infrared Array Sensor
https://github.com/apache/nuttx/pull/12829
Moved:
These drivers can be used with sensor connected over SPI or I2C bus
Bosch Sensortec BMI160
Bosch Sensortec BMI088
Signed-off-by: simbit18 <simbit18@gmail.com>
Fixed a few bugs in the initial stm32_usbdrdhost.c implementation
when using a USB hub. Fixed fault when freeing control endpoints.
Fixed crash when disconnecting devices from hubs due ot use after free.
Signed-off-by: daniellizewski <daniellizewski@geotab.com>
Move the #endif preprocessor guard to after bmi160_transferspi()
so that both bmi160_configspi() and bmi160_transferspi() are
properly enclosed within the SPI conditional compilation block.
Signed-off-by: likun17 <likun17@xiaomi.com>
Serialization has been added to the paths of fb_read/fb_write, as well as
partial reading of plane/video information, updatearea, pandisplay, etc.
This covers the scenario where "one thread draws/switches via the character
device interface while another thread reads the framebuffer via the
character device interface", ensuring that the read framebuffer data
is complete and preventing screen tearing.
Signed-off-by: zhanxiaoqi <zhanxiaoqi@bytedance.com>
Implement get_supported_value, get_value and set_value callbacks
for IMGSENSOR_ID_HFLIP_VIDEO / IMGSENSOR_ID_HFLIP_STILL. This
allows applications to mirror the camera preview horizontally at
runtime via VIDIOC_S_CTRL + V4L2_CID_HFLIP.
The hardware mirror is controlled by register 0x14 (CISCTL_MODE1)
bit[0], which reverses the pixel readout order with zero CPU cost.
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
GC0308 register 0x24 bits[3:0] = 0x06 selects RGB565 output per
datasheet. On an 8-bit DVP bus the high byte is clocked out first,
so the pixel data arrives in memory in big-endian order (RGB565X).
Report V4L2_PIX_FMT_RGB565X so that userspace can detect this and
byte-swap if needed for a little-endian display path.
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
On power-up, MX25L25673G uses 3-byte addresses, so only the lower
128Mb (half the memory) can be accessed. This change ensures 4-byte
addresses are used so the whole memory can be used.
Co-Authored-By: Randy Rossi <randyrossi@geotab.com>
Signed-off-by: Carlos Sanchez <carlossanchez@geotab.com>
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.
A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.
Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
Add documentation for the RC/LIRC character driver subsystem covering
device registration, the LIRC interface, and usage from user space.
Remove placeholder empty files under drivers/rmt that were left over
from the rmtchar era and are no longer referenced.
Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
Replace the ESP-specific rmtchar upper-half with arch-local esp_lirc
adapters for Xtensa and RISC-V.
This moves the RMT upper-half out of drivers/rmt, registers LIRC
devices from the ESP board bring-up paths, and removes the old common
rmtchar driver and headers.
Also update the ESP Kconfig and build wiring to build esp_lirc when
ESP_RMT and DRIVERS_RC are enabled.
Fixes discovered during hardware validation:
- register TX as /dev/lirc1 so RX and TX do not collide
- parse the RX worker thread argument from the correct argv slot
- keep RX devices from advertising TX capability
Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
Add ES7210 audio ADC driver for NuttX implementing the audio
lower-half interface. Supports 4-channel recording via I2S with
configurable sample rate, bit depth, and mic gain.
- drivers/audio/es7210.c: Codec driver using LPWORK for async buffer
management, I2C register access, and NuttX audio buffer management
- drivers/audio/es7210.h: Internal register definitions and macros
- include/nuttx/audio/es7210.h: Public header with platform config
structure and es7210_initialize() API
- drivers/audio/Kconfig, Make.defs, CMakeLists.txt: Build system
integration for CONFIG_AUDIO_ES7210
Key implementation details:
- ES7210_SDP_NORMAL (normal I2S) instead of TDM, matching NuttX
I2S standard Philips mode
- ES7210_ADC_PGA_POWER_ON bit in gain registers REG43-46, required
for analog front-end amplifier power-on
- 50ms startup delay in es7210_start for codec clock stabilization
- I2S_IOCTL(AUDIOIOC_STOP) in es7210_stop to notify I2S layer,
preventing DMA from running without buffers after stop
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Add USB Video Class 1.1 gadget driver supporting Bulk transport
with uncompressed YUY2 video streaming. Resolution and frame
interval are negotiated dynamically via PROBE/COMMIT control.
- uvc.h: protocol constants, streaming control struct, public API
- uvc.c: class driver with PROBE/COMMIT, bulk EP, /dev/uvc0 chardev
- Kconfig/Make.defs: USBUVC config and build rules
- boardctl.c: BOARDIOC_USBDEV_UVC standalone init path
Hardened against host disconnect:
- Removed nxmutex_lock from USB interrupt context paths
- Added 30s semaphore timeout in uvc_write with EP_CANCEL fallback
- Drain stale wrsem counts in VS_COMMIT before new stream
- Guard uvc_streaming_stop() against double EP_CANCEL race
- Handle EP_SUBMIT returning -ESHUTDOWN gracefully
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
GC0308 sensor supports multiple output formats via register 0x24.
Add YUYV (YCbCr422) alongside existing RGB565 in fmtdescs and
configure the output format register dynamically in start_capture()
based on the requested pixel format.
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Ignore unsupported telnet subnegotiation payload until `IAC SE` so
option bytes do not leak into the first NSH command.
Keep existing NAWS handling intact and also treat `IAC IAC` inside
subnegotiation payload as an escaped `0xFF` data byte rather than a
subnegotiation terminator.
This makes subnegotiation parsing RFC-compliant for both unsupported
options and NAWS payload processing.
Signed-off-by: Shunchao Hu <ankohuu@gmail.com>
The MMC CMD6 bus width switch was gated on priv->buswidth which is
derived from the SD SCR register. For MMC cards this field is never
set (unless SDIO_CAPS_4BIT_ONLY), so the CMD6 was skipped while the
host PROCTL DTW was still changed - causing a bus width mismatch and
data transfer timeouts.
Fix by checking priv->caps instead of priv->buswidth for MMC cards.
Also select EXT_CSD_BUS_WIDTH_8 when host reports SDIO_CAPS_8BIT.
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
Correct duplicate "is is" word found in 181 files throughout the
codebase.
In most cases "is is" was changed to "is", but in contexts like
"MCU is is sleep mode" it was corrected to "MCU in sleep mode".
Also fixes a "the the" typo in net/inet/inet_sockif.c.
This is a pure style/documentation fix that improves code readability.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Fix 269 occurrences of duplicate "the" word typo found in 209 files
across source code, header files, and configuration.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
If power down mode is set, trying to read ID ends in an infinite loop
because w25_waitwritecomplete never returns as status register never
signalizes write complete. Therefore ensure the device is not in a
power down mode before trying to read from it.
This can be an issue if the board is trying to check for more NOR
memories on one SPI bus and one chip select. For example GD25 driver
returns the memory to power down state after read id is finished,
therefore board initialization is stuck in an infinite loop if it first
checks for GD25 and then fallbacks to W25.
The commit fixes the possible issue by ensuring W25 is brought back
to normal operation mode before trying to obtain the manufacturer ID.
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit adds the possibility to check for expander errors when
reading the data. This is optional if glerr_check or interr_check
fields in configuration are not zero.
If not zero, read operation also reads ISO1I813T_GLERR and
ISO1I813T_INTERR register and returns error if there is some error.
The user can control which errors he wants to check with
glerr_check and interr_check masks.
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
ftl_write() unconditionally routes writes through rwb_write() when
FTL_HAVE_RWBUFFER is defined, ignoring the O_DIRECT flag stored in
dev->oflags. This means callers that open with O_DIRECT expecting
unbuffered writes still get their data buffered in RAM.
The O_DIRECT flag is already checked in ftl_flush() to select
between direct and read-modify-write paths, but the buffering
decision in ftl_write() never consults it.
Add O_DIRECT checks in both ftl_write() and ftl_read() to bypass
rwbuffer entirely when the flag is set. For writes, go directly to
ftl_flush() and normalize the return value to match the block
driver convention (nsectors on success). For reads, go directly to
ftl_reload(), bypassing any read-ahead cache.
This gives O_DIRECT callers a complete bypass of the rwbuffer layer
for both reads and writes, matching the documented contract.
Signed-off-by: Neil Berkman <neil@xuku.com>
Add support for the GalaxyCore GC0308 VGA CMOS image sensor.
The driver implements the NuttX imgsensor interface and supports
VGA (640x480), QVGA (320x240), and QQVGA (160x120) resolutions
via Kconfig selection. Output format is RGB565X (big-endian).
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Add big-endian RGB565 (RGB565X) pixel format throughout the V4L2
video pipeline:
- IMGDATA_PIX_FMT_RGB565X in imgdata.h
- IMGSENSOR_PIX_FMT_RGB565X in imgsensor.h
- Format conversion and buffer size handling in v4l2_cap.c
This is needed by 8-bit DVP camera sensors that output RGB565 in
big-endian byte order (high byte first on the data bus).
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This patch introduces CONFIG_CC1101_SPIFREQ_BURST and
CONFIG_CC1101_SPIFREQ_SINGLE to Kconfig, allowing users to override
the default SPI frequencies for the CC1101 wireless driver.
Previously, these values were hardcoded to 6.5 MHz and 9.0 MHz
respectively. While these are safe defaults for many setups, specific
hardware designs, high routing capacitance, or platforms utilizing
internal GPIO switching matrices (such as the ESP32) can suffer from
signal integrity degradation at these speeds. By exposing these to
Kconfig, users can easily adjust the clock speeds to match their
hardware capabilities without modifying the core driver source.
Impact:
- Build: Adds two new Kconfig options under WL_CC1101.
- Runtime: Retains 6.5 MHz / 9.0 MHz defaults. Behavior only changes
if overridden via menuconfig.
Testing:
- Built with default values and custom Kconfig overrides.
- Hardware Testing: Tested on a sub-optimal platform utilizing an
internal GPIO matrix (ESP32). The CC1101 failed to load at the
default 6.5/9.0 MHz due to signal integrity issues. Downclocking
the frequencies to 4.0 MHz via Kconfig successfully restored
signal integrity and allowed the driver to initialize and operate
normally.
Signed-off-by: Chip L. <chplee@gmail.com>
This commit overhauls the CC1101 RF driver to address physical hardware
constraints, prevent register wrap-around overflows, and support accurate
dBm power scaling via the standard IOCTL interface.
What this change does:
1. Adds WLIOC_MSK and WLIOC_4FSK modulation support in `ioctl.h` and driver.
2. Replaces static PATABLE initialization with a dynamic Ramp-up curve
generator `cc1101_ioctl_apply_power()` based on lab calibration data.
3. Modifies WLIOC_SETTXPOWER and WLIOC_GETTXPOWER to process actual dBm
values with a nearest-match algorithm instead of raw array indices.
4. Removes DEBUGASSERT on user-space IOCTL pointers and replaces them
with strict -EFAULT checks.
5. Implements saturation clamping (e.g., mantissa to 256-511) to prevent
bitrate and frequency deviation calculation overflows.
6. Rebuilds volatile PATABLE memory upon SLEEP mode wake-up.
Why it is necessary & what it fixes:
- Fixes severe OOK modulation distortion and FSK spectral splatter caused
by statically assigned PATABLE indices.
- Fixes potential kernel panic in flat builds when IOCTL receives a NULL
pointer from user space.
- Fixes register wrap-around (silent failures) when users pass
out-of-bounds baud rate or FDEV values.
- Prevents RF silence after SLEEP mode due to PATABLE volatility.
- Resolves inaccurate power output when changing frequencies dynamically.
Impact:
Changes the behavior of CC1101 TX power and modulation IOCTLs to strictly
comply with standard `wlioc` definitions. Improves overall driver stability
and hardware safety.
Signed-off-by: Chip L. <chplee@gmail.com>
This commit refactors the CC1101 driver's read interface to comply with
the standard NuttX wireless character driver API and introduces extended
hardware operation modes.
- Migrate `cc1101_file_read` to accept and populate the standard
`struct wlioc_rx_hdr_s` instead of returning raw byte arrays.
- Implement `cc1101_calc_rssi_dbm_x100` to preserve the hardware's
0.5 dBm RSSI precision when scaling to 1/100 dBm units, eliminating
the integer truncation loss present in the legacy calculation.
- Add `CC1101IOC_SETOPMODE` and `CC1101IOC_GETOPMODE` IOCTLs.
- Introduce four RF operation modes (`enum cc1101_opmode_e`):
1. NORMAL: Standard packet mode with hardware filtering.
2. PROMISCUOUS: Packet mode bypassing address filtering and retaining
packets with CRC errors.
3. SYNC_SERIAL: Bypasses FIFO, routes clock and data to GDO0/GDO2.
4. ASYNC_SERIAL: Bypasses FIFO, routes async data to GDO2.
- Fix the `GS2200M_FIRST` IOCTL block offset in `wireless/ioctl.h` and
allocate a dedicated IOCTL block for CC1101.
Signed-off-by: Chip L. <chplee@gmail.com>