#pragma once
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"

#define I2c_DELAY 4 //delay in loop repetitions

class I2c
{
    public:
		I2c();
        I2c(GPIO_TypeDef* gpio, uint16_t scl_pin, uint16_t sda_pin);
        bool begin(); //sending start bit
        bool begin(uint8_t adress, bool dir); //start bit with adress and direction
        bool end(); //sending stop bit
        void writeByte(uint8_t byte); //write byte to line
        bool readAck(); //read acknowledge
        uint8_t readByte(); //read byte from line
        void generateAck(); //generate acknowledge
        void generateNAck(); //gernerate non acknowledge
    private:
        void m_delay(); //i2c loop delay
        void m_sclHigh(); //SCL set
        void m_sclLow();
        void m_sdaHigh(); //SDA set
        void m_sdaLow();
        bool m_sclRead(); //SCL SDA read
        bool m_sdaRead();
	
		GPIO_TypeDef* m_gpio;
		uint16_t m_scl_pin, m_sda_pin;
};
