mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Adding FreeRToS constructs to I2C driver
This commit is contained in:
@@ -13,38 +13,81 @@ FRToSI2C::FRToSI2C(I2C_HandleTypeDef* i2chandle) {
|
||||
}
|
||||
|
||||
void FRToSI2C::MasterTxCpltCallback() {
|
||||
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
}
|
||||
|
||||
void FRToSI2C::MemRxCpltCallback() {
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
}
|
||||
void FRToSI2C::MemTxCpltCallback() {
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
}
|
||||
|
||||
void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
|
||||
taskENTER_CRITICAL();
|
||||
HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
|
||||
taskEXIT_CRITICAL();
|
||||
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
|
||||
|| RToSUP == false) {
|
||||
//no RToS, run blocking code
|
||||
HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
} else {
|
||||
//RToS is active, run threading
|
||||
//Get the mutex so we can use the I2C port
|
||||
//Wait up to 1 second for the mutex
|
||||
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
|
||||
HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData,
|
||||
Size, 5000);
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
|
||||
taskENTER_CRITICAL();
|
||||
HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
|
||||
taskEXIT_CRITICAL();
|
||||
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
|
||||
|| RToSUP == false) {
|
||||
//no RToS, run blocking code
|
||||
HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
} else {
|
||||
//RToS is active, run threading
|
||||
//Get the mutex so we can use the I2C port
|
||||
//Wait up to 1 second for the mutex
|
||||
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
|
||||
HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData,
|
||||
Size, 5000);
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FRToSI2C::FRToSInit() {
|
||||
I2CSemaphore = xSemaphoreCreateMutex();
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
RToSUP = true;
|
||||
}
|
||||
|
||||
void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) {
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
|
||||
taskENTER_CRITICAL();
|
||||
HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
|
||||
taskEXIT_CRITICAL();
|
||||
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
|
||||
|| RToSUP == false) {
|
||||
//no RToS, run blocking code
|
||||
HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
|
||||
} else {
|
||||
//RToS is active, run threading
|
||||
//Get the mutex so we can use the I2C port
|
||||
//Wait up to 1 second for the mutex
|
||||
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
|
||||
HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
|
||||
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ OLED::OLED(FRToSI2C* i2cHandle) {
|
||||
|
||||
void OLED::initialize() {
|
||||
HAL_Delay(5);
|
||||
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(5);
|
||||
//Send the setup settings
|
||||
|
||||
@@ -77,7 +77,7 @@ void SystemClock_Config(void) {
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; //TIM 2,3,4,5,6,7,12,13,14
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; //64 mhz to soem peripherals and adc
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; //64 mhz to some peripherals and adc
|
||||
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ int main(void) {
|
||||
*/
|
||||
HAL_Init();
|
||||
Setup_HAL(); // Setup all the HAL objects
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
setTipPWM(0);
|
||||
lcd.initialize(); // start up the LCD
|
||||
lcd.setFont(0); // default to bigger font
|
||||
@@ -641,6 +642,7 @@ static void gui_solderingMode() {
|
||||
|
||||
/* StartGUITask function */
|
||||
void startGUITask(void const *argument) {
|
||||
i2cDev.FRToSInit();
|
||||
/*
|
||||
* Main program states:
|
||||
*
|
||||
@@ -1085,3 +1087,16 @@ void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c) {
|
||||
}
|
||||
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c) {
|
||||
i2cDev.MasterTxCpltCallback();
|
||||
}
|
||||
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c) {
|
||||
i2cDev.MemTxCpltCallback();
|
||||
}
|
||||
|
||||
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c) {
|
||||
i2cDev.MemRxCpltCallback();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user