/** @file exti_regs.h
 * Module defining the EXTI registers
 *
 * Mainly made to be used by the exti module. It is recommanded to go through
 * the functions provided by that module instead of directly using the registers
 * defined here.
 */

#ifndef _EXTI_REGS_H_
#define _EXTI_REGS_H_

//--includes--------------------------------------------------------------------

#include "reg.h"

#include "stdint.h"


//--type definitions------------------------------------------------------------

#define EXTI_BASE_ADDRESS 0x40010400

union EXTI_IMR {
	struct __attribute__((packed)) {
		uint32_t MR0:1;
		uint32_t MR1:1;
		uint32_t MR2:1;
		uint32_t MR3:1;
		uint32_t MR4:1;
		uint32_t MR5:1;
		uint32_t MR6:1;
		uint32_t MR7:1;
		uint32_t MR8:1;
		uint32_t MR9:1;
		uint32_t MR10:1;
		uint32_t MR11:1;
		uint32_t MR12:1;
		uint32_t MR13:1;
		uint32_t MR14:1;
		uint32_t MR15:1;
		uint32_t MR16:1;
		uint32_t MR17:1;
		uint32_t MR18:1;
		uint32_t reserved1:13;
	};
	uint32_t word;
};

#define EXTI_IMR_MR0	   reg_def( 0,  1)
#define EXTI_IMR_MR1	   reg_def( 1,  1)
#define EXTI_IMR_MR2	   reg_def( 2,  1)
#define EXTI_IMR_MR3	   reg_def( 3,  1)
#define EXTI_IMR_MR4	   reg_def( 4,  1)
#define EXTI_IMR_MR5	   reg_def( 5,  1)
#define EXTI_IMR_MR6	   reg_def( 6,  1)
#define EXTI_IMR_MR7	   reg_def( 7,  1)
#define EXTI_IMR_MR8	   reg_def( 8,  1)
#define EXTI_IMR_MR9	   reg_def( 9,  1)
#define EXTI_IMR_MR10	   reg_def(10,  1)
#define EXTI_IMR_MR11	   reg_def(11,  1)
#define EXTI_IMR_MR12	   reg_def(12,  1)
#define EXTI_IMR_MR13	   reg_def(13,  1)
#define EXTI_IMR_MR14	   reg_def(14,  1)
#define EXTI_IMR_MR15	   reg_def(15,  1)
#define EXTI_IMR_MR16	   reg_def(16,  1)
#define EXTI_IMR_MR17	   reg_def(17,  1)
#define EXTI_IMR_MR18	   reg_def(18,  1)
#define EXTI_IMR_reserved1 reg_def(19, 13)

union EXTI_EMR {
	struct __attribute__((packed)) {
		uint32_t MR0:1;
		uint32_t MR1:1;
		uint32_t MR2:1;
		uint32_t MR3:1;
		uint32_t MR4:1;
		uint32_t MR5:1;
		uint32_t MR6:1;
		uint32_t MR7:1;
		uint32_t MR8:1;
		uint32_t MR9:1;
		uint32_t MR10:1;
		uint32_t MR11:1;
		uint32_t MR12:1;
		uint32_t MR13:1;
		uint32_t MR14:1;
		uint32_t MR15:1;
		uint32_t MR16:1;
		uint32_t MR17:1;
		uint32_t MR18:1;
		uint32_t reserved1:13;
	};
	uint32_t word;
};

#define EXTI_EMR_MR0	   reg_def( 0,  1)
#define EXTI_EMR_MR1	   reg_def( 1,  1)
#define EXTI_EMR_MR2	   reg_def( 2,  1)
#define EXTI_EMR_MR3	   reg_def( 3,  1)
#define EXTI_EMR_MR4	   reg_def( 4,  1)
#define EXTI_EMR_MR5	   reg_def( 5,  1)
#define EXTI_EMR_MR6	   reg_def( 6,  1)
#define EXTI_EMR_MR7	   reg_def( 7,  1)
#define EXTI_EMR_MR8	   reg_def( 8,  1)
#define EXTI_EMR_MR9	   reg_def( 9,  1)
#define EXTI_EMR_MR10	   reg_def(10,  1)
#define EXTI_EMR_MR11	   reg_def(11,  1)
#define EXTI_EMR_MR12	   reg_def(12,  1)
#define EXTI_EMR_MR13	   reg_def(13,  1)
#define EXTI_EMR_MR14	   reg_def(14,  1)
#define EXTI_EMR_MR15	   reg_def(15,  1)
#define EXTI_EMR_MR16	   reg_def(16,  1)
#define EXTI_EMR_MR17	   reg_def(17,  1)
#define EXTI_EMR_MR18	   reg_def(18,  1)
#define EXTI_EMR_reserved1 reg_def(19, 13)

union EXTI_RTSR {
	struct __attribute__((packed)) {
		uint32_t TR0:1;
		uint32_t TR1:1;
		uint32_t TR2:1;
		uint32_t TR3:1;
		uint32_t TR4:1;
		uint32_t TR5:1;
		uint32_t TR6:1;
		uint32_t TR7:1;
		uint32_t TR8:1;
		uint32_t TR9:1;
		uint32_t TR10:1;
		uint32_t TR11:1;
		uint32_t TR12:1;
		uint32_t TR13:1;
		uint32_t TR14:1;
		uint32_t TR15:1;
		uint32_t TR16:1;
		uint32_t TR17:1;
		uint32_t TR18:1;
		uint32_t reserved1:13;
	};
	uint32_t word;
};

#define EXTI_RTSR_TR0	    reg_def( 0,  1)
#define EXTI_RTSR_TR1	    reg_def( 1,  1)
#define EXTI_RTSR_TR2	    reg_def( 2,  1)
#define EXTI_RTSR_TR3	    reg_def( 3,  1)
#define EXTI_RTSR_TR4	    reg_def( 4,  1)
#define EXTI_RTSR_TR5	    reg_def( 5,  1)
#define EXTI_RTSR_TR6	    reg_def( 6,  1)
#define EXTI_RTSR_TR7	    reg_def( 7,  1)
#define EXTI_RTSR_TR8	    reg_def( 8,  1)
#define EXTI_RTSR_TR9	    reg_def( 9,  1)
#define EXTI_RTSR_TR10	    reg_def(10,  1)
#define EXTI_RTSR_TR11	    reg_def(11,  1)
#define EXTI_RTSR_TR12	    reg_def(12,  1)
#define EXTI_RTSR_TR13	    reg_def(13,  1)
#define EXTI_RTSR_TR14	    reg_def(14,  1)
#define EXTI_RTSR_TR15	    reg_def(15,  1)
#define EXTI_RTSR_TR16	    reg_def(16,  1)
#define EXTI_RTSR_TR17	    reg_def(17,  1)
#define EXTI_RTSR_TR18	    reg_def(18,  1)
#define EXTI_RTSR_reserved1 reg_def(19, 13)

union EXTI_FTSR {
	struct __attribute__((packed)) {
		uint32_t TR0:1;
		uint32_t TR1:1;
		uint32_t TR2:1;
		uint32_t TR3:1;
		uint32_t TR4:1;
		uint32_t TR5:1;
		uint32_t TR6:1;
		uint32_t TR7:1;
		uint32_t TR8:1;
		uint32_t TR9:1;
		uint32_t TR10:1;
		uint32_t TR11:1;
		uint32_t TR12:1;
		uint32_t TR13:1;
		uint32_t TR14:1;
		uint32_t TR15:1;
		uint32_t TR16:1;
		uint32_t TR17:1;
		uint32_t TR18:1;
		uint32_t reserved1:13;
	};
	uint32_t word;
};

#define EXTI_FTSR_TR0	    reg_def( 0,  1)
#define EXTI_FTSR_TR1	    reg_def( 1,  1)
#define EXTI_FTSR_TR2	    reg_def( 2,  1)
#define EXTI_FTSR_TR3	    reg_def( 3,  1)
#define EXTI_FTSR_TR4	    reg_def( 4,  1)
#define EXTI_FTSR_TR5	    reg_def( 5,  1)
#define EXTI_FTSR_TR6	    reg_def( 6,  1)
#define EXTI_FTSR_TR7	    reg_def( 7,  1)
#define EXTI_FTSR_TR8	    reg_def( 8,  1)
#define EXTI_FTSR_TR9	    reg_def( 9,  1)
#define EXTI_FTSR_TR10	    reg_def(10,  1)
#define EXTI_FTSR_TR11	    reg_def(11,  1)
#define EXTI_FTSR_TR12	    reg_def(12,  1)
#define EXTI_FTSR_TR13	    reg_def(13,  1)
#define EXTI_FTSR_TR14	    reg_def(14,  1)
#define EXTI_FTSR_TR15	    reg_def(15,  1)
#define EXTI_FTSR_TR16	    reg_def(16,  1)
#define EXTI_FTSR_TR17	    reg_def(17,  1)
#define EXTI_FTSR_TR18	    reg_def(18,  1)
#define EXTI_FTSR_reserved1 reg_def(19, 13)

union EXTI_SWIER {
	struct __attribute__((packed)) {
		uint32_t SWIER0:1;
		uint32_t SWIER1:1;
		uint32_t SWIER2:1;
		uint32_t SWIER3:1;
		uint32_t SWIER4:1;
		uint32_t SWIER5:1;
		uint32_t SWIER6:1;
		uint32_t SWIER7:1;
		uint32_t SWIER8:1;
		uint32_t SWIER9:1;
		uint32_t SWIER10:1;
		uint32_t SWIER11:1;
		uint32_t SWIER12:1;
		uint32_t SWIER13:1;
		uint32_t SWIER14:1;
		uint32_t SWIER15:1;
		uint32_t SWIER16:1;
		uint32_t SWIER17:1;
		uint32_t SWIER18:1;
		uint32_t reserved1:13;
	};
	uint32_t word;
};

#define EXTI_SWIER_SWIER0	 reg_def( 0,  1)
#define EXTI_SWIER_SWIER1	 reg_def( 1,  1)
#define EXTI_SWIER_SWIER2	 reg_def( 2,  1)
#define EXTI_SWIER_SWIER3	 reg_def( 3,  1)
#define EXTI_SWIER_SWIER4	 reg_def( 4,  1)
#define EXTI_SWIER_SWIER5	 reg_def( 5,  1)
#define EXTI_SWIER_SWIER6	 reg_def( 6,  1)
#define EXTI_SWIER_SWIER7	 reg_def( 7,  1)
#define EXTI_SWIER_SWIER8	 reg_def( 8,  1)
#define EXTI_SWIER_SWIER9	 reg_def( 9,  1)
#define EXTI_SWIER_SWIER10	 reg_def(10,  1)
#define EXTI_SWIER_SWIER11	 reg_def(11,  1)
#define EXTI_SWIER_SWIER12	 reg_def(12,  1)
#define EXTI_SWIER_SWIER13	 reg_def(13,  1)
#define EXTI_SWIER_SWIER14	 reg_def(14,  1)
#define EXTI_SWIER_SWIER15	 reg_def(15,  1)
#define EXTI_SWIER_SWIER16	 reg_def(16,  1)
#define EXTI_SWIER_SWIER17	 reg_def(17,  1)
#define EXTI_SWIER_SWIER18	 reg_def(18,  1)
#define EXTI_SWIER_reserved1 reg_def(19, 13)

union EXTI_PR {
	struct __attribute__((packed)) {
		uint32_t PR0:1;
		uint32_t PR1:1;
		uint32_t PR2:1;
		uint32_t PR3:1;
		uint32_t PR4:1;
		uint32_t PR5:1;
		uint32_t PR6:1;
		uint32_t PR7:1;
		uint32_t PR8:1;
		uint32_t PR9:1;
		uint32_t PR10:1;
		uint32_t PR11:1;
		uint32_t PR12:1;
		uint32_t PR13:1;
		uint32_t PR14:1;
		uint32_t PR15:1;
		uint32_t PR16:1;
		uint32_t PR17:1;
		uint32_t PR18:1;
		uint32_t reserved1:13;
	};
	uint32_t word;
};

#define EXTI_PR_PR0		 reg_def( 0,  1)
#define EXTI_PR_PR1	 	 reg_def( 1,  1)
#define EXTI_PR_PR2	 	 reg_def( 2,  1)
#define EXTI_PR_PR3	 	 reg_def( 3,  1)
#define EXTI_PR_PR4	 	 reg_def( 4,  1)
#define EXTI_PR_PR5	 	 reg_def( 5,  1)
#define EXTI_PR_PR6	 	 reg_def( 6,  1)
#define EXTI_PR_PR7	 	 reg_def( 7,  1)
#define EXTI_PR_PR8	 	 reg_def( 8,  1)
#define EXTI_PR_PR9	 	 reg_def( 9,  1)
#define EXTI_PR_PR10	 reg_def(10,  1)
#define EXTI_PR_PR11	 reg_def(11,  1)
#define EXTI_PR_PR12	 reg_def(12,  1)
#define EXTI_PR_PR13	 reg_def(13,  1)
#define EXTI_PR_PR14	 reg_def(14,  1)
#define EXTI_PR_PR15	 reg_def(15,  1)
#define EXTI_PR_PR16	 reg_def(16,  1)
#define EXTI_PR_PR17	 reg_def(17,  1)
#define EXTI_PR_PR18	 reg_def(18,  1)
#define EXTI_PR_reserved1 reg_def(19, 13)

struct __attribute__((packed)) EXTI {
	union EXTI_IMR IMR;
	union EXTI_EMR EMR;
	union EXTI_RTSR RTSR;
	union EXTI_FTSR FTSR;
	union EXTI_SWIER SWIER;
	union EXTI_PR PR;
};


//--functions-------------------------------------------------------------------

#endif //_EXTI_REGS_H_

