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

if ARCH_CHIP_ESP32C3

comment "ESP32-C3 Configuration Options"

choice
	prompt "ESP32-C3 Chip Selection"
	default ARCH_CHIP_ESP32C3WROOM02

config ARCH_CHIP_ESP32C3X
	bool "ESP32-C3"
	select ESP32C3_ESP32C3XXX
	---help---
		ESP32-C3 chip with a single RISC-V IMC core, no embedded Flash memory

config ARCH_CHIP_ESP32C3FX4
	bool "ESP32-C3Fx4"
	select ESP32C3_ESP32C3XXX
	select ESP32C3_FLASH_4M
	---help---
		ESP32-C3 chip with a single RISC-V IMC core, 4 MB of in-package Flash memory

config ARCH_CHIP_ESP32C3MINI1
	bool "ESP32-C3-MINI-1"
	select ESP32C3_ESP32C3XXX
	select ESP32C3_FLASH_4M
	---help---
		Generic module with an embedded ESP32-C3Fx4 chip

config ARCH_CHIP_ESP32C3WROOM02
	bool "ESP32-C3-WROOM-02"
	select ESP32C3_ESP32C3XXX
	select ESP32C3_FLASH_4M
	---help---
		Generic module with an embedded ESP32-C3 chip, 4 MB of Flash memory

endchoice # ESP32-C3 Chip Selection

config ESP32C3_SINGLE_CPU
	bool
	default n

config ESP32C3_DUAL_CPU
	bool
	default n

config ESP32C3_ESP32C3XXX
	bool
	default n
	select ESP32C3_SINGLE_CPU
	select ARCH_HAVE_I2CRESET

config ESP32C3_FLASH_2M
	bool
	default n

config ESP32C3_FLASH_4M
	bool
	default n

config ESP32C3_FLASH_8M
	bool
	default n

config ESP32C3_FLASH_16M
	bool
	default n

config ESP32C3_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 ESP32C3_FLASH_DETECT
	bool "Auto-detect FLASH size"
	default n
	---help---
		Auto detect flash size when flashing.

choice ESP32C3_CPU_FREQ
	prompt "CPU frequency"
	default ESP32C3_CPU_FREQ_160
	---help---
		CPU frequency to be set on application startup.

config ESP32C3_CPU_FREQ_40
	bool "40 MHz"
	---help---
		Set the CPU to 40 MHz. This frequency is obtained from the XTAL.

config ESP32C3_CPU_FREQ_80
	bool "80 MHz"
	---help---
		Set the CPU to 80 MHz. This frequency is obtained from the 480 MHz PLL.

config ESP32C3_CPU_FREQ_160
	bool "160 MHz"
	---help---
		Set the CPU to 160 MHz. This frequency is obtained from the 480 MHz PLL.

endchoice # ESP32C3_CPU_FREQ

config ESP32C3_CPU_FREQ_MHZ
	int
	default 40 if ESP32C3_CPU_FREQ_40
	default 80 if ESP32C3_CPU_FREQ_80
	default 160 if ESP32C3_CPU_FREQ_160

config ESP32C3_REGION_PROTECTION
	bool "Enable region protection"
	default y
	select ARCH_USE_MPU
	---help---
		Configure the MPU to disable access to invalid memory regions.

config ESP32C3_RT_TIMER
	bool "Real-time Timer"
	default n
	select ESP32C3_TIMER
	---help---
		Real-time Timer is relying upon the Systimer 1.

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

config ESP32C3_EXCEPTION_ENABLE_CACHE
	bool
	default y
	depends on ESP32C3_SPIFLASH
	---help---
		When exception triggers, panic function enables SPI Flash cache to
		let functions be able to call functions which locate in SPI Flash.

menu "ESP32-C3 Peripheral Support"

config ESP32C3_ADC
	bool
	default n
	select ANALOG
	select ADC

config ESP32C3_UART
	bool
	default n

config ESP32C3_I2C
	bool
	default n

config ESP32C3_TWAI
	bool
	default n
	select CAN

config ESP32C3_TIMER
	bool
	default n

config ESP32C3_WDT
	bool
	default n

config ESP32C3_EFUSE
	bool "EFUSE support"
	default n
	---help---
		Enable ESP32-C3 efuse support.

config ESP32C3_SPI
	bool
	default n

config ESP32C3_LEDC
	bool "LEDC (PWM)"
	default n
	select PWM
	select ARCH_HAVE_PWM_MULTICHAN

config ESP32C3_GPIO_IRQ
	bool "GPIO pin interrupts"
	default n
	---help---
		Enable support for interrupting GPIO pins

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

config ESP32C3_UART0
	bool "UART0"
	default y
	select ESP32C3_UART
	select UART0_SERIALDRIVER
	select ARCH_HAVE_SERIAL_TERMIOS

config ESP32C3_UART1
	bool "UART1"
	default n
	select ESP32C3_UART
	select UART1_SERIALDRIVER
	select ARCH_HAVE_SERIAL_TERMIOS

config ESP32C3_USBSERIAL
	bool "USB-Serial Driver"
	default n
	select OTHER_UART_SERIALDRIVER
	select ARCH_HAVE_SERIAL_TERMIOS

config ESP32C3_I2C0
	bool "I2C 0"
	default n
	select ESP32C3_I2C

config ESP32C3_TWAI0
	bool "TWAI (CAN) 0"
	default n
	select ESP32C3_TWAI

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

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

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

config ESP32C3_SPIFLASH
	bool "SPI Flash"
	default n

config ESP32C3_SPI2
	bool "SPI 2"
	default n
	select ESP32C3_SPI
	select SPI

config ESP32C3_DMA
	bool "General DMA (GDMA)"
	default n
	select ARCH_DMA

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

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

config ESP32C3_RWDT
	bool "RTC Watchdog Timer"
	default n
	select ESP32C3_WDT
	select ESP32C3_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 ESP32C3_ADC1
	bool "ADC1"
	default n
	select ESP32C3_ADC

config ESP32C3_WIRELESS
	bool
	default n
	select NET
	select ARCH_PHY_INTERRUPT
	select ESP32C3_RT_TIMER
	---help---
		Enable Wireless support

config ESP32C3_AES_ACCELERATOR
	bool "AES Accelerator"
	default n
config ESP32C3_SHA_ACCELERATOR
	bool "SHA Accelerator"
	default n
	---help---
		Enable ESP32-C3 SHA accelerator support.

config ESP32C3_BIGNUM_ACCELERATOR
	bool "BIGNUM Accelerator"
	default n
	---help---
		Enable ESP32-C3 BIGNUM accelerator support.

config ESP32C3_RSA_ACCELERATOR
	bool "RSA Accelerator"
	default n
	---help---
		Enable ESP32-C3 RSA accelerator support.

config ESP32C3_WIFI
	bool "Wi-Fi"
	default n
	select ESP32C3_WIRELESS
	---help---
		Enable Wi-Fi support

config ESP32C3_BLE
	bool "BLE"
	default n
	select ESP32C3_WIRELESS
	---help---
		Enable BLE support

config ESP32C3_BROWNOUT_DET
	bool "Brownout Detect"
	default y
	---help---
		The ESP32-C3 has a built-in brownout detector which can detect if the voltage is lower than
		a specific value. If this happens, it will reset the chip in order to prevent unintended
		behaviour.

endmenu # ESP32-C3 Peripheral Support

menuconfig ESP32C3_WIFI_BT_COEXIST
	bool "Wi-Fi and BT coexist"
	default n
	depends on ESP32C3_WIFI && ESP32C3_BLE

menu "I2C Configuration"
	depends on ESP32C3_I2C

if ESP32C3_I2C0

config ESP32C3_I2C0_SCLPIN
	int "I2C0 SCL Pin"
	default 6
	range 0 21

config ESP32C3_I2C0_SDAPIN
	int "I2C0 SDA Pin"
	default 5
	range 0 21

endif # ESP32C3_I2C0

config ESP32C3_I2CTIMEOSEC
	int "Timeout seconds"
	default 0

config ESP32C3_I2CTIMEOMS
	int "Timeout milliseconds"
	default 500

endmenu # I2C configuration

menu "TWAI driver options"
	depends on ESP32C3_TWAI

if ESP32C3_TWAI0

config ESP32C3_TWAI0_TXPIN
	int "TWAI0 TX Pin"
	default 2

config ESP32C3_TWAI0_RXPIN
	int "TWAI0 RX Pin"
	default 3

config ESP32C3_TWAI0_BITRATE
	int "TWAI0 bitrate"
	default 1000000
	---help---
		TWAI0 bit rate.  Required if ESP32C3_TWAI0 is defined.

config ESP32C3_TWAI0_SAMPLEP
	int "TWAI0 sample point"
	default 80
	---help---
		TWAI0 sample point location as a percent value.  Required
		if ESP32C3_TWAI0 is defined.

config ESP32C3_TWAI0_SJW
	int "TWAI0 synchronization jump width"
	default 3
	---help---
		SJW limits the number of Time Quanta corrections during bit
		Resynchronization. Default: 3

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

endif # ESP32C3_TWAI0

config ESP32C3_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 #ESP32C3_TWAI

menu "SPI configuration"
	depends on ESP32C3_SPI

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

config ESP32C3_SPI_UDCS
	bool "User defined CS"
	default n
	depends on ESP32C3_SPI_SWCS
	---help---
		Use user-defined CS.

if ESP32C3_SPI2

config ESP32C3_SPI2_SLAVE
	bool "SPI2 Slave mode"
	default n
	depends on SPI_SLAVE
	select ESP32C3_GPIO_IRQ
	---help---
		Configure SPI2 to operate in Slave mode.

config ESP32C3_SPI2_DMA
	bool "SPI2 use GDMA"
	default n
	depends on ESP32C3_DMA
	---help---
		Enable support for transfers using the GDMA engine.

config ESP32C3_SPI2_DMADESC_NUM
	int "SPI2 Master GDMA maximum number of descriptors"
	default 2
	depends on ESP32C3_SPI2_DMA
	---help---
		Configure the maximum number of out-link/in-link descriptors to
		be chained for a GDMA transfer.

config ESP32C3_SPI2_DMATHRESHOLD
	int "SPI2 Master GDMA threshold"
	default 64
	depends on ESP32C3_SPI2_DMA
	---help---
		When SPI GDMA is enabled, GDMA transfers whose size are below the
		defined threshold will be performed by polling logic.

config ESP32C3_SPI2_SLAVE_BUFSIZE
	int "SPI2 Slave buffer size"
	default 2048
	depends on ESP32C3_SPI2_SLAVE
	---help---
		Configure the size of SPI2 Slave controller's internal buffers.

config ESP32C3_SPI2_CSPIN
	int "SPI2 CS Pin"
	default 10
	range 0 21

config ESP32C3_SPI2_CLKPIN
	int "SPI2 CLK Pin"
	default 6
	range 0 21

config ESP32C3_SPI2_MOSIPIN
	int "SPI2 MOSI Pin"
	default 7
	range 0 21

config ESP32C3_SPI2_MISOPIN
	int "SPI2 MISO Pin"
	default 2
	range 0 21

endif # ESP32C3_SPI2

endmenu # SPI configuration

menu "UART configuration"
	depends on ESP32C3_UART

if ESP32C3_UART0

config ESP32C3_UART0_TXPIN
	int "UART0 TX Pin"
	default 21

config ESP32C3_UART0_RXPIN
	int "UART0 RX Pin"
	default 20

config ESP32C3_UART0_RTSPIN
	int "UART0 RTS Pin"
	depends on SERIAL_IFLOWCONTROL
	default 16
	range 0 21

config ESP32C3_UART0_CTSPIN
	int "UART0 CTS Pin"
	depends on SERIAL_OFLOWCONTROL
	default 15
	range 0 21

endif # ESP32C3_UART0

if ESP32C3_UART1

config ESP32C3_UART1_TXPIN
	int "UART1 TX Pin"
	default 8

config ESP32C3_UART1_RXPIN
	int "UART1 RX Pin"
	default 9

config ESP32C3_UART1_RTSPIN
	int "UART1 RTS Pin"
	depends on SERIAL_IFLOWCONTROL
	default 1
	range 0 21

config ESP32C3_UART1_CTSPIN
	int "UART1 CTS Pin"
	depends on SERIAL_OFLOWCONTROL
	default 2
	range 0 21

endif # ESP32C3_UART1

endmenu

menu "Real-Time Timer"
	depends on ESP32C3_RT_TIMER

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

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

config ESP32C3_RT_TIMER_TASK_STACK_SIZE
	int "Timer task stack size"
	default 2048

endmenu # Real-Time Timer

if ESP32C3_TIMER
menu "Timer/counter Configuration"

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

config ESP32C3_FREERUN
	bool "TIM 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
endif # ESP32C3_TIMER

menu "LEDC configuration"
	depends on ESP32C3_LEDC

menuconfig ESP32C3_LEDC_TIM0
	bool "Timer 0"
	default n

if ESP32C3_LEDC_TIM0

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

endif # ESP32C3_LEDC_TIM0

menuconfig ESP32C3_LEDC_TIM1
	bool "Timer 1"
	default n

if ESP32C3_LEDC_TIM1

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

endif # ESP32C3_LEDC_TIM1

menuconfig ESP32C3_LEDC_TIM2
	bool "Timer 2"
	default n

if ESP32C3_LEDC_TIM2

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

endif # ESP32C3_LEDC_TIM2

config ESP32C3_LEDC_CHANNEL0_PIN
	int "Channel 0 pin"
	default 2

config ESP32C3_LEDC_CHANNEL1_PIN
	int "Channel 1 pin"
	default 3

config ESP32C3_LEDC_CHANNEL2_PIN
	int "Channel 2 pin"
	default 4

config ESP32C3_LEDC_CHANNEL3_PIN
	int "Channel 3 pin"
	default 5

config ESP32C3_LEDC_CHANNEL4_PIN
	int "Channel 4 pin"
	default 6

config ESP32C3_LEDC_CHANNEL5_PIN
	int "Channel 5 pin"
	default 7

endmenu # LEDC configuration

menu "ADC Configuration"
	depends on ESP32C3_ADC

if ESP32C3_ADC1

choice ESP32C3_ADC_VOL_RANGES
	prompt "ADC1 voltage ranges"
	default ESP32C3_ADC_VOL_750

config ESP32C3_ADC_VOL_750
	bool "0~750mV"

config ESP32C3_ADC_VOL_1050
	bool "0~1050mV"

config ESP32C3_ADC_VOL_1300
	bool "0~1300mV"

config ESP32C3_ADC_VOL_2500
	bool "0~2500mV"

endchoice

config ESP32C3_ADC1_CHANNEL0
	bool "ADC1 channel 0"
	default n

config ESP32C3_ADC1_CHANNEL1
	bool "ADC1 channel 1"
	default n

config ESP32C3_ADC1_CHANNEL2
	bool "ADC1 channel 2"
	default n

config ESP32C3_ADC1_CHANNEL3
	bool "ADC1 channel 3"
	default n

config ESP32C3_ADC1_CHANNEL4
	bool "ADC1 channel 4"
	default n

endif # ESP32C3_ADC1
endmenu # ADC Configuration

menu "Wi-Fi configuration"
	depends on ESP32C3_WIFI

choice
	prompt "ESP32-C3 Wi-Fi mode"
	default ESP32C3_WIFI_STATION

config ESP32C3_WIFI_STATION
	bool "Station mode"

config ESP32C3_WIFI_SOFTAP
	bool "SoftAP mode"

config ESP32C3_WIFI_STATION_SOFTAP
	bool "Station + SoftAP"

endchoice # ESP32-C3 Wi-Fi mode

config ESP32C3_WIFI_STATIC_RXBUF_NUM
	int "Wi-Fi static RX buffer number"
	default 10

config ESP32C3_WIFI_DYNAMIC_RXBUF_NUM
	int "Wi-Fi dynamic RX buffer number"
	default 32

config ESP32C3_WIFI_DYNAMIC_TXBUF_NUM
	int "Wi-Fi dynamic TX buffer number"
	default 32

config ESP32C3_WIFI_TX_AMPDU
	bool "Wi-Fi TX AMPDU"
	default y

config ESP32C3_WIFI_RX_AMPDU
	bool "Wi-Fi RX AMPDU"
	default y

config ESP32C3_WIFI_RXBA_AMPDU_WZ
	int "Wi-Fi RX BA AMPDU windown size"
	default 6

config ESP32C3_WIFI_CONNECT_TIMEOUT
	int "Connect timeout by second"
	default 10
	---help---
		Max waiting time of connecting to AP.

config ESP32C3_WIFI_SCAN_RESULT_SIZE
	int "Scan result buffer"
	default 4096
	---help---
		Maximum scan result buffer size.

config ESP32C3_WIFI_STA_DISCONNECT_PM
	bool "Power Management for station when disconnected"
	default n
	---help---
		Select this option to enable power management for station when disconnected.
		Chip will do modem-sleep when RF module is not in use anymore.

config EXAMPLE_WIFI_LISTEN_INTERVAL
	int "Wi-Fi listen interval"
	default 3
	---help---
		Interval for station to listen to beacon from AP. The unit of listen interval is one beacon interval.
		For example, if beacon interval is 100 ms and listen interval is 3, the interval for station to listen
		to beacon is 300 ms.

choice EXAMPLE_POWER_SAVE_MODE
	prompt "Power save mode"
	default EXAMPLE_POWER_SAVE_NONE
	---help---
		Power save mode for the ESP32-C3 to use. Modem sleep mode includes minimum and maximum power save modes.
		In minimum power save mode, station wakes up every DTIM to receive beacon. Broadcast data will not be
		lost because it is transmitted after DTIM. However, it can not save much more power if DTIM is short
		for DTIM is determined by AP.
		In maximum power save mode, station wakes up every listen interval to receive beacon. Broadcast data
		may be lost because station may be in sleep state at DTIM time. If listen interval is longer, more power
		is saved but broadcast data is more easy to lose.

config EXAMPLE_POWER_SAVE_NONE
	bool "none"

config EXAMPLE_POWER_SAVE_MIN_MODEM
	bool "minimum modem"

config EXAMPLE_POWER_SAVE_MAX_MODEM
	bool "maximum modem"

endchoice

config ESP32C3_WIFI_RECONNECT
	bool "Enable Wi-Fi to reconnect"
	default n
	---help---
		Select this option to enable Wi-Fi to reconnect for station when disconnected.

choice ESP32C3_WIFI_LOG_LEVEL
	depends on DEBUG_INFO
	prompt "WiFi debug log level"
	default WIFI_LOG_LEVEL_INFO
	---help---
		The WiFi log is divided into the following levels: ERROR,WARNING,INFO,DEBUG,VERBOSE.

config WIFI_LOG_LEVEL_NONE
	bool "No output"

config WIFI_LOG_LEVEL_ERROR
	bool "Error"

config WIFI_LOG_LEVEL_WARN
	bool "Warning"

config WIFI_LOG_LEVEL_INFO
	bool "Info"

config WIFI_LOG_LEVEL_DEBUG
	bool "Debug"

config WIFI_LOG_LEVEL_VERBOSE
	bool "Verbose"

endchoice

config WIFI_LOG_LEVEL
	int
	default 0 if WIFI_LOG_LEVEL_NONE
	default 1 if WIFI_LOG_LEVEL_ERROR
	default 2 if WIFI_LOG_LEVEL_WARN
	default 3 if WIFI_LOG_LEVEL_INFO
	default 4 if WIFI_LOG_LEVEL_DEBUG
	default 5 if WIFI_LOG_LEVEL_VERBOSE

endmenu # Wi-Fi configuration

menu "BLE Configuration"
	depends on ESP32C3_BLE

config ESP32C3_BLE_TTY_NAME
	string "BLE TTY device name"
	default "/dev/ttyHCI0"
	depends on UART_BTH4

config ESP32C3_BLE_TASK_STACK_SIZE
	int "Controller task stack size"
	default 4096

config ESP32C3_BLE_TASK_PRIORITY
	int "Controller task priority"
	default 253

endmenu # BLE Configuration

menu "SPI Flash configuration"

choice ESP32C3_FLASH_MODE
	prompt "SPI Flash mode"
	default ESP32C3_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 ESP32C3_FLASH_MODE_DIO
	bool "Dual IO (DIO)"

config ESP32C3_FLASH_MODE_DOUT
	bool "Dual Output (DOUT)"

config ESP32C3_FLASH_MODE_QIO
	bool "Quad IO (QIO)"

config ESP32C3_FLASH_MODE_QOUT
	bool "Quad Output (QOUT)"

endchoice # ESP32C3_FLASH_MODE

choice ESP32C3_FLASH_FREQ
	prompt "SPI Flash frequency"
	default ESP32C3_FLASH_FREQ_40M
	---help---
		SPI Flash frequency.

config ESP32C3_FLASH_FREQ_80M
	bool "80 MHz"

config ESP32C3_FLASH_FREQ_40M
	bool "40 MHz"

config ESP32C3_FLASH_FREQ_26M
	bool "26 MHz"

config ESP32C3_FLASH_FREQ_20M
	bool "20 MHz"

endchoice # ESP32C3_FLASH_FREQ

if ESP32C3_HAVE_OTA_PARTITION

comment "Application Image OTA Update support"

config ESP32C3_OTA_PARTITION_ENCRYPT
	bool "Encrypt OTA partitions"
	default y
	depends on ESP32C3_SECURE_FLASH_ENC_ENABLED

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

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

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

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

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

config ESP32C3_OTA_SCRATCH_OFFSET
	hex "Scratch partition offset"
	default 0x210000

config ESP32C3_OTA_SCRATCH_SIZE
	hex "Scratch partition size"
	default 0x40000

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

endif

if ESP32C3_SPIFLASH

comment "General storage MTD configuration"

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

config ESP32C3_SPIFLASH_MTD_BLKSIZE
	int "Storage MTD block size"
	default 64
	depends on ESP32C3_MTD

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

if ESP32C3_APP_FORMAT_LEGACY

comment "Partition Table configuration"

config ESP32C3_PARTITION_TABLE
	bool "Create MTD partitions from Partition Table"
	default n
	---help---
		Decode partition table and initialize partitions as MTD.

config ESP32C3_PARTITION_MOUNTPT
	string "Partition mount point"
	default "/dev/esp/partition/"
	depends on ESP32C3_PARTITION_TABLE

endif # ESP32C3_APP_FORMAT_LEGACY

endif # ESP32C3_SPIFLASH

endmenu # SPI Flash configuration

menu "GDMA Configuration"
	depends on ESP32C3_DMA

endmenu # GDMA Configuration

config ESP32C3_AUTO_SLEEP
	bool "Auto-sleep"
	default n
	select PM
	select ESP32C3_RT_TIMER
	select ESP32C3_TICKLESS
	---help---
		Enable ESP32-C3 Auto-sleep

config ESP32C3_TICKLESS
	bool "Enable ESP32-C3 tickless OS"
	default n
	select ARCH_HAVE_TICKLESS
	select SCHED_TICKLESS

config ESP32C3_HAVE_OTA_PARTITION
	bool
	default n

menu "Application Image Configuration"

choice
	prompt "Application Image Format"
	default ESP32C3_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 ESP32C3_APP_FORMAT_LEGACY
	bool "Legacy format"
	---help---
		This is the legacy application image format, as supported by the ESP-IDF
		2nd stage bootloader.

config ESP32C3_APP_FORMAT_MCUBOOT
	bool "MCUboot-bootable format"
	depends on !MCUBOOT_BOOTLOADER
	select ESP32C3_HAVE_OTA_PARTITION
	---help---
		The Espressif port of MCUboot supports the loading of unsegmented firmware
		images.

endchoice # Application Image Format

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

config ESP32C3_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 (ESP32C3_APP_FORMAT_LEGACY or ESP32C3_APP_FORMAT_MCUBOOT)

config ESP32C3_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
		(ESP32C3_APP_FORMAT_LEGACY or ESP32C3_APP_FORMAT_MCUBOOT) and partition information.

endchoice

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

config ESP32C3_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 ESP32C3_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 ESP32C3_APP_MCUBOOT_HEADER_SIZE
	int "Application image header size (in bytes)"
	default 32
	depends on ESP32C3_APP_FORMAT_MCUBOOT

config ESP32C3_PARTITION_TABLE_OFFSET
	hex "Partition Table offset"
	default 0x8000
	depends on ESP32C3_APP_FORMAT_LEGACY

if BUILD_PROTECTED

config ESP32C3_USER_IMAGE_OFFSET
	hex "User image offset"
	default 0x90000
	---help---
		Offset in SPI Flash for flashing the User application firmware image.

endif

source "arch/risc-v/src/esp32c3/Kconfig.security"

endmenu # Application Image Configuration

menu "Brownout Detect Configuration"
	depends on ESP32C3_BROWNOUT_DET

choice ESP32C3_BROWNOUT_DET_LVL_SEL
	prompt "Brownout voltage level"
	default ESP32C3_BROWNOUT_DET_LVL_SEL_7
	---help---
		The brownout detector will reset the chip when the supply voltage is approximately
		below this level. Note that there may be some variation of brownout voltage level
		between each chip.

		#The voltage levels here are estimates, more work needs to be done to figure out the exact voltages
		#of the brownout threshold levels.

config ESP32C3_BROWNOUT_DET_LVL_SEL_7
	bool "2.51V"

config ESP32C3_BROWNOUT_DET_LVL_SEL_6
	bool "2.64V"

config ESP32C3_BROWNOUT_DET_LVL_SEL_5
	bool "2.76V"

config ESP32C3_BROWNOUT_DET_LVL_SEL_4
	bool "2.92V"

config ESP32C3_BROWNOUT_DET_LVL_SEL_3
	bool "3.10V"

config ESP32C3_BROWNOUT_DET_LVL_SEL_2
	bool "3.27V"

endchoice

config ESP32C3_BROWNOUT_DET_LVL
	int
	default 2 if ESP32C3_BROWNOUT_DET_LVL_SEL_2
	default 3 if ESP32C3_BROWNOUT_DET_LVL_SEL_3
	default 4 if ESP32C3_BROWNOUT_DET_LVL_SEL_4
	default 5 if ESP32C3_BROWNOUT_DET_LVL_SEL_5
	default 6 if ESP32C3_BROWNOUT_DET_LVL_SEL_6
	default 7 if ESP32C3_BROWNOUT_DET_LVL_SEL_7

endmenu # ESP32C3_BROWNOUT_DET

endif # ARCH_CHIP_ESP32C3
