@@ -162,21 +162,15 @@ STATIC void pyb_can_print(void (*print)(void *env, const char *fmt, ...), void *
162162 }
163163}
164164
165- /// \method init(mode, extframe=False, prescaler=100, *, sjw=1, bs1=6, bs2=8)
166- ///
167- /// Initialise the CAN bus with the given parameters:
168- ///
169- /// - `mode` is one of: NORMAL, LOOPBACK, SILENT, SILENT_LOOPBACK
165+ // init(mode, extframe=False, prescaler=100, *, sjw=1, bs1=6, bs2=8)
170166STATIC mp_obj_t pyb_can_init_helper (pyb_can_obj_t * self , mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
171167 static const mp_arg_t allowed_args [] = {
172168 { MP_QSTR_mode , MP_ARG_REQUIRED | MP_ARG_INT , {.u_int = CAN_MODE_NORMAL } },
173169 { MP_QSTR_extframe , MP_ARG_BOOL , {.u_bool = false} },
174170 { MP_QSTR_prescaler , MP_ARG_INT , {.u_int = 100 } },
175- /*
176171 { MP_QSTR_sjw , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
177172 { MP_QSTR_bs1 , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 6 } },
178173 { MP_QSTR_bs2 , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 8 } },
179- */
180174 };
181175
182176 // parse args
@@ -190,9 +184,9 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, mp_uint_t n_args, const
190184 CAN_InitTypeDef * init = & self -> can .Init ;
191185 init -> Mode = args [0 ].u_int << 4 ; // shift-left so modes fit in a small-int
192186 init -> Prescaler = args [2 ].u_int ;
193- init -> SJW = CAN_SJW_1TQ ; // TODO set from args
194- init -> BS1 = CAN_BS1_6TQ ; // TODO set from args
195- init -> BS2 = CAN_BS2_8TQ ; // TODO set from args
187+ init -> SJW = (( args [ 3 ]. u_int - 1 ) & 3 ) << 24 ;
188+ init -> BS1 = (( args [ 4 ]. u_int - 1 ) & 0xf ) << 16 ;
189+ init -> BS2 = (( args [ 5 ]. u_int - 1 ) & 7 ) << 20 ;
196190 init -> TTCM = DISABLE ;
197191 init -> ABOM = DISABLE ;
198192 init -> AWUM = DISABLE ;
0 commit comments