IR Exported Functions
- group IR_Exported_Functions
Functions
-
void IR_DeInit(void)
Deinitialize the IR peripheral registers to their default values.
Example usage
void driver_ir_init(void) { IR_DeInit(); }
- Returns:
None.
-
void IR_Init(IR_InitTypeDef *IR_InitStruct)
Initialize the IR peripheral according to the specified parameters in IR_InitStruct.
Example usage
void driver_ir_init(void) { RCC_PeriphClockCmd(APBPeriph_IR, APBPeriph_IR_CLOCK, ENABLE); IR_InitTypeDef IR_InitStruct; IR_StructInit(&IR_InitStruct); IR_InitStruct.IR_Freq = 38000;// IR carrier frequency is 38KHz IR_InitStruct.IR_Mode = IR_MODE_RX;// IR receiving mode IR_InitStruct.IR_RxStartMode = IR_RX_AUTO_MODE; IR_InitStruct.IR_RxFIFOThrLevel = IR_RX_FIFO_THR_LEVEL; // Configure RX FIFO threshold level to trigger IR_INT_RF_LEVEL interrupt IR_InitStruct.IR_RxFIFOFullCtrl = IR_RX_FIFO_FULL_DISCARD_NEWEST;// Discard the latest received data if RX FIFO is full IR_InitStruct.IR_RxFilterTime = IR_RX_FILTER_TIME_50ns;// If high to low or low to high transition time <= 50ns, filter it out. IR_InitStruct.IR_RxTriggerMode = IR_RX_FALL_EDGE;// Configure trigger type IR_InitStruct.IR_RxCntThrType = IR_RX_Count_High_Level;// IR_RX_Count_High_Level is counting high level IR_InitStruct.IR_RxCntThr = 0x1F40;// Configure RX counter threshold. This can be used to decide when to stop receiving IR data IR_Init(&IR_InitStruct); IR_Cmd(IR_MODE_RX, ENABLE); IR_ClearRxFIFO(); }
- Parameters:
IR_InitStruct – [in] Pointer to an IR_InitTypeDef structure that contains the configuration information for the specified IR peripheral.
- Returns:
None.
-
void IR_StructInit(IR_InitTypeDef *IR_InitStruct)
Fill each IR_InitStruct member with its default value.
Example usage
void driver_ir_init(void) { RCC_PeriphClockCmd(APBPeriph_IR, APBPeriph_IR_CLOCK, ENABLE); IR_InitTypeDef IR_InitStruct; IR_StructInit(&IR_InitStruct); IR_InitStruct.IR_Freq = 38000;// IR carrier frequency is 38KHz IR_InitStruct.IR_Mode = IR_MODE_RX;// IR receiving mode IR_InitStruct.IR_RxStartMode = IR_RX_AUTO_MODE; IR_InitStruct.IR_RxFIFOThrLevel = IR_RX_FIFO_THR_LEVEL; // Configure RX FIFO threshold level to trigger IR_INT_RF_LEVEL interrupt IR_InitStruct.IR_RxFIFOFullCtrl = IR_RX_FIFO_FULL_DISCARD_NEWEST;// Discard the latest received data if RX FIFO is full IR_InitStruct.IR_RxFilterTime = IR_RX_FILTER_TIME_50ns;// If high to low or low to high transition time <= 50ns, filter it out. IR_InitStruct.IR_RxTriggerMode = IR_RX_FALL_EDGE;// Configure trigger type IR_InitStruct.IR_RxCntThrType = IR_RX_Count_High_Level;// IR_RX_Count_High_Level is counting high level IR_InitStruct.IR_RxCntThr = 0x1F40;// Configure RX counter threshold. This can be used to decide when to stop receiving IR data IR_Init(&IR_InitStruct); IR_Cmd(IR_MODE_RX, ENABLE); IR_ClearRxFIFO(); }
- Parameters:
IR_InitStruct – [in] Pointer to an IR_InitTypeDef structure which will be initialized.
- Returns:
None.
-
void IR_Cmd(uint32_t mode, FunctionalState NewState)
Enable or disable the selected IR mode.
Example usage
void driver_ir_init(void) { RCC_PeriphClockCmd(APBPeriph_IR, APBPeriph_IR_CLOCK, ENABLE); IR_InitTypeDef IR_InitStruct; IR_StructInit(&IR_InitStruct); IR_InitStruct.IR_Freq = 38000;// IR carrier frequency is 38KHz IR_InitStruct.IR_Mode = IR_MODE_RX;// IR receiving mode IR_InitStruct.IR_RxStartMode = IR_RX_AUTO_MODE; IR_InitStruct.IR_RxFIFOThrLevel = IR_RX_FIFO_THR_LEVEL; // Configure RX FIFO threshold level to trigger IR_INT_RF_LEVEL interrupt IR_InitStruct.IR_RxFIFOFullCtrl = IR_RX_FIFO_FULL_DISCARD_NEWEST;// Discard the latest received data if RX FIFO is full IR_InitStruct.IR_RxFilterTime = IR_RX_FILTER_TIME_50ns;// If high to low or low to high transition time <= 50ns, filter it out. IR_InitStruct.IR_RxTriggerMode = IR_RX_FALL_EDGE;// Configure trigger type IR_InitStruct.IR_RxCntThrType = IR_RX_Count_High_Level;// IR_RX_Count_High_Level is counting high level IR_InitStruct.IR_RxCntThr = 0x1F40;// Configure RX counter threshold. This can be used to decide when to stop receiving IR data IR_Init(&IR_InitStruct); IR_Cmd(IR_MODE_RX, ENABLE); IR_ClearRxFIFO(); }
- Parameters:
mode – [in] Selected IR operation mode. This parameter can be one of the following values, which refers to IR Mode.
IR_MODE_TX: Transmission mode.
IR_MODE_RX: Receiving mode.
NewState – [in] New state of the operation mode. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void IR_StartManualRxTrigger(void)
Start trigger receive, only in manual receive mode.
Example usage
void ir_demo(void) { IR_StartManualRxTrigger(); }
- Returns:
None.
-
void IR_SetRxCounterThreshold(uint32_t IR_RxCntThrType, uint32_t IR_RxCntThr)
Config counter threshold value in receiving mode. It can be used to stop receiving IR data.
Example usage
void ir_demo(void) { IR_SetRxCounterThreshold(IR_RX_Count_Low_Level, 0x100); }
- Parameters:
IR_RxCntThrType – [in] Count threshold type. This parameter can be the following values, which refers to IR RX Counter Threshold Type.
IR_RX_Count_Low_Level: Low level counter value >= IR_RxCntThr, trigger IR_INT_RX_CNT_THR interrupt.
IR_RX_Count_High_Level: High level counter value >= IR_RxCntThr, trigger IR_INT_RX_CNT_THR interrupt.
IR_RxCntThr – [in] Configure IR Rx counter threshold value which can be 0 to 0x7fffffff.
- Returns:
None.
-
void IR_SendBuf(uint32_t *pBuf, uint32_t len, FunctionalState IsLastPacket)
Send data buffer.
Example usage
void ir_demo(void) { uint32_t data_buf[80] = {0}; IR_SendBuf(data_buf, 68, DISABLE); }
- Parameters:
pBuf – [in] Data buffer to send.
len – [in] Send data length.
IsLastPacket – [in] Is it the last package of data. This parameter can be one of the following values:
ENABLE: The last data in IR packet and there is no continuous data. In other words, an infrared data transmission is completed.
DISABLE: There is data to be transmitted continuously.
- Returns:
None.
-
void IR_SendCompenBuf(IR_TX_COMPEN_TYPE comp_type, uint32_t *pBuf, uint32_t len, FunctionalState IsLastPacket)
Send compensation data.
Example usage
void ir_demo(void) { uint32_t data_buf[80] = {0}; IR_SendCompenBuf(IR_COMPEN_FLAG_1_2_CARRIER, data_buf, 68, DISABLE); }
- Parameters:
comp_type – [in] Compensation data type. This parameter can be one of the following values, which refers to IR Compensation Flag.
IR_COMPEN_FLAG_1_2_CARRIER: 1/2 carrier frequency.
IR_COMPEN_FLAG_1_4_CARRIER: 1/4 carrier frequency.
IR_COMPEN_FLAG_1_N_SYSTEM_CLK: MOD((0x48[27:16]+0x00[11:0]), 4095)/40MHz. User can call function of IR_ConfigCompParam to configure 0x48[27:16].
buf – [in] Data buffer to send.
length – [in] Data length.
IsLastPacket – [in] Is it the last package of data. This parameter can be the following values:
ENABLE: The last data in IR packet and there is no continuous data. In other words, an infrared data transmission is completed.
DISABLE: There is data to be transmitted continuously.
- Returns:
None.
-
void IR_ReceiveBuf(uint32_t *pBuf, uint32_t length)
Read data From RX FIO.
Example usage
void ir_demo(void) { uint32_t data_buf[80] = {0}; IR_ReceiveBuf(data_buf, 68); }
- Parameters:
pBuf – [out] Buffer address to receive data.
length – [in] Read data length.
- Returns:
None.
-
void IR_INTConfig(uint32_t IR_INT, FunctionalState newState)
Enable or disable the specified IR interrupt source.
Example usage
void ir_demo(void) { IR_INTConfig(IR_INT_TF_EMPTY, ENABLE); }
- Parameters:
IR_INT – [in] Specify the IR interrupt source to be enabled or disabled. This parameter can be one of the following values, which refers to IR Interrupt Definition.
IR_INT_TF_EMPTY: When TX FIFO is empty, TX FIFO Empty Interrupt will be triggered.
IR_INT_TF_LEVEL: When TX FIFO offset <= threshold value, trigger TX FIFO Level Interrupt.
IR_INT_TF_OF: When TX FIFO is full, data continues to be written to TX FIFO, TX FIFO overflow interrupt will be triggered.
IR_INT_TX_FINISH: When TX finished, TX Finish Interrupt will be triggered.
IR_INT_RF_FULL: When RX FIFO offset = 32, RX FIFO Full Interrupt will be triggered.
IR_INT_RF_LEVEL: When RX FIFO offset > threshold value, trigger RX FIFO Level Interrupt.
IR_INT_RX_CNT_OF: When RX counter overflows, RX counter overflow interrupt will be triggered.
IR_INT_RF_OF: When RX FIFO is full and continues to be written, RX FIFO overflow interrupt will be triggered.
IR_INT_RX_CNT_THR: When RX counter >= IR_RX_CNT_THR, RX Counter Threshold Interrupt will be triggered.
IR_INT_RF_ERROR: When RX FIFO is empty and continues to be read, RX FIFO error read interrupt will be triggered.
IR_INT_RISING_EDGE: When RX FIFO receives a low to high pulse, RX Rising Edge Interrupt will be triggered.
IR_INT_FALLING_EDGE: When RX FIFO receives a high to low pulse, RX Falling Edge Interrupt will be triggered.
newState – [in] New state of the specified IR interrupt. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void IR_MaskINTConfig(uint32_t IR_INT, FunctionalState newState)
Mask or unmask the specified IR interrupt source.
Example usage
void ir_demo(void) { IR_MaskINTConfig(IR_INT_TF_EMPTY, ENABLE); }
- Parameters:
IR_INT – [in] Specify the IR interrupts sources to be masked or unmasked. This parameter can be the following values, which refers to IR Interrupt Definition.
IR_INT_TF_EMPTY: When TX FIFO is empty, TX FIFO Empty Interrupt will be triggered.
IR_INT_TF_LEVEL: When TX FIFO offset <= threshold value, trigger TX FIFO Level Interrupt.
IR_INT_TF_OF: When TX FIFO is full, data continues to be written to TX FIFO, TX FIFO Overflow interrupt will be triggered.
IR_INT_TX_FINISH: When TX finished, TX Finish Interrupt will be triggered.
IR_INT_RF_FULL: When RX FIFO offset = 32, RX FIFO Full Interrupt will be triggered.
IR_INT_RF_LEVEL: When RX FIFO offset > threshold value, trigger RX FIFO Level Interrupt.
IR_INT_RX_CNT_OF: When RX counter overflows, RX counter overflow interrupt will be triggered.
IR_INT_RF_OF: When RX FIFO is full and continues to be written, RX FIFO overflow interrupt will be triggered.
IR_INT_RX_CNT_THR: When RX counter >= IR_RX_CNT_THR, RX Counter Threshold Interrupt will be triggered.
IR_INT_RF_ERROR: When RX FIFO is empty and continues to be read, RX FIFO error read interrupt will be triggered.
IR_INT_RISING_EDGE: When RX FIFO receives a low to high pulse, RX Rising Edge Interrupt will be triggered.
IR_INT_FALLING_EDGE: When RX FIFO receives a high to low pulse, RX Falling Edge Interrupt will be triggered.
newState – [in] New state of the specified IR interrupts. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
ITStatus IR_GetINTStatus(uint32_t IR_INT)
Get the specified IR interrupt status.
Example usage
void ir_demo(void) { ITStatus int_status = IR_GetINTStatus(IR_INT_TF_EMPTY); }
- Parameters:
IR_INT – [in] the specified IR interrupts. This parameter can be one of the following values, which refers to IR Interrupt Definition.
IR_INT_TF_EMPTY: When TX FIFO is empty, TX FIFO Empty Interrupt will be triggered.
IR_INT_TF_LEVEL: When TX FIFO offset <= threshold value, trigger TX FIFO Level Interrupt.
IR_INT_TF_OF: When TX FIFO is full, data continues to be written to TX FIFO, TX FIFO Overflow interrupt will be triggered.
IR_INT_TX_FINISH: When TX finished, TX Finish Interrupt will be triggered.
IR_INT_RF_FULL: When RX FIFO offset = 32, RX FIFO Full Interrupt will be triggered.
IR_INT_RF_LEVEL: When RX FIFO offset > threshold value, trigger RX FIFO Level Interrupt.
IR_INT_RX_CNT_OF: When RX counter overflows, RX counter overflow interrupt will be triggered.
IR_INT_RF_OF: When RX FIFO is full and continues to be written, RX FIFO overflow interrupt will be triggered.
IR_INT_RX_CNT_THR: When RX counter >= IR_RX_CNT_THR, RX Counter Threshold Interrupt will be triggered.
IR_INT_RF_ERROR: When RX FIFO is empty and continues to be read, RX FIFO error read interrupt will be triggered.
IR_INT_RISING_EDGE: When RX FIFO receives a low to high pulse, RX Rising Edge Interrupt will be triggered.
IR_INT_FALLING_EDGE: When RX FIFO receives a high to low pulse, RX Falling Edge Interrupt will be triggered.
- Returns:
The new state of IR_INT (SET or RESET).
-
void IR_ClearINTPendingBit(uint32_t IR_CLEAR_INT)
Clear the IR interrupt pending bit.
Example usage
void ir_demo(void) { IR_ClearINTPendingBit(IR_INT_RX_CNT_OF_CLR); }
- Parameters:
IR_CLEAR_INT – [in] Specify the interrupt pending bit to clear. This parameter can be any combination of the following values, which refers to IR Interrupts Clear Flag.
IR_INT_TF_EMPTY_CLR: Clear TX FIFO empty interrupt.
IR_INT_TF_LEVEL_CLR: Clear TX FIFO threshold interrupt.
IR_INT_TF_OF_CLR: Clear TX FIFO overflow interrupt.
IR_INT_TX_FINISH_CLR: Clear TX finish interrupt.
IR_INT_RF_FULL_CLR: Clear RX FIFO full interrupt.
IR_INT_RF_LEVEL_CLR: Clear RX FIFO threshold interrupt.
IR_INT_RX_CNT_OF_CLR: Clear RX counter overflow interrupt.
IR_INT_RF_OF_CLR: Clear RX FIFO overflow interrupt.
IR_INT_RX_CNT_THR_CLR: Clear RX counter threshold interrupt.
IR_INT_RF_ERROR_CLR: Clear RX FIFO error read interrupt. Trigger when RX FIFO empty and read RX FIFO.
IR_INT_RX_RISING_EDGE_CLR: Clear RX Rising edge interrupt.
IR_INT_RX_FALLING_EDGE_CLR: Clear RX Falling edge interrupt.
- Returns:
None.
-
uint16_t IR_GetTxFIFOFreeLen(void)
Get free size of TX FIFO.
Example usage
void ir_demo(void) { uint16_t data_len = IR_GetTxFIFOFreeLen(); }
- Returns:
The free size of TX FIFO.
-
uint16_t IR_GetRxDataLen(void)
Get data size in RX FIFO.
Example usage
void ir_demo(void) { uint16_t data_len = IR_GetRxDataLen(); }
- Returns:
Current data size in RX FIFO.
-
void IR_SendData(uint32_t data)
Send one data.
Example usage
void ir_demo(void) { IR_SendData(0x80000100); }
- Parameters:
data – [in] Send data.
- Returns:
None.
-
uint32_t IR_ReceiveData(void)
Read one data.
Example usage
void ir_demo(void) { uint32_t data = IR_ReceiveData(); }
- Returns:
Data which is read from RX FIFO.
-
void IR_SetTxThreshold(uint8_t thd)
Set tx threshold, when TX FIFO depth <= threshold value, trigger interrupt.
Example usage
void ir_demo(void) { IR_SetTxThreshold(30); }
- Parameters:
thd – [in] Tx threshold.
- Returns:
None.
-
void IR_SetRxThreshold(uint8_t thd)
Set rx threshold, when RX FIFO depth > threshold value, trigger interrupt.
Example usage
void ir_demo(void) { IR_SetRxThreshold(2); }
- Parameters:
thd – [in] Rx threshold.
- Returns:
None.
-
uint32_t IR_GetRxCurrentCount(void)
Get IR RX current count.
Example usage
void ir_demo(void) { uint32_t count = IR_GetRxCurrentCount(); }
- Returns:
Current counter.
-
void IR_ClearTxFIFO(void)
Clear IR TX FIFO.
Example usage
void ir_demo(void) { IR_ClearTxFIFO(); }
- Returns:
None.
-
void IR_ClearRxFIFO(void)
Clear IR RX FIFO.
Example usage
void ir_demo(void) { IR_ClearRxFIFO(); }
- Returns:
None.
-
FlagStatus IR_GetFlagStatus(uint32_t IR_FLAG)
Check whether the specified IR flag is set.
Example usage
void ir_demo(void) { FlagStatus flag_status = IR_GetFlagStatus(IR_FLAG_TF_EMPTY); }
- Parameters:
IR_FLAG – [in] Specify the flag to check. This parameter can be one of the following values, which refer to IR Flag.
IR_FLAG_TF_EMPTY: TX FIFO empty or not. If SET, TX FIFO is empty.
IR_FLAG_TF_FULL: TX FIFO full or not. If SET, TX FIFO is full.
IR_FLAG_TX_RUN: TX run or not. If SET, TX is running.
IR_FLAG_RF_EMPTY: RX FIFO empty or not. If SET, RX FIFO is empty.
IR_FLAG_RF_FULL: RX FIFO full or not. If SET, RX FIFO is full.
IR_FLAG_RX_RUN: RX run or not. If SET, RX is running.
- Returns:
The new state of IR_FLAG (SET or RESET).
-
void IR_SetTxInverse(FunctionalState NewState)
Enable TX FIFO inverse or not.
Example usage
void ir_demo(void) { IR_SetTxInverse(ENABLE); }
- Parameters:
NewState – [in] This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void IR_TxOutputInverse(FunctionalState NewState)
Enable TX active output inverse or not.
Example usage
void ir_demo(void) { IR_TxOutputInverse(ENABLE); }
- Parameters:
NewState – [in] This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
uint32_t IR_GetRxCurrentLevel(void)
Get IR RX Level.
Example usage
void ir_demo(void) { uint32_t level = IR_GetRxCurrentLevel(); }
- Returns:
Current Level.
-
void IR_DeInit(void)