2525#define CLASS_SPIMASTER " ioio/smallbasic/SpiMasterImpl"
2626#define CLASS_IOIO " ioio/smallbasic/IOIOImpl"
2727#define CLASS_IOTASK_ID 1
28- #define SPI_WRITE_MAX 63
29- #define TWI_WRITE_MAX ARRAY_SIZE
28+ #define SPI_WRITE_MAX 62
29+ #define TWI_WRITE_MAX 255
3030
3131struct IOTask : JavaProxy {
3232 IOTask () : JavaProxy() {
@@ -47,7 +47,7 @@ struct IOTask : JavaProxy {
4747 // int readWrite(bytes, byte[] write) {
4848 int invokeSpiReadWrite (int argc, slib_par_t *arg, var_s *retval) {
4949 int result = 0 ;
50- int writeLen = populateByteArray (argc, arg, 1 );
50+ int writeLen = populateByteArray (argc, arg, 1 , SPI_WRITE_MAX );
5151 if (writeLen > SPI_WRITE_MAX) {
5252 error (retval, " write array" , 1 , SPI_WRITE_MAX);
5353 } else if (_instance != nullptr ) {
@@ -67,12 +67,17 @@ struct IOTask : JavaProxy {
6767 return result;
6868 }
6969
70- // int write(byte[] write) {
70+ // int write(byte[] write, int length ) {
7171 int invokeSpiWrite (int argc, slib_par_t *arg, var_s *retval) {
7272 int result = 0 ;
73- int writeLen = populateByteArray (argc, arg, 0 );
74- if (writeLen > ARRAY_SIZE) {
75- error (retval, " write array" , 1 , ARRAY_SIZE);
73+ int maxSize = SPI_WRITE_MAX;
74+ if (is_param_array (argc, arg, 0 )) {
75+ // allow an entire LCD to be updated within one IOIOLooper.loop() call
76+ maxSize = v_asize (arg[0 ].var_p );
77+ }
78+ int writeLen = populateByteArray (argc, arg, 0 , maxSize);
79+ if (writeLen > maxSize) {
80+ error (retval, " write array" , 1 , maxSize);
7681 } else if (_instance != nullptr ) {
7782 attachCurrentThread ();
7883 jmethodID method = g_env->GetMethodID (_clazz, " write" , " ([BI)V" );
@@ -90,7 +95,7 @@ struct IOTask : JavaProxy {
9095 // int readWrite(int address, byte[] write) {
9196 int invokeTwiReadWrite (int argc, slib_par_t *arg, var_s *retval) {
9297 int result = 0 ;
93- int writeLen = populateByteArray (argc, arg, 2 );
98+ int writeLen = populateByteArray (argc, arg, 2 , TWI_WRITE_MAX );
9499 if (writeLen > TWI_WRITE_MAX) {
95100 error (retval, " write array" , 1 , TWI_WRITE_MAX);
96101 } else if (_instance != nullptr ) {
@@ -114,7 +119,7 @@ struct IOTask : JavaProxy {
114119 // int write(int address, byte[] write) {
115120 int invokeTwiWrite (int argc, slib_par_t *arg, var_s *retval) {
116121 int result = 0 ;
117- int writeLen = populateByteArray (argc, arg, 1 );
122+ int writeLen = populateByteArray (argc, arg, 1 , TWI_WRITE_MAX );
118123 if (writeLen > TWI_WRITE_MAX) {
119124 error (retval, " write array" , 1 , TWI_WRITE_MAX);
120125 } else if (_instance != nullptr ) {
@@ -155,7 +160,7 @@ static int cmd_twimaster_readwrite(var_s *self, int argc, slib_par_t *arg, var_s
155160 int result = 0 ;
156161 auto readBytes = get_param_int (argc, arg, 1 , 0 );
157162 if (argc < 2 ) {
158- error (retval, " TwiMaster.readWrite(address, read-bytes, [data]" , 2 , ARRAY_SIZE );
163+ error (retval, " TwiMaster.readWrite(address, read-bytes, [data]" , 2 , TWI_WRITE_MAX );
159164 } else if (readBytes < 1 || readBytes > 8 ) {
160165 error (retval, " read-bytes value out of range. Expected a number between 1 and 8" );
161166 } else {
@@ -170,7 +175,7 @@ static int cmd_twimaster_readwrite(var_s *self, int argc, slib_par_t *arg, var_s
170175static int cmd_twimaster_write (var_s *self, int argc, slib_par_t *arg, var_s *retval) {
171176 int result = 0 ;
172177 if (argc < 2 ) {
173- error (retval, " TwiMaster.write" , 2 , ARRAY_SIZE );
178+ error (retval, " TwiMaster.write" , 2 , TWI_WRITE_MAX );
174179 } else {
175180 int id = get_io_class_id (self, retval);
176181 if (id != -1 ) {
@@ -184,7 +189,7 @@ static int cmd_spimaster_readwrite(var_s *self, int argc, slib_par_t *arg, var_s
184189 int result = 0 ;
185190 auto readBytes = get_param_int (argc, arg, 0 , 0 );
186191 if (argc < 2 ) {
187- error (retval, " SpiMaster.readWrite(read-bytes, [data]" , 2 , ARRAY_SIZE );
192+ error (retval, " SpiMaster.readWrite(read-bytes, [data]" , 2 , SPI_WRITE_MAX );
188193 } else if (readBytes < 1 || readBytes > 8 ) {
189194 error (retval, " read-bytes value out of range. Expected a number between 1 and 8" );
190195 } else {
@@ -199,7 +204,7 @@ static int cmd_spimaster_readwrite(var_s *self, int argc, slib_par_t *arg, var_s
199204static int cmd_spimaster_write (var_s *self, int argc, slib_par_t *arg, var_s *retval) {
200205 int result = 0 ;
201206 if (argc < 1 ) {
202- error (retval, " SpiMaster.write" , 1 , ARRAY_SIZE );
207+ error (retval, " SpiMaster.write" , 1 , SPI_WRITE_MAX );
203208 } else {
204209 int id = get_io_class_id (self, retval);
205210 if (id != -1 ) {
0 commit comments