Skip to content

Commit 762ba08

Browse files
author
Jim Lindblom
committed
SAMD21 support - fixing SAMD21 SPI support and PROGMEM errors.
1 parent 7462bc3 commit 762ba08

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Micro OLED Breakout
2-
version=1.1.3
2+
version=1.2.0
33
author=SparkFun Electronics <techsupport@sparkfun.com>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the <a href="https://www.sparkfun.com/products/13003">SparkFun Micro OLED Breakout</a>.

src/SFE_MicroOLED.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5050
//#define INCLUDE_LARGE_LETTER_FONT
5151

5252
// This fixed ugly GCC warning "only initialized variables can be placed into program memory area"
53+
#if defined(__AVR__)
5354
#undef PROGMEM
5455
#define PROGMEM __attribute__((section(".progmem.data")))
56+
#endif
5557

5658
// Add header of the fonts here. Remove as many as possible to conserve FLASH memory.
5759
#include "util/font5x7.h"

src/hardware.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4040

4141
#define I2C_FREQ 400000L // I2C Frequency is 400kHz (fast as possible)
4242

43+
// Configure SPI settings - Max clk frequency for display is 10MHz
44+
SPISettings oledSettings(10000000, MSBFIRST, SPI_MODE0);
45+
4346
/** \brief Set Up SPI Interface
4447
4548
Sets up the SPI pins, initializes the Arduino's SPI interface.
@@ -52,10 +55,9 @@ void MicroOLED::spiSetup()
5255
pinMode(csPin, OUTPUT); // CS is an OUTPUT
5356
digitalWrite(csPin, HIGH); // Start CS High
5457

55-
// Initialize the SPI library:
56-
SPI.setClockDivider(SPI_CLOCK_DIV2); // Fastest SPI clock possible
57-
SPI.setDataMode(SPI_MODE0); // CPOL=0 and CPHA=0, SPI mode 0
58+
#if defined(__AVR__)
5859
pinMode(10, OUTPUT); // Required for setting into Master mode
60+
#endif
5961
SPI.begin();
6062
}
6163

@@ -66,9 +68,11 @@ void MicroOLED::spiSetup()
6668
**/
6769
void MicroOLED::spiTransfer(byte data)
6870
{
69-
digitalWrite(csPin, LOW);
71+
SPI.beginTransaction(oledSettings);
72+
digitalWrite(csPin, LOW);
7073
SPI.transfer(data);
71-
digitalWrite(csPin, HIGH);
74+
digitalWrite(csPin, HIGH);
75+
SPI.endTransaction();
7276
}
7377

7478
/** \brief Initialize the I2C Interface

0 commit comments

Comments
 (0)