Skip to content

Commit

Permalink
code reduction & cleanup (#2920)
Browse files Browse the repository at this point in the history
  • Loading branch information
digant73 committed Mar 25, 2024
1 parent a6ef076 commit 540ab0c
Show file tree
Hide file tree
Showing 281 changed files with 4,652 additions and 4,025 deletions.
2 changes: 1 addition & 1 deletion TFT/src/User/API/AddonHardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void FIL_SFS_SetAlive(bool alive)
sfs_alive = alive;
}

bool FIL_NormalRunoutDetect(void)
static bool FIL_NormalRunoutDetect(void)
{
static bool runout = false;
static int32_t trigBalance = 0;
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/BuzzerControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {
#endif

#include <stdbool.h>
#include "variants.h" // for BUZZER_PIN etc...
#include "variants.h" // for BUZZER_PIN etc.

typedef enum
{
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/FanControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define FAN_REFRESH_TIME 500 // 1 second is 1000

const char * fanID[MAX_FAN_COUNT] = FAN_DISPLAY_ID;
const char * fanID[MAX_FAN_COUNT] = FAN_DISPLAY_ID;
const char * fanCmd[MAX_FAN_COUNT] = FAN_CMD;

static uint8_t setFanSpeed[MAX_FAN_COUNT] = {0};
Expand Down
13 changes: 10 additions & 3 deletions TFT/src/User/API/FlashStore.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,31 @@ enum
PARA_NOT_STORED = (1 << 1),
};

uint8_t paraStatus = 0;
static uint8_t paraStatus = 0;

void wordToByte(uint32_t word, uint8_t *bytes)
static void wordToByte(uint32_t word, uint8_t * bytes)
{
uint8_t len = 4;
uint8_t i = 0;

for (i = 0; i < len; i++)
{
bytes[i] = (word >> 24) & 0xFF;
word <<= 8;
}
}

uint32_t byteToWord(uint8_t *bytes, uint8_t len)
static uint32_t byteToWord(uint8_t * bytes, uint8_t len)
{
uint32_t word = 0;
uint8_t i = 0;

for (i = 0; i < len; i++)
{
word <<= 8;
word |= bytes[i];
}

return word;
}

Expand All @@ -55,16 +58,19 @@ void readStoredPara(void)
#endif

sign = byteToWord(data + (index += 4), 4);

if (sign == TSC_SIGN)
{
paraStatus |= PARA_TSC_EXIST; // if the touch screen calibration parameter already exists

for (int i = 0; i < sizeof(TS_CalPara) / sizeof(TS_CalPara[0]); i++)
{
TS_CalPara[i] = byteToWord(data + (index += 4), 4);
}
}

sign = byteToWord(data + (index += 4), 4);

if (sign != PARA_SIGN) // if the settings parameter is illegal, reset settings parameter
{
paraStatus |= PARA_NOT_STORED;
Expand All @@ -83,6 +89,7 @@ void storePara(void)
uint32_t index = 0;

wordToByte(TSC_SIGN, data + (index += 4));

for (int i = 0; i < sizeof(TS_CalPara) / sizeof(TS_CalPara[0]); i++)
{
wordToByte(TS_CalPara[i], data + (index += 4));
Expand Down
78 changes: 39 additions & 39 deletions TFT/src/User/API/Gcode/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ void abortRequestCommandInfo(void)
}

static void resetRequestCommandInfo(
const char * string_start, // The magic to identify the start
const char * string_stop, // The magic to identify the stop
const char * string_error0, // The first magic to identify the error response
const char * string_error1, // The second error magic
const char * string_error2 // The third error magic
const char * string_start, // the magic to identify the start
const char * string_stop, // the magic to identify the stop
const char * string_error0, // the first magic to identify the error response
const char * string_error1, // the second error magic
const char * string_error2 // the third error magic
)
{
clearRequestCommandInfo(); // release requestCommandInfo.cmd_rev_buf before allocating a new one
Expand Down Expand Up @@ -81,11 +81,11 @@ void detectAdvancedOk(void)

TASK_LOOP_WHILE(isPendingCmd() && isNotEmptyCmdQueue()); // wait for the communication to be clean

resetRequestCommandInfo("ok", // The magic to identify the start
"ok", // The magic to identify the stop
NULL, // The first magic to identify the error response
NULL, // The second error magic
NULL); // The third error magic
resetRequestCommandInfo("ok", // the magic to identify the start
"ok", // the magic to identify the stop
NULL, // the first magic to identify the error response
NULL, // the second error magic
NULL); // the third error magic

// send any gcode replied by the mainboard with a regular OK response ("ok\n") or an ADVANCED_OK response (e.g. "ok N10 P15 B3\n")
mustStoreCmd("M220\n");
Expand Down Expand Up @@ -118,29 +118,29 @@ void detectAdvancedOk(void)
*/
bool request_M21(void)
{
resetRequestCommandInfo("SD card ", // The magic to identify the start
"ok", // The magic to identify the stop
"No SD card", // The first magic to identify the error response
"SD init fail", // The second error magic
"volume.init failed"); // The third error magic
resetRequestCommandInfo("SD card ", // the magic to identify the start
"ok", // the magic to identify the stop
"No SD card", // the first magic to identify the error response
"SD init fail", // the second error magic
"volume.init failed"); // the third error magic

mustStoreCmd((infoMachineSettings.multiVolume == ENABLED) ? ((infoFile.onboardSource == BOARD_SD) ? "M21 S\n" : "M21 U\n") : "M21\n");

waitForResponse(); // wait for response

clearRequestCommandInfo();

// Check reponse
// check reponse
return !requestCommandInfo.inError;
}

char * request_M20(void)
{
resetRequestCommandInfo("Begin file list", // The magic to identify the start
"End file list", // The magic to identify the stop
"Error", // The first magic to identify the error response
NULL, // The second error magic
NULL); // The third error magic
resetRequestCommandInfo("Begin file list", // the magic to identify the start
"End file list", // the magic to identify the stop
"Error", // the first magic to identify the error response
NULL, // the second error magic
NULL); // the third error magic

if (infoMachineSettings.longFilename == ENABLED) // if long filename is supported
mustStoreCmd("M20 L\n"); // L option is supported since Marlin 2.0.9
Expand All @@ -149,7 +149,7 @@ char * request_M20(void)

waitForResponse(); // wait for response

//clearRequestCommandInfo(); // shall be call after copying the buffer ...
//clearRequestCommandInfo(); // shall be call after copying the buffer
return requestCommandInfo.cmd_rev_buf;
}

Expand All @@ -161,11 +161,11 @@ char * request_M20(void)
*/
char * request_M33(const char * filename)
{
resetRequestCommandInfo("/", // The magic to identify the start
"ok", // The magic to identify the stop
"Cannot open subdir", // The first magic to identify the error response
NULL, // The second error magic
NULL); // The third error magic
resetRequestCommandInfo("/", // the magic to identify the start
"ok", // the magic to identify the stop
"Cannot open subdir", // the first magic to identify the error response
NULL, // the second error magic
NULL); // the third error magic

if (filename[0] != '/')
mustStoreCmd("M33 /%s\n", filename); // append '/' to short file path
Expand Down Expand Up @@ -199,11 +199,11 @@ long request_M23_M36(const char * filename)

if (infoMachineSettings.firmwareType != FW_REPRAPFW) // all other firmwares except RepRap firmware
{
resetRequestCommandInfo("File opened", // The magic to identify the start
"File selected", // The magic to identify the stop
"open failed", // The first magic to identify the error response
NULL, // The second error magic
NULL); // The third error magic
resetRequestCommandInfo("File opened", // the magic to identify the start
"File selected", // the magic to identify the stop
"open failed", // the first magic to identify the error response
NULL, // the second error magic
NULL); // the third error magic

// skip source and first "/" character (e.g. "oMD:/sub_dir/cap2.gcode" -> "sub_dir/cap2.gcode")
mustStoreCmd("M23 %s\n", filename + strlen(getFS()) + 1);
Expand All @@ -212,11 +212,11 @@ long request_M23_M36(const char * filename)
}
else // RepRap firmware
{
resetRequestCommandInfo("{\"err\"", // The magic to identify the start
"}", // The magic to identify the stop
"Error:", // The first magic to identify the error response
NULL, // The second error magic
NULL); // The third error magic
resetRequestCommandInfo("{\"err\"", // the magic to identify the start
"}", // the magic to identify the stop
"Error:", // the first magic to identify the error response
NULL, // the second error magic
NULL); // the third error magic

mustStoreCmd("M36 /%s\n", filename);

Expand All @@ -235,7 +235,7 @@ long request_M23_M36(const char * filename)
if (infoMachineSettings.firmwareType == FW_REPRAPFW)
mustStoreCmd("M23 /%s\n", filename); // send M23 for RepRap firmware

// Find file size and report it
// find file size and report it
strPtr = strstr(requestCommandInfo.cmd_rev_buf, sizeTag);

if (strPtr != NULL)
Expand Down Expand Up @@ -309,7 +309,7 @@ void request_M98(const char * filename)

rrfStatusQueryFast();

// Wait for macro to complete
// wait for macro to complete
TASK_LOOP_WHILE(rrfStatusIsBusy());

rrfStatusQueryNormal();
Expand Down
23 changes: 11 additions & 12 deletions TFT/src/User/API/Gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ typedef void (* FP_STREAM_HANDLER)(const char *);

typedef struct
{
char * cmd_rev_buf; // Buffer where store the command response
const char * startMagic; // The magic to identify the start
const char * stopMagic; // The magic to identify the stop
const char * errorMagic[MAX_ERROR_NUM];
// The magic to identify the error response
// Some gcodes respond to multiple errors, such as M21 - "SD card failed", "No SD card", "volume.init failed"
uint8_t error_num; // Number of error magic corresponding to current gcode
bool inResponse; // true if between start and stop magic
bool inWaitResponse; // true if waiting for start magic
bool done; // true if command is executed and response is received
bool inError; // true if error response
bool inJson; // true if !inResponse and !inWaitResponse and '{' is found
char * cmd_rev_buf; // buffer where store the command response
const char * startMagic; // the magic to identify the start
const char * stopMagic; // the magic to identify the stop
const char * errorMagic[MAX_ERROR_NUM]; // the magic to identify the error response. Some gcodes respond to multiple errors,
// such as M21 - "SD card failed", "No SD card", "volume.init failed"
uint8_t error_num; // number of error magic corresponding to current gcode
bool inResponse; // "true" if between start and stop magic
bool inWaitResponse; // "true" if waiting for start magic
bool done; // "true" if command is executed and response is received
bool inError; // "true" if error response
bool inJson; // "true" if !inResponse and !inWaitResponse and '{' is found
FP_STREAM_HANDLER stream_handler;
} REQUEST_COMMAND_INFO;

Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/Gcode/mygcodefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static inline void rrfScanPrintFilesGcodeFs(void)
*
* So the long name will be parsed "0.00 @:0 B@:0" instead of "1.gcode" if the truncated character is "\n" not string "\nok"
*/
void addName(bool isFile, char * longPath, const char * shortPath, const char * relativePath)
static void addName(bool isFile, char * longPath, const char * shortPath, const char * relativePath)
{
char * longName = NULL; // initialize to NULL in case long filename is not supported or no long name exists

Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/HW_Init.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "i2c_eeprom.h"
#endif

void HW_GetClocksFreq(CLOCKS *clk)
static inline void HW_GetClocksFreq(CLOCKS * clk)
{
#if defined(GD32F2XX) || defined(GD32F3XX)
RCU_GetClocksFreq(&clk->rccClocks);
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/LCD_Colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ extern "C" {
#endif

#include <stdint.h>
#include "Configuration.h" // for KEYBOARD_MATERIAL_THEME, LIVE_TEXT_COMMON_COLOR etc...
#include "Configuration.h" // for KEYBOARD_MATERIAL_THEME, LIVE_TEXT_COMMON_COLOR etc.
#include "menu.h"

// Color Definition
// color definition
#define WHITE 0xFFFF
#define BLACK 0x0000
#define RED 0xF800
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/LCD_Dimming.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef struct
bool locked;
} LCD_AUTO_DIM;

LCD_AUTO_DIM lcd_dim = {0, false, false};
static LCD_AUTO_DIM lcd_dim = {0, false, false};

bool LCD_IsBlocked(void)
{
Expand Down Expand Up @@ -160,7 +160,7 @@ void LCD_CheckDimming(void)

#ifdef KNOB_LED_COLOR_PIN

bool knob_led_idle = false;
static bool knob_led_idle = false;

void LCD_SetKnobLedIdle(bool enabled)
{
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/LCD_Dimming.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

#include "variants.h" // for LCD_LED_PWM_CHANNEL, KNOB_LED_COLOR_PIN etc...
#include "variants.h" // for LCD_LED_PWM_CHANNEL, KNOB_LED_COLOR_PIN etc.
#include "menu.h"

#ifdef LCD_LED_PWM_CHANNEL
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/LED_Colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ uint16_t LED_GetRGBColor(LED_COLOR * led)
uint8_t r = (*led)[0] >> 3;
uint8_t g = (*led)[1] >> 2;
uint8_t b = (*led)[2] >> 3;

return ((r & 0x001F) << 11) | ((g & 0x003F) << 5) | ((b & 0x001F)); // RGB color in RGB 565 16 bit format
}

Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/LED_Colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern "C" {
#define GRB_INDIGO 0x00004B82
#define GRB_VIOLET 0x0000FEFE

// Color macro // 颜色宏定 // R G B
// color macro // 颜色宏定 // R G B
#define COLOR_LIGHTPINK 0xFFB6C1 // 浅粉
#define COLOR_PINK 0xFFC0CB // 粉红
#define COLOR_CRIMSON 0xDC143C // 猩红
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/LED_Event.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define COLD_TEMPERATURE 0
#endif

inline static bool nextUpdate(void)
static inline bool nextUpdate(void)
{
static uint32_t lastUpdateTime = 0;

Expand All @@ -29,7 +29,7 @@ inline static bool nextUpdate(void)

#ifdef ROOM_TEMPERATURE

void getColdTemperature(void)
static inline void getColdTemperature(void)
{ // let's estimate the room temperature
if (coldTemperature == 0)
{
Expand Down
Loading

0 comments on commit 540ab0c

Please sign in to comment.