/*
 * Smart Blocks SDK
 * Author & Copyright: Michał Lower
 * All rights reserved 2016-
 *
 */

#ifndef APP_CONFIG_H
#define APP_CONFIG_H

// <<< Use Configuration Wizard in Context Menu >>>\n

// <q> LF_CLK_INTERNAL - use RC synthetized LFCLK instead of crystal
#ifndef LF_CLK_INTERNAL
#define LF_CLK_INTERNAL 0
#endif

//defines
// <h> App_twi configuration

// <o> APP_TWI_QUEUE_SIZE - maximum number of pending TWI transactions
#ifndef APP_TWI_QUEUE_SIZE
#define APP_TWI_QUEUE_SIZE 6
#endif


// </h>

// <h> Scheduler settings

// SCHED_MAX_EVENT_DATA_SIZE - Maximum size of single scheduler context
#ifndef SCHED_MAX_EVENT_DATA_SIZE
#define SCHED_MAX_EVENT_DATA_SIZE 			APP_TIMER_SCHED_EVENT_DATA_SIZE
#endif

// <o> SCHED_QUEUE_SIZE - Maximum number of events that can be queued
#ifndef SCHED_QUEUE_SIZE
#define SCHED_QUEUE_SIZE 10
#endif

// </h>

// <h> BLE Settings

// <h> BLE event handler manager
// <o> BLE_HANDLERS_MAX - maximum number of BLE event handlers btle_event_manager can register
// <1-255>
#ifndef BLE_HANDLERS_MAX
#define BLE_HANDLERS_MAX 8
#endif

// <o> SYS_HANDLERS_MAX - maximum number of SYS event handlers btle_event_manager can register
// <1-255>
#ifndef SYS_HANDLERS_MAX
#define SYS_HANDLERS_MAX 3
#endif

// <q> BTLE_EVENT_HANDLER_PROFILING - print extra debug messages that allow to profile BLE_HANDLERS_MAX and SYS_HANDLERS_MAX
#ifndef BTLE_EVENT_HANDLER_PROFILING
#define BTLE_EVENT_HANDLER_PROFILING 0
#endif

// </h>

// <h> GATT settings

// <q> IS_SRVC_CHANGED_CHARACT_PRESENT - Include or not the service_changed characteristic. if not enabled, the server's database cannot be changed for the lifetime of the device
#ifndef IS_SRVC_CHANGED_CHARACT_PRESENT
#define IS_SRVC_CHANGED_CHARACT_PRESENT  0
#endif

// <o> NRF_BLE_GATT_MAX_MTU_SIZE - Size of GATT packets that application uses. Default: 23 bytes. Max: 158 bytes.
// <23-158>
#ifndef NRF_BLE_GATT_MAX_MTU_SIZE
#define NRF_BLE_GATT_MAX_MTU_SIZE 23
#endif

// <s> DEVICE_NAME - Name of device. Will be included in the advertising data.
#ifndef DEVICE_NAME
#define DEVICE_NAME                      "SM_Template"
#endif

// <s> MANUFACTURER_NAME - Manufacturer. Will be passed to Device Information Service.
#ifndef MANUFACTURER_NAME
#define MANUFACTURER_NAME                "Smablo"
#endif

// <o> MANUFACTURER_COMPANY_ID - Officially assigned BL SIG Manufacturer ID, used in manufacturer specific data
#ifndef MANUFACTURER_COMPANY_ID
#define MANUFACTURER_COMPANY_ID			 		 940
#endif

// <o> DEVICE_TYPE - device type advertised as the first byte of manufacturer specific data
// <0-255>
#ifndef DEVICE_TYPE
#define DEVICE_TYPE 0x01
#endif

// <o> MAX_CHAR_LEN - maximum length of characteristic data used in queued write buffer length
// <36-255>
#ifndef MAX_CHAR_LEN
#define MAX_CHAR_LEN 40
#endif
 
// <o> HVN_TX_QUEUE_SIZE - Minimum guaranteed number of Handle Value Notifications that can be queued for transmission 
// <1-100> 
#ifndef HVN_TX_QUEUE_SIZE 
#define HVN_TX_QUEUE_SIZE 1 
#endif 

// </h>

// <h> Advertising parameters

// <o> APP_ADV_INTERVAL - Application advertising interval in ms
// <20-10240>
#ifndef APP_ADV_INTERVAL
#define APP_ADV_INTERVAL                 MSEC_TO_UNITS(500, UNIT_0_625_MS)
#endif

// </h>

// <h> Scanning parameters

// <o> SCAN_INTERVAL - Scan interval in ms
// <3-10240>
#ifndef SCAN_INTERVAL
#define SCAN_INTERVAL           				 MSEC_TO_UNITS(100, UNIT_0_625_MS)
#endif

// <o> SCAN_WINDOW - Scan window in ms
// <3-10240>
#ifndef SCAN_WINDOW
#define SCAN_WINDOW             				 MSEC_TO_UNITS(32, UNIT_0_625_MS)
#endif

// <q> SCAN_ACTIVE - if enabled perform active scanning (scan requests)
#ifndef SCAN_ACTIVE
#define SCAN_ACTIVE             				 0
#endif

// <q> SCAN_SELECTIVE - if enabled use whitelist for scanning
#ifndef SCAN_SELECTIVE
#define SCAN_SELECTIVE          				 0
#endif

// <o> SCAN_TIMEOUT - how long scanning should last in seconds (0 - scan forever)
// <0-0xFFFF>
#ifndef SCAN_TIMEOUT
#define SCAN_TIMEOUT            				 0
#endif

// </h>

// <h> Connection parameters

// <o> MIN_CONNECTION_INTERVAL - Determines minimum connection interval in milliseconds
// <8-4000>
#ifndef MIN_CONNECTION_INTERVAL
#define MIN_CONNECTION_INTERVAL_MS 100
#define MIN_CONNECTION_INTERVAL 				 MSEC_TO_UNITS(MIN_CONNECTION_INTERVAL_MS, UNIT_1_25_MS)
#endif

// <o> MAX_CONNECTION_INTERVAL - Determines maximum connection interval in milliseconds
// <8-4000>
#ifndef MAX_CONNECTION_INTERVAL
#define MAX_CONNECTION_INTERVAL_MS 120
#define MAX_CONNECTION_INTERVAL 				 MSEC_TO_UNITS(MAX_CONNECTION_INTERVAL_MS, UNIT_1_25_MS)
#endif

// <o> SLAVE_LATENCY - Determines slave latency in counts of connection events
// <0-0x01F3>
#ifndef SLAVE_LATENCY
#define SLAVE_LATENCY           				 2
#endif

// <o> SUPERVISION_TIMEOUT - Determines supervision time-out in milliseconds
// <100-32000>
#ifndef SUPERVISION_TIMEOUT
#define SUPERVISION_TIMEOUT_MS 5000
#define SUPERVISION_TIMEOUT     				 MSEC_TO_UNITS(SUPERVISION_TIMEOUT_MS, UNIT_10_MS)
#endif

//The Supervision_Timeout in milliseconds shall be larger than
//(1 + Conn_Latency) * Conn_Interval_Max * 2, where Conn_Interval_Max is given in milliseconds.
#if SUPERVISION_TIMEOUT_MS <= (1+ SLAVE_LATENCY) * MAX_CONNECTION_INTERVAL_MS *2

#error "Wrong connection parameters: \
The SUPERVISION_TIMEOUT in milliseconds shall be larger than \
(1 + SLAVE_LATENCY) * MAX_CONNECTION_INTERVAL * 2, where MAX_CONNECTION_INTERVAL is given in milliseconds."

#endif

// <q> DISCONNECT_ON_FAIL - Disconnect if connection parameters negotiation fails
#ifndef DISCONNECT_ON_FAIL
#define DISCONNECT_ON_FAIL 0
#endif

// <o> MAX_CONN_PARAMS_UPDATE_COUNT - How many times retry connection parameters negotiation
// <1-10>
#ifndef MAX_CONN_PARAMS_UPDATE_COUNT
#define MAX_CONN_PARAMS_UPDATE_COUNT 3
#endif

// <o> FIRST_CONN_PARAMS_UPDATE_DELAY - delay before first parameters negotiation in ms
// <10-60000>
#ifndef FIRST_CONN_PARAMS_UPDATE_DELAY
#define FIRST_CONN_PARAMS_UPDATE_DELAY 1000
#endif

// <o> NEXT_CONN_PARAMS_UPDATE_DELAY - delay before next parameters negotiation in ms
// <10-60000>
#ifndef NEXT_CONN_PARAMS_UPDATE_DELAY
#define NEXT_CONN_PARAMS_UPDATE_DELAY 30000
#endif


// <o> CONN_EVENT_LENGTH - The time set aside for this connection on every connection interval in 1.25 ms units
// <1-1000>
#ifndef CONN_EVENT_LENGTH
#define CONN_EVENT_LENGTH 3
#endif

// <o> CONN_COUNT - The number of concurrent connections the application can create
// <1-20>
#ifndef CONN_COUNT
#define CONN_COUNT 1
#endif

//</h>

// <h> Connection security

// <q> SEC_PARAM_BOND - Perform bonding, if disabled do only pairing
#ifndef SEC_PARAM_BOND
#define SEC_PARAM_BOND              		 1
#endif

// <q> SEC_PARAM_MITM - Enable Man In The Middle protection
#ifndef SEC_PARAM_MITM
#define SEC_PARAM_MITM              		 0
#endif

// <q> SEC_PARAM_LESC - Enable LE Secure Connections
#ifndef SEC_PARAM_LESC
#define SEC_PARAM_LESC              		 0
#endif

// <q> SEC_PARAM_KEYPRESS - Enable Keypress notifications
#ifndef SEC_PARAM_KEYPRESS
#define SEC_PARAM_KEYPRESS          		 0
#endif

//!!! This is 'enum' field
// <o> SEC_PARAM_IO_CAPABILITIES - I/O capabilities for pairing
// <0x00=> BLE_GAP_IO_CAPS_DISPLAY_ONLY - Display Only
// <0x01=> BLE_GAP_IO_CAPS_DISPLAY_YESNO - Display and Yes/No entry
// <0x02=> BLE_GAP_IO_CAPS_KEYBOARD_ONLY - Keyboard Only
// <0x03=> BLE_GAP_IO_CAPS_NONE - No I/O capabilities
// <0x04=> BLE_GAP_IO_CAPS_KEYBOARD_DISPLAY - Keyboard and Display
#define SEC_PARAM_IO_CAPABILITIES_E   		 3

#ifndef SEC_PARAM_IO_CAPABILITIES
//decode the enum
#if SEC_PARAM_IO_CAPABILITIES_E == 0x00
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_DISPLAY_ONLY
#elif SEC_PARAM_IO_CAPABILITIES_E == 0x01
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_DISPLAY_YESNO
#elif SEC_PARAM_IO_CAPABILITIES_E == 0x02
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_KEYBOARD_ONLY
#elif SEC_PARAM_IO_CAPABILITIES_E == 0x03
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE
#elif SEC_PARAM_IO_CAPABILITIES_E == 0x04
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_KEYBOARD_DISPLAY
#endif
#endif

// <q> SEC_PARAM_OOB - Enable Out Of Band pairing key negotiation channel
#ifndef SEC_PARAM_OOB
#define SEC_PARAM_OOB               		 0
#endif

// <o> SEC_PARAM_MIN_KEY_SIZE - Minimum encryption key size in octets
// <7-16>
#ifndef SEC_PARAM_MIN_KEY_SIZE
#define SEC_PARAM_MIN_KEY_SIZE      		 7
#endif

// <o> SEC_PARAM_MAX_KEY_SIZE - Maximum encryption key size in octets
// <7-16>
#ifndef SEC_PARAM_MAX_KEY_SIZE
#define SEC_PARAM_MAX_KEY_SIZE      		 16
#endif

// <q> SEC_PARAM_CONN_REPAIR - Should allow bond repair when already bonded peer asks for rebonding?
#ifndef SEC_PARAM_CONN_REPAIR
#define SEC_PARAM_CONN_REPAIR 1
#endif

//</h>

// <h> Softdevice settings

// <o> CENTRAL_LINK_COUNT - Maximum number of concurrent master connections
// <0-8>
#ifndef CENTRAL_LINK_COUNT
#define CENTRAL_LINK_COUNT 0
#endif

// <o> PERIPHERAL_LINK_COUNT - Maximum number of concurrent slave connections
// <0-1>
#ifndef PERIPHERAL_LINK_COUNT
#define PERIPHERAL_LINK_COUNT 1
#endif

// <o> CENTRAL_SEC_COUNT - Maximum number of SMP instances shared between all connections acting as centrals.
// <0-8>
#ifndef CENTRAL_SEC_COUNT
#define CENTRAL_SEC_COUNT 0
#endif

// <o> VS_UUID_COUNT - Maximum number of vendor specific (128 bit) UUIDS
// <0-1>
#ifndef VS_UUID_COUNT
#define VS_UUID_COUNT 2
#endif

//</h>

// Configuration wizard doesnt support negative enum values!!

//so this is 'internal enum' not exact value
// <o> TX_POWER_DBM - Radio TX power
// <140=> -40 dBm
// <130=> -30 dBm
// <120=> -20 dBm
// <116=> -16 dBm
// <112=> -12 dBm
// <108=> -8 dBm
// <104=> -4 dBm
// <0=> 0 dBm
// <3=> +3 dBm
// <4=> +4 dBm

#ifndef TX_POWER_DBM
//convert 'internal enum' to value
#define TX_POWER_DBM_E 0
#if TX_POWER_DBM_E > 100
#define TX_POWER_DBM (0-(TX_POWER_DBM_E-100))
#else
#define TX_POWER_DBM TX_POWER_DBM_E
#endif
#endif

// </h>


#endif
