2022-05-20 15:45:25 +01:00
|
|
|
#include <new>
|
|
|
|
|
|
|
|
#define MP_OBJ_TO_PTR2(o, t) ((t *)(uintptr_t)(o))
|
|
|
|
|
|
|
|
// SDA/SCL on even/odd pins, I2C0/I2C1 on even/odd pairs of pins.
|
|
|
|
#define IS_VALID_SCL(i2c, pin) (((pin) & 1) == 1 && (((pin) & 2) >> 1) == (i2c))
|
|
|
|
#define IS_VALID_SDA(i2c, pin) (((pin) & 1) == 0 && (((pin) & 2) >> 1) == (i2c))
|
|
|
|
|
|
|
|
#define IS_VALID_PERIPH(spi, pin) ((((pin) & 8) >> 3) == (spi))
|
|
|
|
#define IS_VALID_SCK(spi, pin) (((pin) & 3) == 2 && IS_VALID_PERIPH(spi, pin))
|
|
|
|
#define IS_VALID_MOSI(spi, pin) (((pin) & 3) == 3 && IS_VALID_PERIPH(spi, pin))
|
|
|
|
#define IS_VALID_MISO(spi, pin) (((pin) & 3) == 0 && IS_VALID_PERIPH(spi, pin))
|
|
|
|
|
|
|
|
|
|
|
|
#define m_new_class(cls, ...) new(m_new(cls, 1)) cls(__VA_ARGS__)
|
2023-03-13 13:38:01 +00:00
|
|
|
#define m_del_class(cls, ptr) ptr->~cls();m_del(cls, ptr, 1)
|
|
|
|
|
|
|
|
#define m_tracked_alloc_class(cls, ...) new(m_tracked_calloc(1, sizeof(cls))) cls(__VA_ARGS__)
|
|
|
|
#define m_tracked_free_class(cls, ptr) ptr->~cls();m_tracked_free(ptr)
|