Skip to content

Commit

Permalink
Compatible with STM32, only compatible with compilation, not tested
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Sep 14, 2024
1 parent 246f746 commit 6bb28e2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/SensorBHI260AP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ class SensorBHI260AP
if (__handler.irq != SENSOR_PIN_NONE) {
#if defined(ARDUINO_ARCH_RP2040)
attachInterrupt((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING);
#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA) || defined(ESP32) || defined(ARDUINO_ARCH_ESP32)
#elif defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32)
attachInterrupt(__handler.irq, handleISR, RISING);
#else
#error "Interrupt registration not implemented"
Expand Down
2 changes: 1 addition & 1 deletion src/SensorBMM150.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class SensorBMM150
*/
#if defined(ARDUINO_ARCH_RP2040)
attachInterrupt((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING);
#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA) || defined(ESP32) || defined(ARDUINO_ARCH_ESP32)
#elif defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32)
attachInterrupt(__handler.irq, handleISR, RISING);
#else
#error "Interrupt registration not implemented"
Expand Down
37 changes: 7 additions & 30 deletions src/SensorCommon.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public:
__wire = &w;
__sda = sda;
__scl = scl;
#if defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
#if defined(ARDUINO_ARCH_NRF52)
if (__sda != 0xFF && __scl != 0xFF) {
__wire->setPins(__sda, __scl);
}
Expand Down Expand Up @@ -115,13 +115,18 @@ public:
return false;
}
if (mosi != -1 && miso != -1 && sck != -1) {
#if defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
#if defined(ARDUINO_ARCH_NRF52)
__spi->begin();
#elif defined(ARDUINO_ARCH_RP2040)
__spi->setSCK(sck);
__spi->setRX(miso);
__spi->setTX(mosi);
__spi->begin();
#elif defined(ARDUINO_ARCH_STM32)
__spi->setSCLK(sck);
__spi->setMISO(miso);
__spi->setMOSI(mosi);
__spi->begin();
#else
__spi->begin(sck, miso, mosi);
#endif
Expand Down Expand Up @@ -660,34 +665,6 @@ protected:
*/
protected:

// bool begin()
// {
// #if defined(ARDUINO)
// if (__has_init) return thisChip().initImpl();
// __has_init = true;

// if (__wire) {
// log_i("SDA:%d SCL:%d", __sda, __scl);
// #if defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
// __wire->begin();
// #elif defined(ARDUINO_ARCH_RP2040)
// __wire->end();
// __wire->setSDA(__sda);
// __wire->setSCL(__scl);
// __wire->begin();
// #else
// __wire->begin(__sda, __scl);
// #endif
// }
// if (__spi) {
// // int cs, int mosi = -1, int miso = -1, int sck = -1, SPIClass &spi = SPI
// begin(__cs, __mosi, __miso, __sck, *__spi);
// }

// #endif /*ARDUINO*/
// return thisChip().initImpl();
// }

void end()
{
#if defined(ARDUINO)
Expand Down
37 changes: 24 additions & 13 deletions src/SensorLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,31 @@
#if defined(ARDUINO_ARCH_RP2040)
#define PLATFORM_SPI_TYPE SPIClassRP2040
#define PLATFORM_WIRE_TYPE TwoWire
#define SPI_DATA_ORDER SPI_MSB_FIRST
#define DEFAULT_SDA (0xFF)
#define DEFAULT_SCL (0xFF)
#define DEFAULT_SPISETTING SPISettings()
#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
#define SPI_DATA_ORDER SPI_MSB_FIRST
#define DEFAULT_SDA (0xFF)
#define DEFAULT_SCL (0xFF)
#define DEFAULT_SPISETTING SPISettings()
#elif defined(ARDUINO_ARCH_STM32)
#define PLATFORM_SPI_TYPE SPIClass
#define PLATFORM_WIRE_TYPE TwoWire
#define SPI_DATA_ORDER MSBFIRST
#define DEFAULT_SDA (0xFF)
#define DEFAULT_SCL (0xFF)
#define DEFAULT_SPISETTING SPISettings()
#define SPI_DATA_ORDER MSBFIRST
#define DEFAULT_SDA (0xFF)
#define DEFAULT_SCL (0xFF)
#define DEFAULT_SPISETTING SPISettings()
#elif defined(ARDUINO_ARCH_NRF52)
#define PLATFORM_SPI_TYPE SPIClass
#define PLATFORM_WIRE_TYPE TwoWire
#define SPI_DATA_ORDER MSBFIRST
#define DEFAULT_SDA (0xFF)
#define DEFAULT_SCL (0xFF)
#define DEFAULT_SPISETTING SPISettings()
#else
#define PLATFORM_SPI_TYPE SPIClass
#define PLATFORM_WIRE_TYPE TwoWire
#define SPI_DATA_ORDER SPI_MSBFIRST
#define DEFAULT_SDA (SDA)
#define DEFAULT_SCL (SCL)
#define DEFAULT_SPISETTING SPISettings(__freq, __dataOrder, __dataMode);
#define SPI_DATA_ORDER SPI_MSBFIRST
#define DEFAULT_SDA (SDA)
#define DEFAULT_SCL (SCL)
#define DEFAULT_SPISETTING SPISettings(__freq, __dataOrder, __dataMode);
#endif

#elif defined(ESP_PLATFORM)
Expand All @@ -89,6 +96,10 @@

#endif

#ifndef I2C_BUFFER_LENGTH
#define I2C_BUFFER_LENGTH (32)
#endif

enum SensorLibInterface {
SENSORLIB_SPI_INTERFACE = 1,
SENSORLIB_I2C_INTERFACE
Expand Down
13 changes: 9 additions & 4 deletions src/bosch/common/bosch_interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool SensorInterfaces::setup_interfaces(SensorLibConfigure config)
config.u.i2c_dev.wire->begin();
#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
config.u.i2c_dev.wire->end();
config.u.i2c_dev.wire->setPins(config.u.i2c_dev.sda,config.u.i2c_dev.scl);
config.u.i2c_dev.wire->setPins(config.u.i2c_dev.sda, config.u.i2c_dev.scl);
config.u.i2c_dev.wire->begin();
#else
config.u.i2c_dev.wire->begin(config.u.i2c_dev.sda, config.u.i2c_dev.scl);
Expand All @@ -74,11 +74,16 @@ bool SensorInterfaces::setup_interfaces(SensorLibConfigure config)
config.u.spi_dev.spi->setRX(config.u.spi_dev.miso);
config.u.spi_dev.spi->setTX(config.u.spi_dev.mosi);
config.u.spi_dev.spi->begin();
#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
config.u.spi_dev.spi->setPins(config.u.spi_dev.miso,config.u.spi_dev.sck, config.u.spi_dev.mosi);
#elif defined(ARDUINO_ARCH_NRF52)
config.u.spi_dev.spi->setPins(config.u.spi_dev.miso, config.u.spi_dev.sck, config.u.spi_dev.mosi);
config.u.spi_dev.spi->begin();
#elif defined(ARDUINO_ARCH_STM32)
config.u.spi_dev.spi->setSCLK(config.u.spi_dev.sck);
config.u.spi_dev.spi->setMISO(config.u.spi_dev.miso);
config.u.spi_dev.spi->setMOSI(config.u.spi_dev.mosi);
config.u.spi_dev.spi->begin();
#else
config.u.spi_dev.spi->begin(config.u.spi_dev.sck, config.u.spi_dev.miso, config.u.spi_dev.mosi);
config.u.spi_dev.spi->begin(config.u.spi_dev.sck, config.u.spi_dev.miso, config.u.spi_dev.mosi);
#endif
break;
default:
Expand Down

0 comments on commit 6bb28e2

Please sign in to comment.