adafruit / Adafruit_CircuitPython_MCP2515

A CircuitPython library for working with the MCP2515 CAN bus controller
MIT License
21 stars 14 forks source link

Use all mask filter pairs #25

Closed karlfl closed 3 months ago

karlfl commented 5 months ago

Addresses #19

This is a simple approach to fixing the issue of not properly using all of the Masks and Filters available on the MCP2515. This update does the following.

  1. When adding a mask, place the actual mask value in the _masks_in_use array so we can search for it later if is used in another match.
  2. Prior to adding the mask, check to see if it's already in the _masks_in_use array, if so just return that index.

As far as I can tell, the previous code was using the _masks_in_use array to store the mask register being used, not the actual mask value. The only purpose for this array seemed to be for checking the array length to determine how many masks were in use. By placing the actual mask value in the _masks_in_use array, we're able to also search for it so more than one filter can be paired with each mask. This change shouldn't affect the checks used to ensure the max number mask/filter pairs is enforced.

This change also expands the documentation for '.listen()', adding details on how to use the matches array to setup the masks and filters on the MCP2515 using this library.

I've tested this change on an RP2040 CAN Bus Feather