Skip to content

Commit 45d8a1e

Browse files
jmriegojmriego
and
jmriego
authored
add experimental due support (#14)
* add experimental due support * update README * due: keep on testing things * due: add some more debugging * due: more tests * due: seems to be working * due: remove SerialUSB hardcode * go back to normal code * due: remove unused code * due: add workflow compile test * due: fix compile * due: correct upload artifacts Co-authored-by: jmriego <[email protected]>
1 parent e2b1367 commit 45d8a1e

File tree

8 files changed

+61
-25
lines changed

8 files changed

+61
-25
lines changed

Diff for: .github/workflows/arduino.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,31 @@ jobs:
1717
- name: Setup Arduino CLI
1818
uses: arduino/[email protected]
1919

20-
- name: Install Arduino Micro platform
20+
- name: Install Arduino platform
2121
run: |
2222
arduino-cli core update-index
2323
arduino-cli core install arduino:avr
24+
arduino-cli core install arduino:sam
2425
25-
- name: Compile Fino Arduino Sketch
26+
- name: Compile Fino Arduino Sketch for Micro
2627
run: |
2728
mkdir -p build/arduino.avr.micro
2829
arduino-cli compile --fqbn arduino:avr:micro --verbose --output-dir build/arduino.avr.micro
2930
30-
- name: Upload Arduino sketch artifact
31+
- name: Upload Arduino Micro sketch artifact
3132
uses: actions/upload-artifact@v2
3233
with:
3334
name: Artifact.Fino
3435
path: build/arduino.avr.micro/Fino.ino.hex
3536

3637

38+
- name: Compile Fino Arduino Sketch for Due
39+
run: |
40+
mkdir -p build/arduino.avr.micro
41+
arduino-cli compile --fqbn arduino:sam:arduino_due_x --verbose --output-dir build/arduino.sam.arduino_due_x
42+
43+
- name: Upload Arduino Due sketch artifact
44+
uses: actions/upload-artifact@v2
45+
with:
46+
name: Artifact.Fino
47+
path: build/arduino.sam.arduino_due_x/Fino.ino.elf

Diff for: Fino.ino

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#define DEBUGNO
2+
#define COMINO
3+
#ifdef _VARIANT_ARDUINO_DUE_X_
4+
#define Serial SerialUSB
5+
#endif
6+
27
// the digits mean Mmmmrrr (M=Major,m=minor,r=revision)
38
#define SKETCH_VERSION 3000001
49

@@ -48,15 +53,21 @@ void setup() {
4853
setupJoystick();
4954

5055
// setup communication
56+
#ifdef COMINO
5157
Serial.begin(SERIAL_BAUD);
58+
#endif
59+
// SerialUSB.begin(115200);
60+
5261
// setup timing and run them as soon as possible
5362
lastEffectsUpdate = 0;
5463
nextJoystickMillis = 0;
5564
nextEffectsMillis = 0;
5665
}
5766

5867
void loop(){
68+
#ifdef COMINO
5969
get_messages_from_serial();
70+
#endif
6071

6172
unsigned long currentMillis;
6273
currentMillis = millis();
@@ -77,9 +88,11 @@ void loop(){
7788
updateEffects(false);
7889
}
7990

91+
#ifdef COMINO
8092
if (forces_requested) {
8193
sendForces();
8294
forces_requested = false;
8395
}
96+
#endif
8497
}
8598
}

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Fino will make a Force Feedback Joystick out of your Arduino
44
### It requires an ATMega32UX chip device such as an Arduino Micro
5+
### or an Arduino Due would also work if you require more memory
56

67
## Usage
78

@@ -11,7 +12,7 @@ There are two different ways you can use this sketch:
1112

1213
## In testing
1314

14-
There is currently experimental support for driving wheels on the [wheel](https://github.com/jmriego/Fino/tree/wheel) branch and for using an Arduino DUE on the [due](https://github.com/jmriego/Fino/tree/due) branch. I don't own any of these two devices so if you want to donate them or if testing them yourself please let me know how it's working for you.
15+
There is currently experimental support for driving wheels on the [wheel](https://github.com/jmriego/Fino/tree/wheel) branch.com/jmriego/Fino/tree/due) branch. I don't own any wheel or similar I could use for testing so if you want to donate them or if you are testing them yourself please let me know how it's working for you.
1516

1617
## Ref
1718

Diff for: com.ino

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef COMINO
12
void sendForces() {
23
write_order(FORCES);
34
write_i32(forces[0]);
@@ -145,3 +146,5 @@ void write_i32(int32_t num)
145146
int8_t buffer[4] = {(int8_t) (num & 0xff), (int8_t) (num >> 8 & 0xff), (int8_t) (num >> 16 & 0xff), (int8_t) (num >> 24 & 0xff)};
146147
Serial.write((uint8_t*)&buffer, 4*sizeof(int8_t));
147148
}
149+
150+
#endif

Diff for: reference/SimpleHIDWrite.exe

485 KB
Binary file not shown.

Diff for: src/DynamicHID/DynamicHID.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#ifdef _VARIANT_ARDUINO_DUE_X_
2727
#define USB_SendControl USBD_SendControl
2828
#define USB_Send USBD_Send
29+
#define USB_Recv USBD_Recv
30+
#define USB_RecvControl USBD_RecvControl
31+
#define USB_Available USBD_Available
2932
#endif
3033

3134
DynamicHID_& DynamicHID()
@@ -110,13 +113,13 @@ int DynamicHID_::SendReport(uint8_t id, const void* data, int len)
110113
int DynamicHID_::RecvData(byte* data)
111114
{
112115
int count = 0;
113-
while (usb_Available()) {
114-
data[count++] = (byte)USB_Recv(PID_ENDPOINT_OUT);
116+
while (usb_Available() > 0) {
117+
data[count++] = USB_Recv(PID_ENDPOINT_OUT);
115118
}
116119
return count;
117120
}
118121

119-
void DynamicHID_::RecvfromUsb()
122+
void DynamicHID_::RecvfromUsb()
120123
{
121124
if (usb_Available() > 0) {
122125
uint8_t out_ffbdata[64];
@@ -143,7 +146,7 @@ bool DynamicHID_::GetReport(USBSetup& setup) {
143146
if (report_type == DYNAMIC_HID_REPORT_TYPE_FEATURE) {
144147
if ((report_id == 6))// && (gNewEffectBlockLoad.reportId==6))
145148
{
146-
_delay_us(500);
149+
delayMicroseconds(500);
147150
USB_SendControl(TRANSFER_RELEASE, pidReportHandler.getPIDBlockLoad(), sizeof(USB_FFBReport_PIDBlockLoad_Feature_Data_t));
148151
pidReportHandler.pidBlockLoad.reportId = 0;
149152
return (true);
@@ -191,6 +194,7 @@ bool DynamicHID_::SetReport(USBSetup& setup) {
191194
return true;
192195
}*/
193196
}
197+
return (false);
194198
}
195199

196200
bool DynamicHID_::setup(USBSetup& setup)

Diff for: src/DynamicHID/DynamicHID.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ class DynamicHID_ : public PluggableUSBModule
135135
uint8_t getShortName(char* name);
136136

137137
private:
138-
uint8_t epType[2];
138+
#ifdef _VARIANT_ARDUINO_DUE_X_
139+
uint32_t epType[2];
140+
#else
141+
uint8_t epType[2];
142+
#endif
139143

140144
DynamicHIDSubDescriptor* rootNode;
141145
uint16_t descriptorSize;

Diff for: src/DynamicHID/PIDReportType.h

+16-16
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ typedef struct//PID state
4747

4848
///Host-->Device
4949

50-
typedef struct //FFB: Set Effect Output Report
50+
typedef struct __attribute__((packed)) //FFB: Set Effect Output Report
5151
{
5252
uint8_t reportId; // =1
5353
uint8_t effectBlockIndex; // 1..40
@@ -62,7 +62,7 @@ typedef struct //FFB: Set Effect Output Report
6262
uint8_t direction[FFB_AXIS_COUNT]; // angle (0=0 .. 255=360deg)
6363
} USB_FFBReport_SetEffect_Output_Data_t;
6464

65-
typedef struct//FFB: Set Envelope Output Report
65+
typedef struct __attribute__((packed)) //FFB: Set Envelope Output Report
6666
{
6767
uint8_t reportId; // =2
6868
uint8_t effectBlockIndex; // 1..40
@@ -72,7 +72,7 @@ typedef struct//FFB: Set Envelope Output Report
7272
uint16_t fadeTime; // ms
7373
} USB_FFBReport_SetEnvelope_Output_Data_t;
7474

75-
typedef struct// FFB: Set Condition Output Report
75+
typedef struct __attribute__((packed)) // FFB: Set Condition Output Report
7676
{
7777
uint8_t reportId; // =3
7878
uint8_t effectBlockIndex; // 1..40
@@ -85,7 +85,7 @@ typedef struct// FFB: Set Condition Output Report
8585
uint16_t deadBand; // 0..255
8686
} USB_FFBReport_SetCondition_Output_Data_t;
8787

88-
typedef struct//FFB: Set Periodic Output Report
88+
typedef struct __attribute__((packed)) //FFB: Set Periodic Output Report
8989
{
9090
uint8_t reportId; // =4
9191
uint8_t effectBlockIndex; // 1..40
@@ -95,63 +95,63 @@ typedef struct//FFB: Set Periodic Output Report
9595
uint16_t period; // 0..32767 ms
9696
} USB_FFBReport_SetPeriodic_Output_Data_t;
9797

98-
typedef struct//FFB: Set ConstantForce Output Report
98+
typedef struct __attribute__((packed)) //FFB: Set ConstantForce Output Report
9999
{
100100
uint8_t reportId; // =5
101101
uint8_t effectBlockIndex; // 1..40
102102
int16_t magnitude; // -255..255
103103
} USB_FFBReport_SetConstantForce_Output_Data_t;
104104

105-
typedef struct//FFB: Set RampForce Output Report
105+
typedef struct __attribute__((packed)) //FFB: Set RampForce Output Report
106106
{
107107
uint8_t reportId; // =6
108108
uint8_t effectBlockIndex; // 1..40
109109
int16_t startMagnitude;
110110
int16_t endMagnitude;
111111
} USB_FFBReport_SetRampForce_Output_Data_t;
112112

113-
typedef struct//FFB: Set CustomForceData Output Report
113+
typedef struct __attribute__((packed)) //FFB: Set CustomForceData Output Report
114114
{
115115
uint8_t reportId; // =7
116116
uint8_t effectBlockIndex; // 1..40
117117
uint16_t dataOffset;
118118
int8_t data[12];
119119
} USB_FFBReport_SetCustomForceData_Output_Data_t;
120120

121-
typedef struct//FFB: Set DownloadForceSample Output Report
121+
typedef struct __attribute__((packed)) //FFB: Set DownloadForceSample Output Report
122122
{
123123
uint8_t reportId; // =8
124124
int8_t x;
125125
int8_t y;
126126
} USB_FFBReport_SetDownloadForceSample_Output_Data_t;
127127

128-
typedef struct//FFB: Set EffectOperation Output Report
128+
typedef struct __attribute__((packed)) //FFB: Set EffectOperation Output Report
129129
{
130130
uint8_t reportId; // =10
131131
uint8_t effectBlockIndex; // 1..40
132132
uint8_t operation; // 1=Start, 2=StartSolo, 3=Stop
133133
uint8_t loopCount;
134134
} USB_FFBReport_EffectOperation_Output_Data_t;
135135

136-
typedef struct//FFB: Block Free Output Report
136+
typedef struct __attribute__((packed)) //FFB: Block Free Output Report
137137
{
138138
uint8_t reportId; // =11
139139
uint8_t effectBlockIndex; // 1..40
140140
} USB_FFBReport_BlockFree_Output_Data_t;
141141

142-
typedef struct//FFB: Device Control Output Report
142+
typedef struct __attribute__((packed)) //FFB: Device Control Output Report
143143
{
144144
uint8_t reportId; // =12
145145
uint8_t control; // 1=Enable Actuators, 2=Disable Actuators, 4=Stop All Effects, 8=Reset, 16=Pause, 32=Continue
146146
} USB_FFBReport_DeviceControl_Output_Data_t;
147147

148-
typedef struct//FFB: DeviceGain Output Report
148+
typedef struct __attribute__((packed)) //FFB: DeviceGain Output Report
149149
{
150150
uint8_t reportId; // =13
151151
uint8_t gain;
152152
} USB_FFBReport_DeviceGain_Output_Data_t;
153153

154-
typedef struct// FFB: Set Custom Force Output Report
154+
typedef struct __attribute__((packed)) // FFB: Set Custom Force Output Report
155155
{
156156
uint8_t reportId; // =14
157157
uint8_t effectBlockIndex; // 1..40
@@ -160,22 +160,22 @@ typedef struct// FFB: Set Custom Force Output Report
160160
} USB_FFBReport_SetCustomForce_Output_Data_t;
161161

162162
///Feature
163-
typedef struct //FFB: Create New Effect Feature Report
163+
typedef struct __attribute__((packed)) //FFB: Create New Effect Feature Report
164164
{
165165
uint8_t reportId; //5
166166
uint8_t effectType; // Enum (1..12): ET 26,27,30,31,32,33,34,40,41,42,43,28
167167
uint16_t byteCount; // 0..511
168168
} USB_FFBReport_CreateNewEffect_Feature_Data_t;
169169

170-
typedef struct// FFB: PID Block Load Feature Report
170+
typedef struct __attribute__((packed)) // FFB: PID Block Load Feature Report
171171
{
172172
uint8_t reportId; // =6
173173
uint8_t effectBlockIndex; // 1..40
174174
uint8_t loadStatus; // 1=Success,2=Full,3=Error
175175
uint16_t ramPoolAvailable; // =0 or 0xFFFF?
176176
} USB_FFBReport_PIDBlockLoad_Feature_Data_t;
177177

178-
typedef struct// FFB: PID Pool Feature Report
178+
typedef struct __attribute__((packed)) // FFB: PID Pool Feature Report
179179
{
180180
uint8_t reportId; // =7
181181
uint16_t ramPoolSize; // ?

0 commit comments

Comments
 (0)