diff --git a/Firmware/FFBoard/UserExtensions/Inc/SPIButtons.h b/Firmware/FFBoard/UserExtensions/Inc/SPIButtons.h index 9f8f061d..9e9fdf57 100644 --- a/Firmware/FFBoard/UserExtensions/Inc/SPIButtons.h +++ b/Firmware/FFBoard/UserExtensions/Inc/SPIButtons.h @@ -19,7 +19,7 @@ // Set this to 64, 128 or 256 to slow down SPI if unstable. #define SPIBUTTONS_SPEED SPI_BAUDRATEPRESCALER_32 -enum class SPI_BtnMode : uint8_t {TM=0,PISOSR=1}; +enum class SPI_BtnMode : uint8_t {TM=0,PISOSR=1,RP2040=2}; struct ButtonSourceConfig{ diff --git a/Firmware/FFBoard/UserExtensions/Src/SPIButtons.cpp b/Firmware/FFBoard/UserExtensions/Src/SPIButtons.cpp index a82e0d71..7aa092ef 100644 --- a/Firmware/FFBoard/UserExtensions/Src/SPIButtons.cpp +++ b/Firmware/FFBoard/UserExtensions/Src/SPIButtons.cpp @@ -15,7 +15,7 @@ static ButtonSourceConfig decodeIntToConf(uint16_t config, uint16_t config_int_2); static std::tuple encodeConfToInt(ButtonSourceConfig* c); -const std::vector SPI_Buttons::mode_names = {"Thrustmaster/HEF4021BT","74xx165"}; +const std::vector SPI_Buttons::mode_names = {"Thrustmaster/HEF4021BT","74xx165","RP2040"}; const std::vector SPI_Buttons::speed_names = {"Fast","Medium","Slow"}; ClassIdentifier SPI_Buttons_1::info = { @@ -111,6 +111,12 @@ void SPI_Buttons::setConfig(ButtonSourceConfig config){ this->spiConfig.peripheral.FirstBit = SPI_FIRSTBIT_LSB; this->spiConfig.peripheral.CLKPhase = SPI_PHASE_2EDGE; 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. + }else if(conf.mode == SPI_BtnMode::RP2040){ + this->conf.cutRight = false; + this->spiConfig.cspol = true; + this->spiConfig.peripheral.FirstBit = SPI_FIRSTBIT_MSB; + this->spiConfig.peripheral.CLKPhase = SPI_PHASE_1EDGE; + this->spiConfig.peripheral.CLKPolarity = SPI_POLARITY_LOW; } this->spiConfig.peripheral.BaudRatePrescaler = speedPresets[this->conf.spi_speed]; initSPI();