Skip to content
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

Added support for STM32duino #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions src/DS3232RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
#elif ARDUINO >= 100
#include <Wire.h>
#define i2cBegin Wire.begin
#define i2cBeginTransmission Wire.beginTransmission
#ifdef __STM32F1__
#define i2cBeginTransmission if (_do_init) { _do_init = false; Wire.begin(); } Wire.beginTransmission
#else
#define i2cBeginTransmission Wire.beginTransmission
#endif
#define i2cEndTransmission Wire.endTransmission
#define i2cRequestFrom Wire.requestFrom
#define i2cRead Wire.read
Expand Down Expand Up @@ -116,7 +120,10 @@ byte DS3232RTC::errCode; // for debug
// the begin() function in the setup code.
DS3232RTC::DS3232RTC(bool initI2C)
{
if (initI2C) i2cBegin();
// At the moment, Arduino for STM32 (STM32duino) doesn't support GPIO or SPI etc operations inside constructors.
#ifndef __STM32F1__
if (initI2C) i2cBegin();
#endif
}

// Initialize the I2C bus.
Expand Down Expand Up @@ -370,6 +377,10 @@ uint8_t __attribute__ ((noinline)) DS3232RTC::bcd2dec(uint8_t n)
return n - 6 * (n >> 4);
}

#ifdef ARDUINO_ARCH_AVR
#if defined(ARDUINO_ARCH_AVR) || defined(__STM32F1__)
DS3232RTC RTC; // instantiate an RTC object
#endif

#ifdef __STM32F1__
bool DS3232RTC::_do_init = true;
#endif
5 changes: 4 additions & 1 deletion src/DS3232RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ class DS3232RTC
private:
uint8_t dec2bcd(uint8_t n);
static uint8_t bcd2dec(uint8_t n);
#ifdef __STM32F1__
static bool _do_init;
#endif
};

#ifdef ARDUINO_ARCH_AVR
#if defined(ARDUINO_ARCH_AVR) || defined(__STM32F1__)
extern DS3232RTC RTC;
#endif

Expand Down