/*
 * irda.h
 *
 *  Created on: Oct 12, 2024
 *      Author: true
 */

#ifndef USER_DEVICE_IRDA_H_
#define USER_DEVICE_IRDA_H_



#include <ch32v00x.h>
#include <stdint.h>


enum {
    IRDA_STATE_IDLE,
    IRDA_STATE_TX_HEADER,
    IRDA_STATE_TX_BODY,
    IRDA_STATE_TX_ACK,
    IRDA_STATE_RX_DATA,
    IRDA_STATE_RX_ACK
};



#define IRDA_HEADER_01  0x5a
#define IRDA_HEADER_02  0xa5


#define IRDA_SD_PORT            GPIOA
#define IRDA_SD_PIN             GPIO_Pin_1

#define IrDA_Shutdown()         IRDA_SD_PORT->BSHR = GPIO_Pin_1
#define IrDA_Enable()           IRDA_SD_PORT->BCR = GPIO_Pin_1

#define IrDA_USART_ENA_TX()     (USART1->CTLR1 &= ~(USART_Mode_Rx); USART1->CTLR1 |= USART_Mode_Tx);
#define IrDA_USART_ENA_RX()     (USART1->CTLR1 &= ~(USART_Mode_Tx); USART1->CTLR1 |= USART_Mode_Rx);



extern uint16_t irda_tx_timer;
extern uint16_t irda_tx_timeout;



void irda_init();
void irda_process();

void irda_mode(uint8_t mode, uint16_t timeout);



#endif /* USER_DEVICE_IRDA_H_ */
