menu "Newlib"

    choice NEWLIB_STDOUT_LINE_ENDING
        prompt "Line ending for UART output"
        default NEWLIB_STDOUT_LINE_ENDING_CRLF
        help
            This option allows configuring the desired line endings sent to UART
            when a newline ('\n', LF) appears on stdout.
            Three options are possible:

            CRLF: whenever LF is encountered, prepend it with CR

            LF: no modification is applied, stdout is sent as is

            CR: each occurrence of LF is replaced with CR

            This option doesn't affect behavior of the UART driver (drivers/uart.h).

        config NEWLIB_STDOUT_LINE_ENDING_CRLF
            bool "CRLF"
        config NEWLIB_STDOUT_LINE_ENDING_LF
            bool "LF"
        config NEWLIB_STDOUT_LINE_ENDING_CR
            bool "CR"
    endchoice

    choice NEWLIB_STDIN_LINE_ENDING
        prompt "Line ending for UART input"
        default NEWLIB_STDIN_LINE_ENDING_CR
        help
            This option allows configuring which input sequence on UART produces
            a newline ('\n', LF) on stdin.
            Three options are possible:

            CRLF: CRLF is converted to LF

            LF: no modification is applied, input is sent to stdin as is

            CR: each occurrence of CR is replaced with LF

            This option doesn't affect behavior of the UART driver (drivers/uart.h).

        config NEWLIB_STDIN_LINE_ENDING_CRLF
            bool "CRLF"
        config NEWLIB_STDIN_LINE_ENDING_LF
            bool "LF"
        config NEWLIB_STDIN_LINE_ENDING_CR
            bool "CR"
    endchoice

    config NEWLIB_NANO_FORMAT
        bool "Enable 'nano' formatting options for printf/scanf family"
        default y if IDF_TARGET_ESP32C2
        help
            In most chips the ROM contains parts of newlib C library, including printf/scanf family
            of functions. These functions have been compiled with so-called "nano"
            formatting option. This option doesn't support 64-bit integer formats and C99
            features, such as positional arguments.

            For more details about "nano" formatting option, please see newlib readme file,
            search for '--enable-newlib-nano-formatted-io':
            https://sourceware.org/newlib/README

            If this option is enabled and the ROM contains functions from newlib-nano, the build system
            will use functions available in ROM, reducing the application binary size.
            Functions available in ROM run faster than functions which run from flash. Functions available
            in ROM can also run when flash instruction cache is disabled.

            Some chips (e.g. ESP32-C6) has the full formatting versions of printf/scanf in ROM instead of
            the nano versions and in this building with newlib nano might actually increase the size of
            the binary. Which functions are present in ROM can be seen from ROM caps:
            ESP_ROM_HAS_NEWLIB_NANO_FORMAT and ESP_ROM_HAS_NEWLIB_NORMAL_FORMAT.

            If you need 64-bit integer formatting support or C99 features, keep this
            option disabled.

    choice NEWLIB_TIME_SYSCALL
        prompt "Timers used for gettimeofday function"
        default NEWLIB_TIME_SYSCALL_USE_RTC_HRT
        help
            This setting defines which hardware timers are used to
            implement 'gettimeofday' and 'time' functions in C library.

            - If both high-resolution (systimer for all targets except ESP32)
                and RTC timers are used, timekeeping will continue in deep sleep.
                Time will be reported at 1 microsecond resolution.
                This is the default, and the recommended option.
            - If only high-resolution timer (systimer) is used, gettimeofday will
                provide time at microsecond resolution.
                Time will not be preserved when going into deep sleep mode.
            - If only RTC timer is used, timekeeping will continue in
                deep sleep, but time will be measured at 6.(6) microsecond
                resolution. Also the gettimeofday function itself may take
                longer to run.
            - If no timers are used, gettimeofday and time functions
                return -1 and set errno to ENOSYS; they are defined as weak,
                so they could be overridden.
                If you want to customize gettimeofday() and other time functions,
                please choose this option and refer to the 'time.c' source file
                for the exact prototypes of these functions.

            - When RTC is used for timekeeping, two RTC_STORE registers are
                used to keep time in deep sleep mode.

        config NEWLIB_TIME_SYSCALL_USE_RTC_HRT
            bool "RTC and high-resolution timer"
            select ESP_TIME_FUNCS_USE_RTC_TIMER
            select ESP_TIME_FUNCS_USE_ESP_TIMER
        config NEWLIB_TIME_SYSCALL_USE_RTC
            bool "RTC"
            select ESP_TIME_FUNCS_USE_RTC_TIMER
        config NEWLIB_TIME_SYSCALL_USE_HRT
            bool "High-resolution timer"
            select ESP_TIME_FUNCS_USE_ESP_TIMER
        config NEWLIB_TIME_SYSCALL_USE_NONE
            bool "None"
            select ESP_TIME_FUNCS_USE_NONE
    endchoice

endmenu # Newlib

config STDATOMIC_S32C1I_SPIRAM_WORKAROUND
    bool
    default SPIRAM && (IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3) && !IDF_TOOLCHAIN_CLANG # TODO IDF-9032