Skip to content

Commit

Permalink
Clean up comments, USB flash, NULLs
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 25, 2020
1 parent 00fbe50 commit ec23e37
Show file tree
Hide file tree
Showing 45 changed files with 231 additions and 238 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
card.getSd2Card().readData(sector_buf);

// RAM -> USB
if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) {
if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
card.getSd2Card().readStop();
return CTRL_FAIL;
}
Expand Down Expand Up @@ -120,7 +120,7 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
while (nb_sector--) {

// USB -> RAM
if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) {
if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
card.getSd2Card().writeStop();
return CTRL_FAIL;
}
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/ESP32/i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int i2s_init() {

// Allocate the array of pointers to the buffers
dma.buffers = (uint32_t **)malloc(sizeof(uint32_t*) * DMA_BUF_COUNT);
if (dma.buffers == nullptr) return -1;
if (!dma.buffers) return -1;

// Allocate each buffer that can be used by the DMA controller
for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
Expand All @@ -194,7 +194,7 @@ int i2s_init() {

// Allocate the array of DMA descriptors
dma.desc = (lldesc_t**) malloc(sizeof(lldesc_t*) * DMA_BUF_COUNT);
if (dma.desc == nullptr) return -1;
if (!dma.desc) return -1;

// Allocate each DMA descriptor that will be used by the DMA controller
for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/LINUX/eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
bool PersistentStore::access_start() {
const char eeprom_erase_value = 0xFF;
FILE * eeprom_file = fopen(filename, "rb");
if (eeprom_file == nullptr) return false;
if (!eeprom_file) return false;

fseek(eeprom_file, 0L, SEEK_END);
std::size_t file_size = ftell(eeprom_file);
Expand All @@ -59,7 +59,7 @@ bool PersistentStore::access_start() {

bool PersistentStore::access_finish() {
FILE * eeprom_file = fopen(filename, "wb");
if (eeprom_file == nullptr) return false;
if (!eeprom_file) return false;
fwrite(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file);
fclose(eeprom_file);
return true;
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/HAL/LINUX/hardware/Gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ class Gpio {
GpioEvent::Type evt_type = value > 1 ? GpioEvent::SET_VALUE : value > pin_map[pin].value ? GpioEvent::RISE : value < pin_map[pin].value ? GpioEvent::FALL : GpioEvent::NOP;
pin_map[pin].value = value;
GpioEvent evt(Clock::nanos(), pin, evt_type);
if (pin_map[pin].cb != nullptr) {
if (pin_map[pin].cb) {
pin_map[pin].cb->interrupt(evt);
}
if (Gpio::logger != nullptr) Gpio::logger->log(evt);
if (Gpio::logger) Gpio::logger->log(evt);
}

static uint16_t get(pin_type pin) {
Expand All @@ -105,8 +105,8 @@ class Gpio {
if (!valid_pin(pin)) return;
pin_map[pin].mode = value;
GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETM);
if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt);
if (Gpio::logger != nullptr) Gpio::logger->log(evt);
if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt);
if (Gpio::logger) Gpio::logger->log(evt);
}

static uint8_t getMode(pin_type pin) {
Expand All @@ -118,8 +118,8 @@ class Gpio {
if (!valid_pin(pin)) return;
pin_map[pin].dir = value;
GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETD);
if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt);
if (Gpio::logger != nullptr) Gpio::logger->log(evt);
if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt);
if (Gpio::logger) Gpio::logger->log(evt);
}

static uint8_t getDir(pin_type pin) {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/SAMD51/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ uint16_t HAL_adc_result;
DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
DMA_STEPSEL_SRC // STEPSEL
);
if (descriptor != nullptr)
if (descriptor)
descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
adc0DMAProgram.startJob();
}
Expand Down Expand Up @@ -337,7 +337,7 @@ uint16_t HAL_adc_result;
DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
DMA_STEPSEL_SRC // STEPSEL
);
if (descriptor != nullptr)
if (descriptor)
descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
adc1DMAProgram.startJob();
}
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/SAMD51/QSPIFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ uint8_t QSPIFlash::_buf[SFLASH_SECTOR_SIZE];
uint32_t QSPIFlash::_addr = INVALID_ADDR;

void QSPIFlash::begin() {
if (_flashBase != nullptr) return;
if (_flashBase) return;

_flashBase = new Adafruit_SPIFlashBase(new Adafruit_FlashTransport_QSPI());
_flashBase->begin(NULL);
_flashBase->begin(nullptr);
}

size_t QSPIFlash::size() {
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/tft/xpt2046.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void XPT2046::Init() {
#endif
}
else {
SPIx.Instance = NULL;
SPIx.Instance = nullptr;
SET_INPUT(TOUCH_MISO_PIN);
SET_OUTPUT(TOUCH_MOSI_PIN);
SET_OUTPUT(TOUCH_SCK_PIN);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
// Private Variables
// ------------------------

HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL };
HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { nullptr };

// ------------------------
// Public functions
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void HAL_idletask();
#endif

#ifndef digitalPinHasPWM
#define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr)
#define digitalPinHasPWM(P) !!PIN_MAP[P].timer_device
#define NO_COMPILE_TIME_PWM
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ static const spi_pins* dev_to_spi_pins(spi_dev *dev) {
#if BOARD_NR_SPI >= 3
case RCC_SPI3: return board_spi_pins + 2;
#endif
default: return NULL;
default: return nullptr;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/fastio.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
#define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD)

#define PWM_PIN(IO) (PIN_MAP[IO].timer_device != nullptr)
#define PWM_PIN(IO) !!PIN_MAP[IO].timer_device

// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class GCodeParser {
#endif

// The code value pointer was set
FORCE_INLINE static bool has_value() { return value_ptr != nullptr; }
FORCE_INLINE static bool has_value() { return !!value_ptr; }

// Seen a parameter with a value
static inline bool seenval(const char c) { return seen(c) && has_value(); }
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ bool GCodeQueue::enqueue_one(const char* cmd) {
* Return 'true' if any commands were processed.
*/
bool GCodeQueue::process_injected_command_P() {
if (injected_commands_P == nullptr) return false;
if (!injected_commands_P) return false;

char c;
size_t i = 0;
Expand Down Expand Up @@ -480,7 +480,7 @@ void GCodeQueue::get_serial_commands() {

if (npos) {

bool M110 = strstr_P(command, PSTR("M110")) != nullptr;
const bool M110 = !!strstr_P(command, PSTR("M110"));

if (M110) {
char* n2pos = strchr(command + 4, 'N');
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ void MarlinUI::draw_status_screen() {
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
ui.encoder_direction_normal();
uint8_t n = lcd_put_u8str_ind_P(0, 1, pstr, itemIndex, itemString, LCD_WIDTH - 1);
if (value != nullptr) {
if (value) {
lcd_put_wchar(':'); n--;
const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space
const lcd_uint_t valrow = n < len ? 2 : 1; // Value on the next row if it won't fit
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() {
lcd.setCursor(0, MIDDLE_Y);
lcd.write(COLOR_EDIT);
lcd_put_u8str_P(pstr);
if (value != nullptr) {
if (value) {
lcd.write(':');
lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y); // Right-justified, padded by spaces
lcd.write(' '); // Overwrite char if value gets shorter
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
if (onpage) lcd_put_u8str_ind_P(0, baseline, pstr, itemIndex, itemString);

// If a value is included, print a colon, then print the value right-justified
if (value != nullptr) {
if (value) {
lcd_put_wchar(':');
if (extra_row) {
// Assume that value is numeric (with no descender)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u

switch (msg) {
case U8G_DEV_MSG_INIT:
dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, NULL);
dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, nullptr);
tftio.Init();
tftio.InitTFT();

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ namespace Anycubic {
}

void ChironTFT::SendtoTFTLN(PGM_P str = nullptr) {
if (str != nullptr) {
if (str) {
#if ACDEBUG(AC_SOME)
SERIAL_ECHOPGM("> ");
#endif
Expand Down
13 changes: 6 additions & 7 deletions Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ void AnycubicTFTClass::OnUserConfirmRequired(const char * const msg) {
}

float AnycubicTFTClass::CodeValue() {
return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], NULL));
return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], nullptr));
}

bool AnycubicTFTClass::CodeSeen(char code) {
TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindr], code);
return (TFTstrchr_pointer != NULL); // Return True if a character was found
return !!TFTstrchr_pointer; // Return True if a character was found
}

bool AnycubicTFTClass::IsNozzleHomed() {
Expand Down Expand Up @@ -536,7 +536,7 @@ void AnycubicTFTClass::OnPrintTimerStopped() {
}

void AnycubicTFTClass::GetCommandFromTFT() {
char *starpos = NULL;
char *starpos = nullptr;
while (LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) {
serial3_char = LCD_SERIAL.read();
if (serial3_char == '\n' ||
Expand All @@ -549,10 +549,10 @@ void AnycubicTFTClass::GetCommandFromTFT() {

TFTcmdbuffer[TFTbufindw][serial3_count] = 0; // terminate string

if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != NULL)) {
if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != nullptr)) {
int16_t a_command;
TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A');
a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL))));
a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], nullptr))));

#if ENABLED(ANYCUBIC_LCD_DEBUG)
if ((a_command > 7) && (a_command != 20)) { // No debugging of status polls, please!
Expand Down Expand Up @@ -682,8 +682,7 @@ void AnycubicTFTClass::GetCommandFromTFT() {
else {
SelectedDirectory[0] = 0;

if (starpos != NULL)
*(starpos - 1) = '\0';
if (starpos) *(starpos - 1) = '\0';

strcpy(SelectedFile, TFTstrchr_pointer + 4);
SENDLINE_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", SelectedFile); // J20 File Selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@
uint16_t FTDI::get_utf8_char_width(utf8_char_t c, font_size_t fs) {
int x = 0, y = 0;
#ifdef TOUCH_UI_UTF8_WESTERN_CHARSET
WesternCharSet::render_glyph(NULL, x, y, fs, c) ||
WesternCharSet::render_glyph(nullptr, x, y, fs, c) ||
#endif
StandardCharSet::render_glyph(NULL, x, y, fs, c);
StandardCharSet::render_glyph(nullptr, x, y, fs, c);
return x;
}

Expand All @@ -165,7 +165,7 @@
*/

uint16_t FTDI::get_utf8_text_width(const char *str, font_size_t fs) {
return render_utf8_text(NULL, 0, 0, str, fs);
return render_utf8_text(nullptr, 0, 0, str, fs);
}

uint16_t FTDI::get_utf8_text_width(progmem_str pstr, font_size_t fs) {
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
draw_return_ui();
}
else {
lv_kb_set_ta(kb, nullptr); /*De-assign the text area to hide it cursor if needed*/
lv_kb_set_ta(kb, nullptr); // De-assign the text area to hide it cursor if needed
lv_obj_del(kb);
return;
}
Expand Down Expand Up @@ -174,7 +174,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
return;
}

/*Add the characters to the text area if set*/
// Add the characters to the text area if set
if (!ext->ta) return;

if (strcmp(txt, "Enter") == 0 || strcmp(txt, LV_SYMBOL_NEW_LINE) == 0)
Expand Down Expand Up @@ -214,7 +214,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
void lv_draw_keyboard() {
scr = lv_screen_create(KEY_BOARD_UI, "");

/*Create styles for the keyboard*/
// Create styles for the keyboard
static lv_style_t rel_style, pr_style;

lv_style_copy(&rel_style, &lv_style_btn_rel);
Expand All @@ -229,7 +229,7 @@ void lv_draw_keyboard() {
pr_style.body.main_color = lv_color_make(0x72, 0x42, 0x15);
pr_style.body.grad_color = lv_color_make(0x6A, 0x3A, 0x0C);

/*Create a keyboard and apply the styles*/
// Create a keyboard and apply the styles
lv_obj_t *kb = lv_kb_create(scr, nullptr);
lv_obj_set_event_cb(kb, lv_kb_event_cb);
lv_kb_set_cursor_manage(kb, true);
Expand All @@ -243,7 +243,7 @@ void lv_draw_keyboard() {
}
#endif

/*Create a text area. The keyboard will write here*/
// Create a text area. The keyboard will write here
lv_obj_t *ta = lv_ta_create(scr, nullptr);
lv_obj_align(ta, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10);
if (keyboard_value == gcodeCommand) {
Expand All @@ -255,7 +255,7 @@ void lv_draw_keyboard() {
lv_ta_set_text(ta, "");
}

/*Assign the text area to the keyboard*/
// Assign the text area to the keyboard
lv_kb_set_ta(kb, ta);
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void MenuEditItemBase::edit_screen(strfunc_t strfunc, loadfunc_t loadfunc) {
if (ui.should_draw())
draw_edit_screen(strfunc(ui.encoderPosition + minEditValue));
if (ui.lcd_clicked || (liveEdit && ui.should_draw())) {
if (editValue != nullptr) loadfunc(editValue, ui.encoderPosition + minEditValue);
if (editValue) loadfunc(editValue, ui.encoderPosition + minEditValue);
if (callbackFunc && (liveEdit || ui.lcd_clicked)) (*callbackFunc)();
if (ui.use_click()) ui.goto_previous_screen();
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void CANVAS::AddText(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, ui

void CANVAS::AddImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors) {
uint16_t *data = (uint16_t *)Images[image].data;
if (data == NULL) return;
if (!data) return;

uint16_t image_width = Images[image].width,
image_height = Images[image].height;
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/tft_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "tft_image.h"
#include <stddef.h>

const tImage NoLogo = { (void *)NULL, 0, 0, NOCOLORS };
const tImage NoLogo = { nullptr, 0, 0, NOCOLORS };

const tImage MarlinLogo112x38x1 = { (void *)marlin_logo_112x38x1, 112, 38, GREYSCALE1 };
const tImage MarlinLogo228x255x2 = { (void *)marlin_logo_228x255x2, 228, 255, GREYSCALE2 };
Expand Down
Loading

0 comments on commit ec23e37

Please sign in to comment.