Skip to content

Commit b505c0b

Browse files
committed
uc comments, format
1 parent 14dee7c commit b505c0b

12 files changed

+77
-102
lines changed

Marlin/src/HAL/HC32/HAL.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#if ENABLED(EMERGENCY_PARSER)
3333

3434
extern "C" void core_hook_usart_rx_irq(uint8_t ch, uint8_t usart) {
35-
// only handle receive on host serial ports
35+
// Only handle receive on host serial ports
3636
if (false
3737
#ifdef SERIAL_PORT
3838
|| usart != SERIAL_PORT
@@ -47,7 +47,7 @@ extern "C" void core_hook_usart_rx_irq(uint8_t ch, uint8_t usart) {
4747
return;
4848
}
4949

50-
// submit character to emergency parser
50+
// Submit character to emergency parser
5151
if (MYSERIAL1.emergency_parser_enabled())
5252
emergency_parser.update(MYSERIAL1.emergency_state, ch);
5353
}

Marlin/src/HAL/HC32/HAL.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#elif WITHIN(SERIAL_PORT, 1, NUM_UARTS)
5454
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
5555
#else
56-
#define MYSERIAL1 MSERIAL(1) // dummy port
56+
#define MYSERIAL1 MSERIAL(1) // Dummy port
5757
static_assert(false, "SERIAL_PORT must be from 1 to " STRINGIFY(NUM_UARTS) ".")
5858
#endif
5959

@@ -63,7 +63,7 @@
6363
#elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS)
6464
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
6565
#else
66-
#define MYSERIAL2 MSERIAL(1) // dummy port
66+
#define MYSERIAL2 MSERIAL(1) // Dummy port
6767
static_assert(false, "SERIAL_PORT_2 must be from 1 to " STRINGIFY(NUM_UARTS) ".")
6868
#endif
6969
#endif
@@ -74,7 +74,7 @@
7474
#elif WITHIN(SERIAL_PORT_3, 1, NUM_UARTS)
7575
#define MYSERIAL3 MSERIAL(SERIAL_PORT_3)
7676
#else
77-
#define MYSERIAL3 MSERIAL(1) // dummy port
77+
#define MYSERIAL3 MSERIAL(1) // Dummy port
7878
static_assert(false, "SERIAL_PORT_3 must be from 1 to " STRINGIFY(NUM_UARTS) ".")
7979
#endif
8080
#endif
@@ -85,7 +85,7 @@
8585
#elif WITHIN(LCD_SERIAL_PORT, 1, NUM_UARTS)
8686
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
8787
#else
88-
#define LCD_SERIAL MSERIAL(1) // dummy port
88+
#define LCD_SERIAL MSERIAL(1) // Dummy port
8989
static_assert(false, "LCD_SERIAL_PORT must be from 1 to " STRINGIFY(NUM_UARTS) ".")
9090
#endif
9191

@@ -134,7 +134,7 @@
134134
// bss_end alias
135135
#define __bss_end __bss_end__
136136

137-
// fix bug in pgm_read_ptr
137+
// Fix bug in pgm_read_ptr
138138
#undef pgm_read_ptr
139139
#define pgm_read_ptr(addr) (*(addr))
140140

Marlin/src/HAL/HC32/MarlinHAL.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include "../../inc/MarlinConfig.h"
2929

30-
#include "HAL.h" // includes MarlinHAL.h
30+
#include "HAL.h" // Includes MarlinHAL.h
3131
#include <IWatchdog.h>
3232
#include <AsyncAnalogRead.h>
3333

@@ -39,7 +39,7 @@
3939
extern "C" char *_sbrk(int incr);
4040

4141
#if ENABLED(POSTMORTEM_DEBUGGING)
42-
// from MinSerial.cpp
42+
// From MinSerial.cpp
4343
extern void install_min_serial();
4444
#endif
4545

@@ -87,7 +87,7 @@ extern "C" char *_sbrk(int incr);
8787
default: break;
8888
}
8989

90-
// done
90+
// Done
9191
SERIAL_ECHOPGM("\n--\n");
9292
}
9393
#endif // MARLIN_DEV_MODE
@@ -210,7 +210,7 @@ void MarlinHAL::adc_init() {}
210210
void MarlinHAL::adc_enable(const pin_t pin) {
211211
#if TEMP_SENSOR_SOC
212212
if (pin == TEMP_SOC_PIN) {
213-
// start OTS, min. 1s between reads
213+
// Start OTS, min. 1s between reads
214214
ChipTemperature.begin();
215215
ChipTemperature.setMinimumReadDeltaMillis(1000);
216216
return;
@@ -226,7 +226,7 @@ void MarlinHAL::adc_start(const pin_t pin) {
226226

227227
#if TEMP_SENSOR_SOC
228228
if (pin == TEMP_SOC_PIN) {
229-
// read OTS
229+
// Read OTS
230230
float temp;
231231
if (ChipTemperature.read(temp))
232232
MarlinHAL::soc_temp = temp;
@@ -262,11 +262,11 @@ uint16_t MarlinHAL::adc_value() {
262262
}
263263

264264
void MarlinHAL::set_pwm_duty(const pin_t pin, const uint16_t value, const uint16_t scale, const bool invert) {
265-
// invert value if requested
265+
// Invert value if requested
266266
const uint16_t val = invert ? scale - value : value;
267267

268-
// analogWrite the value, core handles the rest
269-
// pin mode should be set by Marlin by calling SET_PWM() before calling this function
268+
// AnalogWrite the value, core handles the rest
269+
// Pin mode should be set by Marlin by calling SET_PWM() before calling this function
270270
analogWriteScaled(pin, val, scale);
271271
}
272272

Marlin/src/HAL/HC32/MarlinSerial.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ constexpr bool serial_handles_emergency(int port) {
4444
}
4545

4646
//
47-
// define serial ports
47+
// Define serial ports
4848
//
4949
#define DEFINE_HWSERIAL_MARLIN(name, n) \
5050
MSerialT name(serial_handles_emergency(n), \
@@ -56,7 +56,7 @@ DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
5656
DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
5757

5858
//
59-
// serial port assertions
59+
// Serial port assertions
6060
//
6161

6262
// Check the type of each serial port by passing it to a template function.

Marlin/src/HAL/HC32/MarlinSerial.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "../../core/serial_hook.h"
2525
#include <drivers/usart/Usart.h>
2626

27-
// optionally set uart IRQ priority to reduce overflow errors
27+
// Optionally set uart IRQ priority to reduce overflow errors
2828
// #define UART_IRQ_PRIO 1
2929

3030
struct MarlinSerial : public Usart {

Marlin/src/HAL/HC32/MinSerial.cpp

+26-30
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,36 @@
2929
#include <drivers/usart/usart_sync.h>
3030

3131
//
32-
// shared by both panic and PostMortem debugging
32+
// Shared by both panic and PostMortem debugging
3333
//
3434
static void minserial_begin() {
3535
#if !WITHIN(SERIAL_PORT, 1, 3)
3636
#warning "MinSerial requires a physical UART port for output."
3737
#warning "Disabling MinSerial because the used serial port is not a HW port."
3838
#else
3939

40-
// prepare usart_sync configuration
40+
// Prepare usart_sync configuration
4141
const stc_usart_uart_init_t usart_config = {
42-
.enClkMode = UsartIntClkCkNoOutput,
43-
.enClkDiv = UsartClkDiv_1,
44-
.enDataLength = UsartDataBits8,
45-
.enDirection = UsartDataLsbFirst,
46-
.enStopBit = UsartOneStopBit,
47-
.enParity = UsartParityNone,
48-
.enSampleMode = UsartSampleBit8,
49-
.enDetectMode = UsartStartBitFallEdge,
50-
.enHwFlow = UsartRtsEnable,
42+
.enClkMode = UsartIntClkCkNoOutput,
43+
.enClkDiv = UsartClkDiv_1,
44+
.enDataLength = UsartDataBits8,
45+
.enDirection = UsartDataLsbFirst,
46+
.enStopBit = UsartOneStopBit,
47+
.enParity = UsartParityNone,
48+
.enSampleMode = UsartSampleBit8,
49+
.enDetectMode = UsartStartBitFallEdge,
50+
.enHwFlow = UsartRtsEnable,
5151
};
5252

53-
// initializes usart_sync driver
53+
// Initializes usart_sync driver
5454
#define __USART_SYNC_INIT(port_no, baud, config) \
5555
usart_sync_init(M4_USART##port_no, \
5656
BOARD_USART##port_no##_TX_PIN, \
5757
baud, \
5858
config);
5959
#define USART_SYNC_INIT(port_no, baud, config) __USART_SYNC_INIT(port_no, baud, config)
6060

61-
// this will reset the baudrate to what is defined in Configuration.h,
61+
// This will reset the baudrate to what is defined in Configuration.h,
6262
// ignoring any changes made with e.g. M575.
6363
// keeping the dynamic baudrate would require re-calculating the baudrate
6464
// using the register values, which is a pain...
@@ -74,8 +74,7 @@ static void minserial_begin() {
7474

7575
static void minserial_putc(char c) {
7676
#if WITHIN(SERIAL_PORT, 1, 3)
77-
#define __USART_SYNC_PUTC(port_no, ch) \
78-
usart_sync_putc(M4_USART##port_no, ch);
77+
#define __USART_SYNC_PUTC(port_no, ch) usart_sync_putc(M4_USART##port_no, ch);
7978
#define USART_SYNC_PUTC(port_no, ch) __USART_SYNC_PUTC(port_no, ch)
8079

8180
USART_SYNC_PUTC(SERIAL_PORT, c);
@@ -86,20 +85,19 @@ static void minserial_putc(char c) {
8685
}
8786

8887
//
89-
// panic only
88+
// Panic only
9089
//
9190
#ifdef PANIC_ENABLE
91+
9292
void panic_begin() {
9393
minserial_begin();
94-
9594
panic_puts("\n\nPANIC:\n");
9695
}
9796

9897
void panic_puts(const char *str) {
99-
while (*str) {
100-
minserial_putc(*str++);
101-
}
98+
while (*str) minserial_putc(*str++);
10299
}
100+
103101
#endif // PANIC_ENABLE
104102

105103
//
@@ -111,9 +109,9 @@ void panic_puts(const char *str) {
111109
#include <drivers/panic/fault_handlers.h>
112110

113111
void fault_handlers_init() {
114-
// enable cpu traps:
115-
// - divide by zero
116-
// - unaligned access
112+
// Enable cpu traps:
113+
// - Divide by zero
114+
// - Unaligned access
117115
SCB->CCR |= SCB_CCR_DIV_0_TRP_Msk; //| SCB_CCR_UNALIGN_TRP_Msk;
118116
}
119117

@@ -138,16 +136,14 @@ extern "C" {
138136
#endif // POSTMORTEM_DEBUGGING || PANIC_ENABLE
139137

140138
//
141-
// panic_end is always required to print the '!!' to the host
139+
// Panic_end is always required to print the '!!' to the host
142140
//
143141
void panic_end() {
144-
// print '!!' to signal error to host
145-
// do it 10x so it's not missed
146-
for (int i = 0; i < 10; i++) {
147-
panic_printf("\n!!\n");
148-
}
142+
// Print '!!' to signal error to host
143+
// Do it 10x so it's not missed
144+
for (uint_fast8_t i = 10; i--;) panic_printf("\n!!\n");
149145

150-
// then, reset the board
146+
// Then, reset the board
151147
NVIC_SystemReset();
152148
}
153149

Marlin/src/HAL/HC32/Servo.cpp

+10-17
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,14 @@ MarlinServo::MarlinServo() {
4343
}
4444

4545
int8_t MarlinServo::attach(const pin_t apin) {
46-
// use last pin if pin not given
47-
if (apin >= 0) {
48-
this->pin = apin;
49-
}
50-
51-
// if attached, do nothing but no fail
52-
if (this->servo.attached()) {
53-
return 0;
54-
}
55-
56-
// attach
57-
uint8_t rc = this->servo.attach(this->pin);
46+
// Use last pin if pin not given
47+
if (apin >= 0) this->pin = apin;
48+
49+
// If attached, do nothing but no fail
50+
if (this->servo.attached()) return 0;
51+
52+
// Attach
53+
const uint8_t rc = this->servo.attach(this->pin);
5854
return rc == INVALID_SERVO ? -1 : rc;
5955
}
6056

@@ -72,11 +68,8 @@ void MarlinServo::write(servo_angle_t angle) {
7268
}
7369

7470
void MarlinServo::move(servo_angle_t angle) {
75-
// attach with pin=-1 to use last pin attach() was called with
76-
if (attach(-1) < 0) {
77-
// attach failed
78-
return;
79-
}
71+
// Attach with pin=-1 to use last pin attach() was called with
72+
if (attach(-1) < 0) return; // Attach failed
8073

8174
write(angle);
8275
safe_delay(servoDelays[this->channel]);

Marlin/src/HAL/HC32/Servo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ class MarlinServo {
9393
servo_angle_t angle;
9494
};
9595

96-
// alias for marlin HAL
96+
// Alias for marlin HAL
9797
typedef MarlinServo hal_servo_t;

Marlin/src/HAL/HC32/eeprom_sdcard.cpp

+7-21
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,23 @@ size_t PersistentStore::capacity() {
4646
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
4747

4848
bool PersistentStore::access_start() {
49-
if (!card.isMounted()) {
50-
return false;
51-
}
49+
if (!card.isMounted()) return false;
5250

5351
MediaFile file, root = card.getroot();
54-
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) {
55-
return true; // false aborts the save
56-
}
52+
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) return true; // False aborts the save
5753

5854
int bytes_read = file.read(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
59-
if (bytes_read < 0) {
60-
return false;
61-
}
55+
if (bytes_read < 0) return false;
6256

63-
for (; bytes_read < MARLIN_EEPROM_SIZE; bytes_read++) {
57+
for (; bytes_read < MARLIN_EEPROM_SIZE; bytes_read++)
6458
HAL_eeprom_data[bytes_read] = 0xFF;
65-
}
6659

6760
file.close();
6861
return true;
6962
}
7063

7164
bool PersistentStore::access_finish() {
72-
if (!card.isMounted()) {
73-
return false;
74-
}
65+
if (!card.isMounted()) return false;
7566

7667
MediaFile file, root = card.getroot();
7768
int bytes_written = 0;
@@ -84,9 +75,7 @@ bool PersistentStore::access_finish() {
8475
}
8576

8677
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
87-
for (size_t i = 0; i < size; i++) {
88-
HAL_eeprom_data[pos + i] = value[i];
89-
}
78+
for (size_t i = 0; i < size; i++) HAL_eeprom_data[pos + i] = value[i];
9079

9180
crc16(crc, value, size);
9281
pos += size;
@@ -96,10 +85,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
9685
bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing /*=true*/) {
9786
for (size_t i = 0; i < size; i++) {
9887
uint8_t c = HAL_eeprom_data[pos + i];
99-
if (writing) {
100-
value[i] = c;
101-
}
102-
88+
if (writing) value[i] = c;
10389
crc16(crc, &c, 1);
10490
}
10591

0 commit comments

Comments
 (0)