2018-11-16 10:25:23 +00:00
|
|
|
#include "hardware.h"
|
|
|
|
|
|
|
|
#if defined(USE_SPIRAM)
|
2014-10-18 11:33:48 +00:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <SpiRAM.h>
|
|
|
|
#include "memory.h"
|
|
|
|
#include "spiram.h"
|
2018-08-10 12:54:00 +00:00
|
|
|
|
2014-10-18 11:33:48 +00:00
|
|
|
extern SPIClass SPIRAM_DEV;
|
|
|
|
|
|
|
|
SpiRAM spiRam(SPIRAM_DEV, SPIRAM_CS);
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
void spiram::operator=(uint8_t b)
|
2014-10-18 11:33:48 +00:00
|
|
|
{
|
2018-08-14 05:18:57 +00:00
|
|
|
spiRam.write_byte(_acc, b);
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
spiram::operator uint8_t()
|
2014-10-18 11:33:48 +00:00
|
|
|
{
|
2018-08-14 05:18:57 +00:00
|
|
|
return spiRam.read_byte(_acc);
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void spiram::checkpoint(Stream &s)
|
|
|
|
{
|
2019-02-24 11:50:10 +00:00
|
|
|
#if !defined(NO_CHECKPOINT)
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t buf[Memory::page_size];
|
2015-11-30 14:49:56 +00:00
|
|
|
for (unsigned i = 0; i < pages(); i++) {
|
2014-10-22 18:47:06 +00:00
|
|
|
spiRam.read_stream(i * 256, buf, sizeof(buf));
|
2014-11-15 23:24:47 +00:00
|
|
|
s.write(buf, sizeof(buf));
|
2014-10-22 18:47:06 +00:00
|
|
|
}
|
2019-02-24 11:50:10 +00:00
|
|
|
#endif
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void spiram::restore(Stream &s)
|
|
|
|
{
|
2019-02-24 11:50:10 +00:00
|
|
|
#if !defined(NO_CHECKPOINT)
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t buf[Memory::page_size];
|
2015-11-30 14:49:56 +00:00
|
|
|
for (unsigned i = 0; i < pages(); i++) {
|
2014-11-15 23:24:47 +00:00
|
|
|
s.readBytes((char *)buf, sizeof(buf));
|
2014-10-22 18:47:06 +00:00
|
|
|
spiRam.write_stream(i * 256, buf, sizeof(buf));
|
|
|
|
}
|
2019-02-24 11:50:10 +00:00
|
|
|
#endif
|
2014-10-18 11:33:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 12:54:00 +00:00
|
|
|
#endif
|