pikapython/package/PikaStdDevice/PikaStdDevice_SPI.c

106 lines
3.1 KiB
C
Raw Normal View History

2022-04-14 23:13:17 +08:00
#include "PikaStdDevice_SPI.h"
#include "BaseObj.h"
#include "PikaObj.h"
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI___init__(PikaObj* self) {
obj_setInt(self, "baudRate", 1000);
obj_setInt(self, "id", 0);
obj_setStr(self, "name", "none");
2022-04-15 15:10:06 +08:00
obj_setInt(self, "phase", 0);
2022-04-14 23:31:47 +08:00
obj_setStr(self, "MISOpin", "none");
obj_setStr(self, "MOSIpin", "none");
obj_setStr(self, "SCKpin", "none");
obj_setInt(self, "polarity", 0);
}
void PikaStdDevice_SPI_disable(PikaObj* self) {
2022-04-14 23:13:17 +08:00
obj_runNativeMethod(self, "platformDisable", NULL);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_enable(PikaObj* self) {
2022-04-14 23:13:17 +08:00
obj_runNativeMethod(self, "platformEnable", NULL);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_write(PikaObj* self, char* data) {
2022-04-14 23:13:17 +08:00
obj_setStr(self, "writeData", data);
obj_runNativeMethod(self, "platformWrite", NULL);
}
2022-05-24 15:26:12 +08:00
void PikaStdDevice_SPI_writeBytes(PikaObj* self, uint8_t* data, int length) {
obj_setBytes(self, "writeData", data, length);
obj_runNativeMethod(self, "platformWriteBytes", NULL);
}
2022-04-14 23:31:47 +08:00
char* PikaStdDevice_SPI_read(PikaObj* self, int length) {
2022-04-14 23:13:17 +08:00
obj_setInt(self, "length", length);
obj_runNativeMethod(self, "platformRead", NULL);
return obj_getStr(self, "readData");
}
2022-05-24 15:26:12 +08:00
Arg* PikaStdDevice_SPI_readBytes(PikaObj* self, int length) {
obj_setInt(self, "length", length);
obj_runNativeMethod(self, "platformReadBytes", NULL);
2022-05-24 15:26:12 +08:00
return arg_copy(obj_getArg(self, "readData"));
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_setBaudRate(PikaObj* self, int baudRate) {
2022-04-14 23:13:17 +08:00
obj_setInt(self, "baudRate", baudRate);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_setId(PikaObj* self, int id) {
2022-04-14 23:13:17 +08:00
obj_setInt(self, "id", id);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_setName(PikaObj* self, char* name) {
2022-04-14 23:13:17 +08:00
obj_setStr(self, "name", name);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_setPhase(PikaObj* self, int phase) {
2022-04-15 15:10:06 +08:00
obj_setInt(self, "phase", phase);
2022-04-14 23:13:17 +08:00
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_setPinMISO(PikaObj* self, char* pin) {
2022-04-14 23:13:17 +08:00
obj_setStr(self, "MISOpin", pin);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_setPinMOSI(PikaObj* self, char* pin) {
2022-04-14 23:13:17 +08:00
obj_setStr(self, "MOSIpin", pin);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_setPinSCK(PikaObj* self, char* pin) {
2022-04-14 23:13:17 +08:00
obj_setStr(self, "SCKpin", pin);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_setPolarity(PikaObj* self, int polarity) {
2022-04-14 23:13:17 +08:00
obj_setInt(self, "polarity", polarity);
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_platformDisable(PikaObj* self) {
2022-04-14 23:13:17 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_platformEnable(PikaObj* self) {
2022-04-14 23:13:17 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_platformWrite(PikaObj* self) {
2022-04-14 23:13:17 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2022-04-14 23:31:47 +08:00
void PikaStdDevice_SPI_platformRead(PikaObj* self) {
2022-04-14 23:13:17 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2022-05-24 15:26:12 +08:00
void PikaStdDevice_SPI_platformWriteBytes(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2022-05-24 15:26:12 +08:00
void PikaStdDevice_SPI_platformReadBytes(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}