#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

#include "stm32l1xx_hal.h"


void Error_Handler(void);

#define SPI1_CS_Pin GPIO_PIN_4
#define SPI1_CS_GPIO_Port GPIOC
#define SD_VCC_Pin GPIO_PIN_5
#define SD_VCC_GPIO_Port GPIOC
#define SNC_VCC_Pin GPIO_PIN_12
#define SNC_VCC_GPIO_Port GPIOB
#define IOT_VCC_Pin GPIO_PIN_15
#define IOT_VCC_GPIO_Port GPIOA
#define IOT_RESET_Pin GPIO_PIN_2
#define IOT_RESET_GPIO_Port GPIOD


#define bit(n)	(1U << (n))

#define F_IOT_RECEIVED	bit(0)
#define F_FTDI_RECEIVED	bit(1)
#define F_MEASURE_ALARM	bit(2)
#define F_SEND_ALARM	bit(3)
#define F_SD_CARD		bit(4)

/* RN2483 */
#define RN_JOIN_OTAA	"mac join otaa"
#define RN_SYS_RESET  	"sys reset"
#define RN_SYS_GET_VDD	"sys get vdd"

typedef enum
{
	iot_OK,
	iot_DATA,
	iot_TIMEOUT,
 /* all other error codes */
	iot_ERR_MAC_INIT,
	iot_ERR_INVALID_PARAM,
	iot_ERR_NOT_JOINED,
	iot_ERR_NO_FREE_CH,
	iot_ERR_SILENT,
	iot_ERR_FR_CNT_REJOIN_NEEDED,
	iot_ERR_BUSY,
	iot_ERR_MAC_PAUSED,
	iot_ERR_INVALID_DATA_LENGTH,
	iot_ERR_KEYS_NOT_INIT,
	iot_ERR_SLEEP_MODE,
 /* all other reply codes */
	iot_REPLY_TX_MAC_OK,
	iot_REPLY_TX_MAC_ERR,
	iot_REPLY_TX_INVALID_DATA_LEN,
	iot_REPLY_TX_MAC_RX,
	iot_REPLY_JOIN_ACCEPTED,
	iot_REPLY_JOIN_DENIED,
	iot_REPLY_TIMEOUT,
	iot_REPLY_OTHER,
}iot_response;

typedef enum
{
	idle,
	power,
	idle2,
	sleep,
	reset,
	joining,
	joined_ok,
	joined,
	transmitting,
	transmitting_ok,
	transmitted,
	receive
}iot_states;




#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
