#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

if ARCH_CHIP_ESP32S3

comment "ESP32-S3 Configuration Options"

choice
	prompt "ESP32-S3 Chip Selection"
	default ARCH_CHIP_ESP32S3WROOM1

config ARCH_CHIP_ESP32S3WROOM1
	bool "ESP32-S3-WROOM-1"
	select ESP32S3_FLASH_4M
	---help---
		Generic module with an embedded ESP32-S3.

config ARCH_CHIP_ESP32S3WROOM2
	bool "ESP32-S3-WROOM-2"
	select ESP32S3_FLASH_16M
	select ESP32S3_PSRAM_8M
	---help---
		Generic module with an embedded ESP32-S3.

config ARCH_CHIP_ESP32S3MINI1
	bool "ESP32-S3-MINI-1"
	select ESP32S3_FLASH_8M
	---help---
		Generic module with an embedded ESP32-S3.

endchoice # ESP32-S3 Chip Selection

choice ESP32S3_DEFAULT_CPU_FREQ
	prompt "CPU frequency"
	default ESP32S3_DEFAULT_CPU_FREQ_240
	---help---
		CPU frequency to be set on application startup.

	config ESP32S3_DEFAULT_CPU_FREQ_80
		bool "80 MHz"

	config ESP32S3_DEFAULT_CPU_FREQ_160
		bool "160 MHz"

	config ESP32S3_DEFAULT_CPU_FREQ_240
		bool "240 MHz"

endchoice # CPU frequency

config ESP32S3_DEFAULT_CPU_FREQ_MHZ
	int
	default 80 if ESP32S3_DEFAULT_CPU_FREQ_80
	default 160 if ESP32S3_DEFAULT_CPU_FREQ_160
	default 240 if ESP32S3_DEFAULT_CPU_FREQ_240

menu "Cache configuration"

choice
	prompt "Instruction cache size"
	default ESP32S3_INSTRUCTION_CACHE_16KB
	---help---
		Instruction cache size to be set on application startup.
		If you use 16KB instruction cache rather than 32KB instruction cache,
		then the other 16KB will be managed by heap allocator.

config ESP32S3_INSTRUCTION_CACHE_16KB
	bool "16KB"
	---help---
		Use 16KB of SRAM as Instruction Cache

config ESP32S3_INSTRUCTION_CACHE_32KB
	bool "32KB"
	---help---
		Use 32KB of SRAM as Instruction Cache

endchoice # Instruction cache size

config ESP32S3_INSTRUCTION_CACHE_SIZE
	hex
	default 0x4000 if ESP32S3_INSTRUCTION_CACHE_16KB
	default 0x8000 if ESP32S3_INSTRUCTION_CACHE_32KB

choice ESP32S3_ICACHE_ASSOCIATED_WAYS
	prompt "Instruction cache associated ways"
	default ESP32S3_INSTRUCTION_CACHE_8WAYS
	---help---
		Instruction cache associated ways to be set on application startup.

	config ESP32S3_INSTRUCTION_CACHE_4WAYS
		bool "4 ways"

	config ESP32S3_INSTRUCTION_CACHE_8WAYS
		bool "8 ways"

endchoice

config ESP32S3_ICACHE_ASSOCIATED_WAYS
	int
	default 4 if ESP32S3_INSTRUCTION_CACHE_4WAYS
	default 8 if ESP32S3_INSTRUCTION_CACHE_8WAYS

choice ESP32S3_INSTRUCTION_CACHE_LINE_SIZE
	prompt "Instruction cache line size"
	default ESP32S3_INSTRUCTION_CACHE_LINE_32B
	---help---
		Instruction cache line size to be set on application startup.

	config ESP32S3_INSTRUCTION_CACHE_LINE_16B
		bool "16 Bytes"
		depends on ESP32S3_INSTRUCTION_CACHE_16KB

	config ESP32S3_INSTRUCTION_CACHE_LINE_32B
		bool "32 Bytes"

endchoice

config ESP32S3_INSTRUCTION_CACHE_LINE_SIZE
	int
	default 16 if ESP32S3_INSTRUCTION_CACHE_LINE_16B
	default 32 if ESP32S3_INSTRUCTION_CACHE_LINE_32B

choice
	prompt "Data cache size"
	default ESP32S3_DATA_CACHE_32KB
	---help---
		Data cache size to be set on application startup.
		If you use 32KB data cache rather than 64KB data cache,
		the other 32KB will be added to the heap.

config ESP32S3_DATA_CACHE_16KB
	bool "16KB"
	---help---
		Use 16KB of SRAM as Data Cache

config ESP32S3_DATA_CACHE_32KB
	bool "32KB"
	---help---
		Use 32KB of SRAM as Data Cache

config ESP32S3_DATA_CACHE_64KB
	bool "64KB"
	---help---
		Use 64KB of SRAM as Data Cache

endchoice # Data cache size

config ESP32S3_DATA_CACHE_SIZE
	hex
	# For 16KB the actual configuration is 32kb cache, but 16kb will be reserved for heap at startup
	default 0x8000 if ESP32S3_DATA_CACHE_16KB
	default 0x8000 if ESP32S3_DATA_CACHE_32KB
	default 0x10000 if ESP32S3_DATA_CACHE_64KB

choice ESP32S3_DCACHE_ASSOCIATED_WAYS
	prompt "Data cache associated ways"
	default ESP32S3_DATA_CACHE_8WAYS
	---help---
		Data cache associated ways to be set on application startup.

	config ESP32S3_DATA_CACHE_4WAYS
		bool "4 ways"

	config ESP32S3_DATA_CACHE_8WAYS
		bool "8 ways"

endchoice

config ESP32S3_DCACHE_ASSOCIATED_WAYS
	int
	default 4 if ESP32S3_DATA_CACHE_4WAYS
	default 8 if ESP32S3_DATA_CACHE_8WAYS

choice ESP32S3_DATA_CACHE_LINE_SIZE
	prompt "Data cache line size"
	default ESP32S3_DATA_CACHE_LINE_32B
	---help---
		Data cache line size to be set on application startup.

	config ESP32S3_DATA_CACHE_LINE_16B
		bool "16 Bytes"
		depends on ESP32S3_DATA_CACHE_16KB || ESP32S3_DATA_CACHE_32KB

	config ESP32S3_DATA_CACHE_LINE_32B
		bool "32 Bytes"

	config ESP32S3_DATA_CACHE_LINE_64B
		bool "64 Bytes"

endchoice

config ESP32S3_DATA_CACHE_LINE_SIZE
	int
	default 16 if ESP32S3_DATA_CACHE_LINE_16B
	default 32 if ESP32S3_DATA_CACHE_LINE_32B
	default 64 if ESP32S3_DATA_CACHE_LINE_64B

endmenu # Cache config

config ESP32S3_ULP_COPROC_ENABLED
	bool "Enable Ultra Low Power (ULP) Coprocessor"
	default n
	---help---
		Set to 'y' if you plan to load a firmware for the coprocessor.

config ESP32S3_ULP_COPROC_RESERVE_MEM
	int
	prompt "RTC slow memory reserved for coprocessor" if ESP32S3_ULP_COPROC_ENABLED
	default 512 if ESP32S3_ULP_COPROC_ENABLED
	range 32 8176 if ESP32S3_ULP_COPROC_ENABLED
	default 0 if !ESP32S3_ULP_COPROC_ENABLED
	range 0 0 if !ESP32S3_ULP_COPROC_ENABLED
	help
		Bytes of memory to reserve for ULP coprocessor firmware & data.
		Data is reserved at the beginning of RTC slow memory.

config ESP32S3_FLASH_4M
	bool
	default n

config ESP32S3_FLASH_8M
	bool
	default n

config ESP32S3_FLASH_16M
	bool
	default n

config ESP32S3_ESPTOOLPY_NO_STUB
	bool "Disable download stub"
	default n
	---help---
		The flasher tool sends a precompiled download stub first by default.
		That stub allows things like compressed downloads and more.
		Usually you should not need to disable that feature.
		It is only required to be disabled in certain scenarios when either
		Secure Boot V2 or Flash Encryption is enabled.

config ESP32S3_FLASH_DETECT
	bool "Auto-detect FLASH size"
	default y
	---help---
		Auto detect flash size when flashing.

config ESP32S3_PSRAM_8M
	bool
	default n

choice ESP32S3_FLASH_MODE
	prompt "SPI FLASH mode"
	default ESP32S3_FLASH_MODE_DIO
	---help---
		These options control how many I/O pins are used for communication
		with the attached SPI flash chip.
		The option selected here is then used by esptool when flashing.

	config ESP32S3_FLASH_MODE_DIO
		bool "Dual IO (DIO)"

	config ESP32S3_FLASH_MODE_DOUT
		bool "Dual Output (DOUT)"

	config ESP32S3_FLASH_MODE_QIO
		bool "Quad IO (QIO)"

	config ESP32S3_FLASH_MODE_QOUT
		bool "Quad Output (QOUT)"

endchoice # ESP32S3_FLASH_MODE

choice ESP32S3_FLASH_FREQ
	prompt "SPI FLASH frequency"
	default ESP32S3_FLASH_FREQ_40M
	---help---
		SPI FLASH frequency

	config ESP32S3_FLASH_FREQ_120M
		bool "120 MHz"

	config ESP32S3_FLASH_FREQ_80M
		bool "80 MHz"

	config ESP32S3_FLASH_FREQ_40M
		bool "40 MHz"

	config ESP32S3_FLASH_FREQ_20M
		bool "20 MHz"

endchoice # ESP32S3_FLASH_FREQ

config ESP32S3_RUN_IRAM
	bool "Run from IRAM"
	default n
	---help---
		This loads all of NuttX inside IRAM. Used to test somewhat small
		images that can fit entirely in IRAM.

menu "ESP32-S3 Peripheral Selection"

config ESP32S3_UART
	bool
	default n

config ESP32S3_TIMER
	bool
	default n

config ESP32S3_WDT
	bool
	default n

config ESP32S3_SPIRAM
	bool "SPI RAM Support"
	default n

config ESP32S3_UART0
	bool "UART 0"
	default n
	select ESP32S3_UART
	select UART0_SERIALDRIVER
	select ARCH_HAVE_SERIAL_TERMIOS

config ESP32S3_UART1
	bool "UART 1"
	default n
	select ESP32S3_UART
	select UART1_SERIALDRIVER
	select ARCH_HAVE_SERIAL_TERMIOS

config ESP32S3_UART2
	bool "UART 2"
	default n
	select ESP32S3_UART
	select UART2_SERIALDRIVER
	select ARCH_HAVE_SERIAL_TERMIOS

config ESP32S3_TIMER0
	bool "54-bit Timer 0 (Group 0 Timer 0)"
	default n
	select ESP32S3_TIMER
	---help---
		Enables Timer 0

config ESP32S3_TIMER1
	bool "54-bit Timer 1 (Group 0 Timer 1)"
	default n
	select ESP32S3_TIMER
	---help---
		Enables Timer 1

config ESP32S3_TIMER2
	bool "54-bit Timer 2 (Group 1 Timer 0)"
	default n
	select ESP32S3_TIMER
	---help---
		Enables Timer 2

config ESP32S3_TIMER3
	bool "54-bit Timer 3 (Group 1 Timer 1)"
	default n
	select ESP32S3_TIMER
	---help---
		Enables Timer 3

config ESP32S3_MWDT0
	bool "Main System Watchdog Timer (Group 0)"
	default n
	select ESP32S3_WDT
	---help---
		Includes MWDT0. This watchdog timer is part of the Group 0
		timer submodule.

config ESP32S3_MWDT1
	bool "Main System Watchdog Timer (Group 1)"
	default n
	select ESP32S3_WDT
	---help---
		Includes MWDT1. This watchdog timer is part of the Group 0
		timer submodule.

config ESP32S3_RWDT
	bool "RTC Watchdog Timer"
	default n
	select ESP32S3_WDT
	---help---
		Includes RWDT. This watchdog timer is from the RTC module.
		When it is selected, if the developer sets it to reset on expiration
		it will reset Main System and the RTC module. If you don't want
		to have the RTC module reset, please, use the Timers' Module WDTs.
		They will only reset Main System.

config ESP32S3_RT_TIMER
	bool "Real-Time Timer"
	default n
	---help---
		Real-Time Timer is relying upon the Systimer 1.

endmenu # ESP32-S3 Peripheral Selection

menu "SPI RAM Configuration"
	depends on ESP32S3_SPIRAM

choice ESP32S3_SPIRAM_MODE
	prompt "Mode (QUAD/OCT) of SPI RAM chip"
	default ESP32S3_SPIRAM_MODE_QUAD

config ESP32S3_SPIRAM_MODE_QUAD
	bool "Quad Mode PSRAM"

config ESP32S3_SPIRAM_MODE_OCT
	bool "Octal Mode PSRAM"

endchoice # ESP32S3_SPIRAM_MODE

config ESP32S3_DEFAULT_PSRAM_CLK_IO
	int "PSRAM CLK pin"
	default 30

config ESP32S3_DEFAULT_PSRAM_CS_IO
	int "PSRAM CS pin"
	default 26

choice ESP32S3_SPIRAM_TYPE
	prompt "Type of SPI RAM chip in use"
	default ESP32S3_SPIRAM_TYPE_AUTO

config ESP32S3_SPIRAM_TYPE_AUTO
	bool "Auto-detect"

config ESP32S3_SPIRAM_TYPE_ESPPSRAM16
	bool "ESP-PSRAM16 or APS1604"

config ESP32S3_SPIRAM_TYPE_ESPPSRAM32
	bool "ESP-PSRAM32 or IS25WP032"

config ESP32S3_SPIRAM_TYPE_ESPPSRAM64
	bool "ESP-PSRAM64, LY68L6400 or APS6408"

endchoice # ESP32S3_SPIRAM_TYPE

config ESP32S3_SPIRAM_SIZE
	int
	default -1 if ESP32S3_SPIRAM_TYPE_AUTO
	default 2097152 if ESP32S3_SPIRAM_TYPE_ESPPSRAM16
	default 4194304 if ESP32S3_SPIRAM_TYPE_ESPPSRAM32
	default 8388608 if ESP32S3_SPIRAM_TYPE_ESPPSRAM64
	default 16777216 if ESP32S3_SPIRAM_TYPE_ESPPSRAM128
	default 33554432 if ESP32S3_SPIRAM_TYPE_ESPPSRAM256
	default 0

config ESP32S3_SPIRAM_FETCH_INSTRUCTIONS
	bool "Cache fetch instructions from SPI RAM"
	default n
	---help---
		If enabled, instruction in flash will be copied into SPIRAM.
		If ESP32S3_SPIRAM_RODATA is also enabled, you can run the instruction
		when erasing or programming the flash.

config ESP32S3_SPIRAM_RODATA
	bool "Cache load read only data from SPI RAM"
	default n
	---help---
		If enabled, rodata in flash will be copied into SPIRAM.
		If ESP32S3_ESP32S2_SPIRAM_FETCH_INSTRUCTIONS is also enabled,
		you can run the instruction when erasing or programming the
		flash.

choice ESP32S3_SPIRAM_SPEED
	prompt "Set RAM clock speed"
	default ESP32S3_SPIRAM_SPEED_40M
	---help---
		Select the speed for the SPI RAM chip.

config ESP32S3_SPIRAM_SPEED_40M
	bool "40MHz clock speed"

config ESP32S3_SPIRAM_SPEED_80M
	bool "80MHz clock speed"

config ESP32S3_SPIRAM_SPEED_120M
	bool "120MHz clock speed"

endchoice # ESP32S3_SPIRAM_SPEED

config ESP32S3_SPIRAM_SPEED
	int
	default 120 if ESP32S3_SPIRAM_SPEED_120M
	default 80 if ESP32S3_SPIRAM_SPEED_80M
	default 40 if ESP32S3_SPIRAM_SPEED_40M

config ESP32S3_SPIRAM_BOOT_INIT
	bool "Initialize SPI RAM during startup"
	depends on ESP32S3_SPIRAM
	default y
	---help---
		If this is enabled, the SPI RAM will be enabled during initial
		boot. Unless you have specific requirements, you'll want to leave
		this enabled so memory allocated during boot-up can also be
		placed in SPI RAM.

config ESP32S3_SPIRAM_IGNORE_NOTFOUND
	bool "Ignore PSRAM when not found"
	default n
	depends on ESP32S3_SPIRAM_BOOT_INIT && !BOOT_SDRAM_DATA
	---help---
		Normally, if psram initialization is enabled during compile time
		but not found at runtime, it is seen as an error making the CPU
		panic. If this is enabled, booting will complete but no PSRAM
		will be available.

endmenu # SPI RAM Configuration

menu "UART Configuration"
	depends on ESP32S3_UART

if ESP32S3_UART0

config ESP32S3_UART0_TXPIN
	int "UART0 Tx Pin"
	default 43
	range 0 48

config ESP32S3_UART0_RXPIN
	int "UART0 Rx Pin"
	default 44
	range 0 48

config ESP32S3_UART0_RTSPIN
	int "UART0 RTS Pin"
	depends on SERIAL_IFLOWCONTROL
	default 15
	range 0 48

config ESP32S3_UART0_CTSPIN
	int "UART0 CTS Pin"
	depends on SERIAL_OFLOWCONTROL
	default 16
	range 0 48

endif # ESP32S3_UART0

if ESP32S3_UART1

config ESP32S3_UART1_TXPIN
	int "UART1 Tx Pin"
	default 17
	range 0 48

config ESP32S3_UART1_RXPIN
	int "UART1 Rx Pin"
	default 18
	range 0 48

config ESP32S3_UART1_RTSPIN
	int "UART1 RTS Pin"
	depends on SERIAL_IFLOWCONTROL
	default 19
	range 0 48

config ESP32S3_UART1_CTSPIN
	int "UART1 CTS Pin"
	depends on SERIAL_OFLOWCONTROL
	default 20
	range 0 48

endif # ESP32S3_UART1

if ESP32S3_UART2

config ESP32S3_UART2_TXPIN
	int "UART2 Tx Pin"
	default 17
	range 0 48

config ESP32S3_UART2_RXPIN
	int "UART2 Rx Pin"
	default 16
	range 0 48

config ESP32S3_UART2_RTSPIN
	int "UART2 RTS Pin"
	depends on SERIAL_IFLOWCONTROL
	default 35
	range 0 48

config ESP32S3_UART2_CTSPIN
	int "UART2 CTS Pin"
	depends on SERIAL_OFLOWCONTROL
	default 36
	range 0 48

endif # ESP32S3_UART2

endmenu # UART Configuration

menu "Timer/Counter Configuration"
	depends on ESP32S3_TIMER

config ESP32S3_ONESHOT
	bool "One-shot wrapper"
	default n
	---help---
		Enable a wrapper around the low level timer/counter functions to
		support one-shot timer.

config ESP32S3_FREERUN
	bool "Free-running wrapper"
	default n
	---help---
		Enable a wrapper around the low level timer/counter functions to
		support a free-running timer.

endmenu # Timer/Counter Configuration

menu "Real-Time Timer Configuration"
	depends on ESP32S3_RT_TIMER

config ESP32S3_RT_TIMER_TASK_NAME
	string "Real-Time Timer task name"
	default "rt_timer"

config ESP32S3_RT_TIMER_TASK_PRIORITY
	int "Real-Time Timer task priority"
	default 223
	---help---
		Priority level of the RT Timer task.
		Must be lower than the SCHED_HPWORKPRIORITY.

config ESP32S3_RT_TIMER_TASK_STACK_SIZE
	int "Real-Time Timer task stack size"
	default 2048

endmenu # Real-Time Timer Configuration

config ESP32S3_TICKLESS
	bool "Enable Tickless OS"
	default n
	select ARCH_HAVE_TICKLESS
	select SCHED_TICKLESS

config ESP32S3_SPIFLASH
	bool "SPI Flash MTD Partition"
	default n

menu "SPI Flash configuration"
	depends on ESP32S3_SPIFLASH

comment "General storage MTD configuration"

config ESP32S3_MTD
	bool "MTD driver"
	default y
	select MTD
	select MTD_BYTE_WRITE
	select MTD_PARTITION
	---help---
		Initialize an MTD driver for the ESP32-S3 SPI Flash, which will
		add an entry at /dev for application access from userspace.

config ESP32S3_SPIFLASH_MTD_BLKSIZE
	int "Storage MTD block size"
	default 256
	depends on ESP32S3_MTD

config ESP32S3_STORAGE_MTD_DEBUG
	bool "Storage MTD Debug"
	default n
	depends on ESP32S3_MTD && DEBUG_FS_INFO
	---help---
		If this option is enabled, Storage MTD driver read and write functions
		will output input parameters and return values (if applicable).

endmenu # SPI Flash configuration

menu "Application Image Configuration"

choice
	prompt "Application Image Format"
	default ESP32S3_APP_FORMAT_LEGACY
	---help---
		Depending on the chosen 2nd stage bootloader, the application may
		be required to be perform a specific startup routine. Furthermore,
		the image binary must be formatted according to the definition from
		the 2nd stage bootloader.

config ESP32S3_APP_FORMAT_LEGACY
	bool "Legacy format"
	---help---
		This is the legacy application image format, as supported by the ESP-IDF
		2nd stage bootloader.

endchoice # Application Image Format

choice
	prompt "Source for bootloader binaries"
	default ESP32S3_BOOTLOADER_DOWNLOAD_PREBUILT
	---help---
		Select the action to be taken by the build system for the
		"make bootloader" target.

config ESP32S3_BOOTLOADER_DOWNLOAD_PREBUILT
	bool "Download prebuilt binaries"
	---help---
		The build system will download the prebuilt binaries from
		https://github.com/espressif/esp-nuttx-bootloader according to the chosen
		Application Image Format (ESP32S3_APP_FORMAT_LEGACY or ESP32S3_APP_FORMAT_MCUBOOT)

config ESP32S3_BOOTLOADER_BUILD_FROM_SOURCE
	bool "Build binaries from source"
	---help---
		The build system will build all the required binaries from source. It will clone
		the https://github.com/espressif/esp-nuttx-bootloader repository and build a
		custom bootloader according to the chosen Application Image Format
		(ESP32S3_APP_FORMAT_LEGACY or ESP32S3_APP_FORMAT_MCUBOOT) and partition information.

endchoice

config ESP32S3_PARTITION_TABLE_OFFSET
	hex "Partition Table offset"
	default 0x8000
	depends on ESP32S3_APP_FORMAT_LEGACY

endmenu # Application Image Configuration

endif # ARCH_CHIP_ESP32S3
