@@ -26,30 +26,30 @@ Constructors
2626 initialised (it has the settings from the last initialisation of
2727 the bus, if any). If extra arguments are given, the bus is initialised.
2828 See ``init `` for parameters of initialisation.
29-
29+
3030 The physical pins of the CAN busses are:
31-
31+
3232 - ``CAN(1) `` is on ``YA ``: ``(RX, TX) = (Y3, Y4) = (PB8, PB9) ``
3333 - ``CAN(2) `` is on ``YB ``: ``(RX, TX) = (Y5, Y6) = (PB12, PB13) ``
3434
3535Class Methods
3636-------------
3737.. method :: CAN.initfilterbanks(nr)
38-
38+
3939 Reset and disable all filter banks and assign how many banks should be available for CAN(1).
40-
40+
4141 STM32F405 has 28 filter banks that are shared between the two available CAN bus controllers.
42- This function configures how many filter banks should be assigned to each. ``nr `` is the number of banks
43- that will be assigned to CAN(1), the rest of the 28 are assigned to CAN(2).
42+ This function configures how many filter banks should be assigned to each. ``nr `` is the number of banks
43+ that will be assigned to CAN(1), the rest of the 28 are assigned to CAN(2).
4444 At boot, 14 banks are assigned to each controller.
45-
45+
4646Methods
4747-------
4848
4949.. method :: can.init(mode, extframe=False, prescaler=100, \*, sjw=1, bs1=6, bs2=8)
5050
5151 Initialise the CAN bus with the given parameters:
52-
52+
5353 - ``mode `` is one of: NORMAL, LOOPBACK, SILENT, SILENT_LOOPBACK
5454 - if ``extframe `` is True then the bus uses extended identifiers in the frames
5555 (29 bits); otherwise it uses standard 11 bit identifiers
@@ -83,14 +83,14 @@ Methods
8383 Turn off the CAN bus.
8484
8585.. method :: can.setfilter(bank, mode, fifo, params)
86-
86+
8787 Configure a filter bank:
88-
88+
8989 - ``bank `` is the filter bank that is to be configured.
9090 - ``mode `` is the mode the filter should operate in.
91- - ``fifo `` is which fifo (0 or 1) a message should be stored in, if it is accepted by this filter.
91+ - ``fifo `` is which fifo (0 or 1) a message should be stored in, if it is accepted by this filter.
9292 - ``params `` is an array of values the defines the filter. The contents of the array depends on the ``mode `` argument.
93-
93+
9494 +-----------+---------------------------------------------------------+
9595 | ``mode`` |contents of parameter array |
9696 +===========+=========================================================+
@@ -106,11 +106,11 @@ Methods
106106 +-----------+---------------------------------------------------------+
107107 | CAN.MASK32 |As with CAN.MASK16 but with only one 32 bit id/mask pair.|
108108 +-----------+---------------------------------------------------------+
109-
109+
110110.. method :: can.clearfilter(bank)
111111
112112 Clear and disables a filter bank:
113-
113+
114114 - ``bank `` is the filter bank that is to be cleared.
115115
116116.. method :: can.any(fifo)
@@ -120,22 +120,56 @@ Methods
120120.. method :: can.recv(fifo, \*, timeout=5000)
121121
122122 Receive data on the bus:
123-
123+
124124 - ``fifo `` is an integer, which is the FIFO to receive on
125125 - ``timeout `` is the timeout in milliseconds to wait for the receive.
126-
126+
127127 Return value: buffer of data bytes.
128128
129129.. method :: can.send(send, addr, \*, timeout=5000)
130130
131131 Send a message on the bus:
132-
132+
133133 - ``send `` is the data to send (an integer to send, or a buffer object).
134134 - ``addr `` is the address to send to
135135 - ``timeout `` is the timeout in milliseconds to wait for the send.
136-
136+
137137 Return value: ``None ``.
138138
139+ .. method :: can.rxcallback(fifo, fun)
140+
141+ Register a function to be called when a message is accepted into a empty fifo:
142+
143+ - ``fifo `` is the receiving fifo.
144+ - ``fun `` is the function to be called when the fifo becomes non empty.
145+
146+ The callback function takes two arguments the first is the can object it self the second is
147+ a integer that indicates the reason for the callback.
148+
149+ +--------+------------------------------------------------+
150+ | Reason | |
151+ +========+================================================+
152+ | 0 | A message has been accepted into a empty FIFO. |
153+ +--------+------------------------------------------------+
154+ | 1 | The FIFO is full |
155+ +--------+------------------------------------------------+
156+ | 2 | A message has been lost due to a full FIFO |
157+ +--------+------------------------------------------------+
158+
159+ Example use of rxcallback::
160+
161+ def cb0(bus, reason):
162+ print('cb0')
163+ if reason == 0:
164+ print('pending')
165+ if reason == 1:
166+ print('full')
167+ if reason == 2:
168+ print('overflow')
169+
170+ can = CAN(1, CAN.LOOPBACK)
171+ can.rxcallback(0, cb0)
172+
139173Constants
140174---------
141175
@@ -151,4 +185,4 @@ Constants
151185.. data :: CAN.LIST32
152186.. data :: CAN.MASK32
153187
154- the operation mode of a filter
188+ the operation mode of a filter
0 commit comments