#include <stdio.h>
#include "iic.h"
#include "log.h"
#include "tool.h"
#include "t_iic.h"
uint8_t CLK_Pin(uint8_t l) {
//    LOGT("CLK", "P:%d", l);
    return l;
}

uint8_t SDA_Set(uint8_t l) {
//    LOGT("SDA", "P:%d", l);
    return l;
}

uint8_t SDA_Mode(uint8_t l) {
    if (l) {
//        LOGT("SDA", "M:IN");
    } else {
//        LOGT("SDA", "M:OUT");
    }
    return l;
}

uint8_t SDA_Read() {
    uint8_t l = rand() % 2;
//    LOGT("SDA", "P:%d", l);
    return l;
}

int Test_iic(void *pVoid) {
    SW_Dev_IIC dev = {
            .CLK_SET = CLK_Pin,
            .SDA_SET = SDA_Set,
            .SDA = SDA_Read,
            .SDA_MODE = SDA_Mode,
            .ADD = 0x34
    };
    uint8_t internalAddress = 0x56;

    uint32_t len = 64;
    uint8_t writeData[len];
    uint8_t readData[len];
    range(i, len)
    {
        writeData[i] = rand() % 200;
    }
    PRINT_ARRAY(writeData, "%3d", 16);

//    foreach(i in writeData) {
//        writeData[i] = rand() % 200;
//    }
    PRINT_ARRAY(writeData, "%3d", 16);
    Buf_Print("<IIC> TX", writeData, len, 16);
    BufPrint("<IIC> TX", writeData, TYPE_T(writeData), len, 16);

    SW_IIC_WL(dev, internalAddress, writeData, len);
    SW_IIC_RL(dev, internalAddress, readData, len, 1);
    BufPrint("<IIC> RX", readData, TYPE_T(readData), len, 16);
}
