Skip to content

Commit 1c0cc5e

Browse files
author
James Foster
committed
Now able to compile in Arduino CI. Workaround for #2 (but see Arduino-CI/arduino_ci#120).
1 parent 5a72669 commit 1c0cc5e

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

src/File.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ File::File(SdFile f, const char *n) {
2222
// oh man you are kidding me, new() doesn't exist? Ok we do it by hand!
2323
_file = (SdFile *)malloc(sizeof(SdFile));
2424
if (_file) {
25-
memcpy(_file, &f, sizeof(SdFile));
25+
memcpy((void*)_file, (void*)&f, sizeof(SdFile));
2626

2727
strncpy(_name, n, 12);
2828
_name[12] = 0;

src/SD.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ namespace SDLib {
5353
void rewindDirectory(void);
5454

5555
using Print::write;
56+
#ifdef ARDUINO_CI
57+
int getWriteError() { return writeError; }
58+
void setWriteError(int value = 1) { writeError = value; }
59+
void clearWriteError() { writeError = 0; }
60+
private:
61+
int writeError;
62+
#endif
5663
};
5764

5865
class SDClass {

src/utility/Sd2PinMap.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifdef ARDUINO_CI
2+
3+
#include "Sd2PinMap.h"
4+
5+
uint8_t avr_io_registers[RAMSTART];
6+
7+
#endif

src/utility/Sd2PinMap.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@
1717
along with the Arduino SdFat Library. If not, see
1818
<http://www.gnu.org/licenses/>.
1919
*/
20+
21+
#ifdef ARDUINO_CI
22+
#include <inttypes.h>
23+
#ifdef _SFR_IO8
24+
#undef _SFR_IO8
25+
#define _AVR_IO_REG(type, mem_addr) (*(type*)(&avr_io_registers[mem_addr]))
26+
#define __SFR_OFFSET 0x20
27+
#define _SFR_IO8(io_addr) _AVR_IO_REG(uint8_t, io_addr + __SFR_OFFSET)
28+
#define _SFR_IO16(io_addr) _AVR_IO_REG(uint16_t, io_addr + __SFR_OFFSET)
29+
#define _SFR_MEM8(mem_addr) _AVR_IO_REG(uint8_t, mem_addr)
30+
#define _SFR_MEM16(mem_addr) _AVR_IO_REG(uint16_t, mem_addr)
31+
#define _SFR_MEM32(mem_addr) _AVR_IO_REG(uint32_t, mem_addr)
32+
33+
extern uint8_t avr_io_registers[RAMSTART];
34+
#endif
35+
#define SDCARD_SS_PIN 4
36+
#define SDCARD_MOSI_PIN 11
37+
#define SDCARD_MISO_PIN 12
38+
#define SDCARD_SCK_PIN 13
39+
#endif
40+
2041
#if defined(__arm__) // Arduino Due Board follows
2142

2243
#ifndef Sd2PinMap_h

src/utility/SdFat.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ class SdFile : public Print {
454454
static uint8_t make83Name(const char* str, uint8_t* name);
455455
uint8_t openCachedEntry(uint8_t cacheIndex, uint8_t oflags);
456456
dir_t* readDirCache(void);
457+
#ifdef ARDUINO_CI
458+
int writeError;
459+
public:
460+
int getWriteError() { return writeError; }
461+
void setWriteError(int value = 1) { writeError = value; }
462+
void clearWriteError() { writeError = 0; }
463+
#endif
457464
};
458465
//==============================================================================
459466
// SdVolume class

src/utility/SdFatUtil.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,31 @@
3434
#endif
3535
#define NOINLINE __attribute__((noinline,unused))
3636
#define UNUSEDOK __attribute__((unused))
37+
38+
#if UINTPTR_MAX == 0xFFFF
39+
typedef int16_t ptr_as_int;
40+
#elif UINTPTR_MAX == 0xFFFFFFFF
41+
typedef int32_t ptr_as_int;
42+
#elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFu
43+
typedef int64_t ptr_as_int;
44+
#else
45+
#error unrecognized pointer size!
46+
#endif
47+
3748
//------------------------------------------------------------------------------
3849
/** Return the number of bytes currently free in RAM. */
3950
static UNUSEDOK int FreeRam(void) {
4051
extern int __bss_end;
4152
extern int* __brkval;
4253
int free_memory;
43-
if (reinterpret_cast<int>(__brkval) == 0) {
54+
if (reinterpret_cast<ptr_as_int>(__brkval) == 0) {
4455
// if no heap use from end of bss section
45-
free_memory = reinterpret_cast<int>(&free_memory)
46-
- reinterpret_cast<int>(&__bss_end);
56+
free_memory = reinterpret_cast<ptr_as_int>(&free_memory)
57+
- reinterpret_cast<ptr_as_int>(&__bss_end);
4758
} else {
4859
// use from top of stack to heap
49-
free_memory = reinterpret_cast<int>(&free_memory)
50-
- reinterpret_cast<int>(__brkval);
60+
free_memory = reinterpret_cast<ptr_as_int>(&free_memory)
61+
- reinterpret_cast<ptr_as_int>(__brkval);
5162
}
5263
return free_memory;
5364
}

0 commit comments

Comments
 (0)