/* Copyright (c) 2026 ZhangYX * SPDX-License-Identifier: Apache-2.0 * * LY-Link Target RTT SDK (SEGGER RTT compatible) * Drop ly_rtt.h and ly_rtt.c into any ARM Cortex-M project (Keil / IAR / GCC). */ #ifndef LY_RTT_H #define LY_RTT_H #include #include #ifdef __cplusplus extern "C" { #endif /* Override via compiler -D flags if needed (default fits even 2 KiB RAM MCUs). */ #ifndef LY_RTT_UP_BUFFER_SIZE #define LY_RTT_UP_BUFFER_SIZE 512U #endif #ifndef LY_RTT_DOWN_BUFFER_SIZE #define LY_RTT_DOWN_BUFFER_SIZE 64U #endif /* * Set -DLY_RTT_REDIRECT_PRINTF=1 to automatically redirect standard printf() * to RTT on Keil MDK (AC5/AC6), IAR EWARM, and ARM GCC (newlib). */ #ifndef LY_RTT_REDIRECT_PRINTF #define LY_RTT_REDIRECT_PRINTF 0 #endif /** * Initialize the RTT control block and publish the "SEGGER RTT" signature. * Calling this early in main() lets LY-Link detect and switch to RTT immediately. * Safe to call multiple times; also called automatically on first read/write. */ void ly_rtt_init(void); /** Write raw bytes to host (Up channel 0, non-blocking, drops on overflow). */ size_t ly_rtt_write(const void *data, size_t len); /** Write a NUL-terminated string to host (Up channel 0). */ size_t ly_rtt_puts(const char *str); /** * Lightweight formatted print to host (Up channel 0). * Supports: %c %s %d %i %u %x %X %p %% with optional width and zero-padding (e.g. %08X). */ int ly_rtt_printf(const char *fmt, ...); /** Return number of unread bytes sent from host (Down channel 0). */ size_t ly_rtt_available(void); /** Read up to max_len bytes from host (Down channel 0, non-blocking). */ size_t ly_rtt_read(void *buf, size_t max_len); /** Read a single byte from host, or -1 if none available. */ int ly_rtt_getchar(void); #ifdef __cplusplus } #endif #endif /* LY_RTT_H */