replace NES defines with rgbLed function calls

This commit is contained in:
smesgr9000 2024-05-26 22:43:41 +02:00
parent 363d18b542
commit cb111077f8
5 changed files with 34 additions and 44 deletions

View File

@ -113,6 +113,7 @@ typedef enum COLOR_T {
turquoise_color, turquoise_color,
yellow_color, yellow_color,
white_color, white_color,
black_color,
} color_t; } color_t;
// Graphic I2C OLED // Graphic I2C OLED
@ -1450,7 +1451,7 @@ void selfTest() {
display_Update(); display_Update();
if (!digitalRead(7)) { if (!digitalRead(7)) {
setColor_RGB(255, 0, 0); rgbLed(red_color);
errorLvl = 1; errorLvl = 1;
println_Msg(F("Error")); println_Msg(F("Error"));
println_Msg(FS(FSTRING_EMPTY)); println_Msg(FS(FSTRING_EMPTY));
@ -1474,7 +1475,7 @@ void selfTest() {
for (byte pinNumber = 2; pinNumber <= 69; pinNumber++) { for (byte pinNumber = 2; pinNumber <= 69; pinNumber++) {
if (isPin_2t9_14t17_22t37_42t49_54t69(pinNumber)) { if (isPin_2t9_14t17_22t37_42t49_54t69(pinNumber)) {
if (!digitalRead(pinNumber)) { if (!digitalRead(pinNumber)) {
setColor_RGB(255, 0, 0); rgbLed(red_color);
errorLvl = 1; errorLvl = 1;
print_Msg(F("Error: Pin ")); print_Msg(F("Error: Pin "));
if ((54 <= pinNumber) && (pinNumber <= 69)) { if ((54 <= pinNumber) && (pinNumber <= 69)) {
@ -1505,7 +1506,7 @@ void selfTest() {
if (isPin_2t9_14t17_22t37_42t49_54t69(pinNumber2) && (pinNumber != pinNumber2)) { if (isPin_2t9_14t17_22t37_42t49_54t69(pinNumber2) && (pinNumber != pinNumber2)) {
pinMode(pinNumber2, INPUT_PULLUP); pinMode(pinNumber2, INPUT_PULLUP);
if (!digitalRead(pinNumber2)) { if (!digitalRead(pinNumber2)) {
setColor_RGB(255, 0, 0); rgbLed(red_color);
errorLvl = 1; errorLvl = 1;
print_Msg(F("Error: Pin ")); print_Msg(F("Error: Pin "));
if ((54 <= pinNumber) && (pinNumber <= 69)) { if ((54 <= pinNumber) && (pinNumber <= 69)) {
@ -1538,7 +1539,7 @@ void selfTest() {
println_Msg(F("Testing Clock Generator")); println_Msg(F("Testing Clock Generator"));
initializeClockOffset(); initializeClockOffset();
if (!i2c_found) { if (!i2c_found) {
setColor_RGB(255, 0, 0); rgbLed(red_color);
errorLvl = 1; errorLvl = 1;
println_Msg(F("Error: Clock Generator")); println_Msg(F("Error: Clock Generator"));
println_Msg(F("not found")); println_Msg(F("not found"));
@ -2095,7 +2096,7 @@ void setup() {
Serial.println(F("Cartridge Reader")); Serial.println(F("Cartridge Reader"));
Serial.println(F("2024 github.com/sanni")); Serial.println(F("2024 github.com/sanni"));
// LED Error // LED Error
setColor_RGB(0, 0, 255); rgbLed(blue_color);
# endif /* ENABLE_SERIAL */ # endif /* ENABLE_SERIAL */
// Init SD card // Init SD card
@ -2262,7 +2263,7 @@ void convertPgm(const char* const pgmOptions[], byte numArrays) {
void _print_Error(void) { void _print_Error(void) {
errorLvl = 1; errorLvl = 1;
setColor_RGB(255, 0, 0); rgbLed(red_color);
display_Update(); display_Update();
} }
@ -2663,6 +2664,9 @@ void rgbLed(byte Color) {
case white_color: case white_color:
setColor_RGB(255, 255, 255); setColor_RGB(255, 255, 255);
break; break;
case black_color:
setColor_RGB(0, 0, 0);
break;
} }
} }
@ -2895,7 +2899,7 @@ unsigned char questionBox_Display(const __FlashStringHelper* question, char answ
} }
// pass on user choice // pass on user choice
setColor_RGB(0, 0, 0); rgbLed(black_color);
#ifdef ENABLE_GLOBAL_LOG #ifdef ENABLE_GLOBAL_LOG
println_Msg(FS(FSTRING_EMPTY)); println_Msg(FS(FSTRING_EMPTY));
@ -3222,7 +3226,7 @@ uint8_t checkButton() {
buttonState = reading; buttonState = reading;
// Button was pressed down // Button was pressed down
if (buttonState == 0) { if (buttonState == 0) {
setColor_RGB(0, 0, 0); rgbLed(black_color);
unsigned long pushTime = millis(); unsigned long pushTime = millis();
// Wait until button was let go again // Wait until button was let go again
while ((PING & (1 << PING2)) >> PING2 == 0) { while ((PING & (1 << PING2)) >> PING2 == 0) {

View File

@ -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_HI PORTF |= (1 << 2)
#define CHR_WRITE_LOW 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 \ #define MODE_READ \
{ \ { \
PORTK = 0xFF; \ PORTK = 0xFF; \
@ -436,9 +428,7 @@ void setup_NES() {
DDRK = 0; DDRK = 0;
set_address(0); set_address(0);
LED_RED_OFF; rgbLed(black_color);
LED_GREEN_OFF;
LED_BLUE_OFF;
} }
/****************************************** /******************************************
@ -948,7 +938,7 @@ FsFile createNewFile(const char* prefix, const char* extension) {
// Could not find an available name, recompose the original name and error out. // 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); snprintf_P(filename, sizeof(filename), _file_name_no_number_fmt, prefix, extension);
LED_RED_ON; rgbLed(red_color);
display_Clear(); display_Clear();
print_Msg(filename); print_Msg(filename);
@ -956,7 +946,7 @@ FsFile createNewFile(const char* prefix, const char* extension) {
display_Update(); display_Update();
print_FatalError(sd_error_STR); print_FatalError(sd_error_STR);
LED_RED_OFF; rgbLed(black_color);
} }
void CreatePRGFileInSD() { void CreatePRGFileInSD() {
@ -987,14 +977,14 @@ void CreateRAMFileInSD() {
strcat(fileName, ".bin"); strcat(fileName, ".bin");
} }
if (!myFile) { if (!myFile) {
LED_RED_ON; rgbLed(red_color);
display_Clear(); display_Clear();
println_Msg(F("RAM FILE FAILED!")); println_Msg(F("RAM FILE FAILED!"));
display_Update(); display_Update();
//print_Error(F("SD Error"), true); //print_Error(F("SD Error"), true);
LED_RED_OFF; rgbLed(black_color);
} }
} }
@ -1676,7 +1666,7 @@ void readPRG(bool readrom) {
display_Clear(); display_Clear();
display_Update(); display_Update();
LED_BLUE_ON; rgbLed(blue_color);
set_address(0); set_address(0);
_delay_us(1); _delay_us(1);
CreatePRGFileInSD(); CreatePRGFileInSD();
@ -2692,7 +2682,7 @@ void readPRG(bool readrom) {
set_address(0); set_address(0);
PHI2_HI; PHI2_HI;
ROMSEL_HI; ROMSEL_HI;
LED_BLUE_OFF; rgbLed(black_color);
} }
void readCHR(bool readrom) { void readCHR(bool readrom) {
@ -2703,7 +2693,7 @@ void readCHR(bool readrom) {
uint16_t banks; uint16_t banks;
LED_GREEN_ON; rgbLed(green_color);
set_address(0); set_address(0);
_delay_us(1); _delay_us(1);
if (chrsize == 0) { if (chrsize == 0) {
@ -3533,7 +3523,7 @@ void readCHR(bool readrom) {
set_address(0); set_address(0);
PHI2_HI; PHI2_HI;
ROMSEL_HI; ROMSEL_HI;
LED_GREEN_OFF; rgbLed(black_color);
} }
/****************************************** /******************************************
@ -3545,8 +3535,7 @@ void readRAM() {
uint16_t banks; uint16_t banks;
LED_BLUE_ON; rgbLed(turquoise_color);
LED_GREEN_ON;
set_address(0); set_address(0);
_delay_us(1); _delay_us(1);
if (ramsize == 0) { if (ramsize == 0) {
@ -3715,8 +3704,7 @@ void readRAM() {
set_address(0); set_address(0);
PHI2_HI; PHI2_HI;
ROMSEL_HI; ROMSEL_HI;
LED_BLUE_OFF; rgbLed(black_color);
LED_GREEN_OFF;
} }
void writeBankPRG(const size_t from, const size_t to, const size_t base) { void writeBankPRG(const size_t from, const size_t to, const size_t base) {
@ -3920,7 +3908,7 @@ void writeRAM() {
break; break;
} }
myFile.close(); myFile.close();
LED_GREEN_ON; rgbLed(green_color);
println_Msg(FS(FSTRING_EMPTY)); println_Msg(FS(FSTRING_EMPTY));
println_Msg(F("RAM FILE WRITTEN!")); println_Msg(F("RAM FILE WRITTEN!"));
@ -3931,8 +3919,7 @@ void writeRAM() {
} }
} }
LED_RED_OFF; rgbLed(black_color);
LED_GREEN_OFF;
sd.chdir(); // root sd.chdir(); // root
filePath[0] = '\0'; // Reset filePath filePath[0] = '\0'; // Reset filePath
} }
@ -4203,7 +4190,7 @@ void NESmaker_ChipErase() { // Typical 70ms
void writeFLASH() { void writeFLASH() {
display_Clear(); display_Clear();
if (!flashfound) { if (!flashfound) {
LED_RED_ON; rgbLed(red_color);
println_Msg(F("FLASH NOT DETECTED")); println_Msg(F("FLASH NOT DETECTED"));
display_Update(); display_Update();
} else { } else {
@ -4221,7 +4208,7 @@ void writeFLASH() {
sd.chdir(); sd.chdir();
sprintf(filePath, "%s/%s", filePath, fileName); sprintf(filePath, "%s/%s", filePath, fileName);
LED_RED_ON; rgbLed(red_color);
display_Clear(); display_Clear();
println_Msg(F("Writing File: ")); println_Msg(F("Writing File: "));
println_Msg(filePath); println_Msg(filePath);
@ -4272,20 +4259,19 @@ void writeFLASH() {
#endif #endif
} }
myFile.close(); myFile.close();
LED_GREEN_ON; rgbLed(green_color);
println_Msg(FS(FSTRING_EMPTY)); println_Msg(FS(FSTRING_EMPTY));
println_Msg(F("FLASH FILE WRITTEN!")); println_Msg(F("FLASH FILE WRITTEN!"));
display_Update(); display_Update();
} else { } else {
LED_RED_ON; rgbLed(red_color);
println_Msg(F("SD ERROR")); println_Msg(F("SD ERROR"));
display_Update(); display_Update();
} }
} }
display_Clear(); display_Clear();
LED_RED_OFF; rgbLed(black_color);
LED_GREEN_OFF;
sd.chdir(); // root sd.chdir(); // root
filePath[0] = '\0'; // Reset filePath filePath[0] = '\0'; // Reset filePath
} }

View File

@ -723,7 +723,7 @@ void getCartInfo_SFM() {
if (checkcart_SFM() == 0) { if (checkcart_SFM() == 0) {
// Checksum either corrupt or 0000 // Checksum either corrupt or 0000
errorLvl = 1; errorLvl = 1;
setColor_RGB(255, 0, 0); rgbLed(red_color);
display_Clear(); display_Clear();
println_Msg(F("ERROR")); println_Msg(F("ERROR"));
println_Msg(F("Rom header corrupt")); println_Msg(F("Rom header corrupt"));

View File

@ -391,7 +391,7 @@ void getCartInfo_SMS() {
default: default:
cartSize = 48 * 1024UL; cartSize = 48 * 1024UL;
// LED Error // LED Error
setColor_RGB(0, 0, 255); rgbLed(blue_color);
break; break;
} }
@ -542,7 +542,7 @@ void getCartInfo_SMS() {
#endif #endif
// Turn off LED // Turn off LED
setColor_RGB(0, 0, 0); rgbLed(black_color);
} }
//****************************************** //******************************************

View File

@ -740,7 +740,7 @@ void getCartInfo_SNES() {
// Checksum either corrupt or 0000 // Checksum either corrupt or 0000
manualConfig = 1; manualConfig = 1;
errorLvl = 1; errorLvl = 1;
setColor_RGB(255, 0, 0); rgbLed(red_color);
display_Clear(); display_Clear();
println_Msg(F("ERROR")); println_Msg(F("ERROR"));