Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Refactor Replicape hardware details into a board detection module
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatWileyGuy committed Mar 21, 2019
1 parent 11efa29 commit 6975a32
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 221 deletions.
30 changes: 0 additions & 30 deletions configs/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ max_rise_temp_E = 10.0
max_fall_temp_E = 10.0
min_temp_E = 20.0
max_temp_E = 250.0
path_adc_E = /sys/bus/iio/devices/iio:device0/in_voltage4_raw
mosfet_E = 5
onoff_E = False
prefix_E = T0
max_power_E = 1.0
Expand All @@ -306,8 +304,6 @@ max_rise_temp_H = 10.0
max_fall_temp_H = 10.0
min_temp_H = 20.0
max_temp_H = 250.0
path_adc_H = /sys/bus/iio/devices/iio:device0/in_voltage5_raw
mosfet_H = 3
onoff_H = False
prefix_H = T1
max_power_H = 1.0
Expand All @@ -321,8 +317,6 @@ max_rise_temp_A = 10.0
max_fall_temp_A = 10.0
min_temp_A = 20.0
max_temp_A = 250.0
path_adc_A = /sys/bus/iio/devices/iio:device0/in_voltage0_raw
mosfet_A = 11
onoff_A = False
prefix_A = T2
max_power_A = 1.0
Expand All @@ -336,8 +330,6 @@ max_rise_temp_B = 10.0
max_fall_temp_B = 10.0
min_temp_B = 20.0
max_temp_B = 250.0
path_adc_B = /sys/bus/iio/devices/iio:device0/in_voltage3_raw
mosfet_B = 12
onoff_B = False
prefix_B = T3
max_power_B = 1.0
Expand All @@ -351,8 +343,6 @@ max_rise_temp_C = 10.0
max_fall_temp_C = 10.0
min_temp_C = 20.0
max_temp_C = 250.0
path_adc_C = /sys/bus/iio/devices/iio:device0/in_voltage2_raw
mosfet_C = 13
onoff_C = False
prefix_C = T4
max_power_C = 1.0
Expand All @@ -366,8 +356,6 @@ max_rise_temp_HBP = 10.0
max_fall_temp_HBP = 10.0
min_temp_HBP = 20.0
max_temp_HBP = 250.0
path_adc_HBP = /sys/bus/iio/devices/iio:device0/in_voltage6_raw
mosfet_HBP = 4
onoff_HBP = False
prefix_HBP = B
max_power_HBP = 1.0
Expand All @@ -383,8 +371,6 @@ has_a = False
has_b = False
has_c = False

inputdev = /dev/input/by-path/platform-ocp:gpio_keys-event

# Number of cycles to wait between checking
# end stops. CPU frequency is 200 MHz
end_stop_delay_cycles = 1000
Expand All @@ -399,22 +385,6 @@ invert_Y2 = False
invert_Z1 = False
invert_Z2 = False

pin_X1 = GPIO3_21
pin_X2 = GPIO0_30
pin_Y1 = GPIO1_17
pin_Y2 = GPIO3_17
pin_Z1 = GPIO0_31
pin_Z2 = GPIO0_4

# On A4A you'll need pin_Y2 = GPIO1_19

keycode_X1 = 112
keycode_X2 = 113
keycode_Y1 = 114
keycode_Y2 = 115
keycode_Z1 = 116
keycode_Z2 = 117

# If one endstop is hit, which steppers and directions are masked.
# The list is comma separated and has format
# x_cw = stepper x clockwise (independent of direction_x)
Expand Down
48 changes: 0 additions & 48 deletions redeem/CascadingConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,6 @@ def timestamp(self):
ts = max(ts, os.lstat(printer_cfg).st_mtime)
return ts

def parse_capes(self):
""" Read the name and revision of each cape on the BeagleBone """
self.replicape_revision = None
self.reach_revision = None

import glob
paths = glob.glob("/sys/bus/i2c/devices/[1-2]-005[4-7]/*/nvmem")
paths.extend(glob.glob("/sys/bus/i2c/devices/[1-2]-005[4-7]/nvmem/at24-[1-4]/nvmem"))
#paths.append(glob.glob("/sys/bus/i2c/devices/[1-2]-005[4-7]/eeprom"))
for i, path in enumerate(paths):
try:
with open(path, "rb") as f:
data = f.read(120)
name = data[58:74].strip()
if name == "BB-BONE-REPLICAP":
self.replicape_revision = data[38:42]
self.replicape_data = data
self.replicape_path = path
elif name[:13] == "BB-BONE-REACH":
self.reach_revision = data[38:42]
self.reach_data = data
self.reach_path = path
if self.replicape_revision != None and self.reach_revision != None:
break
except IOError as e:
pass
# Parameters from the hardware
self.setup_key()

def get_default_settings(self):
fs = []
for config_file in self.config_files:
Expand Down Expand Up @@ -163,25 +134,6 @@ def check(self, filename):
logging.warning("{} contains errors.".format(filename))
return local_ok

def setup_key(self):
""" Get the generated key from the config or create one """
self.replicape_key = "".join(struct.unpack('20c', self.replicape_data[100:120]))
logging.debug("Found Replicape key: '" + self.replicape_key + "'")
if self.replicape_key == '\x00' * 20:
logging.debug("Replicape key invalid")
import random
import string
self.replicape_key = ''.join(
random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(20))
self.replicape_data = self.replicape_data[:100] + self.replicape_key
logging.debug("New Replicape key: '" + self.replicape_key + "'")
#logging.debug("".join(struct.unpack('20c', self.new_replicape_data[100:120])))
try:
with open(self.replicape_path, "wb") as f:
f.write(self.replicape_data[:120])
except IOError as e:
logging.warning("Unable to write new key to EEPROM")


if __name__ == '__main__':
logging.basicConfig(
Expand Down
3 changes: 3 additions & 0 deletions redeem/Printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ class Printer:
def __init__(self):
self.steppers = {}
self.heaters = {}
self.thermistor_inputs = {}
self.thermistors = {}
self.mosfets = {}
self.end_stop_inputs = {}
self.end_stop_keycodes = {}
self.end_stops = {}
self.fans = []
self.cold_ends = []
Expand Down
2 changes: 1 addition & 1 deletion redeem/PruFirmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def make_config_file(self):
end_stop_delay = self.config.getint('Endstops', 'end_stop_delay_cycles')
configFile.write("#define END_STOP_DELAY " + str(end_stop_delay) + "\n")

revision = self.printer.config.replicape_revision.strip('0')
revision = self.printer.revision.strip('0')

# Note that these are all cycle counts of the 200MHz PRU - 1 cycle is 5ns
if revision.startswith('A'): # DRV8825
Expand Down
114 changes: 15 additions & 99 deletions redeem/Redeem.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"""

import glob
import importlib
import inspect
import logging
import logging.handlers
import os
Expand All @@ -32,6 +34,7 @@
import Queue
import numpy as np
import sys
import boards.probe

from Mosfet import Mosfet
from Stepper import *
Expand Down Expand Up @@ -121,7 +124,7 @@ def __init__(self, config_location="/etc/redeem"):
printer.config.check(printer_path)
printer.config.check(os.path.join(config_location, 'local.cfg'))

# Get the revision and loglevel from the Config file
# Get the loglevel from the Config file
level = self.printer.config.getint('System', 'loglevel')
if level > 0:
logging.getLogger().setLevel(level)
Expand All @@ -137,99 +140,37 @@ def __init__(self, config_location="/etc/redeem"):
logging.getLogger().addHandler(printer.redeem_logging_handler)
logging.info("-- Logfile configured --")

# Find out which capes are connected
self.printer.config.parse_capes()
self.revision = self.printer.config.replicape_revision
if self.revision:
logging.info("Found Replicape rev. {}".format(self.revision))
# probe for the actual hardware
boards.probe.probe_all_boards(self.printer)

if hasattr(self.printer, "board"):
logging.info("Found board: %s %s", self.printer.board, self.printer.revision)
else:
logging.warning("Oh no! No Replicape present!")
self.revision = "0B3A"
# We set it to 5 axis by default
Printer.NUM_AXES = 5
if self.printer.config.reach_revision:
logging.info("Found Reach rev. " + self.printer.config.reach_revision)
if self.printer.config.reach_revision == "00A0":
Printer.NUM_AXES = 8
elif self.printer.config.reach_revision == "00B0":
Printer.NUM_AXES = 7

if self.revision in ["00A4", "0A4A", "00A3"]:
PWM.set_frequency(100)
elif self.revision in ["00B1", "00B2", "00B3", "0B3A"]:
PWM.set_frequency(1000)
logging.error("No printer control board found - exiting")
sys.exit()

# Init the Watchdog timer
printer.watchdog = Watchdog()

# Enable PWM and steppers
printer.enable = Enable("P9_41")
printer.enable.set_disabled()

printer.NUM_EXTRUDERS = printer.config.getint('Steppers', 'number_of_extruders')

# Init the Paths
printer.axis_config = printer.config.getint('Geometry', 'axis_config')

# Init the end stops
EndStop.inputdev = self.printer.config.get("Endstops", "inputdev")
# Set up key listener
Key_pin.listener = Key_pin_listener(EndStop.inputdev)

homing_only_endstops = self.printer.config.get('Endstops', 'homing_only_endstops')

for es in ["Z2", "Y2", "X2", "Z1", "Y1",
"X1"]: # Order matches end stop inversion mask in Firmware
pin = self.printer.config.get("Endstops", "pin_" + es)
keycode = self.printer.config.getint("Endstops", "keycode_" + es)
pin = self.printer.end_stop_inputs[es]
keycode = self.printer.end_stop_keycodes[es]
invert = self.printer.config.getboolean("Endstops", "invert_" + es)
self.printer.end_stops[es] = EndStop(printer, pin, keycode, es, invert)
self.printer.end_stops[es].stops = self.printer.config.get('Endstops',
'end_stop_' + es + '_stops')
self.printer.end_stops[es].stops = printer.config.get('Endstops', 'end_stop_' + es + '_stops')

# activate all the endstops
self.printer.set_active_endstops()

# Init the 5 Stepper motors (step, dir, fault, DAC channel, name)
Stepper.printer = printer
if self.revision == "00A3":
printer.steppers["X"] = Stepper_00A3("GPIO0_27", "GPIO1_29", "GPIO2_4", 0, "X")
printer.steppers["Y"] = Stepper_00A3("GPIO1_12", "GPIO0_22", "GPIO2_5", 1, "Y")
printer.steppers["Z"] = Stepper_00A3("GPIO0_23", "GPIO0_26", "GPIO0_15", 2, "Z")
printer.steppers["E"] = Stepper_00A3("GPIO1_28", "GPIO1_15", "GPIO2_1", 3, "E")
printer.steppers["H"] = Stepper_00A3("GPIO1_13", "GPIO1_14", "GPIO2_3", 4, "H")
elif self.revision == "00B1":
printer.steppers["X"] = Stepper_00B1("GPIO0_27", "GPIO1_29", "GPIO2_4", 11, 0, "X")
printer.steppers["Y"] = Stepper_00B1("GPIO1_12", "GPIO0_22", "GPIO2_5", 12, 1, "Y")
printer.steppers["Z"] = Stepper_00B1("GPIO0_23", "GPIO0_26", "GPIO0_15", 13, 2, "Z")
printer.steppers["E"] = Stepper_00B1("GPIO1_28", "GPIO1_15", "GPIO2_1", 14, 3, "E")
printer.steppers["H"] = Stepper_00B1("GPIO1_13", "GPIO1_14", "GPIO2_3", 15, 4, "H")
elif self.revision == "00B2":
printer.steppers["X"] = Stepper_00B2("GPIO0_27", "GPIO1_29", "GPIO2_4", 11, 0, "X")
printer.steppers["Y"] = Stepper_00B2("GPIO1_12", "GPIO0_22", "GPIO2_5", 12, 1, "Y")
printer.steppers["Z"] = Stepper_00B2("GPIO0_23", "GPIO0_26", "GPIO0_15", 13, 2, "Z")
printer.steppers["E"] = Stepper_00B2("GPIO1_28", "GPIO1_15", "GPIO2_1", 14, 3, "E")
printer.steppers["H"] = Stepper_00B2("GPIO1_13", "GPIO1_14", "GPIO2_3", 15, 4, "H")
elif self.revision in ["00B3", "0B3A"]:
printer.steppers["X"] = Stepper_00B3("GPIO0_27", "GPIO1_29", 90, 11, 0, "X")
printer.steppers["Y"] = Stepper_00B3("GPIO1_12", "GPIO0_22", 91, 12, 1, "Y")
printer.steppers["Z"] = Stepper_00B3("GPIO0_23", "GPIO0_26", 92, 13, 2, "Z")
printer.steppers["E"] = Stepper_00B3("GPIO1_28", "GPIO1_15", 93, 14, 3, "E")
printer.steppers["H"] = Stepper_00B3("GPIO1_13", "GPIO1_14", 94, 15, 4, "H")
elif self.revision in ["00A4", "0A4A"]:
printer.steppers["X"] = Stepper_00A4("GPIO0_27", "GPIO1_29", "GPIO2_4", 0, 0, "X")
printer.steppers["Y"] = Stepper_00A4("GPIO1_12", "GPIO0_22", "GPIO2_5", 1, 1, "Y")
printer.steppers["Z"] = Stepper_00A4("GPIO0_23", "GPIO0_26", "GPIO0_15", 2, 2, "Z")
printer.steppers["E"] = Stepper_00A4("GPIO1_28", "GPIO1_15", "GPIO2_1", 3, 3, "E")
printer.steppers["H"] = Stepper_00A4("GPIO1_13", "GPIO1_14", "GPIO2_3", 4, 4, "H")
# Init Reach steppers, if present.
if printer.config.reach_revision == "00A0":
printer.steppers["A"] = Stepper_reach_00A4("GPIO2_2", "GPIO1_18", "GPIO0_14", 5, 5, "A")
printer.steppers["B"] = Stepper_reach_00A4("GPIO1_16", "GPIO0_5", "GPIO0_14", 6, 6, "B")
printer.steppers["C"] = Stepper_reach_00A4("GPIO0_3", "GPIO3_19", "GPIO0_14", 7, 7, "C")
elif printer.config.reach_revision == "00B0":
printer.steppers["A"] = Stepper_reach_00B0("GPIO1_16", "GPIO0_5", "GPIO0_3", 5, 5, "A")
printer.steppers["B"] = Stepper_reach_00B0("GPIO2_2", "GPIO0_14", "GPIO0_3", 6, 6, "B")

# Enable the steppers and set the current, steps pr mm and
# microstepping
Expand Down Expand Up @@ -271,14 +212,9 @@ def __init__(self, config_location="/etc/redeem"):

# Make Mosfets, temperature sensors and extruders
heaters = ["E", "H", "HBP"]
if self.printer.config.reach_revision:
heaters.extend(["A", "B", "C"])
for e in heaters:
# Mosfets
channel = self.printer.config.getint("Heaters", "mosfet_" + e)
self.printer.mosfets[e] = Mosfet(channel)
# Thermistors
adc = self.printer.config.get("Heaters", "path_adc_" + e)
adc = self.printer.thermistor_inputs[e]
if not self.printer.config.has_option("Heaters", "sensor_" + e):
sensor = self.printer.config.get("Heaters", "temp_chart_" + e)
logging.warning("Deprecated config option temp_chart_" + e + " use sensor_" + e +
Expand Down Expand Up @@ -310,26 +246,6 @@ def __init__(self, config_location="/etc/redeem"):
'Heaters', 'max_fall_temp_' + e)
self.printer.heaters[e].max_power = self.printer.config.getfloat('Heaters', 'max_power_' + e)

# Init the three fans. Argument is PWM channel number
self.printer.fans = []
if self.revision == "00A3":
self.printer.fans.append(Fan(0))
self.printer.fans.append(Fan(1))
self.printer.fans.append(Fan(2))
elif self.revision == "0A4A":
self.printer.fans.append(Fan(8))
self.printer.fans.append(Fan(9))
self.printer.fans.append(Fan(10))
elif self.revision in ["00B1", "00B2", "00B3", "0B3A"]:
self.printer.fans.append(Fan(7))
self.printer.fans.append(Fan(8))
self.printer.fans.append(Fan(9))
self.printer.fans.append(Fan(10))
if printer.config.reach_revision == "00A0":
self.printer.fans.append(Fan(14))
self.printer.fans.append(Fan(15))
self.printer.fans.append(Fan(7))

# Set default value for all fans
for i, f in enumerate(self.printer.fans):
f.set_value(self.printer.config.getfloat('Fans', "default-fan-{}-value".format(i)))
Expand Down
Empty file added redeem/boards/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions redeem/boards/probe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import replicape


def probe_all_boards(printer):
replicape.probe_replicape(printer)
Loading

0 comments on commit 6975a32

Please sign in to comment.