#include <stdint.h>

#define GPIO_BASE 0x48000000
#define GPIOC ((GPIO_Type*) (GPIO_BASE + 0x00000800))

typedef struct {
	volatile uint32_t MODER;   /* mode                 0x00  */
	volatile uint16_t OTYPER;  /* output type          0x04  */
	uint16_t RESERVED0;        /* reserved             0x06  */
	volatile uint32_t OSPEEDR; /* output speed         0x08  */
	volatile uint32_t PUPDR;   /* pull-up/pull-down    0x0C  */
	volatile uint16_t IDR;     /* input data           0x10  */
	uint16_t RESERVED1;        /* reserved             0x12  */
	volatile uint16_t ODR;     /* output data          0x14  */
	uint16_t RESERVED2;        /* reserved             0x16  */
	volatile uint32_t BSRR;    /* bit set / reset      0x18  */
	volatile uint32_t LCKR;    /* config lock          0x1C  */
	volatile uint32_t AFR[2];  /* alternate function   0x20  */
	volatile uint16_t BRR;     /* bit reset            0x28  */
	uint16_t RESERVED3;        /* reserved             0x2A  */
} GPIO_Type;

void delay(void)
{
	int i;
	for(i = 0; i < 1000000; ++i) {};
}

int mainprog(void)
{
	// Nastavenie pinov PC8 a PC9 do output režimu
	GPIOC->MODER = (1 << 16 | 1 << 18);
	// Nastavenie PC8 a PC9 do Push-pull režimu
	GPIOC->OTYPER &= ~(1 << 8 | 1 << 9);
	// Vypnutie pull-up a pull-down rezistoru pre PC8 a PC9
	GPIOC->PUPDR &= ~(3 << 16 | 3 << 18);
	for(;;) {
		// Vypnutie PC8 a zapnutie PC9
		GPIOC->BSRR = (1 << (16 + 8) | 1 << 9);
		delay();
		// Vypnutie PC9 a zapnutie PC8
		GPIOC->BSRR = (1 << (16 + 9) | 1 << 8);
		delay();
	}
	return 0;
}

