|
@@ -0,0 +1,61 @@
|
|
|
+#include "freertos/FreeRTOS.h"
|
|
|
+#include "freertos/task.h"
|
|
|
+#include "freertos/queue.h"
|
|
|
+#include "esp_log.h"
|
|
|
+#include "driver/rmt.h"
|
|
|
+
|
|
|
+#include "toshiba_ir.h"
|
|
|
+#include "config.h"
|
|
|
+
|
|
|
+// RMT values
|
|
|
+#define RMT_TX_CHANNEL RMT_CHANNEL_0
|
|
|
+#define RMT_TX_GPIO GPIO_NUM_26
|
|
|
+// channel clock period = 1 uS
|
|
|
+#define RMT_CLK_DIV 80
|
|
|
+
|
|
|
+// RAM item that holds the IR protocol
|
|
|
+rmt_item32_t toshiba_rmt[1 + 72 + 1];
|
|
|
+
|
|
|
+
|
|
|
+void initIrTransmit() {
|
|
|
+
|
|
|
+ rmt_config_t rmt_tx = RMT_DEFAULT_CONFIG_TX(GPIO_IR_TX_DATA, RMT_TX_CHANNEL);;
|
|
|
+ rmt_tx.rmt_mode = RMT_MODE_TX;
|
|
|
+ rmt_tx.channel = RMT_TX_CHANNEL;
|
|
|
+ rmt_tx.gpio_num = GPIO_IR_TX_DATA;
|
|
|
+ rmt_tx.mem_block_num = 1;
|
|
|
+ rmt_tx.clk_div = RMT_CLK_DIV;
|
|
|
+ rmt_tx.tx_config.loop_en = false;
|
|
|
+ rmt_tx.tx_config.carrier_duty_percent = 30;
|
|
|
+ rmt_tx.tx_config.carrier_freq_hz = 38000;
|
|
|
+ rmt_tx.tx_config.carrier_level = RMT_CARRIER_LEVEL_HIGH;
|
|
|
+ rmt_tx.tx_config.carrier_en = true;
|
|
|
+ rmt_tx.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
|
|
|
+ rmt_tx.tx_config.idle_output_en = true;
|
|
|
+
|
|
|
+ ESP_ERROR_CHECK( rmt_config(&rmt_tx) );
|
|
|
+ ESP_ERROR_CHECK( rmt_driver_install(rmt_tx.channel, 0, 0) );
|
|
|
+
|
|
|
+ // Init the ir data field
|
|
|
+ toshiba_rmt[0].val = (kToshibaAcHdrMark << 17) | (1 << 16) | (kToshibaAcHdrSpace << 1) | 0; // Header of IR Transmit
|
|
|
+ toshiba_rmt[73].val = (kToshibaAcBitMark << 17) | (1 << 16) | (kToshibaAcZeroSpace << 1) | 0; // End IR Transmit
|
|
|
+
|
|
|
+ for(int i=1;i<72;i++) {
|
|
|
+ toshiba_rmt[i].val = (kToshibaAcBitMark << 17) | (1 << 16) | (kToshibaAcHdrSpace << 1) | 0; // Header of IR Transmit
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ printf("RMT initialized\n");
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void sendToshibaIRData() {
|
|
|
+
|
|
|
+ ESP_ERROR_CHECK(rmt_write_items(RMT_TX_CHANNEL, toshiba_rmt, sizeof(toshiba_rmt) / sizeof(toshiba_rmt[0]), true));
|
|
|
+
|
|
|
+}
|