Проверка в analogWrite(), добавление экземпляров для Wire, SPI, Serial

В функции analogWrite() добавлена проверка, включен ли уже канал - если включен, применяется новое значение только если оно отличается от текущего.
В модулях Wire, SPI, Serial теперь по два экземпляра в соответствии с периферией МК. Для каждой платы задается свой экземпляр, используемый по умолчанию
Co-authored-by: KLASSENTS <klassen@elron.tech>
Co-committed-by: KLASSENTS <klassen@elron.tech>
This commit was merged in pull request #21.
This commit is contained in:
klassents authored and klassents committed 2025-05-27 12:35:36 +03:00
1 parent f1e091bf77
commit 778608b576
29 files changed
+186 -130

No files matched your search

+14 -11
View File
@@ -122,6 +122,7 @@ static inline void additionalPinsDeinit(uint32_t PinNumber){}
// UART
// available uarts quantity
#define SERIAL_PORT_QTY 2
#define DEFAULT_SERIAL Serial0
// ADC
#define MCU_ADC_RESOLUTION 12 // bits
@@ -135,7 +136,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
return (p < 32) && ((p & 0xF) < 4);
}
// return true if digitalPin configured as pwm
bool digitalPinPwmIsOn(uint8_t digitalPin);
int8_t digitalPinPwmIsOn(uint8_t digitalPin);
// determines which timer the pin belongs to
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
// determines which timer channel the pin belongs to
@@ -143,6 +144,7 @@ HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber);
// SPI
#define SPI_COMMON_QTY 2
#define DEFAULT_SPI SPI1
#define PIN_SPI_SS P1_3
#define PIN_SPI_MOSI P1_1
@@ -153,14 +155,14 @@ static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
#define PIN_SPI1_SS P0_3
#define PIN_SPI1_MOSI P0_1
#define PIN_SPI1_MISO P0_0
#define PIN_SPI1_SCK P0_2
static const uint8_t SS1 = PIN_SPI1_SS;
static const uint8_t MOSI1 = PIN_SPI1_MOSI;
static const uint8_t MISO1 = PIN_SPI1_MISO;
static const uint8_t SCK1 = PIN_SPI1_SCK;
#define PIN_SPI0_SS P0_3
#define PIN_SPI0_MOSI P0_1
#define PIN_SPI0_MISO P0_0
#define PIN_SPI0_SCK P0_2
static const uint8_t SS0 = PIN_SPI0_SS;
static const uint8_t MOSI0 = PIN_SPI0_MOSI;
static const uint8_t MISO0 = PIN_SPI0_MISO;
static const uint8_t SCK0 = PIN_SPI0_SCK;
// check if pwm is used on spi pins
void spi_onBegin(uint8_t spiNum);
@@ -168,12 +170,13 @@ static inline void spi_onEnd(uint8_t spiNum){}
// I2C
#define I2C_COMMON_QTY 2
// Wire (I2C1)
#define DEFAULT_WIRE Wire0 // use I2C0 by default
// Wire1 (I2C1)
#define PIN_WIRE_SDA P1_12
#define PIN_WIRE_SCL P1_13
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
// Wire1 (I2C0)
// Wire0 (I2C0)
#define PIN_WIRE_SDA1 P0_9
#define PIN_WIRE_SCL1 P0_10
static const uint8_t SDA1 = PIN_WIRE_SDA1;
+11 -13
View File
@@ -101,27 +101,25 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
}
// ---------------------- PWM ---------------------- //
// use only if digitalPinHasPWM() == true
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin) & 16) ? 1 : 0)
// use only if digitalPinHasPWM() == true
// return true if digitalPin configured as pwm
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
// return 1 if digitalPin configured as pwm and enabled,
// 0 if pwm on pin is disabled,
// -1 if pin doesn't support pwm
__attribute__((noinline, section(".ram_text"))) int8_t digitalPinPwmIsOn(uint8_t digitalPin)
{
if (digitalPinHasPWM(digitalPin))
{
uint8_t config = 0;
uint8_t pinShift = digitalPin & 3;
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
if ((digitalPin & 16) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, (digitalPin & 3));
else
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, (digitalPin & 3));
if (config == 2)
return true;
return 1; // pwm is on
else
return 0; // pwm is off
}
return false;
return -1; // pin doesn't support pwm
}
// function is used only if digitalPinHasPWM() is true