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);
|
||||
}
|
@@ -44,19 +44,19 @@ void Test_spi() {
|
||||
};
|
||||
uint8_t r, t = rand() % 10;
|
||||
r = HW_SPI_RW(ltl, t);
|
||||
LOGI("Tx:%d,Rx:%d", t, r);
|
||||
LOGI("<SPI> Tx:%d,Rx:%d", t, r);
|
||||
uint8_t rbuf[64], tbuf[64];
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
tbuf[i] = rand() % 10;
|
||||
}
|
||||
HW_SPI_RWL(ltl, rbuf, tbuf, 64);
|
||||
BufPrint("TX", tbuf, 8, 64, 8);
|
||||
BufPrint("RX", rbuf, 8, 64, 8);
|
||||
BufPrint("<SPI> TX", tbuf, 8, 64, 8);
|
||||
BufPrint("<SPI> RX", rbuf, 8, 64, 8);
|
||||
uint16_t rbuf16[64], tbuf16[64];
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
tbuf16[i] = rand() % 1000;
|
||||
}
|
||||
HW_SPI_RWL16(ltl, rbuf16, tbuf16, 64);
|
||||
BufPrint("TX", tbuf16, 16,64, 16);
|
||||
BufPrint("RX", rbuf16, 16,64, 16);
|
||||
BufPrint("<SPI> TX[16]", tbuf16, 16, 64, 16);
|
||||
BufPrint("<SPI> RX[16]", rbuf16, 16, 64, 16);
|
||||
}
|
Reference in New Issue
Block a user