1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-27 05:48:43 +00:00

General cleanup, use _BV

This commit is contained in:
Scott Lahteine 2021-01-16 19:03:06 -06:00
parent 69a6d26c80
commit b41f41589a
19 changed files with 56 additions and 81 deletions

View File

@ -50,7 +50,7 @@
#define PWM_PIN(P) WITHIN(P, 2, 13)
#ifndef MASK
#define MASK(PIN) (1 << PIN)
#define MASK(PIN) _BV(PIN)
#endif
/**

View File

@ -121,7 +121,7 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
// missing from CMSIS: Check if interrupt is enabled or not
static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) {
return (NVIC->ISER[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F))) != 0;
return TEST(NVIC->ISER[uint32_t(IRQn) >> 5], uint32_t(IRQn) & 0x1F);
}
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {

View File

@ -30,7 +30,7 @@ class Servo {
MAX_PULSE_WIDTH = 2400, // Longest pulse sent to a servo
TAU_MSEC = 20,
TAU_USEC = (TAU_MSEC * 1000),
MAX_COMPARE = ((1 << 16) - 1), // 65535
MAX_COMPARE = _BV(16) - 1, // 65535
CHANNEL_MAX_NUM = 16;
public:

View File

@ -25,7 +25,7 @@
* Emulate EEPROM storage using Flash Memory
*
* Use a single 32K flash sector to store EEPROM data. To reduce the
* number of erase operations a simple "levelling" scheme is used that
* number of erase operations a simple "leveling" scheme is used that
* maintains a number of EEPROM "slots" within the larger flash sector.
* Each slot is used in turn and the entire sector is only erased when all
* slots have been used.

View File

@ -152,7 +152,7 @@ FORCE_INLINE static void HAL_timer_disable_interrupt(const uint8_t timer_num) {
// This function is missing from CMSIS
FORCE_INLINE static bool NVIC_GetEnableIRQ(IRQn_Type IRQn) {
return (NVIC->ISER[((uint32_t)IRQn) >> 5] & (1 << ((uint32_t)IRQn) & 0x1F)) != 0;
return TEST(NVIC->ISER[uint32_t(IRQn) >> 5], uint32_t(IRQn) & 0x1F);
}
FORCE_INLINE static bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {

View File

@ -31,7 +31,7 @@
*/
#ifndef MASK
#define MASK(PIN) (1 << PIN)
#define MASK(PIN) _BV(PIN)
#endif
/**

View File

@ -157,7 +157,7 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
// missing from CMSIS: Check if interrupt is enabled or not
static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) {
return (NVIC->ISER[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F))) != 0;
return TEST(NVIC->ISER[uint32_t(IRQn) >> 5], uint32_t(IRQn) & 0x1F);
}
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {

View File

@ -45,7 +45,7 @@ uint8_t ServoCount = 0;
*
* This uses the smallest prescaler that allows an overflow < 2^16.
*/
#define MAX_OVERFLOW UINT16_MAX //((1 << 16) - 1)
#define MAX_OVERFLOW UINT16_MAX // _BV(16) - 1
#define CYC_MSEC (1000 * CYCLES_PER_MICROSECOND)
#define TAU_MSEC 20
#define TAU_USEC (TAU_MSEC * 1000)

View File

@ -28,7 +28,7 @@
*/
#ifndef MASK
#define MASK(PIN) (1 << PIN)
#define MASK(PIN) _BV(PIN)
#endif
#define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)

View File

@ -28,7 +28,7 @@
*/
#ifndef MASK
#define MASK(PIN) (1 << PIN)
#define MASK(PIN) _BV(PIN)
#endif
#define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)

View File

@ -28,9 +28,9 @@
#undef DISABLED // Redefined by ESP32
#undef M_PI // Redefined by all
#undef _BV // Redefined by some
#undef sq // Redefined by teensy3/wiring.h
#undef SBI // Redefined by arduino/const_functions.h
#undef CBI // Redefined by arduino/const_functions.h
#undef sq // Redefined by teensy3/wiring.h
#undef UNUSED // Redefined by stm32f4xx_hal_def.h
#include <Arduino.h> // NOTE: If included earlier then this line is a NOOP
@ -40,18 +40,16 @@
#undef _BV
#define _BV(b) (1UL << (b))
#ifndef SBI
#define SBI(A,B) (A |= _BV(B))
#endif
#ifndef CBI
#define CBI(A,B) (A &= ~_BV(B))
#endif
#undef sq
#define sq(x) ((x)*(x))
#ifndef SBI
#define SBI(A,B) (A |= (1 << (B)))
#endif
#ifndef CBI
#define CBI(A,B) (A &= ~(1 << (B)))
#endif
#ifndef __AVR__
#ifndef strchr_P // Some platforms define a macro (DUE, teensy35)
inline const char* strchr_P(const char *s, int c) { return strchr(s,c); }

View File

@ -128,11 +128,8 @@ static UnwResult UnwTabStateInit(const UnwindCallbacks *cb, UnwTabState *ucb, ui
* Execute unwinding instructions
*/
static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabState *ucb) {
int instruction;
uint32_t mask;
uint32_t reg;
uint32_t vsp;
uint32_t mask, reg, vsp;
/* Consume all instruction byte */
while ((instruction = UnwTabGetNextInstruction(cb, ucb)) != -1) {
@ -140,12 +137,12 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat
if ((instruction & 0xC0) == 0x00) { // ARM_EXIDX_CMD_DATA_POP
/* vsp = vsp + (xxxxxx << 2) + 4 */
ucb->vrs[13] += ((instruction & 0x3F) << 2) + 4;
} else
if ((instruction & 0xC0) == 0x40) { // ARM_EXIDX_CMD_DATA_PUSH
}
else if ((instruction & 0xC0) == 0x40) { // ARM_EXIDX_CMD_DATA_PUSH
/* vsp = vsp - (xxxxxx << 2) - 4 */
ucb->vrs[13] -= ((instruction & 0x3F) << 2) - 4;
} else
if ((instruction & 0xF0) == 0x80) {
}
else if ((instruction & 0xF0) == 0x80) {
/* pop under mask {r15-r12},{r11-r4} or refuse to unwind */
instruction = instruction << 8 | UnwTabGetNextInstruction(cb, ucb);
@ -171,17 +168,17 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat
}
/* Patch up the vrs sp if it was in the mask */
if ((instruction & (1 << (13 - 4))) != 0)
if (instruction & (1 << (13 - 4)))
ucb->vrs[13] = vsp;
} else
if ((instruction & 0xF0) == 0x90 && // ARM_EXIDX_CMD_REG_TO_SP
instruction != 0x9D &&
instruction != 0x9F) {
}
else if ((instruction & 0xF0) == 0x90 // ARM_EXIDX_CMD_REG_TO_SP
&& instruction != 0x9D
&& instruction != 0x9F
) {
/* vsp = r[nnnn] */
ucb->vrs[13] = ucb->vrs[instruction & 0x0F];
} else
if ((instruction & 0xF0) == 0xA0) { // ARM_EXIDX_CMD_REG_POP
}
else if ((instruction & 0xF0) == 0xA0) { // ARM_EXIDX_CMD_REG_POP
/* pop r4-r[4+nnn] or pop r4-r[4+nnn], r14*/
vsp = ucb->vrs[13];
@ -204,8 +201,8 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat
ucb->vrs[13] = vsp;
} else
if (instruction == 0xB0) { // ARM_EXIDX_CMD_FINISH
}
else if (instruction == 0xB0) { // ARM_EXIDX_CMD_FINISH
/* finished */
if (ucb->vrs[15] == 0)
ucb->vrs[15] = ucb->vrs[14];
@ -213,8 +210,8 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat
/* All done unwinding */
return UNWIND_SUCCESS;
} else
if (instruction == 0xB1) { // ARM_EXIDX_CMD_REG_POP
}
else if (instruction == 0xB1) { // ARM_EXIDX_CMD_REG_POP
/* pop register under mask {r3,r2,r1,r0} */
vsp = ucb->vrs[13];
mask = UnwTabGetNextInstruction(cb, ucb);
@ -234,16 +231,15 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat
}
ucb->vrs[13] = (uint32_t)vsp;
} else
if (instruction == 0xB2) { // ARM_EXIDX_CMD_DATA_POP
}
else if (instruction == 0xB2) { // ARM_EXIDX_CMD_DATA_POP
/* vps = vsp + 0x204 + (uleb128 << 2) */
ucb->vrs[13] += 0x204 + (UnwTabGetNextInstruction(cb, ucb) << 2);
} else
if (instruction == 0xB3 || // ARM_EXIDX_CMD_VFP_POP
instruction == 0xC8 ||
instruction == 0xC9) {
}
else if (instruction == 0xB3 // ARM_EXIDX_CMD_VFP_POP
|| instruction == 0xC8
|| instruction == 0xC9
) {
/* pop VFP double-precision registers */
vsp = ucb->vrs[13];
@ -266,27 +262,20 @@ static UnwResult UnwTabExecuteInstructions(const UnwindCallbacks *cb, UnwTabStat
}
ucb->vrs[13] = vsp;
} else
if ((instruction & 0xF8) == 0xB8 ||
(instruction & 0xF8) == 0xD0) {
}
else if ((instruction & 0xF8) == 0xB8 || (instruction & 0xF8) == 0xD0) {
/* Pop VFP double precision registers D[8]-D[8+nnn] */
ucb->vrs[14] = 0x80 | (instruction & 0x07);
if ((instruction & 0xF8) == 0xD0) {
if ((instruction & 0xF8) == 0xD0)
ucb->vrs[14] = 1 << 17;
}
} else
}
else
return UNWIND_UNSUPPORTED_DWARF_INSTR;
}
return UNWIND_SUCCESS;
}
static inline __attribute__((always_inline)) uint32_t read_psp() {
/* Read the current PSP and return its value as a pointer */
uint32_t psp;

View File

@ -84,17 +84,13 @@
#define _BV(n) (1<<(n))
#define TEST(n,b) (!!((n)&_BV(b)))
#define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
#ifndef SBI
#define SBI(A,B) (A |= (1 << (B)))
#define SBI(A,B) (A |= _BV(B))
#endif
#ifndef CBI
#define CBI(A,B) (A &= ~(1 << (B)))
#define CBI(A,B) (A &= ~_BV(B))
#endif
#define TBI(N,B) (N ^= _BV(B))
#define _BV32(b) (1UL << (b))
#define TEST32(n,b) !!((n)&_BV32(b))
#define SBI32(n,b) (n |= _BV32(b))

View File

@ -93,8 +93,8 @@ namespace DirectStepping {
static constexpr int DIRECTIONAL = dir ? 1 : 0;
static constexpr int SEGMENTS = segments;
static constexpr int NUM_SEGMENTS = 1 << BITS_SEGMENT;
static constexpr int SEGMENT_STEPS = (1 << (BITS_SEGMENT - DIRECTIONAL)) - 1;
static constexpr int NUM_SEGMENTS = _BV(BITS_SEGMENT);
static constexpr int SEGMENT_STEPS = _BV(BITS_SEGMENT - DIRECTIONAL) - 1;
static constexpr int TOTAL_STEPS = SEGMENT_STEPS * SEGMENTS;
static constexpr int PAGE_SIZE = (NUM_AXES * BITS_SEGMENT * SEGMENTS) / 8;

View File

@ -86,9 +86,9 @@ namespace Anycubic {
safe_delay(200);
// Enable levelling and Disable end stops during print
// Enable leveling and Disable end stops during print
// as Z home places nozzle above the bed so we need to allow it past the end stops
injectCommands_P(AC_cmnd_enable_levelling);
injectCommands_P(AC_cmnd_enable_leveling);
// Startup tunes are defined in Tunes.h
//PlayTune(BEEPER_PIN, Anycubic_PowerOn, 1);
@ -762,7 +762,7 @@ namespace Anycubic {
selectedmeshpoint.x = selectedmeshpoint.y = 99;
}
break;
case 'D': // Save Z Offset tables and restore levelling state
case 'D': // Save Z Offset tables and restore leveling state
if (!isPrinting()) {
setAxisPosition_mm(1.0,Z);
injectCommands_P(PSTR("M500"));
@ -784,7 +784,7 @@ namespace Anycubic {
float Zshift = atof(&panel_command[4]);
setSoftEndstopState(false); // disable endstops
// Allow temporary Z position nudging during print
// From the levelling panel use the all points UI to adjust the print pos.
// From the leveling panel use the all points UI to adjust the print pos.
if (isPrinting()) {
#if ACDEBUG(AC_INFO)
SERIAL_ECHOLNPAIR("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift);

View File

@ -105,7 +105,7 @@
#define AC_cmnd_manual_load_filament PSTR("M83\nG1 E50 F700\nM82") // replace the manual panel commands with something a little faster
#define AC_cmnd_manual_unload_filament PSTR("M83\nG1 E-50 F1200\nM82")
#define AC_cmnd_enable_levelling PSTR("M420 S1 V1")
#define AC_cmnd_enable_leveling PSTR("M420 S1 V1")
#define AC_cmnd_power_loss_recovery PSTR("G28 X Y R5\nG28 Z") // Lift, home X and Y then home Z when in 'safe' position
namespace Anycubic {

View File

@ -56,7 +56,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1);
}
}
#if !defined(SINGLENOZZLE) && HAS_MULTI_EXTRUDER
#if DISABLED(SINGLENOZZLE) && HAS_MULTI_EXTRUDER
else if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) {
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1);
}

View File

@ -35,10 +35,6 @@
#include "../../module/motion.h"
#endif
#if ENABLED(SINGLENOZZLE)
#include "../../module/tool_change.h"
#endif
//
// "Temperature" submenu items
//

View File

@ -38,10 +38,6 @@
#include "../../feature/bedlevel/bedlevel.h"
#endif
#if ENABLED(SINGLENOZZLE)
#include "../../module/tool_change.h"
#endif
#if ENABLED(BABYSTEPPING)
#include "../../feature/babystep.h"