Skip to content

Commit

Permalink
replace NES defines with rgbLed function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
smesgr9000 committed May 26, 2024
1 parent 363d18b commit cb11107
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 44 deletions.
20 changes: 12 additions & 8 deletions Cart_Reader/Cart_Reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ typedef enum COLOR_T {
turquoise_color,
yellow_color,
white_color,
black_color,
} color_t;

// Graphic I2C OLED
Expand Down Expand Up @@ -1450,7 +1451,7 @@ void selfTest() {
display_Update();

if (!digitalRead(7)) {
setColor_RGB(255, 0, 0);
rgbLed(red_color);
errorLvl = 1;
println_Msg(F("Error"));
println_Msg(FS(FSTRING_EMPTY));
Expand All @@ -1474,7 +1475,7 @@ void selfTest() {
for (byte pinNumber = 2; pinNumber <= 69; pinNumber++) {
if (isPin_2t9_14t17_22t37_42t49_54t69(pinNumber)) {
if (!digitalRead(pinNumber)) {
setColor_RGB(255, 0, 0);
rgbLed(red_color);
errorLvl = 1;
print_Msg(F("Error: Pin "));
if ((54 <= pinNumber) && (pinNumber <= 69)) {
Expand Down Expand Up @@ -1505,7 +1506,7 @@ void selfTest() {
if (isPin_2t9_14t17_22t37_42t49_54t69(pinNumber2) && (pinNumber != pinNumber2)) {
pinMode(pinNumber2, INPUT_PULLUP);
if (!digitalRead(pinNumber2)) {
setColor_RGB(255, 0, 0);
rgbLed(red_color);
errorLvl = 1;
print_Msg(F("Error: Pin "));
if ((54 <= pinNumber) && (pinNumber <= 69)) {
Expand Down Expand Up @@ -1538,7 +1539,7 @@ void selfTest() {
println_Msg(F("Testing Clock Generator"));
initializeClockOffset();
if (!i2c_found) {
setColor_RGB(255, 0, 0);
rgbLed(red_color);
errorLvl = 1;
println_Msg(F("Error: Clock Generator"));
println_Msg(F("not found"));
Expand Down Expand Up @@ -2095,7 +2096,7 @@ void setup() {
Serial.println(F("Cartridge Reader"));
Serial.println(F("2024 github.com/sanni"));
// LED Error
setColor_RGB(0, 0, 255);
rgbLed(blue_color);
# endif /* ENABLE_SERIAL */

// Init SD card
Expand Down Expand Up @@ -2262,7 +2263,7 @@ void convertPgm(const char* const pgmOptions[], byte numArrays) {

void _print_Error(void) {
errorLvl = 1;
setColor_RGB(255, 0, 0);
rgbLed(red_color);
display_Update();
}

Expand Down Expand Up @@ -2663,6 +2664,9 @@ void rgbLed(byte Color) {
case white_color:
setColor_RGB(255, 255, 255);
break;
case black_color:
setColor_RGB(0, 0, 0);
break;
}
}

Expand Down Expand Up @@ -2895,7 +2899,7 @@ unsigned char questionBox_Display(const __FlashStringHelper* question, char answ
}

// pass on user choice
setColor_RGB(0, 0, 0);
rgbLed(black_color);

#ifdef ENABLE_GLOBAL_LOG
println_Msg(FS(FSTRING_EMPTY));
Expand Down Expand Up @@ -3222,7 +3226,7 @@ uint8_t checkButton() {
buttonState = reading;
// Button was pressed down
if (buttonState == 0) {
setColor_RGB(0, 0, 0);
rgbLed(black_color);
unsigned long pushTime = millis();
// Wait until button was let go again
while ((PING & (1 << PING2)) >> PING2 == 0) {
Expand Down
50 changes: 18 additions & 32 deletions Cart_Reader/NES.ino
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,6 @@ const char _file_name_with_number_fmt[] PROGMEM = "%s.%02d.%s";
#define CHR_WRITE_HI PORTF |= (1 << 2)
#define CHR_WRITE_LOW PORTF &= ~(1 << 2)

// RGB LED COMMON ANODE
#define LED_RED_OFF setColor_RGB(0, 0, 0)
#define LED_RED_ON setColor_RGB(255, 0, 0)
#define LED_GREEN_OFF setColor_RGB(0, 0, 0)
#define LED_GREEN_ON setColor_RGB(0, 255, 0)
#define LED_BLUE_OFF setColor_RGB(0, 0, 0)
#define LED_BLUE_ON setColor_RGB(0, 0, 255)

#define MODE_READ \
{ \
PORTK = 0xFF; \
Expand Down Expand Up @@ -436,9 +428,7 @@ void setup_NES() {
DDRK = 0;

set_address(0);
LED_RED_OFF;
LED_GREEN_OFF;
LED_BLUE_OFF;
rgbLed(black_color);
}

/******************************************
Expand Down Expand Up @@ -948,15 +938,15 @@ FsFile createNewFile(const char* prefix, const char* extension) {
// Could not find an available name, recompose the original name and error out.
snprintf_P(filename, sizeof(filename), _file_name_no_number_fmt, prefix, extension);

LED_RED_ON;
rgbLed(red_color);

display_Clear();
print_Msg(filename);
println_Msg(F(": no available name"));
display_Update();
print_FatalError(sd_error_STR);

LED_RED_OFF;
rgbLed(black_color);
}

void CreatePRGFileInSD() {
Expand Down Expand Up @@ -987,14 +977,14 @@ void CreateRAMFileInSD() {
strcat(fileName, ".bin");
}
if (!myFile) {
LED_RED_ON;
rgbLed(red_color);

display_Clear();
println_Msg(F("RAM FILE FAILED!"));
display_Update();
//print_Error(F("SD Error"), true);

LED_RED_OFF;
rgbLed(black_color);
}
}

Expand Down Expand Up @@ -1676,7 +1666,7 @@ void readPRG(bool readrom) {
display_Clear();
display_Update();

LED_BLUE_ON;
rgbLed(blue_color);
set_address(0);
_delay_us(1);
CreatePRGFileInSD();
Expand Down Expand Up @@ -2692,7 +2682,7 @@ void readPRG(bool readrom) {
set_address(0);
PHI2_HI;
ROMSEL_HI;
LED_BLUE_OFF;
rgbLed(black_color);
}

void readCHR(bool readrom) {
Expand All @@ -2703,7 +2693,7 @@ void readCHR(bool readrom) {

uint16_t banks;

LED_GREEN_ON;
rgbLed(green_color);
set_address(0);
_delay_us(1);
if (chrsize == 0) {
Expand Down Expand Up @@ -3533,7 +3523,7 @@ void readCHR(bool readrom) {
set_address(0);
PHI2_HI;
ROMSEL_HI;
LED_GREEN_OFF;
rgbLed(black_color);
}

/******************************************
Expand All @@ -3545,8 +3535,7 @@ void readRAM() {

uint16_t banks;

LED_BLUE_ON;
LED_GREEN_ON;
rgbLed(turquoise_color);
set_address(0);
_delay_us(1);
if (ramsize == 0) {
Expand Down Expand Up @@ -3715,8 +3704,7 @@ void readRAM() {
set_address(0);
PHI2_HI;
ROMSEL_HI;
LED_BLUE_OFF;
LED_GREEN_OFF;
rgbLed(black_color);
}

void writeBankPRG(const size_t from, const size_t to, const size_t base) {
Expand Down Expand Up @@ -3920,7 +3908,7 @@ void writeRAM() {
break;
}
myFile.close();
LED_GREEN_ON;
rgbLed(green_color);

println_Msg(FS(FSTRING_EMPTY));
println_Msg(F("RAM FILE WRITTEN!"));
Expand All @@ -3931,8 +3919,7 @@ void writeRAM() {
}
}

LED_RED_OFF;
LED_GREEN_OFF;
rgbLed(black_color);
sd.chdir(); // root
filePath[0] = '\0'; // Reset filePath
}
Expand Down Expand Up @@ -4203,7 +4190,7 @@ void NESmaker_ChipErase() { // Typical 70ms
void writeFLASH() {
display_Clear();
if (!flashfound) {
LED_RED_ON;
rgbLed(red_color);
println_Msg(F("FLASH NOT DETECTED"));
display_Update();
} else {
Expand All @@ -4221,7 +4208,7 @@ void writeFLASH() {
sd.chdir();
sprintf(filePath, "%s/%s", filePath, fileName);

LED_RED_ON;
rgbLed(red_color);
display_Clear();
println_Msg(F("Writing File: "));
println_Msg(filePath);
Expand Down Expand Up @@ -4272,20 +4259,19 @@ void writeFLASH() {
#endif
}
myFile.close();
LED_GREEN_ON;
rgbLed(green_color);

println_Msg(FS(FSTRING_EMPTY));
println_Msg(F("FLASH FILE WRITTEN!"));
display_Update();
} else {
LED_RED_ON;
rgbLed(red_color);
println_Msg(F("SD ERROR"));
display_Update();
}
}
display_Clear();
LED_RED_OFF;
LED_GREEN_OFF;
rgbLed(black_color);
sd.chdir(); // root
filePath[0] = '\0'; // Reset filePath
}
Expand Down
2 changes: 1 addition & 1 deletion Cart_Reader/SFM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ void getCartInfo_SFM() {
if (checkcart_SFM() == 0) {
// Checksum either corrupt or 0000
errorLvl = 1;
setColor_RGB(255, 0, 0);
rgbLed(red_color);
display_Clear();
println_Msg(F("ERROR"));
println_Msg(F("Rom header corrupt"));
Expand Down
4 changes: 2 additions & 2 deletions Cart_Reader/SMS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void getCartInfo_SMS() {
default:
cartSize = 48 * 1024UL;
// LED Error
setColor_RGB(0, 0, 255);
rgbLed(blue_color);
break;
}

Expand Down Expand Up @@ -542,7 +542,7 @@ void getCartInfo_SMS() {
#endif

// Turn off LED
setColor_RGB(0, 0, 0);
rgbLed(black_color);
}

//******************************************
Expand Down
2 changes: 1 addition & 1 deletion Cart_Reader/SNES.ino
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ void getCartInfo_SNES() {
// Checksum either corrupt or 0000
manualConfig = 1;
errorLvl = 1;
setColor_RGB(255, 0, 0);
rgbLed(red_color);

display_Clear();
println_Msg(F("ERROR"));
Expand Down

0 comments on commit cb11107

Please sign in to comment.