Проверка в 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:
1 parent
f1e091bf77
commit
778608b576
29 files changed
+186
-130
No files matched your search
@@ -81,6 +81,7 @@ 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
|
||||
@@ -97,7 +98,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
|
||||
return false;
|
||||
}
|
||||
// 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
|
||||
@@ -105,6 +106,7 @@ HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber);
|
||||
|
||||
// SPI
|
||||
#define SPI_COMMON_QTY 2
|
||||
#define DEFAULT_SPI SPI1
|
||||
|
||||
#define PIN_SPI_SS 10
|
||||
#define PIN_SPI_MOSI 11
|
||||
@@ -116,14 +118,14 @@ static const uint8_t MISO = PIN_SPI_MISO;
|
||||
static const uint8_t SCK = PIN_SPI_SCK;
|
||||
|
||||
|
||||
#define PIN_SPI1_SS 9
|
||||
#define PIN_SPI1_MOSI 5
|
||||
#define PIN_SPI1_MISO 3
|
||||
#define PIN_SPI1_SCK 6
|
||||
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 9
|
||||
#define PIN_SPI0_MOSI 5
|
||||
#define PIN_SPI0_MISO 3
|
||||
#define PIN_SPI0_SCK 6
|
||||
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;
|
||||
|
||||
// config SEL_NSS1 to replace D10 to different controller pin,
|
||||
// because NSS which is D9/D10 by default is needed to spi
|
||||
@@ -131,9 +133,10 @@ void spi_onBegin(uint8_t spiNum);
|
||||
void spi_onEnd(uint8_t spiNum);
|
||||
|
||||
// I2C
|
||||
#define I2C_COMMON_QTY 1
|
||||
#define DEFAULT_WIRE Wire1 // use I2C1 by default
|
||||
#define PIN_WIRE_SDA 18
|
||||
#define PIN_WIRE_SCL 19
|
||||
#define I2C_COMMON_QTY 1
|
||||
static const uint8_t SDA = PIN_WIRE_SDA;
|
||||
static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
// available frequencies
|
||||
|
||||
@@ -204,27 +204,27 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
||||
}
|
||||
|
||||
// ---------------------- PWM ---------------------- //
|
||||
// use only if digitalPinHasPWM() == true
|
||||
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)||(pin==12)||(pin==13)) ? 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 = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
|
||||
|
||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||
else
|
||||
if ((digitalPin==10)||(digitalPin==11)||(digitalPin==12)||(digitalPin==13))
|
||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||
else
|
||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||
|
||||
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
|
||||
|
||||
@@ -76,6 +76,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
|
||||
@@ -92,7 +93,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
|
||||
return false;
|
||||
}
|
||||
// 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
|
||||
@@ -100,6 +101,7 @@ HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber);
|
||||
|
||||
// SPI
|
||||
#define SPI_COMMON_QTY 2
|
||||
#define DEFAULT_SPI SPI1
|
||||
|
||||
#define PIN_SPI_SS 10
|
||||
#define PIN_SPI_MOSI 11
|
||||
@@ -110,14 +112,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 9
|
||||
#define PIN_SPI1_MOSI 5
|
||||
#define PIN_SPI1_MISO 3
|
||||
#define PIN_SPI1_SCK 6
|
||||
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 9
|
||||
#define PIN_SPI0_MOSI 5
|
||||
#define PIN_SPI0_MISO 3
|
||||
#define PIN_SPI0_SCK 6
|
||||
static const uint8_t SS1 = PIN_SPI0_SS;
|
||||
static const uint8_t MOSI1 = PIN_SPI0_MOSI;
|
||||
static const uint8_t MISO1 = PIN_SPI0_MISO;
|
||||
static const uint8_t SCK1 = PIN_SPI0_SCK;
|
||||
|
||||
// config SEL_NSS1 to replace D10 to different controller pin,
|
||||
// because NSS which is D9/D10 by default is needed to spi
|
||||
@@ -125,9 +127,10 @@ void spi_onBegin(uint8_t spiNum);
|
||||
void spi_onEnd(uint8_t spiNum);
|
||||
|
||||
// I2C
|
||||
#define I2C_COMMON_QTY (1)
|
||||
#define DEFAULT_WIRE Wire1 // use I2C1 by default
|
||||
#define PIN_WIRE_SDA (18)
|
||||
#define PIN_WIRE_SCL (19)
|
||||
#define I2C_COMMON_QTY (1)
|
||||
static const uint8_t SDA = PIN_WIRE_SDA;
|
||||
static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
// available frequencies
|
||||
|
||||
@@ -167,26 +167,27 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
||||
}
|
||||
|
||||
// ---------------------- PWM ---------------------- //
|
||||
// use only if digitalPinHasPWM() == true
|
||||
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)||(pin==12)||(pin==13)) ? 1:0)
|
||||
|
||||
// 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 = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
|
||||
|
||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||
else
|
||||
if ((digitalPin==10)||(digitalPin==11)||(digitalPin==12)||(digitalPin==13))
|
||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||
else
|
||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||
|
||||
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
|
||||
|
||||
@@ -109,6 +109,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
|
||||
@@ -122,7 +123,7 @@ static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
|
||||
return (p <= P1_15) && ((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
|
||||
@@ -130,6 +131,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
|
||||
@@ -140,14 +142,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 SS1 = PIN_SPI0_SS;
|
||||
static const uint8_t MOSI1 = PIN_SPI0_MOSI;
|
||||
static const uint8_t MISO1 = PIN_SPI0_MISO;
|
||||
static const uint8_t SCK1 = PIN_SPI0_SCK;
|
||||
|
||||
// check if pwm is used on spi pins
|
||||
void spi_onBegin(uint8_t spiNum);
|
||||
@@ -155,12 +157,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
@@ -105,27 +105,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 & 0x3;
|
||||
|
||||
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 & 0x3));
|
||||
else
|
||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, (digitalPin & 0x3));
|
||||
|
||||
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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user