Skip to content

Commit 3a9a3ac

Browse files
author
Daniel Noguerol
committed
Added support for Arduino Uno and SD breakout board.
1 parent 8d7c19a commit 3a9a3ac

File tree

6 files changed

+87
-59
lines changed

6 files changed

+87
-59
lines changed

SIO2Arduino.ino

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,34 @@
2525
#include "atari.h"
2626
#include "sio_channel.h"
2727
#include "disk_drive.h"
28-
#include "log.h"
2928
#ifdef LCD_DISPLAY
3029
#include <LiquidCrystal.h>
3130
#endif
32-
#ifndef HARDWARE_UART
33-
#include <SoftwareSerial.h>
34-
#endif
35-
36-
#define STATE_INIT 1
37-
#define STATE_WAIT_CMD_START 2
38-
#define STATE_READ_CMD 3
39-
#define STATE_WAIT_CMD_END 4
4031

41-
// globals
32+
/**
33+
* Global variables
34+
*/
4235
DriveAccess driveAccess(getDeviceStatus, readSector, writeSector, format);
4336
DriveControl driveControl(getFileList, mountFile);
44-
#ifdef HARDWARE_UART
45-
SIOChannel sioChannel(PIN_ATARI_CMD, &HARDWARE_UART, &driveAccess, &driveControl);
46-
#else
47-
SoftwareSerial serial(PIN_SERIAL_RX, PIN_SERIAL_TX);
48-
SIOChannel sioChannel(PIN_ATARI_CMD, &serial, &driveAccess, &driveControl);
49-
#endif
50-
#ifdef LCD_DISPLAY
51-
LiquidCrystal lcd(PIN_LCD_RD,PIN_LCD_ENABLE,PIN_LCD_DB4,PIN_LCD_DB5,PIN_LCD_DB6,PIN_LCD_DB7);
52-
#endif
37+
SIOChannel sioChannel(PIN_ATARI_CMD, &SIO_UART, &driveAccess, &driveControl);
5338
File root;
5439
File file; // TODO: make this unnecessary
5540
DiskDrive drive1;
41+
#ifdef SELECTOR_BUTTON
5642
boolean isSwitchPressed = false;
43+
#endif
44+
#ifdef LCD_DISPLAY
45+
LiquidCrystal lcd(PIN_LCD_RD,PIN_LCD_ENABLE,PIN_LCD_DB4,PIN_LCD_DB5,PIN_LCD_DB6,PIN_LCD_DB7);
46+
#endif
5747

5848
void setup() {
49+
#ifdef DEBUG
5950
// set up logging serial port
60-
Serial.begin(115200);
51+
LOGGING_UART.begin(115200);
52+
#endif
6153

6254
// initialize serial port to Atari
63-
#ifdef HARDWARE_UART
64-
HARDWARE_UART.begin(19200);
65-
#else
66-
serial.begin(19200);
67-
#endif
55+
SIO_UART.begin(19200);
6856

6957
// set pin modes
7058
#ifdef SELECTOR_BUTTON
@@ -79,8 +67,8 @@ void setup() {
7967

8068
// initialize SD card
8169
LOG_MSG("Initializing SD card...");
82-
pinMode(PIN_SD_CARD, OUTPUT);
83-
if (!SD.begin(PIN_SD_CARD)) {
70+
pinMode(PIN_SD_CS, OUTPUT);
71+
if (!SD.begin(PIN_SD_CS)) {
8472
LOG_MSG_CR(" failed.");
8573
return;
8674
}
@@ -107,7 +95,7 @@ void loop() {
10795
#endif
10896
}
10997

110-
void serialEvent1() {
98+
void SIO_CALLBACK() {
11199
// inform the SIO channel that an incoming byte is available
112100
sioChannel.processIncomingByte();
113101
}

config.h

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,86 @@
2020
* along with SIO2Arduino; if not, write to the Free Software
2121
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
23+
#ifndef CONFIG_H
24+
#define CONFIG_H
2325

24-
/*
26+
/**
2527
* These are SIO2Arduino feature definitions.
2628
*/
2729

28-
// uncomment to use an LCD display
30+
// These are the Arduino devices that can be used. I'm sure others would work,
31+
// but these are the only ones I have to test with. Only one of these should
32+
// be uncommented.
33+
#define ARDUINO_UNO // Arduino Uno board
34+
//#define ARDUINO_MEGA // Arduino Mega 2560/ADK board
35+
36+
// Uncomment this line if you are using an LCD display
2937
//#define LCD_DISPLAY
3038

31-
// uncomment to use a selector button
39+
// Uncomment this line if you are using a hardware button for image selection
3240
#define SELECTOR_BUTTON
3341

34-
// uncomment (and name appropriately) to use a hardware UART for serial communication (e.g. Arduino Mega)
35-
//#define HARDWARE_UART Serial1
42+
// uncomment if using an Ethernet sheild for SD capabilities
43+
//#define ETHERNET_SHIELD
44+
45+
// uncomment this to enable debug logging -- make sure the HARDWARE_UART isn't the same as
46+
// the LOGGING_UART defined at the bottom of the file
47+
#define DEBUG
3648

3749
/*
3850
* These are the Arduino pin definitions.
3951
*/
4052

41-
#define PIN_ATARI_CMD 2 // the Atari SIO command line
42-
#define PIN_SD_CARD 4 // the SD card pin
53+
#define PIN_ATARI_CMD 2 // the Atari SIO command line - usually the purple wire on the SIO cable
4354

44-
#ifndef HARDWARE_UART
45-
#define PIN_SERIAL_RX 5
46-
#define PIN_SERIAL_TX 6
55+
#ifdef ETHERNET_SHIELD
56+
#define PIN_SD_CS 4 // the SD CS line
57+
#else
58+
#ifdef ARDUINO_MEGA
59+
#define PIN_SD_CS 53 // the SD breakout board's CD (card detect) pin
60+
#define PIN_SD_DI 52 // the SD breakout board's DI pin
61+
#define PIN_SD_DO 51 // the SD breakout board's DO pin
62+
#define PIN_SD_CLK 50 // the SD breakout board's CLK pin
63+
#else
64+
#define PIN_SD_CS 10 // the SD breakout board's CD (card detect) pin
65+
#define PIN_SD_DI 11 // the SD breakout board's DI pin
66+
#define PIN_SD_DO 12 // the SD breakout board's DO pin
67+
#define PIN_SD_CLK 13 // the SD breakout board's CLK pin
68+
#endif
4769
#endif
4870

4971
#ifdef SELECTOR_BUTTON
50-
#define PIN_SELECTOR 8 // the selector button pin
72+
#define PIN_SELECTOR 3 // the selector button pin
5173
#endif
5274

5375
#ifdef LCD_DISPLAY
54-
#define PIN_LCD_RD 30 // *
55-
#define PIN_LCD_ENABLE 32 // *
56-
#define PIN_LCD_DB4 40 // * LCD display pins
57-
#define PIN_LCD_DB5 38 // *
58-
#define PIN_LCD_DB6 36 // *
59-
#define PIN_LCD_DB7 34 // *
76+
#define PIN_LCD_RD 4 // *
77+
#define PIN_LCD_ENABLE 5 // *
78+
#define PIN_LCD_DB4 9 // * LCD display pins
79+
#define PIN_LCD_DB5 8 // *
80+
#define PIN_LCD_DB6 7 // *
81+
#define PIN_LCD_DB7 6 // *
82+
#endif
83+
84+
// the hardware UART to use for SIO bus communication
85+
#ifdef ARDUINO_MEGA
86+
#define SIO_UART Serial1
87+
#define SIO_CALLBACK serialEvent1
88+
#else
89+
#define SIO_UART Serial
90+
#define SIO_CALLBACK serialEvent
91+
#endif
92+
93+
/**
94+
* Logging/debug config
95+
*/
96+
#ifdef DEBUG
97+
#define LOGGING_UART Serial
98+
#define LOG_MSG(...) LOGGING_UART.print(__VA_ARGS__)
99+
#define LOG_MSG_CR(...) LOGGING_UART.println(__VA_ARGS__)
100+
#else
101+
#define LOG_MSG(...)
102+
#define LOG_MSG_CR(...)
103+
#endif
104+
60105
#endif

disk_drive.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
2323
#include "disk_drive.h"
24-
#include "log.h"
2524

2625
DiskDrive::DiskDrive() {
2726
// reset device status

disk_image.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
2323
#include "disk_image.h"
24-
#include "log.h"
24+
#include "config.h"
2525

2626
DiskImage::DiskImage() {
2727
m_fileRef = NULL;
@@ -41,8 +41,13 @@ boolean DiskImage::setFile(File* file) {
4141
if (loadFile(file)) {
4242
// create new sector buffer
4343
m_sectorBuffer.data = (byte*)malloc(sizeof(byte) * m_sectorSize);
44-
LOG_MSG_CR(file->name());
45-
return true;
44+
if (!m_sectorBuffer.data) {
45+
LOG_MSG_CR("Unable to allocate memory for sector buffer");
46+
return false;
47+
} else {
48+
LOG_MSG_CR(file->name());
49+
return true;
50+
}
4651
} else {
4752
m_fileRef = NULL;
4853
}

log.h

Lines changed: 0 additions & 9 deletions
This file was deleted.

sio_channel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
2323
#include "sio_channel.h"
24-
#include "log.h"
24+
#include "config.h"
2525

2626
SIOChannel::SIOChannel(int cmdPin, Stream* stream, DriveAccess *driveAccess, DriveControl *driveControl) {
2727
m_cmdPin = cmdPin;

0 commit comments

Comments
 (0)