Skip to content

Commit

Permalink
merge software related portions of 1624
Browse files Browse the repository at this point in the history
  • Loading branch information
gcormier committed Sep 10, 2022
1 parent 33df068 commit 77d86ab
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 59 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/push_fab_outputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@
# below.
name: "KiBot - Fabrication and Documentation (push)"

on:
push:
branches:
- master

#on:
# workflow_dispatch:
# inputs:
# version:
# description: "Design version"
# required: true
# default: "gerb-review"
on: push


jobs:
FabricationOutputs:
Expand Down Expand Up @@ -47,7 +37,7 @@ jobs:
# Actually run KiBot to generate all the files. The KiBot script used is
# in the .kibot/release.kibot.yaml folder.
- name: KiBot
uses: INTI-CMNB/KiBot@v1_k6
uses: INTI-CMNB/KiBot@v2_k6
with:
config: PCB/.kibot/megadesk.kibot.yaml
dir: ${{ env.OutputFolder }}
Expand Down
33 changes: 26 additions & 7 deletions .github/workflows/version_pio_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
tags:
- v*
workflow_dispatch:

jobs:
build:
Expand All @@ -19,24 +18,44 @@ jobs:
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Build noserial
run: pio run --project-dir ./Code --environment attiny841_noserial
- name: Build t841 noserial
run: pio run --project-dir ./Code --environment attiny841_noserial
- name: Rename noserial firmware
run: |
mv ./Code/.pio/build/attiny841_noserial/firmware.hex ./Code/.pio/build/attiny841_noserial/megadesk-$GITHUB_REF_NAME.hex
FILENAME=./Code/.pio/build/attiny841_noserial/megadesk-$GITHUB_REF_NAME.hex
FILENAME=./Code/.pio/build/attiny841_noserial/megadesk-$GITHUB_REF_NAME-t841.hex
echo "FILENAME=$FILENAME" >> $GITHUB_ENV
- name: Build serial
run: pio run --project-dir ./Code --environment attiny841_serial
- name: Build t841 serial
run: pio run --project-dir ./Code --environment attiny841_serial
- name: Rename serial firmware
run: |
mv ./Code/.pio/build/attiny841_serial/firmware.hex ./Code/.pio/build/attiny841_serial/megadesk-$GITHUB_REF_NAME-serial.hex
SFILENAME=./Code/.pio/build/attiny841_serial/megadesk-$GITHUB_REF_NAME-serial.hex
SFILENAME=./Code/.pio/build/attiny841_serial/megadesk-$GITHUB_REF_NAME-t841-serial.hex
echo "SFILENAME=$SFILENAME" >> $GITHUB_ENV
- name: Build t1624 noserial
run: pio run --project-dir ./Code --environment attiny1624_noserial
- name: Rename noserial firmware
run: |
mv ./Code/.pio/build/attiny1624_noserial/firmware.hex ./Code/.pio/build/attiny1624_noserial/megadesk-$GITHUB_REF_NAME.hex
FILENAME=./Code/.pio/build/attiny1624_noserial/megadesk-$GITHUB_REF_NAME-t1624.hex
echo "FILENAME=$FILENAME" >> $GITHUB_ENV
- name: Build t1624 serial
run: pio run --project-dir ./Code --environment attiny1624_serial
- name: Rename serial firmware
run: |
mv ./Code/.pio/build/attiny1624_serial/firmware.hex ./Code/.pio/build/attiny1624_serial/megadesk-$GITHUB_REF_NAME-serial.hex
SFILENAME=./Code/.pio/build/attiny1624_serial/megadesk-$GITHUB_REF_NAME-t1624-serial.hex
echo "SFILENAME=$SFILENAME" >> $GITHUB_ENV
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
Expand Down
37 changes: 27 additions & 10 deletions Code/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
description = megadesk_bekant
default_envs = attiny841
Expand Down Expand Up @@ -35,6 +25,15 @@ board_fuses.hfuse = 0xD6
upload_flags =
-B0.5

[env:attiny1624]
platform = atmelmegaavr
board = ATtiny1624
framework = arduino
upload_protocol = atmelice_updi
build_flags = -D AVR2=1
board_build.f_cpu = 16000000L
board_fuses.osccfg = 0x01 # Run at 16MHz instead of default 20MHz. Saves power.

[env:attiny841_pololu_windows]
platform = atmelavr
board = attiny841
Expand Down Expand Up @@ -87,5 +86,23 @@ framework = arduino
board_fuses.lfuse = 0xE2
board_fuses.efuse = 0xFE
board_fuses.hfuse = 0xD6
build_flags=
-DSERIALCOMMS

[env:attiny1624_noserial]
platform = atmelmegaavr
board = ATtiny1624
framework = arduino
build_flags = -D AVR2=1
board_build.f_cpu = 16000000L
board_fuses.osccfg = 0x01 # Run at 16MHz instead of default 20MHz. Saves power.

[env:attiny1624_serial]
platform = atmelmegaavr
board = ATtiny1624
framework = arduino
build_flags = -D AVR2=1
board_build.f_cpu = 16000000L
board_fuses.osccfg = 0x01 # Run at 16MHz instead of default 20MHz. Saves power.
build_flags=
-DSERIALCOMMS
2 changes: 1 addition & 1 deletion Code/src/lin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void Lin::begin(int speed)
void Lin::serialBreak(void)
{
serial.end();

pinMode(txPin, OUTPUT);
digitalWrite(txPin, LOW); // Send BREAK
delayMicroseconds(breakTime);

Expand Down
68 changes: 40 additions & 28 deletions Code/src/megadesk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,28 @@ uint16_t oldHeight = 0; // previously reported height

#define HYSTERESIS 137 // ignore movement requests < this distance
#define MOVE_OFFSET 159 // amount to move when moving manually
#define PIN_UP 10
#define PIN_DOWN 9
#define PIN_BEEP 7
#define PIN_SERIAL 1

#ifdef AVR2
#define PIN_UP PIN_PA5
#define PIN_DOWN PIN_PA6
#define PIN_BEEP PIN_PA7
#define PIN_LIN_SERIAL PIN_PA1

HardwareSerial &userSerial = Serial;
HardwareSerial &linSerial = Serial1;

#else
#define PIN_UP PIN_PB0
#define PIN_DOWN PIN_PB1
#define PIN_BEEP PIN_PA7
#define PIN_LIN_SERIAL PIN_PA1

HardwareSerial &userSerial = Serial1;
HardwareSerial &linSerial = Serial;
#endif
// click durations
#define CLICK_TIMEOUT 400UL // Timeout in MS. for long-hold and release idle.
#define CLICK_LONG 10000UL // very-long holdtime in MS.
#define CLICK_TIMEOUT 400UL // Timeout in MS. for long-hold and release idle.
#define CLICK_LONG 10000UL // very-long holdtime in MS.

// beeps
#define PIP_DURATION 20
Expand Down Expand Up @@ -155,7 +169,7 @@ unsigned long lastPushTime = 0;
unsigned long refTime = 0;
//////////////////

Lin lin(Serial, PIN_SERIAL);
Lin lin(linSerial, PIN_LIN_SERIAL);

uint16_t currentHeight = 0;
uint16_t targetHeight = 0;
Expand Down Expand Up @@ -200,7 +214,9 @@ void startFresh()
// use a constructor to disable the watchdog well before setup() is called
softReset::softReset()
{
MCUSR = 0;
#ifndef AVR2
MCUSR = 0;
#endif
wdt_disable();
}
softReset soft;
Expand Down Expand Up @@ -256,7 +272,7 @@ void setup()
}

#ifdef SERIALCOMMS
Serial1.begin(115200);
userSerial.begin(115200);
#endif

// init + arpeggio
Expand Down Expand Up @@ -405,7 +421,7 @@ int digits=0;
int readdigits()
{
int r;
while ((r = Serial1.read()) > 0) {
while ((r = userSerial.read()) > 0) {
if ((r < 0x30) || (r > 0x39)) {
// non-digit we're done, return what we have
return digits;
Expand All @@ -431,7 +447,7 @@ void recvData()
int r; // read char/digit

// read 2 chars
while ((ndx < numChars) && ((r = Serial1.read()) != -1))
while ((ndx < numChars) && ((r = userSerial.read()) != -1))
{
if ((ndx == 0) && (r != rxMarker))
{
Expand Down Expand Up @@ -466,7 +482,7 @@ void recvData()
static uint8_t ndx = 0;
int r; // read char

while ((r = Serial1.read()) != -1)
while ((r = userSerial.read()) != -1)
{
if ((ndx == 0) && (r != rxMarker))
{
Expand All @@ -489,17 +505,17 @@ void recvData()
void writeSerial(byte operation, uint16_t position, uint8_t push_addr, byte marker)
{
// note. serial.write only ever writes bytes. ints/longs get truncated!
Serial1.write(marker);
Serial1.write(operation);
userSerial.write(marker);
userSerial.write(operation);
#ifdef HUMANSERIAL
Serial1.print(position); // Tx human-readable output option
Serial1.print(',');
Serial1.print(push_addr);
Serial1.print('\n');
userSerial.print(position); // Tx human-readable output option
userSerial.print(',');
userSerial.print(push_addr);
userSerial.print('\n');
#else
Serial1.write(position >> 8); // high byte
Serial1.write(position & 0xff); // low byte
Serial1.write(push_addr);
userSerial.write(position >> 8); // high byte
userSerial.write(position & 0xff); // low byte
userSerial.write(push_addr);
#endif
}

Expand Down Expand Up @@ -1329,15 +1345,11 @@ void initAndReadEEPROM(bool force)

if ((signature != MAGIC_SIG) || force)
{
// use 8bit wraparound as exit-condition
for (uint8_t index = 2; index != 0; index++) {
eepromPut16(index,0);
// 2nd half of eeprom could be a back-up of the 1st half...
// then swap/copy between the two (for different users? backups?)
}
for (uint16_t index = 0; index < EEPROM.length() - 1; index++)
EEPROM.write(index, 0);

// Store signature value
eepromPut16(EEPROM_SIG_SLOT, MAGIC_SIG);

}
#ifdef MINMAX
// retrieve max/min height
Expand Down

0 comments on commit 77d86ab

Please sign in to comment.