File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed
Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -88,9 +88,12 @@ void SPIClass::usingInterrupt(int interruptNumber)
8888 interruptMode = SPI_IMODE_GLOBAL;
8989 else
9090 {
91- if (irqMap == NULL ) {
92- irqMap = (uint8_t *)malloc (EXTERNAL_NUM_INTERRUPTS);
93- }
91+ #ifdef USE_MALLOC_FOR_IRQ_MAP
92+ if (irqMap == NULL ) {
93+ irqMap = (uint8_t *)malloc (EXTERNAL_NUM_INTERRUPTS);
94+ }
95+ #endif
96+
9497 interruptMode |= SPI_IMODE_EXTINT;
9598 if (interruptNumber < 32 ) {
9699 interruptMask_lo |= 1 << interruptNumber;
@@ -116,8 +119,10 @@ void SPIClass::notUsingInterrupt(int interruptNumber)
116119
117120 if (interruptMask_lo == 0 && interruptMask_hi == 0 ) {
118121 interruptMode = SPI_IMODE_NONE;
119- free (irqMap);
120- irqMap = NULL ;
122+ #ifdef USE_MALLOC_FOR_IRQ_MAP
123+ free (irqMap);
124+ irqMap = NULL ;
125+ #endif
121126 }
122127}
123128
@@ -181,8 +186,8 @@ void SPIClass::beginTransaction(SPISettings settings)
181186 {
182187 detachMaskedInterrupts ();
183188 }
184- config (settings);
185189 }
190+ config (settings);
186191}
187192
188193void SPIClass::endTransaction (void )
Original file line number Diff line number Diff line change 2222
2323#include < Arduino.h>
2424
25+ #ifndef USE_MALLOC_FOR_IRQ_MAP
26+ #define USE_MALLOC_FOR_IRQ_MAP 1
27+ #endif
28+
2529// SPI_HAS_TRANSACTION means SPI has
2630// - beginTransaction()
2731// - endTransaction()
@@ -161,6 +165,7 @@ class SPIClass {
161165 void setClockDivider (uint8_t uc_div);
162166
163167 private:
168+
164169 void init ();
165170 void config (SPISettings settings);
166171
@@ -184,9 +189,15 @@ class SPIClass {
184189 char interruptSave;
185190 uint32_t interruptMask_lo;
186191 uint32_t interruptMask_hi;
187- uint8_t * irqMap = NULL ;
192+
193+ #if USE_MALLOC_FOR_IRQ_MAP
194+ uint8_t * irqMap = NULL ;
195+ #else
196+ volatile uint8_t irqMap[EXTERNAL_NUM_INTERRUPTS];
197+ #endif
188198};
189199
200+
190201#if SPI_INTERFACES_COUNT > 0
191202 extern SPIClass SPI;
192203#endif
@@ -199,4 +210,4 @@ class SPIClass {
199210#define SPI_CLOCK_DIV64 ( SPI_PRESC_DIV64_gc )
200211#define SPI_CLOCK_DIV128 ( SPI_PRESC_DIV128_gc )
201212
202- #endif
213+ #endif
You can’t perform that action at this time.
0 commit comments