Procházet zdrojové kódy

Added RMT-files for IR Transmit

Thomas Chef před 2 roky
rodič
revize
0e5aa776e3
10 změnil soubory, kde provedl 101 přidání a 14 odebrání
  1. 1 0
      .gitignore
  2. 5 2
      main/config.h
  3. 61 0
      main/ir_transmit.c
  4. 4 0
      main/ir_transmit.h
  5. 8 1
      main/main.c
  6. 3 1
      main/readTemps.c
  7. 7 3
      main/receiver.c
  8. 4 0
      main/rxTimer.c
  9. 0 7
      main/toshiba_ir.c
  10. 8 0
      main/toshiba_ir.h

+ 1 - 0
.gitignore

@@ -77,3 +77,4 @@ wifi_manager/doc/
 .ipynb_checkpoints/
 Untitled.ipynb
 debug.log
+dependencies.lock

+ 5 - 2
main/config.h

@@ -6,12 +6,15 @@
 #define SW_VERSION "1.0"
 
 // These defines configures which code to generate (to save download time during development)
-#define WIFI_ENABLED
-#define MQTT_ENABLED
+//#define WIFI_ENABLED
+//#define MQTT_ENABLED
 //#define ENABLE_DS18B20
 
 #define MQTT_DEBUG              // Add an extra debug string to the topic-string
 
+//#define RX_TIMER
+//#define IR_RECEIVER
+
 #define ONE_WIRE_BUS_IO           GPIO_NUM_16   // Temp sensors
 
 #define GPIO_IR_RX_DATA              GPIO_NUM_26   // IR Receiver

+ 61 - 0
main/ir_transmit.c

@@ -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));
+
+}

+ 4 - 0
main/ir_transmit.h

@@ -0,0 +1,4 @@
+
+
+void initIrTransmit();
+void sendToshibaIRData();

+ 8 - 1
main/main.c

@@ -7,6 +7,7 @@
 #include "readTemps.h"
 #include "rxTimer.h"
 #include "receiver.h"
+#include "ir_transmit.h"
 
 
 // Chip info:
@@ -22,7 +23,9 @@ void app_main(void)
     vTaskDelay(1000.0 / portTICK_PERIOD_MS);
 
 
+#ifdef RX_TIMER
     rxTimerInit();          // First we start the Timer (which samples Rx and handles uS-delays)
+#endif
 
 #ifdef ENABLE_DS18B20
     initTempReadings();
@@ -36,7 +39,9 @@ void app_main(void)
     mqtt_init();
 #endif
 
+#ifdef IR_RECEIVER
     initReceiver();         // Init receiver-task
+#endif
 
     TickType_t vLastWakeTime = xTaskGetTickCount();
 
@@ -46,7 +51,9 @@ void app_main(void)
     // ---------------- MAIN WHILE -------------------
     while(1) {
 
-        vTaskDelayUntil( &vLastWakeTime, 60000 / portTICK_PERIOD_MS );
+        vTaskDelayUntil( &vLastWakeTime, 1000 / portTICK_PERIOD_MS );
+
+        sendToshibaIRData();
 
     }
 

+ 3 - 1
main/readTemps.c

@@ -7,11 +7,13 @@
 #include "readTemps.h"
 #include "mqtt.h"
 
+#ifdef ENABLE_DS18B20
+
 #include "owb.h"
 #include "owb_rmt.h"
 #include "ds18b20.h"
 
-#ifdef ENABLE_DS18B20
+
 
 #define GPIO_DS18B20_0       (ONE_WIRE_BUS_IO)
 #define MAX_DEVICES          (8)

+ 7 - 3
main/receiver.c

@@ -23,6 +23,8 @@
 #include "wifi.h"
 #include "mqtt.h"
 
+#ifdef IR_RECEIVER
+
 
 uint32_t dataArr[1000];
 uint32_t dataArrIdx = 0;
@@ -42,13 +44,13 @@ void receiverTask(void *pvParameter)
 
     while (1) {
 
-        while( xQueueReceive( toshibaTxQueue, data, portMAX_DELAY ) == pdTRUE ) {
+        while( xQueueReceive( toshibaTxQueue, data, 100 ) == pdTRUE ) {
 
             ESP_LOGI("TOSHIBA","Received a TX from MQTT");
             sendToshibaIRCode(data);
         }
 
-        while( xQueueReceive( rxQueue, &width, portMAX_DELAY ) == pdTRUE ) {
+        while( xQueueReceive( rxQueue, &width, 100 ) == pdTRUE ) {
 
             //ESP_LOGI("D", "%u", width);
 
@@ -95,4 +97,6 @@ void initReceiver() {
     ESP_LOGI("RX", "Receiver has been initialized.");
 
     xTaskCreatePinnedToCore(&receiverTask, "receiverTask", 8192, NULL, tskIDLE_PRIORITY + 5, NULL, 0);
-}
+}
+
+#endif

+ 4 - 0
main/rxTimer.c

@@ -16,6 +16,8 @@
 #include "esp_intr_alloc.h"
 #include "config.h"
 
+#ifdef RX_TIMER
+
 
 static intr_handle_t s_timer_handle;
 
@@ -119,3 +121,5 @@ void delayMicroseconds(uint32_t delay)
 
 	while( tenUsCounter < endtime ) ;
 }
+
+#endif

+ 0 - 7
main/toshiba_ir.c

@@ -31,13 +31,6 @@ uint8_t xorBytes(const uint8_t * const start, const uint16_t length);
  * 
  */
 
-// Toshiba A/C
-const uint32_t kToshibaAcHdrMark = 4420;
-const uint32_t kToshibaAcHdrSpace = 4450;
-const uint32_t kToshibaAcBitMark = 570;
-const uint32_t kToshibaAcOneSpace = 1600;
-const uint32_t kToshibaAcZeroSpace = 510;
-const uint32_t kToshibaAcUsualGap = 7960;  // Others
 
 
 uint8_t data[kToshibaNumberOfBytes];            // Temp data during rx

+ 8 - 0
main/toshiba_ir.h

@@ -4,6 +4,14 @@
 #include <stdbool.h>
 #include <stdint.h>
 
+// Toshiba A/C
+const uint32_t kToshibaAcHdrMark = 4420;    // 4.4mS
+const uint32_t kToshibaAcHdrSpace = 4450;
+const uint32_t kToshibaAcBitMark = 570;
+const uint32_t kToshibaAcOneSpace = 1600;
+const uint32_t kToshibaAcZeroSpace = 510;
+const uint32_t kToshibaAcUsualGap = 7960;  // Others
+
 void Toshiba_ir_ResetDecoder ();
 
 uint8_t* nextPulseToshiba_ir(uint32_t width);