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

if ARCH_CHIP_ESP32S2

comment "ESP32-S2 Configuration Options"

choice
	prompt "ESP32-S2 Chip Selection"
	default ARCH_CHIP_ESP32S2WROVER

config ARCH_CHIP_ESP32S2WROVER
	bool "ESP32-S2-WROVER"
	select ESP32S2_FLASH_4M
	select ESP32S2_PSRAM_2M
	select ARCH_HAVE_I2CRESET
	---help---
		Generic module with an embedded ESP32-S2

endchoice # ESP32-S2 Chip Selection

config ESPRESSIF_CHIP_SERIES
	string
	default "esp32s2"

choice ESP32S2_DEFAULT_CPU_FREQ
	prompt "CPU Frequency"
	default ESP32S2_DEFAULT_CPU_FREQ_240
	---help---
		CPU frequency to be set on application startup.

config ESP32S2_DEFAULT_CPU_FREQ_80
	bool "80 MHz"

config ESP32S2_DEFAULT_CPU_FREQ_160
	bool "160 MHz"

config ESP32S2_DEFAULT_CPU_FREQ_240
	bool "240 MHz"

endchoice # CPU Frequency

config ESP32S2_DEFAULT_CPU_FREQ_MHZ
	int
	default 80 if ESP32S2_DEFAULT_CPU_FREQ_80
	default 160 if ESP32S2_DEFAULT_CPU_FREQ_160
	default 240 if ESP32S2_DEFAULT_CPU_FREQ_240

menu "Cache Configuration"

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

config ESP32S2_INSTRUCTION_CACHE_8KB
	bool "8KB"
	---help---
		Use 8KB of SRAM as Instruction Cache

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

endchoice # Instruction cache size

config ESP32S2_INSTRUCTION_CACHE_SIZE
	hex
	default 0x2000 if ESP32S2_INSTRUCTION_CACHE_8KB
	default 0x4000 if ESP32S2_INSTRUCTION_CACHE_16KB

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

config ESP32S2_INSTRUCTION_CACHE_LINE_16B
	bool "16 Bytes"
	depends on ESP32S2_INSTRUCTION_CACHE_16KB

config ESP32S2_INSTRUCTION_CACHE_LINE_32B
	bool "32 Bytes"

endchoice

config ESP32S2_INSTRUCTION_CACHE_LINE_SIZE
	int
	default 16 if ESP32S2_INSTRUCTION_CACHE_LINE_16B
	default 32 if ESP32S2_INSTRUCTION_CACHE_LINE_32B

choice ESP32S2_DATA_CACHE_SIZE
	prompt "Data cache size"
	default ESP32S2_DATA_CACHE_0KB if !ESP32S2_SPIRAM
	default ESP32S2_DATA_CACHE_8KB if ESP32S2_SPIRAM
	---help---
		Data cache size to be set on application startup.
		If you use 0KB data cache, the other 16KB will be added to the heap.
		If you use 8KB data cache rather than 16KB data cache, the other 8KB
		will be added to the heap.

config ESP32S2_DATA_CACHE_0KB
	depends on !ESP32S2_SPIRAM
	bool "No DATA CACHE"
	---help---
		Disable Data Cache

config ESP32S2_DATA_CACHE_8KB
	bool "8KB"
	---help---
		Use 8KB of SRAM as Data Cache

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

endchoice # Data cache size

config ESP32S2_DATA_CACHE_SIZE
	hex
	default 0x0 if ESP32S2_DATA_CACHE_0KB
	default 0x2000 if ESP32S2_DATA_CACHE_8KB
	default 0x4000 if ESP32S2_DATA_CACHE_16KB

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

config ESP32S2_DATA_CACHE_LINE_16B
	bool "16 Bytes"

config ESP32S2_DATA_CACHE_LINE_32B
	bool "32 Bytes"

endchoice

config ESP32S2_DATA_CACHE_LINE_SIZE
	int
	default 16 if ESP32S2_DATA_CACHE_LINE_16B
	default 32 if ESP32S2_DATA_CACHE_LINE_32B

endmenu # Cache Configuration

config ESP32S2_FLASH_2M
	bool
	default n

config ESP32S2_FLASH_4M
	bool
	default n

config ESP32S2_FLASH_8M
	bool
	default n

config ESP32S2_FLASH_16M
	bool
	default n

config ESP32S2_PSRAM_2M
	bool
	default n

config ESP32S2_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 ESP32S2_FLASH_DETECT
	bool "Auto-detect FLASH size"
	default y
	---help---
		Auto detect flash size when flashing.

config ESP32S2_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-S2 Peripheral Selection"

source "arch/xtensa/src/common/espressif/Kconfig"

config ESP32S2_UART
	bool
	default n

config ESP32S2_I2C
	bool
	default n

config ESP32S2_SPI
	bool
	default n

config ESP32S2_TIMER
	bool
	default n

config ESP32S2_WDT
	bool
	default n

config ESP32S2_RNG
	bool "Random Number Generator (RNG)"
	default n
	select ARCH_HAVE_RNG
	---help---
		ESP32-S2 supports a RNG that passed on Dieharder test suite.

config ESP32S2_I2S
	bool "I2S"
	default n
	select I2S
	select ARCH_DMA
	select ESP32S2_GPIO_IRQ
	---help---
		See the Board Selection menu to configure the pins used by I2S.

if ESP32S2_I2S

config ESP32S2_I2S_RX
	bool "Enable I2S receiver"
	default y
	---help---
		Enable I2S receive logic

config ESP32S2_I2S_TX
	bool "Enable I2S transmitter"
	default y
	---help---
		Enable I2S transmit logic

choice
	prompt "I2S role"
	default ESP32S2_I2S_ROLE_MASTER
	---help---
		Selects the operation role of the I2S.

config ESP32S2_I2S_ROLE_MASTER
	bool "Master"

config ESP32S2_I2S_ROLE_SLAVE
	bool "Slave"

endchoice

choice
	prompt "Bit width"
	---help---
		Selects the valid data bits per sample.
		Note that this option may be overwritten by the audio
		according to the bit width of the file being played

config ESP32S2_I2S_DATA_BIT_WIDTH_8BIT
	bool "8 bits"

config ESP32S2_I2S_DATA_BIT_WIDTH_16BIT
	bool "16 bits"

config ESP32S2_I2S_DATA_BIT_WIDTH_24BIT
	bool "24 bits"

config ESP32S2_I2S_DATA_BIT_WIDTH_32BIT
	bool "32 bits"

endchoice

config ESP32S2_I2S_DATA_BIT_WIDTH
	int
	default 8 if ESP32S2_I2S_DATA_BIT_WIDTH_8BIT
	default 16 if ESP32S2_I2S_DATA_BIT_WIDTH_16BIT
	default 24 if ESP32S2_I2S_DATA_BIT_WIDTH_24BIT
	default 32 if ESP32S2_I2S_DATA_BIT_WIDTH_32BIT

config ESP32S2_I2S_SAMPLE_RATE
	int "I2S sample rate"
	default 44100
	range 8000 48000
	---help---
		Selects the sample rate.
		Note that this option may be overwritten by the audio
		according to the bit width of the file being played

config ESP32S2_I2S_BCLKPIN
	int "I2S BCLK pin"
	default 35
	range 0 45 if ESP32S2_I2S_ROLE_MASTER
	range 0 46 if ESP32S2_I2S_ROLE_SLAVE

config ESP32S2_I2S_WSPIN
	int "I2S WS pin"
	default 34
	range 0 45 if ESP32S2_I2S_ROLE_MASTER
	range 0 46 if ESP32S2_I2S_ROLE_SLAVE

config ESP32S2_I2S_DINPIN
	int "I2S DIN pin"
	depends on ESP32S2_I2S_RX
	default 37
	range 0 46

config ESP32S2_I2S_DOUTPIN
	int "I2S DOUT pin"
	depends on ESP32S2_I2S_TX
	default 36
	range 0 45

config ESP32S2_I2S_MCLK
	bool "Enable I2S Master Clock"
	depends on ESP32S2_I2S_ROLE_MASTER
	default n
	---help---
		Enable I2S master clock

config ESP32S2_I2S_MCLKPIN
	int "I2S MCLK pin"
	depends on ESP32S2_I2S_MCLK
	default 33
	range 0 45

config I2S_DMADESC_NUM
	int "I2S DMA maximum number of descriptors"
	default 2
	---help---
		Configure the maximum number of out-link/in-link descriptors to
		be chained for a I2S DMA transfer.

endif #ESP32S2_I2S

config ESP32S2_SPI2
	bool "SPI 2"
	default n
	select ESP32S2_SPI
	select SPI

config ESP32S2_SPI3
	bool "SPI 3"
	default n
	select ESP32S2_SPI
	select SPI

config ESP32S2_SPIFLASH
	bool "SPI Flash"
	default n

config ESP32S2_SPIRAM
	bool "SPI RAM Support"
	default n

config ESP32S2_EFUSE
	bool "EFUSE support"
	default n
	---help---
		Enable ESP32-S2 efuse support.

config ESP32S2_TIMER0
	bool "64-bit Timer 0 (Group 0 Timer 0)"
	default n
	select ESP32S2_TIMER
	---help---
		Enables Timer

config ESP32S2_TIMER1
	bool "64-bit Timer 1 (Group 0 Timer 1)"
	default n
	select ESP32S2_TIMER
	---help---
		Enables Timer

config ESP32S2_TIMER2
	bool "64-bit Timer 2 (Group 1 Timer 0)"
	default n
	select ESP32S2_TIMER
	---help---
		Enables Timer

config ESP32S2_TIMER3
	bool "64-bit Timer 3 (Group 1 Timer 1)"
	default n
	select ESP32S2_TIMER
	---help---
		Enables Timer

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

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

config ESP32S2_RWDT
	bool "RTC Watchdog Timer"
	default n
	select ESP32S2_WDT
	select ESP32S2_RTCIO_IRQ
	---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 ESP32S2_XTWDT
	bool "XTAL32K Watchdog Timer"
	depends on ESP32S2_RTC_CLK_EXT_OSC || ESP32S2_RTC_CLK_EXT_XTAL
	default n
	select ESP32S2_WDT
	select ESP32S2_RTCIO_IRQ
	---help---
		Includes XTWDT. This watchdog timer monitors the status of the
		external 32 kHz crystal oscillator (XTAL32K). When XTAL32K_CLK works
		as the clock source of RTC_SLOW_CLK and it stops oscillating, the
		XTAL32K watchdog timer first switches to BACKUP32K_CLK derived from
		RC_SLOW_CLK (if ESP32S2_XTWDT_BACKUP_CLK_ENABLE) and, then, generates
		an interrupt that could be captured by WDIOC_CAPTURE.

config ESP32S2_XTWDT_BACKUP_CLK_ENABLE
	bool "Automatically switch to BACKUP32K_CLK when timer expires"
	depends on ESP32S2_XTWDT
	default y
	---help---
		Enable this to automatically switch to BACKUP32K_CLK as the source of
		RTC_SLOW_CLK when the watchdog timer expires.

config ESP32S2_RTC
	bool "Real Time Clock (RTC)"
	default y

config ESP32S2_UART0
	bool "UART 0"
	default n
	select ESP32S2_UART
	select UART0_SERIALDRIVER
	select ARCH_HAVE_SERIAL_TERMIOS

config ESP32S2_UART1
	bool "UART 1"
	default n
	select ESP32S2_UART
	select UART1_SERIALDRIVER
	select ARCH_HAVE_SERIAL_TERMIOS

config ESP32S2_I2C0
	bool "I2C 0"
	default n
	select ESP32S2_I2C
	select I2C

config ESP32S2_I2C1
	bool "I2C 1"
	default n
	select ESP32S2_I2C
	select I2C

config ESP32S2_TWAI
	bool "TWAI (CAN)"
	default n
	select CAN

config ESP32S2_LEDC
	bool "LEDC (PWM)"
	default n
	select PWM
	select ARCH_HAVE_PWM_MULTICHAN
	---help---
		Enable support to PWM on ESP32S2 using LEDC peripheral.

config ESP32S2_RT_TIMER
	bool "Real-time Timer"
	select ESP32S2_TIMER
	default n

endmenu # ESP32-S2 Peripheral Selection

menu "Memory Configuration"

config ESP32S2_TRACEMEM_RESERVE_DRAM
	int "Reserved trace memory DRAM"
	default 0

config ESP32S2_ULP_COPROC_RESERVE_MEM
	int "Reserved ULP co-processor DRAM"
	default 0

comment "Additional Heaps"

config ESP32S2_RTC_HEAP
	bool "Use the RTC memory as a separate heap"
	select ARCH_HAVE_EXTRA_HEAPS
	default n

endmenu # Memory Configuration

config ESP32S2_GPIO_IRQ
	bool "GPIO pin interrupts"
	---help---
		Enable support for interrupting GPIO pins.

config ESP32S2_RTCIO_IRQ
	bool "RTC IO interrupts"
	default n
	---help---
		Enable support for RTC peripherals interruptions.

menu "SPI configuration"
	depends on ESP32S2_SPI

config ESP32S2_SPI_SWCS
	bool "SPI software CS"
	default n
	---help---
		Use SPI software CS.

config ESP32S2_SPI_UDCS
	bool "User defined CS"
	default n
	depends on ESP32S2_SPI_SWCS
	---help---
		Use user-defined CS.

config ESP32S2_SPI2_SLAVE
	bool "SPI2 Slave mode"
	default n
	depends on SPI_SLAVE && ESP32S2_SPI2
	select ESP32S2_GPIO_IRQ
	---help---
		Configure SPI2 to operate in Slave mode.

config ESP32S2_SPI2_DMA
	bool "SPI2 use DMA"
	default y
	depends on ESP32S2_SPI2

config ESP32S2_SPI3_SLAVE
	bool "SPI3 Slave mode"
	default n
	depends on SPI_SLAVE && ESP32S2_SPI3
	select ESP32S2_GPIO_IRQ
	---help---
		Configure SPI3 to operate in Slave mode.

config ESP32S2_SPI3_DMA
	bool "SPI3 use DMA"
	default y
	depends on ESP32S2_SPI3

config ESP32S2_SPI_DMA_BUFSIZE
	int "SPI Master GDMA buffer size"
	default 2048
	depends on ESP32S2_SPI2_DMA || ESP32S2_SPI3_DMA
	---help---
		This is used to calculate and allocate DMA description buffer,
		not really allocate TX/RX buffer.

config ESP32S2_SPI_SLAVE_BUFSIZE
	int "SPI Slave buffer size"
	default 2048
	depends on SPI_SLAVE

config ESP32S2_SPI_DMATHRESHOLD
	int "SPI DMA threshold"
	default 64
	depends on ESP32S2_SPI2_DMA || ESP32S2_SPI3_DMA
	---help---
		When SPI DMA is enabled, DMA transfers whose size are below the
		defined threshold will be performed by polling logic.

if ESP32S2_SPI2

config ESP32S2_SPI2_CSPIN
	int "SPI2 CS Pin"
	default 10
	range 0 48

config ESP32S2_SPI2_CLKPIN
	int "SPI2 CLK Pin"
	default 12
	range 0 48

config ESP32S2_SPI2_MOSIPIN
	int "SPI2 MOSI Pin"
	default 11
	range 0 48

config ESP32S2_SPI2_MISOPIN
	int "SPI2 MISO Pin"
	default 13
	range 0 48

config ESP32S2_SPI2_IO2PIN
	int "SPI2 IO2 Pin"
	default 14
	range 0 48
	depends on ESP32S2_SPI_IO_QIO

config ESP32S2_SPI2_IO3PIN
	int "SPI2 IO3 Pin"
	default 9
	range 0 48
	depends on ESP32S2_SPI_IO_QIO
endif # ESP32S2_SPI2

if ESP32S2_SPI3
config ESP32S2_SPI3_CSPIN
	int "SPI3 CS Pin"
	default 10
	range 0 48

config ESP32S2_SPI3_CLKPIN
	int "SPI3 CLK Pin"
	default 12
	range 0 48

config ESP32S2_SPI3_MOSIPIN
	int "SPI3 MOSI Pin"
	default 11
	range 0 48

config ESP32S2_SPI3_MISOPIN
	int "SPI3 MISO Pin"
	default 13
	range 0 48

endif # ESP32S2_SPI3
endmenu

menu "UART Configuration"
	depends on ESP32S2_UART

if ESP32S2_UART0

config ESP32S2_UART0_RS485
	bool "RS-485 on UART0"
	default n
	---help---
		Enable RS-485 interface on UART0. Your board config will have to
		provide GPIO_UART0_RS485_DIR pin definition.

config ESP32S2_UART0_RS485_DIR_PIN
	int "UART0 RS-485 DIR pin"
	default 25
	range 0 46
	depends on ESP32S2_UART0_RS485
	---help---
		DIR pin for RS-485 on UART0. This pin will control the RS485 enable
		TX of the RS485 transceiver.

config ESP32S2_UART0_RS485_DIR_POLARITY
	int "UART0 RS-485 DIR pin polarity"
	default 1
	range 0 1
	depends on ESP32S2_UART0_RS485
	---help---
		Polarity of DIR pin for RS-485 on UART0. Set to state on DIR pin which
		enables TX (0 - low / nTXEN, 1 - high / TXEN).

config ESP32S2_UART0_TXPIN
	int "UART0 Tx Pin"
	default 43
	range 0 46

config ESP32S2_UART0_RXPIN
	int "UART0 Rx Pin"
	default 44
	range 0 46

config ESP32S2_UART0_RTSPIN
	int "UART0 RTS Pin"
	depends on SERIAL_IFLOWCONTROL
	default 16
	range 0 46

config ESP32S2_UART0_CTSPIN
	int "UART0 CTS Pin"
	depends on SERIAL_OFLOWCONTROL
	default 15
	range 0 46

endif # ESP32S2_UART0

if ESP32S2_UART1

config ESP32S2_UART1_RS485
	bool "RS-485 on UART1"
	default n
	---help---
		Enable RS-485 interface on UART1. Your board config will have to
		provide GPIO_UART1_RS485_DIR pin definition.

config ESP32S2_UART1_RS485_DIR_PIN
	int "UART1 RS-485 DIR pin"
	default 14
	range 0 46
	depends on ESP32S2_UART1_RS485
	---help---
		DIR pin for RS-485 on UART1. This pin will control the RS485 enable
		TX of the RS485 transceiver.

config ESP32S2_UART1_RS485_DIR_POLARITY
	int "UART1 RS-485 DIR pin polarity"
	default 1
	range 0 1
	depends on ESP32S2_UART1_RS485
	---help---
		Polarity of DIR pin for RS-485 on UART1. Set to state on DIR pin which
		enables TX (0 - low / nTXEN, 1 - high / TXEN).

config ESP32S2_UART1_TXPIN
	int "UART1 Tx Pin"
	default 17
	range 0 46

config ESP32S2_UART1_RXPIN
	int "UART1 Rx Pin"
	default 18
	range 0 46

config ESP32S2_UART1_RTSPIN
	int "UART1 RTS Pin"
	depends on SERIAL_IFLOWCONTROL
	default 35
	range 0 46

config ESP32S2_UART1_CTSPIN
	int "UART1 CTS Pin"
	depends on SERIAL_OFLOWCONTROL
	default 36
	range 0 46

endif # ESP32S2_UART1

endmenu # UART Configuration

menu "I2C Configuration"
	depends on ESP32S2_I2C

if ESP32S2_I2C0

config ESP32S2_I2C0_SCLPIN
	int "I2C0 SCL Pin"
	default 19
	range 0 46

config ESP32S2_I2C0_SDAPIN
	int "I2C0 SDA Pin"
	default 18
	range 0 46

endif # ESP32S2_I2C0

if ESP32S2_I2C1

config ESP32S2_I2C1_SCLPIN
	int "I2C1 SCL Pin"
	default 6
	range 0 46

config ESP32S2_I2C1_SDAPIN
	int "I2C1 SDA Pin"
	default 7
	range 0 46

endif # ESP32S2_I2C1

config ESP32S2_I2CTIMEOSEC
	int "Timeout seconds"
	default 0

config ESP32S2_I2CTIMEOMS
	int "Timeout milliseconds"
	default 500

endmenu # I2C Configuration

menu "TWAI driver options"
	depends on ESP32S2_TWAI

if ESP32S2_TWAI

config ESP32S2_TWAI_TXPIN
	int "TWAI TX Pin"
	default 0

config ESP32S2_TWAI_RXPIN
	int "TWAI RX Pin"
	default 2

config ESP32S2_TWAI_BITRATE
	int "TWAI bitrate"
	default 1000000
	---help---
		TWAI bit rate.

config ESP32S2_TWAI_SAMPLEP
	int "TWAI sample point"
	default 80
	---help---
		TWAI sample point location as a percent value.

config ESP32S2_TWAI_SJW
	int "TWAI synchronization jump width"
	default 3
	---help---
		SJW limits the number of Time Quanta corrections during bit
		Resynchronization.

config ESP32S2_TWAI_SAM
	bool "TWAI sampling"
	default n
	---help---
		The bus is sampled 3 times (recommended for low to medium speed buses
		to spikes on the bus-line).

endif # ESP32S2_TWAI

config ESP32S2_TWAI_REGDEBUG
	bool "TWAI register level debug"
	depends on DEBUG_CAN_INFO
	default n
	---help---
		Output detailed register-level TWAI debug information. Requires also
		CONFIG_DEBUG_CAN_INFO.

endmenu #ESP32S2_TWAI

menu "SPI Flash Configuration"

choice ESP32S2_FLASH_MODE
	prompt "SPI Flash mode"
	default ESP32S2_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 ESP32S2_FLASH_MODE_DIO
	bool "Dual IO (DIO)"

config ESP32S2_FLASH_MODE_DOUT
	bool "Dual Output (DOUT)"

config ESP32S2_FLASH_MODE_QIO
	bool "Quad IO (QIO)"

config ESP32S2_FLASH_MODE_QOUT
	bool "Quad Output (QOUT)"

endchoice # ESP32S2_FLASH_MODE

choice ESP32S2_FLASH_FREQ
	prompt "SPI Flash frequency"
	default ESP32S2_FLASH_FREQ_40M
	---help---
		SPI Flash frequency.

config ESP32S2_FLASH_FREQ_80M
	bool "80 MHz"

config ESP32S2_FLASH_FREQ_40M
	bool "40 MHz"

config ESP32S2_FLASH_FREQ_26M
	bool "26 MHz"

config ESP32S2_FLASH_FREQ_20M
	bool "20 MHz"

endchoice # ESP32S2_FLASH_FREQ

if ESP32S2_HAVE_OTA_PARTITION

comment "Application Image OTA Update support"

config ESP32S2_OTA_PRIMARY_SLOT_OFFSET
	hex "Application image primary slot offset"
	default 0x10000

config ESP32S2_OTA_PRIMARY_SLOT_DEVPATH
	string "Application image primary slot device path"
	default "/dev/ota0"

config ESP32S2_OTA_SECONDARY_SLOT_OFFSET
	hex "Application image secondary slot offset"
	default 0x110000

config ESP32S2_OTA_SECONDARY_SLOT_DEVPATH
	string "Application image secondary slot device path"
	default "/dev/ota1"

config ESP32S2_OTA_SLOT_SIZE
	hex "Application image slot size (in bytes)"
	default 0x100000

config ESP32S2_OTA_SCRATCH_OFFSET
	hex "Scratch partition offset"
	default 0x210000

config ESP32S2_OTA_SCRATCH_SIZE
	hex "Scratch partition size"
	default 0x40000

config ESP32S2_OTA_SCRATCH_DEVPATH
	string "Scratch partition device path"
	default "/dev/otascratch"

endif

if ESP32S2_SPIFLASH

comment "General storage MTD configuration"

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

config ESP32S2_SPIFLASH_MTD_BLKSIZE
	int "Storage MTD block size"
	default 256
	depends on ESP32S2_MTD

config ESP32S2_STORAGE_MTD_DEBUG
	bool "Storage MTD Debug"
	default n
	depends on ESP32S2_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).

endif # ESP32S2_SPIFLASH

endmenu # SPI Flash Configuration

menu "SPI RAM Configuration"
	depends on ESP32S2_SPIRAM

config ESP32S2_DEFAULT_PSRAM_CLK_IO
	int "PSRAM CLK pin"
	default 30

config ESP32S2_DEFAULT_PSRAM_CS_IO
	int "PSRAM CS pin"
	default 26

choice ESP32S2_SPIRAM_TYPE
	prompt "Type of SPI RAM chip in use"
	default ESP32S2_SPIRAM_TYPE_AUTO

config ESP32S2_SPIRAM_TYPE_AUTO
	bool "Auto-detect"

config ESP32S2_SPIRAM_TYPE_ESPPSRAM32
	bool "ESP-PSRAM32 or IS25WP032"

config ESP32S2_SPIRAM_TYPE_ESPPSRAM64
	bool "ESP-PSRAM64 or LY68L6400"

endchoice # ESP32S2_SPIRAM_TYPE

config ESP32S2_SPIRAM_SIZE
	int
	default -1 if ESP32S2_SPIRAM_TYPE_AUTO
	default 4194304 if ESP32S2_SPIRAM_TYPE_ESPPSRAM32
	default 8388608 if ESP32S2_SPIRAM_TYPE_ESPPSRAM64
	default 0

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

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

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

config ESP32S2_SPIRAM_SPEED_40M
	bool "40MHz clock speed"

config ESP32S2_SPIRAM_SPEED_80M
	bool "80MHz clock speed"

endchoice # ESP32S2_SPIRAM_SPEED

config ESP32S2_SPIRAM_SPEED
	int
	default 80 if ESP32S2_SPIRAM_SPEED_80M
	default 40 if ESP32S2_SPIRAM_SPEED_40M

config ESP32S2_SPIRAM_BOOT_INIT
	bool "Initialize SPI RAM during startup"
	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 ESP32S2_SPIRAM_IGNORE_NOTFOUND
	bool "Ignore PSRAM when not found"
	default "n"
	depends on ESP32S2_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 "RTC Configuration"
	depends on ESP32S2_RTC

choice ESP32S2_RTC_CLK_SRC
	prompt "RTC clock source"
	default ESP32S2_RTC_CLK_INT_RC
	---help---
		Choose which clock is used as RTC clock source.

		- "Internal 90KHz oscillator" option provides lowest deep sleep current
			consumption, and does not require extra external components. However
			frequency stability with respect to temperature is poor, so time may
			drift in deep/light sleep modes.
		- "External 32KHz crystal" provides better frequency stability, at the
			expense of slightly higher (1uA) deep sleep current consumption.
		- "External 32KHz oscillator" allows using 32KHz clock generated by an
			external circuit. In this case, external clock signal must be connected
			to 32K_XN pin. Amplitude should be <1.2V in case of sine wave signal,
			and <1V in case of square wave signal. Common mode voltage should be
			0.1 < Vcm < 0.5Vamp, where Vamp is the signal amplitude.
			Additionally, 1nF capacitor must be connected between 32K_XP pin and
			ground. 32K_XP pin can not be used as a GPIO in this case.
		- "Internal 8.5MHz oscillator divided by 256" option results in higher
			deep sleep current (by 5uA) but has better frequency stability than
			the internal 90KHz oscillator. It does not require external components.

config ESP32S2_RTC_CLK_INT_RC
	bool "Internal 90KHz RC oscillator"

config ESP32S2_RTC_CLK_EXT_XTAL
	bool "External 32KHz crystal"
	select ESP_SYSTEM_RTC_EXT_XTAL

config ESP32S2_RTC_CLK_EXT_OSC
	bool "External 32KHz oscillator at 32K_XN pin"
	select ESP_SYSTEM_RTC_EXT_XTAL

config ESP32S2_RTC_CLK_INT_8MD256
	bool "Internal 8.5MHz oscillator, divided by 256 (~33kHz)"

endchoice
endmenu # "RTC Configuration"

menu "Real-Time Timer Configuration"
	depends on ESP32S2_RT_TIMER

config ESP32S2_RT_TIMER_TASK_NAME
	string "Timer task name"
	default "rt_timer"

config ESP32S2_RT_TIMER_TASK_PRIORITY
	int "Timer task priority"
	default 223 # Lower than high priority workqueue

config ESP32S2_RT_TIMER_TASK_STACK_SIZE
	int "Timer task stack size"
	default 2048

endmenu # Real-Time Timer Configuration

menu "Timer/Counter Configuration"
	depends on ESP32S2_TIMER

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

config ESP32S2_FREERUN
	bool "Freerun timer wrapper"
	default n
	---help---
		Enable a wrapper around the low level timer/counter functions to
		support freerun timer.

endmenu # Timer/Counter Configuration

menu "LEDC Configuration"
	depends on ESP32S2_LEDC

menuconfig ESP32S2_LEDC_TIM0
	bool "Timer 0"
	default n

if ESP32S2_LEDC_TIM0

config ESP32S2_LEDC_TIM0_CHANNELS
	int "Number of Timer 0 channels"
	default 2

endif # ESP32S2_LEDC_TIM0

menuconfig ESP32S2_LEDC_TIM1
	bool "Timer 1"
	default n

if ESP32S2_LEDC_TIM1

config ESP32S2_LEDC_TIM1_CHANNELS
	int "Number of Timer 1 channels"
	default 2

endif # ESP32S2_LEDC_TIM1

menuconfig ESP32S2_LEDC_TIM2
	bool "Timer 2"
	default n

if ESP32S2_LEDC_TIM2

config ESP32S2_LEDC_TIM2_CHANNELS
	int "Number of Timer 2 channels"
	default 2

endif # ESP32S2_LEDC_TIM2

menuconfig ESP32S2_LEDC_TIM3
	bool "Timer 3"
	default n

if ESP32S2_LEDC_TIM3

config ESP32S2_LEDC_TIM3_CHANNELS
	int "Number of Timer 3 channels"
	default 2

endif # ESP32S2_LEDC_TIM2

config ESP32S2_LEDC_CHANNEL0_PIN
	int "Channel 0 pin"
	default 2

config ESP32S2_LEDC_CHANNEL1_PIN
	int "Channel 1 pin"
	default 3

config ESP32S2_LEDC_CHANNEL2_PIN
	int "Channel 2 pin"
	default 4

config ESP32S2_LEDC_CHANNEL3_PIN
	int "Channel 3 pin"
	default 5

config ESP32S2_LEDC_CHANNEL4_PIN
	int "Channel 4 pin"
	default 6

config ESP32S2_LEDC_CHANNEL5_PIN
	int "Channel 5 pin"
	default 7

config ESP32S2_LEDC_CHANNEL6_PIN
	int "Channel 6 pin"
	default 8

config ESP32S2_LEDC_CHANNEL7_PIN
	int "Channel 7 pin"
	default 9

endmenu # LEDC configuration

config ESP32S2_HAVE_OTA_PARTITION
	bool
	default n

menu "Bootloader and Image Configuration"

config ESP32S2_APP_FORMAT_LEGACY
	bool
	default y if !ESP32S2_APP_FORMAT_MCUBOOT
	depends on !ESP32S2_APP_FORMAT_MCUBOOT
	---help---
		This is the legacy application image format, as supported by the ESP-IDF
		2nd stage bootloader.

config ESP32S2_APP_FORMAT_MCUBOOT
	bool "Enable MCUboot-bootable format"
	depends on !MCUBOOT_BOOTLOADER
	select ESP32S2_HAVE_OTA_PARTITION
	select ESP32S2_BOOTLOADER_BUILD_FROM_SOURCE
	---help---
		Enables the Espressif port of MCUboot to be used as 2nd stage bootloader.

config ESP32S2_BOOTLOADER_DOWNLOAD_PREBUILT
	bool
	default y if !ESP32S2_BOOTLOADER_BUILD_FROM_SOURCE
	depends on !ESP32S2_BOOTLOADER_BUILD_FROM_SOURCE
	---help---
		The build system will download the prebuilt binaries from
		https://github.com/espressif/esp-nuttx-bootloader according to the chosen
		Application Image Format (ESP32S2_APP_FORMAT_LEGACY or ESP32S2_APP_FORMAT_MCUBOOT)

config ESP32S2_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
		(ESP32S2_APP_FORMAT_LEGACY or ESP32S2_APP_FORMAT_MCUBOOT) and partition information.

choice
	prompt "Target slot for image flashing"
	default ESP32S2_ESPTOOL_TARGET_PRIMARY
	depends on ESP32S2_HAVE_OTA_PARTITION
	---help---
		Slot to which ESPTOOL will flash the generated binary image.

config ESP32S2_ESPTOOL_TARGET_PRIMARY
	bool "Application image primary slot"
	---help---
		This assumes that the generated image is already pre-validated.
		This is the recommended option for the initial stages of the
		application firmware image development.

config ESP32S2_ESPTOOL_TARGET_SECONDARY
	bool "Application image secondary slot"
	---help---
		The application needs to confirm the generated image as valid,
		otherwise the bootloader may consider it invalid and perform the
		rollback of the update after a reset.
		This is the choice most suitable for the development and verification
		of a secure firmware update workflow.

endchoice

config ESP32S2_MCUBOOT_VERSION
	string "MCUboot version"
	default "b206b99b1555ca15f790a3287e57dc98ef3df2ac"
	depends on ESP32S2_APP_FORMAT_MCUBOOT

config ESP32S2_APP_MCUBOOT_HEADER_SIZE
	int "Application image header size (in bytes)"
	default 32
	depends on ESP32S2_APP_FORMAT_MCUBOOT

config ESP32S2_PARTITION_TABLE_OFFSET_DEFAULT
	hex
	default 0x8000
	depends on ESP32S2_APP_FORMAT_LEGACY

config ESP32S2_CUSTOM_PARTITION_TABLE_OFFSET
	bool "Customize partition table offset"
	default n
	depends on ESP32S2_APP_FORMAT_LEGACY
	select ESP32S2_BOOTLOADER_BUILD_FROM_SOURCE
	---help---
		Enable to select the offset of the partition table in the flash.

if ESP32S2_CUSTOM_PARTITION_TABLE_OFFSET

config ESP32S2_PARTITION_TABLE_OFFSET
	hex "Partition Table offset"
	default ESP32S2_PARTITION_TABLE_OFFSET_DEFAULT
	depends on ESP32S2_APP_FORMAT_LEGACY

endif # ESP32S2_CUSTOM_PARTITION_TABLE_OFFSET

if !ESP32S2_CUSTOM_PARTITION_TABLE_OFFSET

config ESP32S2_PARTITION_TABLE_OFFSET
	hex
	default ESP32S2_PARTITION_TABLE_OFFSET_DEFAULT
	depends on ESP32S2_APP_FORMAT_LEGACY

endif # !ESP32S2_CUSTOM_PARTITION_TABLE_OFFSET

source "arch/xtensa/src/esp32s2/Kconfig.security"

endmenu # Bootloader and Image Configuration

endif # ARCH_CHIP_ESP32S2
