Extended condition macros (#13419)

Allow `ENABLED`, `DISABLED`, `PIN_EXISTS`, and `BUTTON_EXISTS` to take multiple arguments. Also add:
- Alias `ANY(...)` for `!DISABLED(...)`
- Alias `ANY_PIN(...)` for `PIN_EXISTS(a) || PIN_EXISTS(b) ...`
- Alias `EITHER(A,B)` for `ANY(...)`
- Alias `ALL(...)` and `BOTH(A,B)` for `ENABLED(...)`
- `NONE(...)` for `DISABLED(...)`
This commit is contained in:
Scott Lahteine
2019-03-16 23:43:06 -05:00
committed by GitHub
parent d20eab4f83
commit 49cf92dc36
281 changed files with 1299 additions and 1288 deletions

View File

@ -182,7 +182,7 @@ FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t freque
#define TIMER_OCR_0 OCR0A
#define TIMER_COUNTER_0 TCNT0
#define _CAT(a, ...) a ## __VA_ARGS__
#define _CAT(a,V...) a##V
#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
#define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
#define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)

View File

@ -286,7 +286,7 @@ enum ClockSource2 : char {
#define PWM_CHK_FAN_B(P) (P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN)
#endif
#if PIN_EXISTS(FAN) || PIN_EXISTS(FAN1) || PIN_EXISTS(FAN2)
#if ANY_PIN(FAN, FAN1, FAN2)
#if PIN_EXISTS(FAN2)
#define PWM_CHK_FAN_A(P) (P == FAN_PIN || P == FAN1_PIN || P == FAN2_PIN)
#elif PIN_EXISTS(FAN1)

View File

@ -23,7 +23,7 @@
#include "../../inc/MarlinConfig.h"
#if ENABLED(EEPROM_SETTINGS) || ENABLED(SD_FIRMWARE_UPDATE)
#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
#include "../shared/persistent_store_api.h"

View File

@ -36,7 +36,7 @@
#include <Arduino.h>
#undef DISABLED
#define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
#define DISABLED(V...) DO(DIS,&&,V)
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"

View File

@ -23,7 +23,7 @@
#include "src/core/macros.h"
#if ENABLED(SDSUPPORT) && ENABLED(DOGLCD) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
#if BOTH(SDSUPPORT, DOGLCD) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
#define LPC_SOFTWARE_SPI // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
// needed due to the speed and mode requred for communicating with each device being different.
// This requirement can be removed if the SPI access to these devices is updated to use

View File

@ -98,7 +98,7 @@ void HAL_init() {
// HAL idle task
void HAL_idletask(void) {
#if ENABLED(SDSUPPORT) && ENABLED(SHARED_SD_CARD)
#if BOTH(SDSUPPORT, SHARED_SD_CARD)
// If Marlin is using the SD card we need to lock it to prevent access from
// a PC via USB.
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but

View File

@ -55,7 +55,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
uint8_t v = *value;
// Save to either external EEPROM, program flash or Backup SRAM
#if ENABLED(SPI_EEPROM) || ENABLED(I2C_EEPROM)
#if EITHER(SPI_EEPROM, I2C_EEPROM)
// EEPROM has only ~100,000 write cycles,
// so only write bytes that have changed!
uint8_t * const p = (uint8_t * const)pos;
@ -87,7 +87,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
do {
// Read from either external EEPROM, program flash or Backup SRAM
const uint8_t c = (
#if ENABLED(SPI_EEPROM) || ENABLED(I2C_EEPROM)
#if EITHER(SPI_EEPROM, I2C_EEPROM)
eeprom_read_byte((uint8_t*)pos)
#elif DISABLED(EEPROM_EMULATED_WITH_SRAM)
eeprom_buffered_read_byte(pos)
@ -105,7 +105,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
}
size_t PersistentStore::capacity() {
#if ENABLED(SPI_EEPROM) || ENABLED(I2C_EEPROM)
#if EITHER(SPI_EEPROM, I2C_EEPROM)
return E2END + 1;
#elif DISABLED(EEPROM_EMULATED_WITH_SRAM)
return E2END + 1;

View File

@ -32,7 +32,7 @@
#include "../../inc/MarlinConfig.h"
// This is for EEPROM emulation in flash
#if ENABLED(EEPROM_SETTINGS) && ENABLED(FLASH_EEPROM_EMULATION)
#if BOTH(EEPROM_SETTINGS, FLASH_EEPROM_EMULATION)
#include "../shared/persistent_store_api.h"

View File

@ -22,7 +22,7 @@
*/
#include "../../inc/MarlinConfigPre.h"
#if ENABLED(EEPROM_SETTINGS) || ENABLED(SD_FIRMWARE_UPDATE)
#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
#include "persistent_store_api.h"
PersistentStore persistentStore;