#
# Copyright (c) 2024
# SPDX-License-Identifier: Apache-2.0
#

# ==============================================================================
# Enable Parent Systems First
# ==============================================================================
CONFIG_GPIO=y
CONFIG_PINCTRL=y
CONFIG_I2C=y
CONFIG_ADC=y
CONFIG_ADC_NRFX_SAADC=y
CONFIG_SENSOR=y
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_POSIX_API=y
CONFIG_NET_NATIVE=n
CONFIG_NRF_MODEM_LIB=y
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_BUILD_WITH_TFM=y
CONFIG_MQTT_LIB=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_NVS=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# ==============================================================================
# Now, configure the specific drivers and features that depend on the above
# ==============================================================================

# Sensor Drivers
CONFIG_LSM6DSO=y
CONFIG_LSM6DSO_TRIGGER_NONE=y  # Use polling mode
CONFIG_LSM6DSO_ENABLE_TEMP=y   # Enable temperature sensor
CONFIG_LSM6DSO_SENSORHUB=n     # Disable sensor hub
CONFIG_BME680=y  # Standard BME680 driver
# CONFIG_BSEC=n
# CONFIG_BME68X_SENSOR_API=n
# CONFIG_BME68X_IAQ=n
# CONFIG_BME68X_IAQ_SETTINGS=n
# CONFIG_BME68X_IAQ_SAMPLE_RATE_LOW_POWER=n
# VEML6030 - Custom driver implementation
# NT3H2111 - I2C-based NFC tag IC (doesn't require nRF NFC hardware)
# The NT3H2111 provides NFC functionality via I2C interface

# Modem and Connectivity
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_TIMEOUT=180

# GNSS Configuration
CONFIG_NRF_CLOUD=y

# DECT NR+ Configuration - disabled for now until we confirm availability
# CONFIG_NRF_MODEM_LIB_DECT_NR_PLUS=y
# CONFIG_DECT_NR_PLUS=y
# CONFIG_DECT_NR_PLUS_MESH=y
# CONFIG_DECT_NR_PLUS_MESH_MAX_NODES=20
# CONFIG_DECT_NR_PLUS_MESH_ROUTING=y

# MQTT Configuration
CONFIG_MQTT_LIB_TLS=y
CONFIG_MQTT_KEEPALIVE=120

# HTTP Client Configuration
CONFIG_HTTP_CLIENT=y
# CONFIG_HTTP_CLIENT_HEADERS=y
# CONFIG_HTTP_CLIENT_PAYLOAD=y
CONFIG_HTTP_PARSER=y
CONFIG_HTTP_PARSER_URL=y

# REST Client Configuration
CONFIG_REST_CLIENT=y

# TLS/SSL Configuration
CONFIG_TLS_CREDENTIALS=y
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=32768

# ==============================================================================
# General Kernel and C Library Settings
# ==============================================================================
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_REBOOT=y

# Logging
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_LOG_DEFAULT_LEVEL=3

# Segger RTT Configuration
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_RTT_MODE_DROP=y
CONFIG_LOG_BACKEND_RTT_MESSAGE_SIZE=256
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=1024
CONFIG_SEGGER_RTT_BUFFER_SIZE_DOWN=256

# C Library and Utilities
CONFIG_NEWLIB_LIBC=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_JSON_LIBRARY=y

# Modem Antenna Configuration for QM13345
CONFIG_MODEM_ANTENNA=y

# Try MAGPIO configuration first (might work even without RFFE support)
# This configures the modem's internal antenna switch control pins
# Format: enabled,mode,pin_config,pin,active,start_freq,stop_freq
CONFIG_MODEM_ANTENNA_AT_MAGPIO="AT%XMAGPIO=1,0,0,1,1,1574,1577"

# Configure RFFE device for QM13345 (USID=7 from schematic)
# These will only work if firmware supports RFFE
CONFIG_MODEM_ANTENNA_AT_MIPIRFFEDEV="AT%XMIPIRFFEDEV=1,7,0"
# Configure RFFE control for INIT phase (enable RF1)
CONFIG_MODEM_ANTENNA_AT_MIPIRFFECTRL_INIT="AT%XMIPIRFFECTRL=1,0,1,0,1"
# Configure RFFE control for ON phase (keep RF1 enabled)
CONFIG_MODEM_ANTENNA_AT_MIPIRFFECTRL_ON="AT%XMIPIRFFECTRL=1,1,1,0,1"
# Configure RFFE control for OFF phase (all off)
CONFIG_MODEM_ANTENNA_AT_MIPIRFFECTRL_OFF="AT%XMIPIRFFECTRL=1,2,1,0,0"
# Configure RFFE control for PWROFF phase (all off)
CONFIG_MODEM_ANTENNA_AT_MIPIRFFECTRL_PWROFF="AT%XMIPIRFFECTRL=1,3,1,0,0"