Pretty much as I described in the title, I am attempting to read the next N bits appearing at a GPIO pin following a call. For context, I am setting a chip select (CS) enable and after two clock cycles I expect a 10 bit sequence. I'm not very worried in this moment about ensuring I have the exactly 10 bits, so much as I'd rather be sure I'm atleast getting the 10 I need, even if I also get some stuff around the edges. I've been using PiGPIO and trying to using the bb_serial_read functionality, however I've been having trouble fulling understanding the functionality of this tool since the documentation isn't too specific and I don't have much experience with bit banging.
I was approaching it this way:
pi.hardware_clock(CLOCK_PIN, CLOCK_FREQ)
pi.bb_serial_read_open(DATA_PIN, CLOCK_FREQ)
enable_CS()
(count, val) = pi.bb_serial_read(DATA_PIN)
disable_CS()
After which I would attempt to convert the value returned to a binary string. The primary obstacles I've run into surrounds the arguments to bb_serial_read_open, as the bb_serial_read returns a bytearray which tends to look like '\x00\x00\x01\x00' or something similar, the values tend to vary. If I want to ensure I am getting some number of consecutive bits, what is the appropriate way to convert this to the raw binary? Also, is there a way to flush the cyclic buffer the the bit bang protocol is storing its values in? I'm pretty sure this is a simple problem, but I've been back and forth between documentation and example code with no luck for a while now.