micropython/micropython — pull request #978 by PappaPeppar (2014-11-16 21:40:32+00:00)
Title: CAN Rx filter management

Hi,

I have added some functionality to manage CAN filters.
The idea is to treat the 28 filter banks as a shared resource between the CAN blocks, so the banks is split between the blocks with the function CAN.initfilterbanks().
Then each bank can be configured to operate in four modes MASK16, MASK32, LIST16 and LIST32. The four modes is described in the STM32 documentation figure 342. The implementation here hides the somewhat messy register layout for the the python programmer.
some examples
1. can.configfilter(1, CAN.LIST16, 1, id1=11, id2=12, id3=13, id4=14)
This will set up the filterbank 1 to receive messages with ids 11, 12, 13 and 14 into FIFO 1. It should be noted that if the can controller is set up to use extended ids this configuration will have no effect since bit 0 to 14 of a extended id is not used when comparing with a 16 bit filter.

2. can.configfilter(0, CAN.LIST32, 0, id1=1, id2=2)
Configures bank 0 to receive ids 1 and 2 into FIFO 0.

3. bus1.configfilter(2, CAN.MASK32, 0, id1=8, mask1=8)
Configures bank 2 to receive all messages with ids which have the forth bit of the extended id set

Please review and comment.
Henrik