Skip to content

Commit

Permalink
Remapable IO
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoffland committed Feb 17, 2022
1 parent afae0ef commit 288aa11
Show file tree
Hide file tree
Showing 49 changed files with 6,643 additions and 755 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Buildbotics CNC Controller Firmware Changelog
=============================================

## v1.0.2
- Remappable IO

## v1.0.1
- Handle case correctly when assigning named GCode variables.
- Increased gamepad deadband to 15% but with rescaling to improve precision.
Expand All @@ -11,6 +14,7 @@ Buildbotics CNC Controller Firmware Changelog
- Correction for voltage measurements.
- Removed load current and faults for newer hardware from indicators and LCD.
- Added DB15 breakout box to indicators page.
- Send stop command to VFD on estop.

## v1.0.0
- Added online GCode editor.
Expand Down
5 changes: 4 additions & 1 deletion jshint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"browser": true,
"devel": true,
"strict": "global",
"esversion": 6,
"globals": {
"$": false,
"require": false,
Expand All @@ -11,6 +12,8 @@
"SockJS": false,
"Gauge": false,
"Clusterize": false,
"CodeMirror": false
"CodeMirror": false,
"Chart": false,
"THREE": false
}
}
47 changes: 31 additions & 16 deletions scripts/avr109-flash
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env python3

import sys
import os
import time
import serial
import binascii
import argparse


dev = '/dev/ttyAMA0'
baud = 921600
boot_id = 'bbctrl '
verbose = False


def crc16(data):
Expand Down Expand Up @@ -70,41 +69,57 @@ def read_intel_hex(f):


def send(data):
if verbose: print('Sending:', data)
if args.verbose: print('Sending:', data)
sp.write(bytes(data, 'utf8'))


def send_int(x, size):
if verbose: print('Sending: %d', x)
if args.verbose: print('Sending: %d', x)
sp.write((x).to_bytes(size, byteorder = 'big'))


def recv(count):
data = sp.read(count).decode('utf8')
if count and verbose: print('Received:', data)
if count and args.verbose: print('Received:', data)
return data


def recv_int(size):
x = int.from_bytes(sp.read(size), byteorder = 'big')
if verbose: print('Received:', x)
if args.verbose: print('Received:', x)
return x

# Parse arguments
parser = argparse.ArgumentParser(description = 'Program AVR over serial port '
'using the AVR109 bootloader protocol.')
parser.add_argument('-b', '--baud', default = 921600, type = int,
help = 'Set baud rate.')
parser.add_argument('-t', '--timeout', default = 10, type = int,
help = 'Timeout in seconds.')
parser.add_argument('-d', '--device', default = '/dev/ttyAMA0',
help = 'Serial device.')
parser.add_argument('-r', '--reset', default = 27, type = int,
help = 'Reset line GPIO.')
parser.add_argument('-v', '--verbose', help = 'Enable verbose logging',
action = 'count', default = 0)
parser.add_argument('file', help = 'The Intel hex file to program.')
args = parser.parse_args()

# Read firmware hex file
data = list(read_intel_hex(open(sys.argv[1], 'r')))
data = list(read_intel_hex(open(args.file, 'r')))

# Open serial port
sp = serial.Serial(dev, baud, timeout = 10)
sp = serial.Serial(args.device, args.baud, timeout = args.timeout)

# Reset AVR
import RPi.GPIO as gpio
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(27, gpio.OUT)
gpio.output(27, 0)
gpio.output(27, 1)
gpio.setup(27, gpio.IN, pull_up_down = gpio.PUD_UP)
reset_gpio_path = '/sys/class/gpio/gpio%s' % args.reset
if not os.path.exists(reset_gpio_path):
with open('/sys/class/gpio/export', 'w') as f:
f.write(str(args.reset))

with open(reset_gpio_path + '/direction', 'w') as f: f.write('out')
with open(reset_gpio_path + '/value', 'w') as f: f.write('0')
with open(reset_gpio_path + '/value', 'w') as f: f.write('1')
time.sleep(0.1)

# Sync
Expand Down
19 changes: 17 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@ while [ $# -gt 0 ]; do
shift 1
done

service bbctrl stop
if [ -e /etc/systemd/system/bbctrl.service ]; then
service bbctrl stop
fi

# Find devices
if [ -e /dev/ttyAMA0 ]; then
AVR_DEV=/dev/ttyAMA0
AVR_RESET=27
elif [ -e /dev/ttyS2 ]; then
AVR_DEV=/dev/ttyS2
AVR_RESET=117
else
>&2 echo "Cannot find AVR serial device."
UPDATE_AVR=false
fi

if $UPDATE_PY; then
# Update service
Expand All @@ -26,7 +40,8 @@ if $UPDATE_PY; then
fi

if $UPDATE_AVR; then
./scripts/avr109-flash src/avr/bbctrl-avr-firmware.hex
./scripts/avr109-flash -d $AVR_DEV -r $AVR_RESET \
src/avr/bbctrl-avr-firmware.hex
fi

# Update config.txt
Expand Down
3 changes: 2 additions & 1 deletion src/avr/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ enum {

#define AXES 6 // number of axes
#define MOTORS 4 // number of motors on the board
#define INS 6 // number of supported pin outputs
#define OUTS 10 // number of supported pin outputs
#define ANALOGS 4 // number of supported analog inputs
#define ANALOGS 2 // number of supported analog inputs
#define DIGITALS 4 // number of supported digital inputs
#define VFDREG 32 // number of supported VFD modbus registers
#define IO_PINS 17 // number of supported i/o pins
Expand Down
1 change: 1 addition & 0 deletions src/avr/src/drv8711.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ static uint8_t _driver_get_torque(drv8711_driver_t *drv) {
}
}


static uint16_t _driver_get_torque_reg(drv8711_driver_t *drv) {
uint16_t reg;

Expand Down
Loading

0 comments on commit 288aa11

Please sign in to comment.