2021-10-22 22:32:35 +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");
|
2021-10-22 22:32:35 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 23:02:40 +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-03-19 09:53:48 +08:00
|
|
|
obj_runNativeMethod(self, "platformEnable", NULL);
|
2021-10-22 22:32:35 +08:00
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_disable(PikaObj* self) {
|
2022-03-19 09:53:48 +08:00
|
|
|
obj_runNativeMethod(self, "platformDisable", NULL);
|
2022-03-07 14:58:21 +08:00
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_setDeviceAddr(PikaObj* self, int addr) {
|
2021-10-22 22:32:35 +08:00
|
|
|
obj_setInt(self, "deviceAddr", addr);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_setPinSCL(PikaObj* self, char* pin) {
|
2021-10-22 22:32:35 +08:00
|
|
|
obj_setStr(self, "SCLpin", pin);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_setPinSDA(PikaObj* self, char* pin) {
|
2021-10-22 22:32:35 +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) {
|
2021-10-22 22:32:35 +08:00
|
|
|
obj_setStr(self, "writeData", data);
|
|
|
|
obj_setInt(self, "writeAddr", addr);
|
2022-03-19 09:53:48 +08:00
|
|
|
obj_runNativeMethod(self, "platformWrite", NULL);
|
2021-10-22 22:32:35 +08:00
|
|
|
}
|
|
|
|
|
2022-05-23 17:10:37 +08:00
|
|
|
void PikaStdDevice_IIC_writeBytes(PikaObj* self,
|
|
|
|
int addr,
|
|
|
|
uint8_t* data,
|
|
|
|
int length) {
|
|
|
|
obj_setBytes(self, "writeData", data, length);
|
|
|
|
obj_setInt(self, "writeAddr", addr);
|
|
|
|
obj_runNativeMethod(self, "platformWriteBytes", NULL);
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
char* PikaStdDevice_IIC_read(PikaObj* self, int addr, int length) {
|
2021-10-22 22:32:35 +08:00
|
|
|
obj_setInt(self, "length", length);
|
|
|
|
obj_setInt(self, "readAddr", addr);
|
2022-03-19 09:53:48 +08:00
|
|
|
obj_runNativeMethod(self, "platformRead", NULL);
|
2021-10-22 22:32:35 +08:00
|
|
|
return obj_getStr(self, "readData");
|
|
|
|
}
|
|
|
|
|
2022-05-23 17:10:37 +08:00
|
|
|
Arg* PikaStdDevice_IIC_readBytes(PikaObj* self, int addr, int length) {
|
2022-05-23 16:54:56 +08:00
|
|
|
obj_setInt(self, "length", length);
|
|
|
|
obj_setInt(self, "readAddr", addr);
|
|
|
|
obj_runNativeMethod(self, "platformReadBytes", NULL);
|
2022-05-24 15:26:12 +08:00
|
|
|
return arg_copy(obj_getArg(self, "readData"));
|
2022-05-23 16:54:56 +08:00
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_platformWrite(PikaObj* self) {
|
2022-08-26 19:41:25 +08:00
|
|
|
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
2021-10-22 22:32:35 +08:00
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_platformEnable(PikaObj* self) {
|
2022-08-26 19:41:25 +08:00
|
|
|
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
2021-10-22 22:32:35 +08:00
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_platformDisable(PikaObj* self) {
|
2022-08-26 19:41:25 +08:00
|
|
|
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
2022-03-19 09:49:19 +08:00
|
|
|
}
|
|
|
|
|
2022-04-14 23:13:17 +08:00
|
|
|
void PikaStdDevice_IIC_platformRead(PikaObj* self) {
|
2022-08-26 19:41:25 +08:00
|
|
|
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
2021-10-22 22:32:35 +08:00
|
|
|
}
|
2022-05-23 16:54:56 +08:00
|
|
|
|
|
|
|
void PikaStdDevice_IIC_platformReadBytes(PikaObj* self) {
|
2022-08-26 19:41:25 +08:00
|
|
|
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
2022-05-23 16:54:56 +08:00
|
|
|
}
|
2022-05-23 17:10:37 +08:00
|
|
|
|
|
|
|
void PikaStdDevice_IIC_platformWriteBytes(PikaObj* self) {
|
2022-08-26 19:41:25 +08:00
|
|
|
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
|
2022-05-23 17:10:37 +08:00
|
|
|
}
|