Skip to content

fix(spi): ensure spi_t structure properly init #2549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@
SPIClass SPI;

/**
* @brief Default constructor. Uses pin configuration of variant.h.
*/
SPIClass::SPIClass()
{
_spi.pin_miso = digitalPinToPinName(MISO);
_spi.pin_mosi = digitalPinToPinName(MOSI);
_spi.pin_sclk = digitalPinToPinName(SCK);
_spi.pin_ssel = NC;
}

/**
* @brief Constructor to create another SPI instance attached to another SPI
* peripheral different of the default SPI. All pins must be attached to
* the same SPI peripheral. See datasheet of the microcontroller.
* @brief Default Constructor. Uses pin configuration of default SPI
* defined in the variant*.h.
* To create another SPI instance attached to another SPI
* peripheral gave the pins as parameters to the constructor.
* @note All pins must be attached to the same SPI peripheral.
* See datasheet of the microcontroller.
* @param mosi: SPI mosi pin. Accepted format: number or Arduino format (Dx)
* or ST format (Pxy).
* or ST format (Pxy). Default is MOSI pin of the default SPI peripheral.
* @param miso: SPI miso pin. Accepted format: number or Arduino format (Dx)
* or ST format (Pxy).
* or ST format (Pxy). Default is MISO pin of the default SPI peripheral.
* @param sclk: SPI clock pin. Accepted format: number or Arduino format (Dx)
* or ST format (Pxy).
* or ST format (Pxy). Default is SCK pin of the default SPI peripheral.
* @param ssel: SPI ssel pin (optional). Accepted format: number or
* Arduino format (Dx) or ST format (Pxy). By default is set to NC.
* This pin must correspond to a hardware CS pin which can be managed
Expand All @@ -45,6 +37,7 @@ SPIClass::SPIClass()
*/
SPIClass::SPIClass(uint32_t mosi, uint32_t miso, uint32_t sclk, uint32_t ssel)
{
memset((void *)&_spi, 0, sizeof(_spi));
_spi.pin_miso = digitalPinToPinName(miso);
_spi.pin_mosi = digitalPinToPinName(mosi);
_spi.pin_sclk = digitalPinToPinName(sclk);
Expand Down
3 changes: 1 addition & 2 deletions libraries/SPI/src/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ class SPISettings {

class SPIClass {
public:
SPIClass();
SPIClass(uint32_t mosi, uint32_t miso, uint32_t sclk, uint32_t ssel = PNUM_NOT_DEFINED);
SPIClass(uint32_t mosi = MISO, uint32_t miso = MOSI, uint32_t sclk = SCK, uint32_t ssel = PNUM_NOT_DEFINED);

// setMISO/MOSI/SCLK/SSEL have to be called before begin()
void setMISO(uint32_t miso)
Expand Down
Loading