IIC Demo
This commit is contained in:
10
demo/iic/t_iic.h
Normal file
10
demo/iic/t_iic.h
Normal file
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by lydxh on 2024/5/9.
|
||||
//
|
||||
|
||||
#ifndef HW_LIB_T_IIC_H
|
||||
#define HW_LIB_T_IIC_H
|
||||
|
||||
void Test_iic();
|
||||
|
||||
#endif //HW_LIB_T_IIC_H
|
51
demo/iic/test.c
Normal file
51
demo/iic/test.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include "iic.h"
|
||||
#include "log.h"
|
||||
#include "tool.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;
|
||||
}
|
||||
|
||||
void Test_iic() {
|
||||
HW_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 = 10;
|
||||
uint8_t writeData[len];
|
||||
uint8_t readData[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
writeData[i] = rand() % 10;
|
||||
}
|
||||
HW_IIC_WL(dev, internalAddress, writeData, len);
|
||||
BufPrint("<IIC> TX", writeData, 8, len, 16);
|
||||
HW_IIC_RL(dev, internalAddress, readData, len, 1);
|
||||
BufPrint("<IIC> RX", readData, 8, len, 16);
|
||||
}
|
Reference in New Issue
Block a user