Skip to content

Commit 288aa11

Browse files
committed
Remapable IO
1 parent afae0ef commit 288aa11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+6643
-755
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Buildbotics CNC Controller Firmware Changelog
22
=============================================
33

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

1519
## v1.0.0
1620
- Added online GCode editor.

jshint.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"browser": true,
44
"devel": true,
55
"strict": "global",
6+
"esversion": 6,
67
"globals": {
78
"$": false,
89
"require": false,
@@ -11,6 +12,8 @@
1112
"SockJS": false,
1213
"Gauge": false,
1314
"Clusterize": false,
14-
"CodeMirror": false
15+
"CodeMirror": false,
16+
"Chart": false,
17+
"THREE": false
1518
}
1619
}

scripts/avr109-flash

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env python3
22

33
import sys
4+
import os
45
import time
56
import serial
67
import binascii
8+
import argparse
79

810

9-
dev = '/dev/ttyAMA0'
10-
baud = 921600
1111
boot_id = 'bbctrl '
12-
verbose = False
1312

1413

1514
def crc16(data):
@@ -70,41 +69,57 @@ def read_intel_hex(f):
7069

7170

7271
def send(data):
73-
if verbose: print('Sending:', data)
72+
if args.verbose: print('Sending:', data)
7473
sp.write(bytes(data, 'utf8'))
7574

7675

7776
def send_int(x, size):
78-
if verbose: print('Sending: %d', x)
77+
if args.verbose: print('Sending: %d', x)
7978
sp.write((x).to_bytes(size, byteorder = 'big'))
8079

8180

8281
def recv(count):
8382
data = sp.read(count).decode('utf8')
84-
if count and verbose: print('Received:', data)
83+
if count and args.verbose: print('Received:', data)
8584
return data
8685

8786

8887
def recv_int(size):
8988
x = int.from_bytes(sp.read(size), byteorder = 'big')
90-
if verbose: print('Received:', x)
89+
if args.verbose: print('Received:', x)
9190
return x
9291

92+
# Parse arguments
93+
parser = argparse.ArgumentParser(description = 'Program AVR over serial port '
94+
'using the AVR109 bootloader protocol.')
95+
parser.add_argument('-b', '--baud', default = 921600, type = int,
96+
help = 'Set baud rate.')
97+
parser.add_argument('-t', '--timeout', default = 10, type = int,
98+
help = 'Timeout in seconds.')
99+
parser.add_argument('-d', '--device', default = '/dev/ttyAMA0',
100+
help = 'Serial device.')
101+
parser.add_argument('-r', '--reset', default = 27, type = int,
102+
help = 'Reset line GPIO.')
103+
parser.add_argument('-v', '--verbose', help = 'Enable verbose logging',
104+
action = 'count', default = 0)
105+
parser.add_argument('file', help = 'The Intel hex file to program.')
106+
args = parser.parse_args()
93107

94108
# Read firmware hex file
95-
data = list(read_intel_hex(open(sys.argv[1], 'r')))
109+
data = list(read_intel_hex(open(args.file, 'r')))
96110

97111
# Open serial port
98-
sp = serial.Serial(dev, baud, timeout = 10)
112+
sp = serial.Serial(args.device, args.baud, timeout = args.timeout)
99113

100114
# Reset AVR
101-
import RPi.GPIO as gpio
102-
gpio.setwarnings(False)
103-
gpio.setmode(gpio.BCM)
104-
gpio.setup(27, gpio.OUT)
105-
gpio.output(27, 0)
106-
gpio.output(27, 1)
107-
gpio.setup(27, gpio.IN, pull_up_down = gpio.PUD_UP)
115+
reset_gpio_path = '/sys/class/gpio/gpio%s' % args.reset
116+
if not os.path.exists(reset_gpio_path):
117+
with open('/sys/class/gpio/export', 'w') as f:
118+
f.write(str(args.reset))
119+
120+
with open(reset_gpio_path + '/direction', 'w') as f: f.write('out')
121+
with open(reset_gpio_path + '/value', 'w') as f: f.write('0')
122+
with open(reset_gpio_path + '/value', 'w') as f: f.write('1')
108123
time.sleep(0.1)
109124

110125
# Sync

scripts/install.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,21 @@ while [ $# -gt 0 ]; do
1414
shift 1
1515
done
1616

17-
service bbctrl stop
17+
if [ -e /etc/systemd/system/bbctrl.service ]; then
18+
service bbctrl stop
19+
fi
20+
21+
# Find devices
22+
if [ -e /dev/ttyAMA0 ]; then
23+
AVR_DEV=/dev/ttyAMA0
24+
AVR_RESET=27
25+
elif [ -e /dev/ttyS2 ]; then
26+
AVR_DEV=/dev/ttyS2
27+
AVR_RESET=117
28+
else
29+
>&2 echo "Cannot find AVR serial device."
30+
UPDATE_AVR=false
31+
fi
1832

1933
if $UPDATE_PY; then
2034
# Update service
@@ -26,7 +40,8 @@ if $UPDATE_PY; then
2640
fi
2741

2842
if $UPDATE_AVR; then
29-
./scripts/avr109-flash src/avr/bbctrl-avr-firmware.hex
43+
./scripts/avr109-flash -d $AVR_DEV -r $AVR_RESET \
44+
src/avr/bbctrl-avr-firmware.hex
3045
fi
3146

3247
# Update config.txt

src/avr/src/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ enum {
9494

9595
#define AXES 6 // number of axes
9696
#define MOTORS 4 // number of motors on the board
97+
#define INS 6 // number of supported pin outputs
9798
#define OUTS 10 // number of supported pin outputs
98-
#define ANALOGS 4 // number of supported analog inputs
99+
#define ANALOGS 2 // number of supported analog inputs
99100
#define DIGITALS 4 // number of supported digital inputs
100101
#define VFDREG 32 // number of supported VFD modbus registers
101102
#define IO_PINS 17 // number of supported i/o pins

src/avr/src/drv8711.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static uint8_t _driver_get_torque(drv8711_driver_t *drv) {
174174
}
175175
}
176176

177+
177178
static uint16_t _driver_get_torque_reg(drv8711_driver_t *drv) {
178179
uint16_t reg;
179180

0 commit comments

Comments
 (0)