2022-04-07 13:32:53 +08:00
|
|
|
#include "PikaStdDevice_IIC.h"
|
|
|
|
#include "BaseObj.h"
|
|
|
|
#include "PikaObj.h"
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_init(PikaObj* self) {
|
|
|
|
obj_setInt(self, "deviceAddr", 0);
|
|
|
|
obj_setStr(self, "SCLpin", "PA0");
|
|
|
|
obj_setStr(self, "SDApin", "PA1");
|
2022-04-07 13:32:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdDevice_IIC___init__(PikaObj* self) {
|
|
|
|
PikaStdDevice_IIC_init(self);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_enable(PikaObj* self) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_runNativeMethod(self, "platformEnable", NULL);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_disable(PikaObj* self) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_runNativeMethod(self, "platformDisable", NULL);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_setDeviceAddr(PikaObj* self, int addr) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setInt(self, "deviceAddr", addr);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_setPinSCL(PikaObj* self, char* pin) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setStr(self, "SCLpin", pin);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_setPinSDA(PikaObj* self, char* pin) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setStr(self, "SDApin", pin);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_write(PikaObj* self, int addr, char* data) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setStr(self, "writeData", data);
|
|
|
|
obj_setInt(self, "writeAddr", addr);
|
|
|
|
obj_runNativeMethod(self, "platformWrite", NULL);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
char* PikaStdDevice_IIC_read(PikaObj* self, int addr, int length) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setInt(self, "length", length);
|
|
|
|
obj_setInt(self, "readAddr", addr);
|
|
|
|
obj_runNativeMethod(self, "platformRead", NULL);
|
|
|
|
return obj_getStr(self, "readData");
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_platformWrite(PikaObj* self) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_platformEnable(PikaObj* self) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_platformDisable(PikaObj* self) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_platformRead(PikaObj* self) {
|
2022-04-07 13:32:53 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|