diff --git a/drivers/adt7310/adt7310.c b/drivers/adt7310/adt7310.c index c29ad6f668..54607d6bc3 100644 --- a/drivers/adt7310/adt7310.c +++ b/drivers/adt7310/adt7310.c @@ -144,17 +144,17 @@ int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs) /* CS */ spi_init_cs(dev->spi, dev->cs); -#if ENABLE_DEBUG - for (int i = 0; i < 8; ++i) { - uint16_t dbg_reg = 0; - status = adt7310_read_reg(dev, i, sizeof(dbg_reg), (uint8_t *)&dbg_reg); - if (status != 0) { - printf("Error reading address 0x%02x", i); + if (IS_ACTIVE(ENABLE_DEBUG)) { + for (int i = 0; i < 8; ++i) { + uint16_t dbg_reg = 0; + status = adt7310_read_reg(dev, i, sizeof(dbg_reg), (uint8_t *)&dbg_reg); + if (status != 0) { + printf("Error reading address 0x%02x", i); + } + dbg_reg = htons(dbg_reg); + printf("%02x: %04" PRIx16 "\n", i, dbg_reg); } - dbg_reg = htons(dbg_reg); - printf("%02x: %04" PRIx16 "\n", i, dbg_reg); } -#endif /* Read ID register from device */ status = adt7310_read_reg(dev, ADT7310_REG_ID, ADT7310_REG_SIZE_ID, ®); diff --git a/drivers/apds99xx/apds99xx.c b/drivers/apds99xx/apds99xx.c index 8f2fd3e49c..e06f965fcc 100644 --- a/drivers/apds99xx/apds99xx.c +++ b/drivers/apds99xx/apds99xx.c @@ -480,7 +480,7 @@ static int _reg_read(const apds99xx_t *dev, uint8_t reg, uint8_t *data, uint16_t return -APDS99XX_ERROR_I2C; } - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[apds99xx] %s i2c dev=%d addr=%02x: read from reg 0x%02x: ", __func__, dev->params.dev, APDS99XX_I2C_ADDRESS, reg); for (uint16_t i = 0; i < len; i++) { @@ -496,7 +496,7 @@ static int _reg_write(const apds99xx_t *dev, uint8_t reg, uint8_t *data, uint16_ { assert(dev != NULL); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[apds99xx] %s i2c dev=%d addr=%02x: write to reg 0x%02x: ", __func__, dev->params.dev, APDS99XX_I2C_ADDRESS, reg); for (uint16_t i = 0; i < len; i++) { diff --git a/drivers/ata8520e/ata8520e.c b/drivers/ata8520e/ata8520e.c index 0d7ec4beaf..a4eeb05e31 100644 --- a/drivers/ata8520e/ata8520e.c +++ b/drivers/ata8520e/ata8520e.c @@ -205,7 +205,7 @@ static void _status(const ata8520e_t *dev) uint8_t sigfox2 = spi_transfer_byte(SPIDEV, CSPIN, false, 0); spi_release(SPIDEV); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { _print_atmel_status(atmel); _print_sigfox_status(sigfox); _print_sigfox_status(sigfox2); @@ -272,7 +272,7 @@ int ata8520e_init(ata8520e_t *dev, const ata8520e_params_t *params) xtimer_usleep(100 * US_PER_MS); /* 100 ms */ - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { char sigfox_id[SIGFOX_ID_LENGTH + 1]; ata8520e_read_id(dev, sigfox_id); diff --git a/drivers/atwinc15x0/atwinc15x0_netdev.c b/drivers/atwinc15x0/atwinc15x0_netdev.c index 2daf2b779e..3c212cdf80 100644 --- a/drivers/atwinc15x0/atwinc15x0_netdev.c +++ b/drivers/atwinc15x0/atwinc15x0_netdev.c @@ -103,9 +103,10 @@ static void _atwinc15x0_eth_cb(uint8_t type, void *msg, void *ctrl_buf) DEBUG("%s type=%u msg=%p len=%d remaining=%d\n", __func__, type, msg, ctrl->u16DataSize, ctrl->u16RemainigDataSize); -#if MODULE_OD && ENABLE_DEBUG_DUMP - od_hex_dump(msg, ctrl->u16DataSize, 16); -#endif + + if (IS_ACTIVE(ENABLE_DEBUG) && IS_USED(MODULE_OD)) { + od_hex_dump(msg, ctrl->u16DataSize, 16); + } /* the buffer shouldn't be used here */ assert(atwinc15x0->rx_buf == NULL); @@ -258,12 +259,13 @@ static int _atwinc15x0_send(netdev_t *netdev, const iolist_t *iolist) } } -#if ENABLE_DEBUG - DEBUG("%s send %d byte", __func__, tx_len); -#if MODULE_OD && ENABLE_DEBUG_DUMP - od_hex_dump(dev->tx_buf, dev->tx_len, OD_WIDTH_DEFAULT); -#endif /* MODULE_OD && ENABLE_DEBUG_HEXDUMP */ -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + DEBUG("%s send %d byte", __func__, tx_len); + if (IS_ACTIVE(ENABLE_DEBUG_DUMP) && IS_USED(MODULE_OD)) { + od_hex_dump(atwinc15x0_eth_buf, tx_len, OD_WIDTH_DEFAULT); + } + } + irq_restore(state); /* send the the packet */ @@ -320,14 +322,15 @@ static int _atwinc15x0_recv(netdev_t *netdev, void *buf, size_t len, void *info) dev->rx_len = 0; dev->rx_buf = NULL; -#if ENABLE_DEBUG - ethernet_hdr_t *hdr = (ethernet_hdr_t *)buf; - DEBUG("%s received %u byte from addr " ATWINC15X0_MAC_STR "\n", - __func__, rx_size, ATWINC15X0_MAC_STR_ARG(hdr->src)); -#if MODULE_OD && ENABLE_DEBUG_DUMP - od_hex_dump(buf, rx_size, OD_WIDTH_DEFAULT); -#endif /* MODULE_OD && ENABLE_DEBUG_HEXDUMP */ -#endif /* ENABLE_DEBUG */ + if (IS_ACTIVE(ENABLE_DEBUG)) { + ethernet_hdr_t *hdr = (ethernet_hdr_t *)buf; + DEBUG("%s received %u byte from addr " ATWINC15X0_MAC_STR "\n", + __func__, rx_size, ATWINC15X0_MAC_STR_ARG(hdr->src)); + + if (IS_ACTIVE(ENABLE_DEBUG_DUMP) && IS_USED(MODULE_OD)) { + od_hex_dump(buf, rx_size, OD_WIDTH_DEFAULT); + } + } irq_restore(state); diff --git a/drivers/ccs811/ccs811.c b/drivers/ccs811/ccs811.c index d066a38ef0..03e2024718 100644 --- a/drivers/ccs811/ccs811.c +++ b/drivers/ccs811/ccs811.c @@ -512,7 +512,7 @@ static int _reg_read(const ccs811_t *dev, uint8_t reg, uint8_t *data, uint32_t l #endif if (res == CCS811_OK) { - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[ccs811] %s dev=%d addr=%02x: read following bytes: ", __func__, dev->params.i2c_dev, dev->params.i2c_addr); for (unsigned i = 0; i < len; i++) { @@ -537,7 +537,7 @@ static int _reg_write(const ccs811_t *dev, uint8_t reg, uint8_t *data, uint32_t int res = CCS811_OK; - if (ENABLE_DEBUG && data && len) { + if (IS_ACTIVE(ENABLE_DEBUG) && data && len) { printf("[css811] %s dev=%d addr=%02x: write following bytes: ", __func__, dev->params.i2c_dev, dev->params.i2c_addr); for (unsigned i = 0; i < len; i++) { diff --git a/drivers/ds3234/ds3234.c b/drivers/ds3234/ds3234.c index 8055a2687f..c3ecb633fd 100644 --- a/drivers/ds3234/ds3234.c +++ b/drivers/ds3234/ds3234.c @@ -79,7 +79,7 @@ int ds3234_pps_init(const ds3234_params_t *dev) } DEBUG("ds3234: init on SPI_DEV(%u)\n", dev->spi); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { for (int k = 0; k <= 0x19; ++k) { uint8_t dbg_reg = 0; ds3234_read_reg(dev, k, 1, &dbg_reg); diff --git a/drivers/hmc5883l/hmc5883l.c b/drivers/hmc5883l/hmc5883l.c index 1388d0caeb..b84c2656c4 100644 --- a/drivers/hmc5883l/hmc5883l.c +++ b/drivers/hmc5883l/hmc5883l.c @@ -243,7 +243,7 @@ static int _reg_read(const hmc5883l_t *dev, uint8_t reg, uint8_t *data, uint16_t i2c_release(dev->dev); if (res == 0) { - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[hmc5883l] %s i2c dev=%d addr=%02x: read following bytes: ", __func__, dev->dev, HMC5883L_I2C_ADDRESS); for (unsigned i = 0; i < len; i++) { @@ -268,7 +268,7 @@ static int _reg_write(const hmc5883l_t *dev, uint8_t reg, uint8_t data) DEBUG_DEV("write register 0x%02x", dev, reg); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[hmc5883l] %s i2c dev=%d addr=%02x: write following bytes: ", __func__, dev->dev, HMC5883L_I2C_ADDRESS); printf("%02x ", data); diff --git a/drivers/kw2xrf/kw2xrf_netdev.c b/drivers/kw2xrf/kw2xrf_netdev.c index ab470228ba..4ee4b17ec0 100644 --- a/drivers/kw2xrf/kw2xrf_netdev.c +++ b/drivers/kw2xrf/kw2xrf_netdev.c @@ -798,7 +798,7 @@ static void _isr(netdev_t *netdev) } kw2xrf_write_dreg(dev, MKW2XDM_IRQSTS2, irqsts2); - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { /* for debugging only */ kw2xrf_read_dregs(dev, MKW2XDM_IRQSTS1, dregs, MKW2XDM_IRQSTS1 + 3); if (dregs[MKW2XDM_IRQSTS1] & 0x7f) { diff --git a/drivers/lsm303dlhc/lsm303dlhc.c b/drivers/lsm303dlhc/lsm303dlhc.c index 338ec62d0e..06e7eba2fb 100644 --- a/drivers/lsm303dlhc/lsm303dlhc.c +++ b/drivers/lsm303dlhc/lsm303dlhc.c @@ -82,7 +82,7 @@ int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params) i2c_release(DEV_I2C); /* configure mag data ready pin */ gpio_init(DEV_MAG_PIN, GPIO_IN); - if (ENABLE_DEBUG && res == 0) { + if (IS_ACTIVE(ENABLE_DEBUG) && res == 0) { DEBUG("[OK]\n"); } else { diff --git a/drivers/mtd_mci/mtd_mci.c b/drivers/mtd_mci/mtd_mci.c index 1e0c579107..a1cf194102 100644 --- a/drivers/mtd_mci/mtd_mci.c +++ b/drivers/mtd_mci/mtd_mci.c @@ -40,7 +40,7 @@ static int mtd_mci_init(mtd_dev_t *dev) return -EIO; } - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { uint32_t block_size; mci_ioctl(GET_BLOCK_SIZE, &block_size); DEBUG("block size: %lu\n", block_size); diff --git a/drivers/mtd_spi_nor/mtd_spi_nor.c b/drivers/mtd_spi_nor/mtd_spi_nor.c index f7ff1b72ef..85a7854fa1 100644 --- a/drivers/mtd_spi_nor/mtd_spi_nor.c +++ b/drivers/mtd_spi_nor/mtd_spi_nor.c @@ -26,12 +26,8 @@ #include #include "mtd.h" -#if MODULE_XTIMER #include "xtimer.h" -#include "timex.h" -#else #include "thread.h" -#endif #include "byteorder.h" #include "mtd_spi_nor.h" @@ -110,7 +106,7 @@ static void mtd_spi_cmd_addr_read(const mtd_spi_nor_t *dev, uint8_t opcode, uint8_t *addr_buf = _be_addr(dev, &addr); - if (ENABLE_TRACE) { + if (IS_ACTIVE(ENABLE_TRACE)) { TRACE("mtd_spi_cmd_addr_read: addr:"); for (unsigned int i = 0; i < dev->params->addr_width; ++i) { TRACE(" %02x", addr_buf[i]); @@ -146,7 +142,7 @@ static void mtd_spi_cmd_addr_write(const mtd_spi_nor_t *dev, uint8_t opcode, uint8_t *addr_buf = _be_addr(dev, &addr); - if (ENABLE_TRACE) { + if (IS_ACTIVE(ENABLE_TRACE)) { TRACE("mtd_spi_cmd_addr_write: addr:"); for (unsigned int i = 0; i < dev->params->addr_width; ++i) { TRACE(" %02x", addr_buf[i]); @@ -313,9 +309,10 @@ static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us { unsigned i = 0, j = 0; uint32_t div = 2; -#if ENABLE_DEBUG && defined(MODULE_XTIMER) - uint32_t diff = xtimer_now_usec(); -#endif + uint32_t diff = 0; + if (IS_ACTIVE(ENABLE_DEBUG) && IS_USED(MODULE_XTIMER)) { + diff = xtimer_now_usec(); + } do { uint8_t status; mtd_spi_cmd_read(dev, dev->params->opcode->rdsr, &status, sizeof(status)); @@ -349,10 +346,10 @@ static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us #endif } while (1); DEBUG("wait loop %u times, yield %u times", i, j); -#if ENABLE_DEBUG && defined(MODULE_XTIMER) - diff = xtimer_now_usec() - diff; - DEBUG(", total wait %"PRIu32"us", diff); -#endif + if (IS_ACTIVE(ENABLE_DEBUG) && IS_ACTIVE(MODULE_XTIMER)) { + diff = xtimer_now_usec() - diff; + DEBUG(", total wait %"PRIu32"us", diff); + } DEBUG("\n"); } diff --git a/drivers/pn532/pn532.c b/drivers/pn532/pn532.c index ce976dd984..f50658e292 100644 --- a/drivers/pn532/pn532.c +++ b/drivers/pn532/pn532.c @@ -78,7 +78,7 @@ /* Length for passive listings */ #define LIST_PASSIVE_LEN_14443(num) (num * 20) -#if ENABLE_DEBUG +#if IS_ACTIVE(ENABLE_DEBUG) #define PRINTBUFF printbuff static void printbuff(uint8_t *buff, unsigned len) { diff --git a/drivers/rn2xx3/rn2xx3_internal.c b/drivers/rn2xx3/rn2xx3_internal.c index c3993a8fa5..a0556e2d0d 100644 --- a/drivers/rn2xx3/rn2xx3_internal.c +++ b/drivers/rn2xx3/rn2xx3_internal.c @@ -100,7 +100,7 @@ void rn2xx3_set_internal_state(rn2xx3_t *dev, uint8_t state) return; } - if (ENABLE_DEBUG) { + if (IS_ACTIVE(ENABLE_DEBUG)) { printf("[rn2xx3] new state: "); switch(state) { case RN2XX3_INT_STATE_CMD: diff --git a/drivers/sht3x/sht3x.c b/drivers/sht3x/sht3x.c index 9b21fd8338..7a9bcc5cce 100644 --- a/drivers/sht3x/sht3x.c +++ b/drivers/sht3x/sht3x.c @@ -322,13 +322,14 @@ static int _read_data(sht3x_dev_t* dev, uint8_t *data, uint8_t len) i2c_release(dev->i2c_dev); if (res == 0) { -#if ENABLE_DEBUG - printf("[sht3x] %s bus=%d addr=%02x: read following bytes: ", - __func__, dev->i2c_dev, dev->i2c_addr); - for (int i=0; i < len; i++) - printf("%02x ", data[i]); - printf("\n"); -#endif /* ENABLE_DEBUG */ + if (IS_ACTIVE(ENABLE_DEBUG)) { + printf("[sht3x] %s bus=%d addr=%02x: read following bytes: ", + __func__, dev->i2c_dev, dev->i2c_addr); + for (int i=0; i < len; i++) { + printf("%02x ", data[i]); + } + printf("\n"); + } } else { DEBUG_DEV("could not read %d bytes from sensor, reason %d", diff --git a/drivers/sx127x/sx127x_getset.c b/drivers/sx127x/sx127x_getset.c index 39f2c50a1b..371ce746be 100644 --- a/drivers/sx127x/sx127x_getset.c +++ b/drivers/sx127x/sx127x_getset.c @@ -44,22 +44,22 @@ uint8_t sx127x_get_state(const sx127x_t *dev) void sx127x_set_state(sx127x_t *dev, uint8_t state) { -#if ENABLE_DEBUG - switch (state) { - case SX127X_RF_IDLE: - DEBUG("[sx127x] Change state: IDLE\n"); - break; - case SX127X_RF_RX_RUNNING: - DEBUG("[sx127x] Change state: RX\n"); - break; - case SX127X_RF_TX_RUNNING: - DEBUG("[sx127x] Change state: TX\n"); - break; - default: - DEBUG("[sx127x] Change state: UNKNOWN\n"); - break; + if (IS_ACTIVE(ENABLE_DEBUG)) { + switch (state) { + case SX127X_RF_IDLE: + DEBUG("[sx127x] Change state: IDLE\n"); + break; + case SX127X_RF_RX_RUNNING: + DEBUG("[sx127x] Change state: RX\n"); + break; + case SX127X_RF_TX_RUNNING: + DEBUG("[sx127x] Change state: TX\n"); + break; + default: + DEBUG("[sx127x] Change state: UNKNOWN\n"); + break; + } } -#endif dev->settings.state = state; } @@ -440,28 +440,28 @@ uint8_t sx127x_get_op_mode(const sx127x_t *dev) void sx127x_set_op_mode(const sx127x_t *dev, uint8_t op_mode) { -#if ENABLE_DEBUG - switch(op_mode) { - case SX127X_RF_OPMODE_SLEEP: - DEBUG("[sx127x] Set op mode: SLEEP\n"); - break; - case SX127X_RF_OPMODE_STANDBY: - DEBUG("[sx127x] Set op mode: STANDBY\n"); - break; - case SX127X_RF_OPMODE_RECEIVER_SINGLE: - DEBUG("[sx127x] Set op mode: RECEIVER SINGLE\n"); - break; - case SX127X_RF_OPMODE_RECEIVER: - DEBUG("[sx127x] Set op mode: RECEIVER\n"); - break; - case SX127X_RF_OPMODE_TRANSMITTER: - DEBUG("[sx127x] Set op mode: TRANSMITTER\n"); - break; - default: - DEBUG("[sx127x] Set op mode: UNKNOWN (%d)\n", op_mode); - break; + if (IS_ACTIVE(ENABLE_DEBUG)) { + switch(op_mode) { + case SX127X_RF_OPMODE_SLEEP: + DEBUG("[sx127x] Set op mode: SLEEP\n"); + break; + case SX127X_RF_OPMODE_STANDBY: + DEBUG("[sx127x] Set op mode: STANDBY\n"); + break; + case SX127X_RF_OPMODE_RECEIVER_SINGLE: + DEBUG("[sx127x] Set op mode: RECEIVER SINGLE\n"); + break; + case SX127X_RF_OPMODE_RECEIVER: + DEBUG("[sx127x] Set op mode: RECEIVER\n"); + break; + case SX127X_RF_OPMODE_TRANSMITTER: + DEBUG("[sx127x] Set op mode: TRANSMITTER\n"); + break; + default: + DEBUG("[sx127x] Set op mode: UNKNOWN (%d)\n", op_mode); + break; + } } -#endif /* Replace previous mode value and setup new mode value */ sx127x_reg_write(dev, SX127X_REG_OPMODE, diff --git a/drivers/tsl2561/tsl2561.c b/drivers/tsl2561/tsl2561.c index a0d4523c6c..546ba05331 100644 --- a/drivers/tsl2561/tsl2561.c +++ b/drivers/tsl2561/tsl2561.c @@ -75,13 +75,14 @@ int tsl2561_init(tsl2561_t *dev, const tsl2561_params_t *params) TSL2561_COMMAND_MODE | TSL2561_REGISTER_TIMING, DEV_INTEGRATION | DEV_GAIN, 0); -#if ENABLE_DEBUG - uint8_t timing; - i2c_read_reg(DEV_I2C, DEV_ADDR, - TSL2561_COMMAND_MODE | TSL2561_REGISTER_TIMING, &timing, 0); - DEBUG("[Info] Timing ? %d (expected: %d)\n", - timing, DEV_INTEGRATION | DEV_GAIN); -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + uint8_t timing; + i2c_read_reg(DEV_I2C, DEV_ADDR, + TSL2561_COMMAND_MODE | TSL2561_REGISTER_TIMING, + &timing, 0); + DEBUG("[Info] Timing ? %d (expected: %d)\n", + timing, DEV_INTEGRATION | DEV_GAIN); + } _disable(dev); i2c_release(DEV_I2C); @@ -187,12 +188,13 @@ static void _enable(const tsl2561_t *dev) i2c_write_reg(DEV_I2C, DEV_ADDR, TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON, 0); -#if ENABLE_DEBUG - uint8_t en; - i2c_read_reg(DEV_I2C, DEV_ADDR, - TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, &en, 0); - DEBUG("[Info] Enabled ? %s\n", en == 3 ? "true" : "false"); -#endif + + if (IS_ACTIVE(ENABLE_DEBUG)) { + uint8_t en; + i2c_read_reg(DEV_I2C, DEV_ADDR, + TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, &en, 0); + DEBUG("[Info] Enabled ? %s\n", en == 3 ? "true" : "false"); + } } @@ -203,12 +205,12 @@ static void _disable(const tsl2561_t *dev) TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF, 0); -#if ENABLE_DEBUG - uint8_t dis; - i2c_read_reg(DEV_I2C, DEV_ADDR, - TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, &dis, 0); - DEBUG("[Info] Disabled ? %s\n", dis == 0 ? "true": "false"); -#endif + if (IS_ACTIVE(ENABLE_DEBUG)) { + uint8_t dis; + i2c_read_reg(DEV_I2C, DEV_ADDR, + TSL2561_COMMAND_MODE | TSL2561_REGISTER_CONTROL, &dis, 0); + DEBUG("[Info] Disabled ? %s\n", dis == 0 ? "true": "false"); + } } static void _read_data(const tsl2561_t *dev, uint16_t *full, uint16_t *ir)