void spiDataRW(int channel, SV* byte_ref, int len){ /* * Custom wrapper for wiringPiSPIDataRW() as we * need to translate an aref into an unsigned char *, * and then send back an array containing the bytes * read from the device */ if (channel != 0 && channel != 1){ croak("channel param must be 0 or 1\n"); } if (! SvROK(byte_ref) || SvTYPE(SvRV(byte_ref)) != SVt_PVAV){ croak("data param must be an array reference\n"); } AV* bytes = (AV*)SvRV(byte_ref); int num_bytes = av_len(bytes) + 1; if (len != num_bytes){ croak("len param doesn't match element count in data\n"); } unsigned char buf[num_bytes]; int i; for (i=0; i 255){ printf("byte %d in data param out of range: (%d)\n", i, elem_int); exit(1); } buf[i] = (unsigned char)SvNV(*elem); } if (wiringPiSPIDataRW(channel, buf, len) < 0){ croak("failed to write to the SPI bus\n"); } inline_stack_vars; inline_stack_reset; int x; for (x=0; x