I’m trying to control a s1d13700 display controller chip. I found a arduino example on the net and tested it using a arduino and it worked. I reworked that into c# code and it works, but it is very slow. Enter RLP. I converted the original code to something that should work as RLP.
As yagarto seems to be unmaintained I took my toolchain from Prebuilt GNU toolchain for ARM (legacy). I also tried keil compiler but it’s results crashed on init bss en procedure loading.
If I compare the action on the display from native code to the managed version I can determine that it completes the native code initialization function fine. However the next break point in c# code is never hit and the debugger looses communication. Luckily I build in the suggested disable rlp trick from the documentation, so I can reflash and try again.
initS1D13700.invokeex never returns. I did not include everything as that might make thing unreadable. If you want to see something more/else ask me,
The code:
struct pin_type {
unsigned char d0;
unsigned char d1;
unsigned char d2;
unsigned char d3;
unsigned char d4;
unsigned char d5;
unsigned char d6;
unsigned char d7;
unsigned char a0;
unsigned char wr;
unsigned char rd;
unsigned char cs;
unsigned char rst;
} pins;
int InitS1D13700(unsigned char *generalArray, void **args, unsigned int argsCount, unsigned int *argSize) {
pins.d0 = generalArray[0];
pins.d1 = generalArray[1];
pins.d2 = generalArray[2];
pins.d3 = generalArray[3];
pins.d4 = generalArray[4];
pins.d5 = generalArray[5];
pins.d6 = generalArray[6];
pins.d7 = generalArray[7];
pins.rd = generalArray[8];
pins.wr = generalArray[9];
pins.a0 = generalArray[10];
pins.cs = generalArray[11];
pins.rst = generalArray[12];
/*Set all data pins as
output and then set them low*/
RLPext->GPIO.EnableOutputMode(pins.d0, 0);
RLPext->GPIO.EnableOutputMode(pins.d1, 0);
RLPext->GPIO.EnableOutputMode(pins.d2, 0);
RLPext->GPIO.EnableOutputMode(pins.d3, 0);
RLPext->GPIO.EnableOutputMode(pins.d4, 0);
RLPext->GPIO.EnableOutputMode(pins.d5, 0);
RLPext->GPIO.EnableOutputMode(pins.d6, 0);
RLPext->GPIO.EnableOutputMode(pins.d7, 0);
/*Set all control pins as
output and then set them high*/
RLPext->GPIO.EnableOutputMode(pins.rd, 1);
RLPext->GPIO.EnableOutputMode(pins.wr, 1);
RLPext->GPIO.EnableOutputMode(pins.a0, 1);
RLPext->GPIO.EnableOutputMode(pins.cs, 1);
RLPext->GPIO.EnableOutputMode(pins.rst, 1);
hardReset();
/* Now we are going to issue the system set command
and specify operating paramters. If these need to
change for your application, you must study the
S1D13700 datasheet and change the values in
S1D13700.h */
writeCommand(S1D13700_SYSTEM_SET);
RLPext->Delay(1000);
writeData(S1D13700_SYS_P1);
RLPext->Delay(1);
writeData(S1D13700_SYS_P2);
RLPext->Delay(1);
writeData(S1D13700_FY);
RLPext->Delay(1);
writeData(S1D13700_CR);
RLPext->Delay(1);
writeData(S1D13700_TCR);
RLPext->Delay(1);
writeData(S1D13700_LF);
RLPext->Delay(1);
writeData(S1D13700_APL);
RLPext->Delay(1);
writeData(S1D13700_APH);
writeCommand(S1D13700_SCROLL);
writeData(S1D13700_SAD1L);
writeData(S1D13700_SAD1H);
writeData(S1D13700_SL1);
writeData(S1D13700_SAD2L);
writeData(S1D13700_SAD2H);
writeData(S1D13700_SL2);
writeData(S1D13700_SAD3L);
writeData(S1D13700_SAD3H);
writeData(S1D13700_SAD4L);
writeData(S1D13700_SAD4H);
writeCommand(S1D13700_CSRFORM);
writeData(S1D13700_CRX);
writeData(S1D13700_CSRF_P2);
writeCommand(S1D13700_CGRAM_ADR);
writeData(S1D13700_SAGL);
writeData(S1D13700_SAGH);
writeCommand(S1D13700_CSRDIR_R);
writeCommand(S1D13700_HDOT_SCR);
writeData(S1D13700_SCRD);
writeCommand(S1D13700_OVLAY);
writeData(S1D13700_OVLAY_P1);
writeCommand(S1D13700_DISP_ON);
writeData(S1D13700_FLASH);
return 0;
}
/* This function is specified inline for speed reasons*/
inline void __attribute__ ((always_inline)) setData(unsigned char data)
{
RLPext->GPIO.EnableOutputMode(pins.d0, (data & 1));
RLPext->GPIO.EnableOutputMode(pins.d1, ((data & (1 << 1)) >> 1));
RLPext->GPIO.EnableOutputMode(pins.d2, ((data & (1 << 2)) >> 2));
RLPext->GPIO.EnableOutputMode(pins.d3, ((data & (1 << 3)) >> 3));
RLPext->GPIO.EnableOutputMode(pins.d4, ((data & (1 << 4)) >> 4));
RLPext->GPIO.EnableOutputMode(pins.d5, ((data & (1 << 5)) >> 5));
RLPext->GPIO.EnableOutputMode(pins.d6, ((data & (1 << 6)) >> 6));
RLPext->GPIO.EnableOutputMode(pins.d7, ((data & (1 << 7)) >> 7));
}
void writeCommand(unsigned char command)
{
setData(command);
RLPext->GPIO.WritePin(pins.wr, 0);
RLPext->GPIO.WritePin(pins.cs, 0);
RLPext->GPIO.WritePin(pins.wr, 1);
RLPext->GPIO.WritePin(pins.cs, 1);
}
void writeData(unsigned char data)
{
setData(data);
RLPext->GPIO.WritePin(pins.a0, 0);
RLPext->GPIO.WritePin(pins.cs, 0);
RLPext->GPIO.WritePin(pins.wr, 0);
RLPext->GPIO.WritePin(pins.cs, 1);
RLPext->GPIO.WritePin(pins.wr, 1);
RLPext->GPIO.WritePin(pins.a0, 1);
}
c# code
#region Definition
RLP.Procedure initS1D13700;
RLP.Procedure writeText;
RLP.Procedure textGoTo;
RLP.Procedure graphicGoTo;
RLP.Procedure clearText;
RLP.Procedure clearGraphic;
RLP.Procedure drawLine;
RLP.Procedure drawBox;
RLP.Procedure drawCircle;
RLP.Procedure drawByteBuffer;
#endregion
#region Low level control and init
public S1D13700(byte RD, byte WR, byte A0, byte CS, byte RST, byte D0, byte D1, byte D2, byte D3, byte D4, byte D5, byte D6, byte D7)
{
RLP.Enable();
RLP.Unlock(....);
byte[] elf_file = Resources.GetBytes(Resources.BinaryResources.RLP_S1D13700);
RLP.LoadELF(elf_file);
RLP.InitializeBSSRegion(elf_file);
initS1D13700 = RLP.GetProcedure(elf_file, "InitS1D13700");
writeText = RLP.GetProcedure(elf_file, "WriteText");
textGoTo = RLP.GetProcedure(elf_file, "TextGoTo");
graphicGoTo = RLP.GetProcedure(elf_file, "GraphicGoTo");
clearText = RLP.GetProcedure(elf_file, "ClearText");
clearGraphic = RLP.GetProcedure(elf_file, "ClearGraphic");
drawLine = RLP.GetProcedure(elf_file, "DrawLine");
drawBox = RLP.GetProcedure(elf_file, "DrawBox");
drawCircle = RLP.GetProcedure(elf_file, "DrawCircle");
drawByteBuffer = RLP.GetProcedure(elf_file, "DrawByteBuffer");
Debug.Print("elfSize = " + elf_file.Length.ToString());
elf_file = null;
Debug.GC(true);
initS1D13700.InvokeEx(new byte[] { D0, D1, D2, D3, D4, D5, D6, D7, RD, WR, A0, CS, RST});
}
I’m trying this on an old usbizi-devsys as that is the only free module I have at the moment. However old should not mean non working:)