Skip to content

Commit

Permalink
GPIOD
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-gorecki committed Jan 31, 2024
1 parent 32c1d82 commit 5f8e06b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rosbot_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<author email="[email protected]">Jakub Delicat</author>
<author email="[email protected]">Rafal Gorecki</author>

<exec_depend>python3-gpiozero</exec_depend>
<exec_depend>python3-libgpiod</exec_depend>
<exec_depend>python3-pyftdi-pip</exec_depend>
<exec_depend>python3-requests</exec_depend>
<exec_depend>python3-serial</exec_depend>
Expand Down
25 changes: 16 additions & 9 deletions rosbot_utils/rosbot_utils/flash-firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import time
import sys
import argparse
from gpiozero import OutputDevice
import gpiod


class FirmwareFlasher:
Expand All @@ -38,41 +38,48 @@ def __init__(self, sys_arch, binary_file):
# Setups ThinkerBoard pins
print("Device: ThinkerBoard\n")
self.serial_port = "/dev/ttyS1"
gpio_chip = "/dev/gpiochip0"
boot0_pin_no = 164
reset_pin_no = 184

elif self.sys_arch == "x86_64":
# Setups UpBoard pins
print("Device: UpBoard\n")
self.serial_port = "/dev/ttyS4"
gpio_chip = "/dev/gpiochip4"
boot0_pin_no = 17
reset_pin_no = 18

elif self.sys_arch == "aarch64":
# Setups RPi pins
print("Device: RPi\n")
self.serial_port = "/dev/ttyAMA0"
gpio_chip = "/dev/gpiochip0"
boot0_pin_no = 17
reset_pin_no = 18

else:
print("Unknown device...")

self.boot0_pin = OutputDevice(boot0_pin_no)
self.reset_pin = OutputDevice(reset_pin_no)
chip = gpiod.Chip(gpio_chip)
self.boot0_pin = chip.get_line(boot0_pin_no)
self.reset_pin = chip.get_line(reset_pin_no)

self.boot0_pin.request("Flash", type=gpiod.LINE_REQ_DIR_OUT, default_val=False)
self.reset_pin.request("Flash", type=gpiod.LINE_REQ_DIR_OUT, default_val=False)

def enter_bootloader_mode(self):
self.boot0_pin.on()
self.reset_pin.on()
self.boot0_pin.set_value(1)
self.reset_pin.set_value(1)
time.sleep(0.2)
self.reset_pin.off()
self.reset_pin.set_value(0)
time.sleep(0.2)

def exit_bootloader_mode(self):
self.boot0_pin.off()
self.reset_pin.on()
self.boot0_pin.set_value(0)
self.reset_pin.set_value(1)
time.sleep(0.2)
self.reset_pin.off()
self.reset_pin.set_value(0)
time.sleep(0.2)

def try_flash_operation(self, operation_name, flash_command, flash_args):
Expand Down

0 comments on commit 5f8e06b

Please sign in to comment.