Skip to content

Fix G27 shifter buttons and add SPI3 support for wheel rim#182

Open
OrlandoEduardo101 wants to merge 4 commits into
Ultrawipf:developmentfrom
OrlandoEduardo101:feature/g27-support
Open

Fix G27 shifter buttons and add SPI3 support for wheel rim#182
OrlandoEduardo101 wants to merge 4 commits into
Ultrawipf:developmentfrom
OrlandoEduardo101:feature/g27-support

Conversation

@OrlandoEduardo101
Copy link
Copy Markdown

Summary

This PR fixes G27 shifter buttons not working in ShifterAnalog G27 mode and adds SPI3 support for connecting the G27 wheel rim buttons on a separate SPI bus.

Problem

  1. G27 Shifter buttons didn't work in ShifterAnalog G27-H mode - only analog gear detection worked
  2. G27 Wheel rim buttons conflicted with shifter when both connected to SPI2 (74HC165 lacks tri-state output)

Solution

ShifterAnalog Fixes

  • Fixed SPI clock configuration (CLKPhase, CLKPolarity) for 74HC165
  • Added CS polarity configuration
  • Changed to synchronous SPI read for reliable data
  • Fixed CS pin index off-by-one error

SPI3 Support (SPI_Buttons_3)

  • Added new button source class using SPI3 peripheral
  • Allows wheel rim (SPI3) and shifter (SPI2) to work simultaneously
  • Pins: PC10 (SCK), PC11 (MISO), PA15 (CS1)

Testing

Tested on STM32F407VET6 board with:

  • G27 Shifter: All 6 gears + reverse + 12 buttons ✅
  • G27 Wheel Rim: All 8 buttons ✅
  • Both working simultaneously ✅

Documentation

Added doc/logitech g27/ folder with:

  • Complete wiring guide
  • Technical reports explaining the bugs and solutions
  • Bilingual (EN/PT)

Checklist

  • Code compiles without warnings
  • Tested on hardware
  • No breaking changes to existing functionality
  • Documentation included

## ShifterAnalog G27 Mode Fix
- Fix SPI clock configuration for 74HC165 (CLKPhase, CLKPolarity)
- Add CS polarity configuration for active-low operation
- Change to synchronous SPI read for reliable button reading
- Fix CS pin index off-by-one error in setMode() and setCSPin()
- Add startRead() method to trigger SPI before processing data

## SPI Buttons 3 (SPI3 Support)
- Add SPI_Buttons_3 class using SPI3 peripheral for separate button source
- Required because 74HC165 lacks tri-state output (cannot share MISO)
- Allows G27 shifter (SPI2) and wheel rim (SPI3) to work simultaneously
- SPI3 pins: PC10 (SCK), PC11 (MISO), PA15 (CS1)

## Hardware Configuration (F407VG)
- Reduce SPI3 baud rate for reliable 74HC165 communication
- Initialize SPI CS pins HIGH (inactive) to prevent bus contention
- Enable SPIBUTTONS3 feature flag

## Documentation
- Add complete wiring guide for all G27 components
- Add technical reports documenting bugs and solutions
- Bilingual documentation (English/Portuguese)

Tested with Logitech G27 on STM32F407VET6 board.

Made-with: Cursor
Orlando Eduardo Pereira and others added 2 commits May 8, 2026 16:37
Changed Clutch pedal pin from PA6 to PC3 (AIN2) to match
the actual F407VG hardware configuration in main.h:
- AIN0 = PA3 (Brake)
- AIN1 = PA2 (Throttle)
- AIN2 = PC3 (Clutch) ← was incorrectly listed as PA6

Co-authored-by: Cursor <cursoragent@cursor.com>
Documented the G27 shifter X/Y analog axis connections:
- X Axis: PC0 (Analog 6) - configurable via shifter.xchan
- Y Axis: PC1 (Analog 5) - configurable via shifter.ychan

Updated files:
- G27_COMPLETE_WIRING_GUIDE.md: Added pin info to tables, diagram
- G27_SHIFTER_ISSUE_REPORT.md: Added analog pins to hardware setup
- README.md: Updated shifter pin summary

Co-authored-by: Cursor <cursoragent@cursor.com>
@Ultrawipf
Copy link
Copy Markdown
Owner

Ultrawipf commented May 9, 2026

Spi 2 has 3 cs pins and is intended for button inputs and addons while spi3 is for high speed addons. Bissc for example does reserve the whole port with no cs pin. It would make more sense to just use a different cs pin on spi2.

The current shift register modules have a tristate buffer to allow shared ports

@OrlandoEduardo101
Copy link
Copy Markdown
Author

Thanks for the clarification — that makes sense for the official OpenFFBoard design.

I agree SPI2 (with CS1/CS2/CS3) is the right place for button/addon inputs, and SPI3 should stay available for high-speed addons like BISS-C.

In my case I used the stock G27 shifter + wheel rim PCBs, which use bare 74HC165 shift registers without a tri-state buffer on MISO. I first tried the intended setup:

  • Shifter on SPI2 CS1 (PB12)
  • Wheel rim on SPI2 CS2 (PD8)
  • Shared SCK/MISO (PB13/PB14)

Result:

  • Shifter alone on CS1: OK
  • Rim alone on CS2: OK
  • Both connected: both failed (even with only one firmware source active), because MISO was always driven.

That’s why I moved the rim to SPI3 in my fork as a hardware-specific workaround.

For this PR I can revise it to:

  1. Keep only the ShifterAnalog G27-mode fixes (SPI timing/sync read/CS index), and
  2. Remove SPI3 / SPI_Buttons_3 changes from upstream scope.

I’ll update the docs to state clearly:

  • Preferred upstream approach: SPI2 different CS pins (works with official SR modules that have tri-state)
  • Stock G27 limitation: bare 74HC165 without tri-state may require separate bus or external buffer

Happy to adjust the PR accordingly. Thanks again.

Per maintainer feedback on PR Ultrawipf#182: SPI2 is the preferred bus for
buttons/addons; SPI3 is reserved for high-speed encoders (BISS-C, SSI).

Removed from this PR:
- SPI_Buttons_3 class and SPIBUTTONS3 define
- EEPROM addresses ADR_SPI_BTN_3_CONF / _CONF_2
- Slow SPI3 prescaler (reverted to upstream PRESCALER_4)
- Restore TIM_TMC_ARR and TIM_FFB accidentally removed in initial commit
- G27-specific SPI3 comments in cpp_target_config.cpp

Kept:
- ShifterAnalog G27 H-pattern fix (cs_pin indexing, DMA read, SPI config)
- SPI2 CS pins initialized HIGH (PB12, PD8, PD9) for correct operation
- SPIBUTTONS2 define

SPI3 wheel rim workaround preserved in tag g27-full-working for personal use.
Upstream preferred solution: SPI2 CS2 with tri-state buffer on MISO.
@OrlandoEduardo101
Copy link
Copy Markdown
Author

Thanks for the review — you're right about SPI bus boundaries. I've updated this PR accordingly.

What I changed:

Agreed on the architecture: SPI2 is for buttons/addons; SPI3 is reserved for high-speed peripherals (BISS-C, SSI, MT encoder). I've removed all SPI3 wheel rim code from this PR.

Why CS1 + CS2 on SPI2 failed on my hardware:

I did test wheel rim on SPI2 CS2 (PD8) alongside the shifter on CS1 (PB12). It failed — not a firmware issue, but a hardware limitation of the stock G27: the 74HC165 shift register has no tri-state output. Both chips continuously drive the MISO line regardless of CS state, causing bus contention the moment both are connected physically. The upstream approach (SPI2 CS2) is correct in general but requires adding a 74HC125 tri-state buffer on MISO for stock G27 hardware. I've documented this in the docs.

What's in this PR now:

  • ShifterAnalog: fix for G27 H-pattern CS pin indexing and SPI config (74HC165 mode)
  • main.c: SPI2 CS pins (PB12, PD8, PD9) initialized HIGH on startup — prevents false triggers on 74HC165 devices
  • Docs updated: SPI2 CS2 = preferred upstream path; SPI3 workaround documented as fork-only (g27-full-working tag)

What was removed:

  • SPI_Buttons_3 class and SPIBUTTONS3 define
  • EEPROM addresses for SPI3 buttons
  • Slow SPI3 prescaler (reverted to upstream default)
  • Also restored TIM_TMC_ARR and TIM_FFB that were accidentally dropped in the original commit

The SPI3 wheel rim workaround is preserved in tag g27-full-working in my fork for personal use on stock hardware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants