Skip to content

Commit

Permalink
renamed settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-merkle committed Apr 9, 2021
1 parent f89e0a7 commit b809f0b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/spi/AS5047P_SPI_Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace AS5047P_ComBackend {
void AS5047P_SPI::write(const uint16_t regAddress, const uint16_t data) {

// init spi interface
#ifdef AS5047P_SPI_INIT_ON_COM_ENAB
#ifdef AS5047P_SPI_ARDUINO_INIT_ON_COM_ENAB
SPI.begin();
#endif
SPI.beginTransaction(__spiSettings);
Expand All @@ -41,7 +41,7 @@ namespace AS5047P_ComBackend {
digitalWrite(__chipSelectPinNo, LOW);
SPI.transfer16(regAddress);
digitalWrite(__chipSelectPinNo, HIGH);
#if defined(F_CPU) && defined(AS5047P_SPI_USE_100NS_NOP_DELAY)
#if defined(F_CPU) && defined(AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY)
__delay100Ns();
#else
delayMicroseconds(1);
Expand All @@ -51,15 +51,15 @@ namespace AS5047P_ComBackend {
digitalWrite(__chipSelectPinNo, LOW);
SPI.transfer16(data);
digitalWrite(__chipSelectPinNo, HIGH);
#if defined(F_CPU) && defined(AS5047P_SPI_USE_100NS_NOP_DELAY)
#if defined(F_CPU) && defined(AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY)
__delay100Ns();
#else
delayMicroseconds(1);
#endif

// close spi interface
SPI.endTransaction();
#ifdef AS5047P_SPI_INIT_ON_COM_ENAB
#ifdef AS5047P_SPI_ARDUINO_INIT_ON_COM_ENAB
SPI.end();
#endif

Expand All @@ -71,7 +71,7 @@ namespace AS5047P_ComBackend {
uint16_t receivedData = 0;

// init spi interface
#ifdef AS5047P_SPI_INIT_ON_COM_ENAB
#ifdef AS5047P_SPI_ARDUINO_INIT_ON_COM_ENAB
SPI.begin();
#endif
SPI.beginTransaction(__spiSettings);
Expand All @@ -80,7 +80,7 @@ namespace AS5047P_ComBackend {
digitalWrite(__chipSelectPinNo, LOW);
SPI.transfer16(regAddress);
digitalWrite(__chipSelectPinNo, HIGH);
#if defined(F_CPU) && defined(AS5047P_SPI_USE_100NS_NOP_DELAY)
#if defined(F_CPU) && defined(AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY)
__delay100Ns();
#else
delayMicroseconds(1);
Expand All @@ -91,7 +91,7 @@ namespace AS5047P_ComBackend {
AS5047P_Types::SPI_Command_Frame_t nopFrame(AS5047P_Types::NOP_t::REG_ADDRESS, AS5047P_TYPES_READ_CMD);
receivedData = SPI.transfer16(nopFrame.data.raw);
digitalWrite(__chipSelectPinNo, HIGH);
#if defined(F_CPU) && defined(AS5047P_SPI_USE_100NS_NOP_DELAY)
#if defined(F_CPU) && defined(AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY)
__delay100Ns();
#else
delayMicroseconds(1);
Expand All @@ -100,15 +100,15 @@ namespace AS5047P_ComBackend {

// close spi interface
SPI.endTransaction();
#ifdef AS5047P_SPI_INIT_ON_COM_ENAB
#ifdef AS5047P_SPI_ARDUINO_INIT_ON_COM_ENAB
SPI.end();
#endif

return receivedData;

}

#if defined(F_CPU) && defined(AS5047P_SPI_USE_100NS_NOP_DELAY)
#if defined(F_CPU) && defined(AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY)

const void AS5047P_SPI::__delay100Ns() {
for (uint16_t i = 0; i < __numberOfNops; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/spi/AS5047P_SPI_Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace AS5047P_ComBackend {
uint8_t __chipSelectPinNo; ///< The pin number of the chip select pin.
SPISettings __spiSettings; ///< The spi bus settings.

#if defined(F_CPU) && defined(AS5047P_SPI_USE_100NS_NOP_DELAY)
#if defined(F_CPU) && defined(AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY)

const uint16_t __numberOfNops = (uint16_t) ((100 * (F_CPU/1000000L))/1000); ///< Number of asm nop operations for 100 ns delay.

Expand Down
4 changes: 2 additions & 2 deletions src/util/AS5047P_Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
* This minimizes the delay while communication with the AS5047P sensor but can lead to an instable communication.
*
*/
#define AS5047P_SPI_USE_100NS_NOP_DELAY
#define AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY

/**
* @brief Uncomment this to init the spi bus every time when a communication is startet.
*
* This can become usefull if multiple libraries are using the spi bus with different settings.
*
*/
//#define AS5047P_SPI_INIT_ON_COM_ENAB
//#define AS5047P_SPI_ARDUINO_INIT_ON_COM_ENAB

#endif // AS5047P_Settings_h

0 comments on commit b809f0b

Please sign in to comment.