Skip to content

Commit

Permalink
refactor(spi): simplify constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Nov 4, 2024
1 parent 021d321 commit 0d760e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
26 changes: 9 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 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

0 comments on commit 0d760e0

Please sign in to comment.