Skip to content

Commit b7624a8

Browse files
committed
Add RP2040 SPI_Buttons mode
1 parent 7cbcb08 commit b7624a8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Firmware/FFBoard/UserExtensions/Inc/SPIButtons.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// Set this to 64, 128 or 256 to slow down SPI if unstable.
2020
#define SPIBUTTONS_SPEED SPI_BAUDRATEPRESCALER_32
2121

22-
enum class SPI_BtnMode : uint8_t {TM=0,PISOSR=1};
22+
enum class SPI_BtnMode : uint8_t {TM=0,PISOSR=1,RP2040=2};
2323

2424

2525
struct ButtonSourceConfig{

Firmware/FFBoard/UserExtensions/Src/SPIButtons.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
static ButtonSourceConfig decodeIntToConf(uint16_t config, uint16_t config_int_2);
1616
static std::tuple<uint16_t, uint16_t> encodeConfToInt(ButtonSourceConfig* c);
1717

18-
const std::vector<std::string> SPI_Buttons::mode_names = {"Thrustmaster/HEF4021BT","74xx165"};
18+
const std::vector<std::string> SPI_Buttons::mode_names = {"Thrustmaster/HEF4021BT","74xx165","RP2040"};
1919
const std::vector<std::string> SPI_Buttons::speed_names = {"Fast","Medium","Slow"};
2020

2121
ClassIdentifier SPI_Buttons_1::info = {
@@ -111,6 +111,12 @@ void SPI_Buttons::setConfig(ButtonSourceConfig config){
111111
this->spiConfig.peripheral.FirstBit = SPI_FIRSTBIT_LSB;
112112
this->spiConfig.peripheral.CLKPhase = SPI_PHASE_2EDGE;
113113
this->spiConfig.peripheral.CLKPolarity = SPI_POLARITY_HIGH; // its actually shifting on the rising edge but 165 will have the first output set even before clocking. First clock cycle is actually second bit so we sample at the falling edge and skip the first bit with that.
114+
}else if(conf.mode == SPI_BtnMode::RP2040){
115+
this->conf.cutRight = false;
116+
this->spiConfig.cspol = true;
117+
this->spiConfig.peripheral.FirstBit = SPI_FIRSTBIT_MSB;
118+
this->spiConfig.peripheral.CLKPhase = SPI_PHASE_1EDGE;
119+
this->spiConfig.peripheral.CLKPolarity = SPI_POLARITY_LOW;
114120
}
115121
this->spiConfig.peripheral.BaudRatePrescaler = speedPresets[this->conf.spi_speed];
116122
initSPI();

0 commit comments

Comments
 (0)