Browse Source

Cleaned up some of the DUE/Mega conditions; shuffled around sd card code a little bit

master
Mike C 8 years ago
parent
commit
bdf9408a5d
  1. 20
      Universal_Serial_Adapter/Project.h
  2. 8
      Universal_Serial_Adapter/UILCD.cpp
  3. 25
      Universal_Serial_Adapter/Universal_Serial_Adapter.ino

20
Universal_Serial_Adapter/Project.h

@ -14,10 +14,11 @@
#ifndef Project_h
#define Project_h
#define DEBUG 2 // NONE = 0; MINIMAL = 1; FULL = 2;
#define DEBUG 1 // NONE = 0; MINIMAL = 1; FULL = 2;
// Whether or not the Arduino Mega 2560 is used as the base board
#define ARD_MEGA_2560 true
// Whether or not the Arduino DUE is used as the base board
// Assume Mega 2560 otherwise
#define ARD_DUE false
// Buttons / Joystick / Input Hardware Pinouts
#define okButtonPin 22
@ -57,22 +58,23 @@
// Don't change anything below here
// -----------------------------------------------------------------------------
// Global SD card so LCD / config can read/write files
extern SdFat sd;
#define FONT_WIDTH 6
#define FONT_HEIGHT 8
// Serial ports
#if ARD_MEGA_2560
extern SerialPort<0, 512, 512> serialPort0;
extern SerialPort<1, 512, 512> serialPort1;
extern SerialPort<2, 512, 512> serialPort2;
extern SerialPort<3, 512, 512> serialPort3;
#else
#if ARD_DUE
extern SerialPort<0, 4096, 4096> serialPort0;
extern SerialPort<1, 4096, 4096> serialPort1;
extern SerialPort<2, 4096, 4096> serialPort2;
extern SerialPort<3, 4096, 4096> serialPort3;
#else
extern SerialPort<0, 512, 512> serialPort0;
extern SerialPort<1, 512, 512> serialPort1;
extern SerialPort<2, 512, 512> serialPort2;
extern SerialPort<3, 512, 512> serialPort3;
#endif
// Serial modes supported

8
Universal_Serial_Adapter/UILCD.cpp

@ -480,7 +480,6 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
serialPort0.println("UILCD::bmpDraw()");
#endif
SdFat sd;
SdFile bmpFile;
int bmpWidth, bmpHeight; // W+H in pixels
uint8_t bmpDepth; // Bit depth (currently must be 24)
@ -498,13 +497,6 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
return;
}
serialPort0.println("Starting SD card");
// Start the SD Card -- FIXME: This should likely get moved to config
if (!sd.begin(SD_CS, SPI_PROJECT_SPEED )) {
serialPort0.println("SD.begin(SD_CS, SPI_HALF_SPEED ) -- failed!");
sd.initErrorHalt();
}
#if DEBUG >= 1
serialPort0.println();
serialPort0.print("Loading image '");

25
Universal_Serial_Adapter/Universal_Serial_Adapter.ino

@ -28,20 +28,23 @@
#include <Metro.h>
#include "RTClib.h"
// Globals used by main classes
UI* ui;
Config* config;
RTC_DS1307 rtc;
//SdFile dataFile;
#if ARD_MEGA_2560
SerialPort<0, 512, 512> serialPort0;
SerialPort<1, 512, 512> serialPort1;
SerialPort<2, 512, 512> serialPort2;
SerialPort<3, 512, 512> serialPort3;
#else
SdFile dataFile;
SdFat sd;
#if ARD_DUE
SerialPort<0, 4096, 4096> serialPort0;
SerialPort<1, 4096, 4096> serialPort1;
SerialPort<2, 4096, 4096> serialPort2;
SerialPort<3, 4096, 4096> serialPort3;
#else
SerialPort<0, 512, 512> serialPort0;
SerialPort<1, 512, 512> serialPort1;
SerialPort<2, 512, 512> serialPort2;
SerialPort<3, 512, 512> serialPort3;
#endif
// helper for interrupt method call
@ -54,6 +57,14 @@ void setup() {
serialPort0.begin(115200);
Wire.begin();
// Start the SD Card -- This should come very early
// Not in config to guarantee it comes online very very early
serialPort0.println("Starting SD card");
if (!sd.begin(SD_CS, SPI_PROJECT_SPEED )) {
serialPort0.println("SD.begin(SD_CS, SPI_SPEED ) -- failed!");
sd.initErrorHalt();
}
// Ensure RTC is set to run on battery
// clear /EOSC bit
// Sometimes necessary to ensure that the clock