Обновление до версии 0.3.0

- обновлен elbear_fw_bootloader - добавлена проверка контрольной суммы каждой строки hex файла.
- в модуль работы с АЦП добавлена функция analogReadResolution(). Функция analogRead() теперь возвращает усредненное по 10 измерениям значение.
- общая функция обработки прерываний перенесена в память RAM. Обработчики прерываний модулей External Interrupts и Advanced I/O (функция tone()) так же перенесены в память RAM для увеличения скорости выполнения кода.
- в пакет добавлены библиотеки EEPROM, Servo, SoftSerial, NeoPixel, MFRC522 адаптированные для работы с платой Elbear Ace-Uno.
- добавлено описание особенностей работы с пакетом
This commit was merged in pull request #6.
This commit is contained in:
klassents committed 2024-10-17 08:27:39 +03:00
1 parent 7a7c552743
commit 766b7b32ea
114 files changed
+11064 -666

No files matched your search

+1 -1
View File
@@ -309,7 +309,7 @@ void TwoWire::onRequest( void (*function)(void) )
}
// С function for trap handler
extern "C" void wire_handler_wrapper(void)
extern "C" void __attribute__((optimize("O3"))) wire_interrupt_handler(void)
{
twi_interruptHandler();
}
+26 -45
View File
@@ -88,36 +88,22 @@ void twi_deinit(void)
{
uint32_t EPICmask;
HAL_I2C_Disable(&hi2c);
// disable clock
#if I2C_NUM == 0
hi2c.Instance = I2C_0;
EPICmask = HAL_EPIC_I2C_0_MASK;
__HAL_PCC_I2C_0_CLK_DISABLE();
#elif I2C_NUM == 1
hi2c.Instance = I2C_1;
EPICmask = HAL_EPIC_I2C_1_MASK;
__HAL_PCC_I2C_1_CLK_DISABLE();
#else
#error "Unsupported I2C_NUM value in pins_arduino.h"
#endif
HAL_I2C_Deinit(&hi2c);
// for slave mode disable interrupts from i2c
if (hi2c.Init.Mode == HAL_I2C_MODE_SLAVE)
HAL_EPIC_MaskLevelClear(EPICmask);
// reconfigure pins to z state
GPIO_InitTypeDef GPIO_InitStruct;
memset(&GPIO_InitStruct, 0, sizeof(GPIO_InitStruct));
// SDA
GPIO_InitStruct.Pin = (HAL_PinsTypeDef)digitalPinToBitMask(PIN_WIRE_SDA);
GPIO_InitStruct.Mode = HAL_GPIO_MODE_GPIO_INPUT;
GPIO_InitStruct.Pull = HAL_GPIO_PULL_NONE;
HAL_GPIO_Init(digitalPinToPort(PIN_WIRE_SDA), &GPIO_InitStruct);
// SCL
GPIO_InitStruct.Pin = (HAL_PinsTypeDef)digitalPinToBitMask(PIN_WIRE_SCL);
HAL_GPIO_Init(digitalPinToPort(PIN_WIRE_SCL), &GPIO_InitStruct);
twiIsOn = false;
}
@@ -252,7 +238,7 @@ uint8_t twi_masterWriteTo(uint8_t address, uint8_t* data, uint8_t length, uint8_
// parse errors
// check separately, because in hal libraries not all functions look at this
if (hi2c.Instance->ISR & I2C_ISR_NACKF_M)
if (HAL_I2C_Get_Interrupts_Status(&hi2c) & I2C_ISR_NACKF_M)
hi2c.ErrorCode = I2C_ERROR_NACK;
if (hi2c.ErrorCode == (HAL_I2C_ErrorTypeDef)I2C_ERROR_TIMEOUT) ret = I2C_TIMEOUT; // timeout
else if (hi2c.ErrorCode == (HAL_I2C_ErrorTypeDef)I2C_ERROR_NACK) ret = I2C_NACK_DATA; // didn't receive ACK
@@ -275,39 +261,35 @@ i2c_status_e twi_slaveWrite(uint8_t *txData, uint8_t bytesNum)
if ((hi2c.ErrorCode != I2C_ERROR_NONE))
HAL_I2C_Reset(&hi2c);
// отправка данных
// send data
HAL_StatusTypeDef error_code = HAL_OK;
hi2c.Instance->CR2 &= ~I2C_CR2_RELOAD_M;
HAL_I2C_Clear_Reload(&hi2c);
if (!(HAL_I2C_Get_CR1_Content(&hi2c) & I2C_CR1_NOSTRETCH_M)) // NOSTRETCH = 0
HAL_I2C_Reset_TXDR_Content(&hi2c);
HAL_I2C_Write_TXDR(&hi2c, txData[0]); // first recording is made in advance
if (!(hi2c.Instance->CR1 & I2C_CR1_NOSTRETCH_M)) // NOSTRETCH = 0
hi2c.Instance->ISR |= I2C_ISR_TXE_M; // Reset TXDR contents
hi2c.Instance->TXDR = txData[0]; // The first recording is made in advance
// Запись байта
// write byte
for (uint32_t tx_count = 1; tx_count < bytesNum; tx_count++)
{
if ((error_code = HAL_I2C_Slave_WaitTXIS(&hi2c, TIMEOUT_TICKS)) != HAL_OK)
{
// неудачная запись
hi2c.Instance->ISR |= I2C_ISR_TXE_M; // Reset TXDR contents
hi2c.Instance->ICR |= I2C_ICR_STOPCF_M; // Clear the STOP detection flag on the bus
// failed to write
HAL_I2C_Reset_TXDR_Content(&hi2c);
HAL_I2C_Reset_Interrupt_Flag(&hi2c, I2C_ICR_STOPCF_M); // Clear the STOP detection flag on the bus
HAL_I2C_Reset(&hi2c);
return I2C_TIMEOUT;
}
hi2c.Instance->TXDR = txData[tx_count];
HAL_I2C_Write_TXDR(&hi2c, txData[tx_count]);
}
if ((error_code = HAL_I2C_WaitBusy(&hi2c, TIMEOUT_TICKS)) != HAL_OK)
{
// неудачное завершение транзакции
// failed to complete transaction
HAL_I2C_Reset(&hi2c);
return I2C_TIMEOUT;
}
hi2c.Instance->ISR |= I2C_ISR_TXE_M; // Reset TXDR contents
hi2c.Instance->ICR |= I2C_ICR_STOPCF_M; // Clear the STOP detection flag on the bus
HAL_I2C_Reset_TXDR_Content(&hi2c);
HAL_I2C_Reset_Interrupt_Flag(&hi2c, I2C_ICR_STOPCF_M); // Clear the STOP detection flag on the bus
return I2C_OK;
}
@@ -341,27 +323,26 @@ void twi_attachSlaveTxEvent( void (*function)(void) )
* Input none
* Output none
*/
void twi_interruptHandler(void)
void __attribute__((optimize("O3"))) twi_interruptHandler(void)
{
uint32_t int_mask = hi2c.Instance->CR1 & I2C_INTMASK; // interrupts allowed
uint32_t interrupt_status = hi2c.Instance->ISR; // current flags
uint32_t int_mask = HAL_I2C_Get_CR1_Content(&hi2c) & I2C_INTMASK; // interrupts allowed
uint32_t interrupt_status = HAL_I2C_Get_Interrupts_Status(&hi2c); // current flags
// master calls by address, device in slave mode
if ((interrupt_status & I2C_ISR_ADDR_M) && (int_mask & I2C_CR1_ADDRIE_M))
{
// reset ADDR flag
hi2c.Instance->ICR |= I2C_ICR_ADDRCF_M;
HAL_I2C_Reset_Interrupt_Flag(&hi2c, I2C_ICR_ADDRCF_M);
// look at the transmission direction and respond to the request
if (interrupt_status & I2C_ISR_DIR_M) // master reads, slave sends
// отправляем данные
twi_onSlaveTransmit();
twi_onSlaveTransmit(); // slave send data
else // master writes, slave reads
{
twi_rxBufferIndex = 0; // write from the beginning of the buffer
hi2c.State = HAL_I2C_STATE_BUSY;
hi2c.Instance->CR2 &= ~I2C_CR2_RELOAD_M;
// wait for interrupts because of receiving a byte or a stop condition
HAL_I2C_Clear_Reload(&hi2c);
// wait for interrupts by receiving a byte or a stop condition
}
}
@@ -369,15 +350,15 @@ void twi_interruptHandler(void)
if ((interrupt_status & I2C_ISR_RXNE_M) && (int_mask & I2C_CR1_RXIE_M))
{
// put new byte into buffer
twi_rxBuffer[twi_rxBufferIndex++] = (uint8_t)hi2c.Instance->RXDR;
twi_rxBuffer[twi_rxBufferIndex++] = HAL_I2C_Get_RXDR(&hi2c);
}
// master sent a STOP to the bus
if ((interrupt_status & I2C_ISR_STOPF_M) && (int_mask & I2C_CR1_STOPIE_M))
{
hi2c.State = HAL_I2C_STATE_END;
hi2c.Instance->ISR |= I2C_ISR_TXE_M; // Reset TXDR contents
hi2c.Instance->ICR |= I2C_ICR_STOPCF_M; // Clear the STOP detection flag on the bus
HAL_I2C_Reset_TXDR_Content(&hi2c);
HAL_I2C_Reset_Interrupt_Flag(&hi2c, I2C_ICR_STOPCF_M); // Clear the STOP detection flag on the bus
// pass the received data to callback function
twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex);
}