Skip to content

Commit

Permalink
gs_usb: Use BitTiming internally to configure bitrate (#1748)
Browse files Browse the repository at this point in the history
* gs_usb: Use BitTiming to configure bitrate.

* use kwargs and format black

---------

Co-authored-by: Tuwuh S Wibowo <tuwuh.wibowo@formulatrix.com>
Co-authored-by: zariiii9003 <52598363+zariiii9003@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 22, 2024
1 parent 867fd92 commit 70901ea
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion can/interfaces/gs_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@ def __init__(
self.channel_info = channel
self._can_protocol = can.CanProtocol.CAN_20

self.gs_usb.set_bitrate(bitrate)
bit_timing = can.BitTiming.from_sample_point(
f_clock=self.gs_usb.device_capability.fclk_can,
bitrate=bitrate,
sample_point=87.5,
)
props_seg = 1
self.gs_usb.set_timing(
prop_seg=props_seg,
phase_seg1=bit_timing.tseg1 - props_seg,
phase_seg2=bit_timing.tseg2,
sjw=bit_timing.sjw,
brp=bit_timing.brp,
)
self.gs_usb.start()

super().__init__(
Expand Down

0 comments on commit 70901ea

Please sign in to comment.