Skip to content

Commit 381ac9e

Browse files
authored
Merge pull request #4 from FrameworkComputer/gh-actions
Add diff files and build on GH Actions
2 parents cf5388b + 1650cf3 commit 381ac9e

File tree

12 files changed

+414
-180
lines changed

12 files changed

+414
-180
lines changed

.github/workflows/build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI
2+
on:
3+
push:
4+
paths:
5+
- '.github/workflows/build.yml'
6+
- 'diff/**'
7+
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Install PlatformIO
16+
run: |
17+
curl -fsSL -o get-platformio.py https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
18+
python3 get-platformio.py
19+
rm get-platformio.py
20+
21+
echo $PATH
22+
mkdir -p ~/.local/bin
23+
ln -s ~/.platformio/penv/bin/platformio ~/.local/bin/platformio
24+
ln -s ~/.platformio/penv/bin/pio ~/.local/bin/pio
25+
ln -s ~/.platformio/penv/bin/piodebuggdb ~/.local/bin/piodebuggdb
26+
27+
- name: Pre-build to fetch sources
28+
run: |
29+
# Build but ignore failure, will install pre-requisites
30+
pio run -e teensy36 || true
31+
pio run -e teensy41 || true
32+
33+
- name: Patch Teensy/Arduino Source
34+
run: |
35+
# Arduino
36+
patch -d ~/.platformio/ -p0 < diff/arduino.py.diff
37+
38+
# Teensy3.6
39+
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.c.diff
40+
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.h.diff
41+
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_inst.cpp.diff
42+
patch -d ~/.platformio/ -p0 < diff/teensy3/yield.cpp.diff
43+
44+
# Teensy4.1
45+
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.c.diff
46+
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.h.diff
47+
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_inst.cpp.diff
48+
patch -d ~/.platformio/ -p0 < diff/teensy4/yield.cpp.diff
49+
50+
- name: Build for Teensy 3.1
51+
run: |
52+
pio run -e teensy31
53+
54+
- name: Build for Teensy 3.6
55+
run: |
56+
pio run -e teensy36
57+
58+
- name: Build for Teensy 4.1
59+
run: |
60+
pio run -e teensy41
61+
62+
- name: Prepare firmware folder
63+
run: |
64+
mkdir build
65+
cp .pio/build/teensy31/firmware.hex build/teensy31_firmware.hex
66+
cp .pio/build/teensy36/firmware.hex build/teensy36_firmware.hex
67+
cp .pio/build/teensy41/firmware.hex build/teensy41_firmware.hex
68+
69+
- name: Upload Teensy Firmware
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: teensy_firmware
73+
path: build

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.vscode/c_cpp_properties.json
44
.vscode/launch.json
55
.vscode/ipch
6+
# PlatformIO installer
7+
get-platformio.py

README.md

Lines changed: 74 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -8,204 +8,98 @@ Supports:
88

99
Right now the backend uses raw hid reports for debug communication, terminal.py will open an interactive terminal to the device.
1010

11-
### How to flash to the teensy board:
11+
### Building
12+
13+
Pre-requisites:
14+
15+
- [Install PlatformIO](https://docs.platformio.org/en/latest/core/installation/index.html)
16+
17+
###### Pre-build
18+
19+
Build all of the platforms you need. It will fetch source and dependencies but
20+
will fail! After this first attempt at building, the patches listed below need
21+
to be applied.
22+
1223
```sh
13-
pio run -e teensy41 --target upload
14-
pio run -e teensy31 --target upload
15-
pio run -e teensy36 --target upload
24+
pio run -e teensy41
25+
pio run -e teensy31
26+
pio run -e teensy36
1627
```
1728

18-
### Modifications required to teensy 3.1 codebase:
19-
20-
For this to work you need to modify the teensy source code to set the RAWHID iInterface field to 2 to use the product string around line 1136 in `~/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_desc.c`
21-
22-
```c
23-
#ifdef RAWHID_INTERFACE
24-
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
25-
9, // bLength
26-
4, // bDescriptorType
27-
RAWHID_INTERFACE, // bInterfaceNumber
28-
0, // bAlternateSetting
29-
2, // bNumEndpoints
30-
0x03, // bInterfaceClass (0x03 = HID)
31-
0x00, // bInterfaceSubClass
32-
0x00, // bInterfaceProtocol
33-
2, // iInterface <-------------------Modify this!
29+
###### Patching Arduino Source
30+
31+
Required for all teensy versions.
32+
33+
```sh
34+
patch -d ~/.platformio/ -p0 < diff/arduino.py.diff
3435
```
3536

36-
`usb_desc.h`
37-
```c
38-
// Add the following to the usb definitions section after USB_EVERYTHING
39-
#elif defined(USB_RAWHID_TRIPLESERIAL)
40-
#define VENDOR_ID 0x16C0
41-
#define PRODUCT_ID 0x048C
42-
#define RAWHID_USAGE_PAGE 0xFFAB // recommended: 0xFF00 to 0xFFFF
43-
#define RAWHID_USAGE 0x0200 // recommended: 0x0100 to 0xFFFF
44-
#define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'}
45-
#define MANUFACTURER_NAME_LEN 11
46-
#define PRODUCT_NAME {'C','M','S','I','S','-','D','A','P'}
47-
#define PRODUCT_NAME_LEN 9
48-
#define EP0_SIZE 64
49-
#define NUM_ENDPOINTS 12
50-
#define NUM_USB_BUFFERS 32
51-
#define NUM_INTERFACE 7
52-
53-
#define CDC_IAD_DESCRIPTOR 1 // Serial
54-
#define CDC_STATUS_INTERFACE 0
55-
#define CDC_DATA_INTERFACE 1
56-
#define CDC_ACM_ENDPOINT 2
57-
#define CDC_RX_ENDPOINT 3
58-
#define CDC_TX_ENDPOINT 4
59-
#define CDC_ACM_SIZE 16
60-
#define CDC_RX_SIZE 64
61-
#define CDC_TX_SIZE 64
62-
63-
#define CDC2_STATUS_INTERFACE 2 // SerialUSB1
64-
#define CDC2_DATA_INTERFACE 3
65-
#define CDC2_ACM_ENDPOINT 5
66-
#define CDC2_RX_ENDPOINT 6
67-
#define CDC2_TX_ENDPOINT 7
68-
#define CDC2_ACM_SIZE 16
69-
#define CDC2_RX_SIZE 64
70-
#define CDC2_TX_SIZE 64
71-
72-
#define CDC3_STATUS_INTERFACE 4 // SerialUSB2
73-
#define CDC3_DATA_INTERFACE 5
74-
#define CDC3_ACM_ENDPOINT 8
75-
#define CDC3_RX_ENDPOINT 9
76-
#define CDC3_TX_ENDPOINT 10
77-
#define CDC3_ACM_SIZE 16
78-
#define CDC3_RX_SIZE 64
79-
#define CDC3_TX_SIZE 64
80-
81-
#define RAWHID_INTERFACE 6 // RawHID
82-
#define RAWHID_TX_ENDPOINT 11
83-
#define RAWHID_TX_SIZE 64
84-
#define RAWHID_TX_INTERVAL 1
85-
#define RAWHID_RX_ENDPOINT 12
86-
#define RAWHID_RX_SIZE 64
87-
#define RAWHID_RX_INTERVAL 1
88-
89-
#define ENDPOINT2_CONFIG ENDPOINT_TRANSMIT_ONLY
90-
#define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_ONLY
91-
#define ENDPOINT4_CONFIG ENDPOINT_TRANSMIT_ONLY
92-
93-
#define ENDPOINT5_CONFIG ENDPOINT_TRANSMIT_ONLY
94-
#define ENDPOINT6_CONFIG ENDPOINT_RECEIVE_ONLY
95-
#define ENDPOINT7_CONFIG ENDPOINT_TRANSMIT_ONLY
96-
97-
#define ENDPOINT8_CONFIG ENDPOINT_TRANSMIT_ONLY
98-
#define ENDPOINT9_CONFIG ENDPOINT_RECEIVE_ONLY
99-
#define ENDPOINT10_CONFIG ENDPOINT_TRANSMIT_ONLY
100-
101-
#define ENDPOINT11_CONFIG ENDPOINT_TRANSMIT_ONLY
102-
#define ENDPOINT12_CONFIG ENDPOINT_RECEIVE_ONLY
37+
###### Patching Teensy3 Source
38+
39+
```sh
40+
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.c.diff
41+
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.h.diff
42+
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_inst.cpp.diff
43+
patch -d ~/.platformio/ -p0 < diff/teensy3/yield.cpp.diff
10344
```
10445

46+
###### Patching Teensy4 Source
10547

106-
`yeld.cpp`
107-
```c
108-
// Need to add USB_RAWHID_TRIPLESERIAL wherever USB_TRIPLE_SERIAL is.
109-
defined(USB_TRIPLE_SERIAL) || defined(USB_RAWHID_TRIPLESERIAL)
48+
```sh
49+
patch -d ~/.platformio/ -p0 < diff/arduino.py.diff
50+
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.c.diff
51+
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.h.diff
52+
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_inst.cpp.diff
53+
patch -d ~/.platformio/ -p0 < diff/teensy4/yield.cpp.diff
11054
```
11155

112-
`usb_inst.cpp`
113-
```c
114-
// Add defined(USB_RAWHID_TRIPLESERIAL) to
115-
defined(USB_SERIAL) || defined(USB_DUAL_SERIAL) ||....
56+
###### Build again
57+
58+
Now all the builds should succeed.
59+
60+
```sh
61+
pio run -e teensy41
62+
pio run -e teensy31
63+
pio run -e teensy36
11664
```
11765

118-
`./platforms/teensy/builder/frameworks/arduino.py`
119-
```c
120-
// Add USB_RAWHID_TRIPLESERIAL
121-
// to the section
122-
BUILTIN_USB_FLAGS = (
66+
### Flashing to Teensy
67+
68+
Flash to whatever teensy hardware you have attached.
69+
70+
```sh
71+
pio run -e teensy41 --target upload
72+
pio run -e teensy31 --target upload
73+
pio run -e teensy36 --target upload
12374
```
12475

76+
### EC Serial
12577

126-
### Modifications required for teensy 4.1
127-
For this to work you need to modify the teensy source code to set the RAWHID iInterface field to 2 to use the product string
128-
--------------------------------------
129-
Around line 1191 in `~/.platformio/packages/framework-arduinoteensy/cores/teensy4/usb_desc.c`
130-
```c
131-
#ifdef RAWHID_INTERFACE
132-
// configuration for 480 Mbit/sec speed
133-
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
134-
9, // bLength
135-
4, // bDescriptorType
136-
RAWHID_INTERFACE, // bInterfaceNumber
137-
0, // bAlternateSetting
138-
2, // bNumEndpoints
139-
0x03, // bInterfaceClass (0x03 = HID)
140-
0x00, // bInterfaceSubClass
141-
0x00, // bInterfaceProtocol
142-
2, // iInterface
78+
```sh
79+
# For example with tio
80+
tio /dev/serial/by-id/usb-Framework_CMSIS-DAP_13993040-if04
81+
82+
# Or picocom/minicom/screen
83+
picocom /dev/ttyACM2 -b 115200
14384
```
14485

86+
### Flashing EC firmware
87+
88+
Run the script for your target platform
14589

146-
`usb_desc.h`
147-
```c
148-
#elif defined(USB_RAWHID_TRIPLESERIAL)
149-
#define VENDOR_ID 0x16C0
150-
#define PRODUCT_ID 0x048C
151-
#define RAWHID_USAGE_PAGE 0xFFAB // recommended: 0xFF00 to 0xFFFF
152-
#define RAWHID_USAGE 0x0200 // recommended: 0x0100 to 0xFFFF
153-
#define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'}
154-
#define MANUFACTURER_NAME_LEN 11
155-
#define PRODUCT_NAME {'T','r','i','p','l','e',' ','S','e','r','i','a','l'}
156-
#define PRODUCT_NAME_LEN 13
157-
#define EP0_SIZE 64
158-
#define NUM_ENDPOINTS 9
159-
#define NUM_INTERFACE 7
160-
161-
#define CDC_IAD_DESCRIPTOR 1 // Serial
162-
#define CDC_STATUS_INTERFACE 0
163-
#define CDC_DATA_INTERFACE 1
164-
#define CDC_ACM_ENDPOINT 2
165-
#define CDC_RX_ENDPOINT 3
166-
#define CDC_TX_ENDPOINT 3
167-
#define CDC_ACM_SIZE 16
168-
#define CDC_RX_SIZE_480 512
169-
#define CDC_TX_SIZE_480 512
170-
#define CDC_RX_SIZE_12 64
171-
#define CDC_TX_SIZE_12 64
172-
#define SEREMU_TX_SIZE 64
173-
174-
#define CDC2_STATUS_INTERFACE 2 // SerialUSB1
175-
#define CDC2_DATA_INTERFACE 3
176-
#define CDC2_ACM_ENDPOINT 4
177-
#define CDC2_RX_ENDPOINT 5
178-
#define CDC2_TX_ENDPOINT 5
179-
180-
#define CDC3_STATUS_INTERFACE 4 // SerialUSB2
181-
#define CDC3_DATA_INTERFACE 5
182-
#define CDC3_ACM_ENDPOINT 6
183-
#define CDC3_RX_ENDPOINT 7
184-
#define CDC3_TX_ENDPOINT 7
185-
186-
#define RAWHID_INTERFACE 6 // RawHID
187-
#define RAWHID_TX_ENDPOINT 8
188-
#define RAWHID_TX_SIZE 64
189-
#define RAWHID_TX_INTERVAL 1 // TODO: is this ok for 480 Mbit speed
190-
#define RAWHID_RX_ENDPOINT 9
191-
#define RAWHID_RX_SIZE 64
192-
#define RAWHID_RX_INTERVAL 1 // TODO: is this ok for 480 Mbit speed
193-
194-
#define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
195-
#define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
196-
#define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
197-
#define ENDPOINT5_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
198-
#define ENDPOINT6_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
199-
#define ENDPOINT7_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
200-
/* for raw hid */
201-
#define ENDPOINT8_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
202-
#define ENDPOINT9_CONFIG ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_UNUSED
90+
```sh
91+
./scripts/flash_tgl_ec.sh
92+
./scripts/flash_adl_ec.sh
20393
```
20494

95+
### Teensy Control Serial
96+
97+
Only for advanced usage, you can probably ignore this.
20598

206-
`./platforms/teensy/builder/frameworks/arduino.py`
207-
```c
208-
// Add USB_RAWHID_TRIPLESERIAL
209-
// to the section
210-
BUILTIN_USB_FLAGS = (
211-
```
99+
```sh
100+
# For example with tio
101+
tio /dev/serial/by-id/usb-Framework_CMSIS-DAP_13993040-if00
102+
103+
# Or picocom/minicom/screen
104+
picocom /dev/ttyACM0 -b 115200
105+
```

diff/arduino.py.diff

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- platforms/teensy/builder/frameworks/arduino.py 2023-12-11 17:06:57.115267304 +0800
2+
+++ platforms/teensy/builder/frameworks/arduino.py 2023-12-11 17:07:13.059123524 +0800
3+
@@ -41,6 +41,7 @@
4+
"USB_SERIAL",
5+
"USB_DUAL_SERIAL",
6+
"USB_TRIPLE_SERIAL",
7+
+ "USB_RAWHID_TRIPLESERIAL",
8+
"USB_KEYBOARDONLY",
9+
"USB_TOUCHSCREEN",
10+
"USB_HID_TOUCHSCREEN",

diff/teensy3/usb_desc.c.diff

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- packages/framework-arduinoteensy/cores/teensy3/usb_desc.c 2023-12-11 17:01:29.574251846 +0800
2+
+++ packages/framework-arduinoteensy/cores/teensy3/usb_desc.c 2023-12-11 17:01:36.194190540 +0800
3+
@@ -1133,7 +1133,7 @@
4+
0x03, // bInterfaceClass (0x03 = HID)
5+
0x00, // bInterfaceSubClass
6+
0x00, // bInterfaceProtocol
7+
- 0, // iInterface
8+
+ 2, // iInterface <-------------------Change this from 0 to 2!
9+
// HID interface descriptor, HID 1.11 spec, section 6.2.1
10+
9, // bLength
11+
0x21, // bDescriptorType

0 commit comments

Comments
 (0)