This pull request gets the C libraries for the Pololu 3pi+ 2040 Robot into a pretty good state. The only major thing missing from the C libraries now is support for the IMU.
Libraries:
Added documentation for everything, except the low-level SH1106 functions in sh1106.h.
button.c: Add the button struct and button_check function that operates on it. Together, these can be used to debounce any function with signature bool is_pressed(void). This is the only part of the library where I let users allocate memory for objects themselves, but I think it's fine: it makes the API simpler and I think C programmers can understand it.
display.c: A new high-level (and high-performance) library that helps you use the SH1106 OLED. Supports 8x16 and 8x8 Unicode text and drawing of filled rectangles. Tried to make its API be similar to MicroPython's framebuf.
ir_sensors.c: Change the timing. Added calibration, including hysteresis for the bump sensors.
sh1106.c: Changed it to use hardware SPI. Added sh1106_sleep, sh1106_contrast, sh1106_invert, sh1106_rotate.
rgb_leds.c: Made it share the hardware SPI with other libraries in a good way.
Examples:
button_test.c: Made it behave like the Python version, but it also reads the left and right bumpers like buttons.
ir_sensors_demo.c: Make it behave like the Python version, but it draws notches to indicate the calibration values, draws extra pixels on top of the bars to show more resolution. It also can be controlled over USB. I made all the rectangles filled; I didn't bother implementing hollow rectangles for the bumpers (I don't think it's needed).
ir_sensors_demo.py: Fixed a typo and some off-screen text that I happened to notice while working on the C code.
This pull request gets the C libraries for the Pololu 3pi+ 2040 Robot into a pretty good state. The only major thing missing from the C libraries now is support for the IMU.
Libraries:
button
struct andbutton_check
function that operates on it. Together, these can be used to debounce any function with signaturebool is_pressed(void)
. This is the only part of the library where I let users allocate memory for objects themselves, but I think it's fine: it makes the API simpler and I think C programmers can understand it.Examples: