Skip to content

Improve SPI library code understanding #161

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 1 commit into from Nov 30, 2017
Merged

Improve SPI library code understanding #161

merged 1 commit into from Nov 30, 2017

Conversation

ghost
Copy link

@ghost ghost commented Nov 29, 2017

Try to improve the clarity of the SPI library code after the feedback #157

@ghost ghost requested review from LMESTM and fpistm November 29, 2017 13:29
@fpistm
Copy link
Member

fpistm commented Nov 29, 2017

Thanks @fprwi6labs.
Will review it soon

Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this update.
Some typo to fix before merge. Else ok for me.

_We do not describe here the [SPI Arduino API](https://www.arduino.cc/en/Reference/SPI) but the functionalities added._

We give to the user 3 possiblities about the management of the CS pin:
* the CS pin is managed directly by the user code before to transfer the data (like the Arduino SPI library)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numbering:
1.
2.
3.

Remove the 'or'.


### New API functions

* **SPIClass::SPIClass(uint8_t mosi, uint8_t miso, uint8_t sclk, uint8_t ssel)**: alternative class constructor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use code formatter

  • SPIClass::SPIClass(uint8_t mosi, uint8_t miso, uint8_t sclk, uint8_t ssel): alternative class constructor

_Params_ SPI sclk pin
_Params_ (optional) SPI ssel pin. This pin must be an hardware CS pin. If you configure this pin, the chip select will be managed by the SPI peripheral. Do not use API functions with CS pin in parameter.

* **void SPIClass::begin(uint8_t _pin)**: initialize the SPI interface and add a CS pin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

* **void SPIClass::begin(uint8_t _pin)**: initialize the SPI interface and add a CS pin
_Params_ spi CS pin to be managed by the SPI library

* **void beginTransaction(uint8_t pin, SPISettings settings)**: allows to configure the SPI with other parameter. These new parameter are saved this an associated CS pin.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

_Params_ SPI CS pin to be managed by the SPI library
_Params_ SPI settings

* **void endTransaction(uint8_t pin)**: removes a CS pin and the SPI settings associated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

* @param _count: number of bytes to send/receive.
* @param _mode: (optional) can be SPI_CONTINUE in case of multiple successive
* send or SPI_LAST to indicate the end of send.
* If the _mode is set to SPI_CONTINUE, keep the spi instance alive.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spi -> SPI

* @param _count: number of bytes to send/receive.
* @param _mode: (optional) can be SPI_CONTINUE in case of multiple successive
* send or SPI_LAST to indicate the end of send.
* If the _mode is set to SPI_CONTINUE, keep the spi instance alive.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spi -> SPI

* another one will contains the data received. begin() or
* beginTransaction() must be called at least once before.
* @param _pin: CS pin to select a device (optional). If the previous transfer
* used another CS pin then the spi instance will be reconfigured.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spi -> SPI

* @brief Transfer several bytes. Only one buffer used to send and receive data.
* begin() or beginTransaction() must be called at least once before.
* @param _pin: CS pin to select a device (optional). If the previous transfer
* used another CS pin then the spi instance will be reconfigured.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spi -> SPI

void setClockDivider(uint8_t _div) {
setClockDivider(CS_PIN_CONTROLLED_BY_USER, _div);
}
// Not implemented functions. Keep for compatibility.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backward compatibility

@ghost
Copy link
Author

ghost commented Nov 30, 2017

Done

@ghost ghost requested a review from fpistm November 30, 2017 10:19
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry missed one typo.

void setClockDivider(uint8_t _div) {
setClockDivider(CS_PIN_CONTROLLED_BY_USER, _div);
}
// Not implemented functions. Keep for backward compatibility.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@ghost ghost requested a review from fpistm November 30, 2017 14:43
@fpistm fpistm merged commit cb4763f into stm32duino:master Nov 30, 2017
benwaffle pushed a commit to benwaffle/Arduino_Core_STM32 that referenced this pull request Apr 10, 2019
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.

1 participant