I was able to program a rudimentary display for the Nextion, and it shows, but so far I can't get anything on the screen to update from LiBCM. In LiBCM.cpp I'm using the Serial1 functions. Are they correctly set up to send data on the wires going to the Nextion?
See LiDisplay.cpp... I will pull pretty much anything logical you write inside this file.
Inside I've defined the following abstraction functions (to Serial1):
LiDisplay_begin() //this will correctly setup LiBCM to transmit/receive data to the Nextion
LiDisplay_bytesAvailableForWrite()
LiDisplay_writeByte()
LiDisplay_readByte()
LiDisplay_bytesAvailableToRead()
...
My recommendation is to mirror the function
USB_userInterface_handler()
... as something like "LiDisplay_hander()"... that'll be the only function you call outside of LiDisplay.cpp (every time the main loop executes)... so if LiDisplay wants LiBCM to do something, then LiDisplay_handler() needs to call out (into the other files) as needed.
...
LiBCM isn't going to have the bandwidth to update every display element on LiDisplay every time through the main loop... so you need to update one (or maybe a few) items each time through the loop. You can see how I do this with the existing 4x20 display by looking at the state machine within lcd_refresh().
It doesn't have to be the same, but again, just a framework on how to build a state machine to transmit just a little bit of data each call... the goal is to NEVER send more data than there is room for it in the serial transmit buffer (63 bytes max). You can query this value with
LiDisplay_bytesAvailableForWrite()
. If you overfill the buffer, you won't lose data, but the code will hang until there are fewer than 63 bytes in the transmit buffer (i.e. the serial transmit buffer is blocking when full)... so never overfill the buffer or LiBCM won't meet timing.
LiBCM's superloop runs at 100 Hz... I believe the default Nextion baud rate is 9600 bps... at that rate, you shouldn't send more than ~20 ascii characters per iteration (or you will immediately/eventually overflow the buffer). Of course, if the buffer is empty, you can fill it completely (all 63 bytes) in one run... but then you can't send anything until the buffer is less full again. If you want to send more than that, then you'll need to increase the baud rate (if possible).
LiDisplay_readByte() also has a 63 element buffer, so you should read it entirely whenever data is available (because at 9600 baud LiDisplay can overflow the receive buffer in 3 cycles). As before, I recommend reading into a circular buffer similar to
USB_userInterface_handler
.
If any of this is unclear, it's because I wrote it in a hurry. Please ask questions as often as you need to. As always, thanks for any and all firmware help.