]> granicus.if.org Git - esp-idf/commitdiff
Implement review comments
authorkrzychb <krzychb@gazeta.pl>
Wed, 22 Nov 2017 06:07:49 +0000 (07:07 +0100)
committerkrzychb <krzychb@gazeta.pl>
Wed, 22 Nov 2017 22:33:29 +0000 (23:33 +0100)
docs/api-reference/peripherals/rmt.rst
examples/peripherals/rmt_tx/main/rmt_tx_main.c

index 7d16efd8de432fa8a03b6fcab2d31a736acfc748..2f7787c207518be17cc6c96fa42f1bef39b6a4c0 100644 (file)
@@ -72,7 +72,30 @@ Now, depending on how the channel is configured, we are ready to either `Transmi
 Transmit Data
 -------------
 
-Before being able to transmit some RMT pulses, we need to define the pulse pattern. The minimum pattern recognized by the RMT controller, later called an 'item', is provided in a structure :cpp:type:`rmt_item32_t`, see :component_file:`soc/esp32/include/soc/rmt_struct.h`. Each 'item' consists of two pairs of two values. The first value in a pair describes the signal duration in ticks, the second provides the signal level (high or low). For example how to define and populate items see an example application :example:`peripherals/rmt_tx`.
+Before being able to transmit some RMT pulses, we need to define the pulse pattern. The minimum pattern recognized by the RMT controller, later called an 'item', is provided in a structure :cpp:type:`rmt_item32_t`, see :component_file:`soc/esp32/include/soc/rmt_struct.h`. Each item consists of two pairs of two values. The first value in a pair describes the signal duration in ticks and is 15 bits long, the second provides the signal level (high or low) and is contained in a single bit. A block of couple of items and the structure of an item is presented below.
+
+.. packetdiag::
+    :caption: Structure of RMT items (L - signal level)
+    :align: center
+
+    packetdiag rmt_items {
+        colwidth = 32  
+        node_width = 10
+        node_height = 24
+        default_fontsize = 12
+
+        0-14: Period (15)
+        15: L
+        16-30: Period (15)
+        31: L
+        32-95: ... [colheight=2]
+        96-110: Period (15)
+        111: L
+        112-126: Period (15)
+        127: L
+    }
+
+For a simple example how to define a block of items see :example:`peripherals/rmt_tx`.
 
 The items are provided to the RMT controller by calling function :cpp:func:`rmt_write_items`. This function also automatically triggers start of transmission. It may be called to wait for transmission completion or exit just after transmission start. In such case you can wait for the transmission end by calling :cpp:func:`rmt_wait_tx_done`. This function does not limit the number of data items to transmit. It is using an interrupt to successively copy the new data chunks to RMT's internal memory as previously provided data are sent out.
 
index b19dbc2b49d4d0b31970bcdd951ea19bb705d5ca..d71663a58e230ad41e7882cd0e4a94dda08d310c 100644 (file)
@@ -15,55 +15,40 @@ static const char *RMT_TX_TAG = "RMT Tx";
 
 #define RMT_TX_CHANNEL RMT_CHANNEL_0
 #define RMT_TX_GPIO 18
-#define RMT_MESSAGE_LENGTH 12
-
-rmt_item32_t items[RMT_MESSAGE_LENGTH];
 
 /*
- * Prepare a table with a message in the Morse code
+ * Prepare a raw table with a message in the Morse code
  *
  * The message is "ESP" : . ... .--.
  *
- * The table structure:
+ * The table structure represents the RMT item structure:
  * {duration, level, duration, level}
  *
  */
-uint32_t message[RMT_MESSAGE_LENGTH][4] = {
+rmt_item32_t items[] = {
     // E : dot
-    {32767, 1, 32767, 0}, // dot
+    {{{ 32767, 1, 32767, 0 }}}, // dot
     //
-    {32767, 0, 32767, 0}, // SPACE
+    {{{ 32767, 0, 32767, 0 }}}, // SPACE
     // S : dot, dot, dot
-    {32767, 1, 32767, 0}, // dot
-    {32767, 1, 32767, 0}, // dot
-    {32767, 1, 32767, 0}, // dot
+    {{{ 32767, 1, 32767, 0 }}}, // dot
+    {{{ 32767, 1, 32767, 0 }}}, // dot
+    {{{ 32767, 1, 32767, 0 }}}, // dot
     //
-    {32767, 0, 32767, 0}, // SPACE
+    {{{ 32767, 0, 32767, 0 }}}, // SPACE
     // P : dot, dash, dash, dot
-    {32767, 1, 32767, 0}, // dot
-    {32767, 1, 32767, 1},
-    {32767, 1, 32767, 0}, // dash
-    {32767, 1, 32767, 1},
-    {32767, 1, 32767, 0}, // dash
-    {32767, 1, 32767, 0}  // dot
+    {{{ 32767, 1, 32767, 0 }}}, // dot
+    {{{ 32767, 1, 32767, 1 }}},
+    {{{ 32767, 1, 32767, 0 }}}, // dash
+    {{{ 32767, 1, 32767, 1 }}},
+    {{{ 32767, 1, 32767, 0 }}}, // dash
+    {{{ 32767, 1, 32767, 0 }}}, // dot
+
+    // RMT end marker
+    {{{ 0, 1, 0, 0 }}}
 };
 
 
-/*
- * Populate the RMT items array
- * with a previously prepared message
- */
-static void populate_rmt_items(void)
-{
-    for (int i = 0; i < RMT_MESSAGE_LENGTH; i++) {
-        items[i].duration0 = message[i][0];
-        items[i].level0    = message[i][1];
-        items[i].duration1 = message[i][2];
-        items[i].level1    = message[i][3];
-    }
-}
-
-
 /*
  * Initialize the RMT Tx channel
  */
@@ -95,25 +80,16 @@ static void rmt_tx_int()
 }
 
 
-/*
- * Transmit all the items in a loop
- */
-static void rmt_tx_task(void *ignore)
-{
-    while (1) {
-        ESP_ERROR_CHECK(rmt_write_items(RMT_TX_CHANNEL, items, RMT_MESSAGE_LENGTH, 1));
-        ESP_LOGI(RMT_TX_TAG, "Transmission complete");
-        vTaskDelay(2000 / portTICK_PERIOD_MS);
-    }
-}
-
-
 void app_main(void *ignore)
 {
     ESP_LOGI(RMT_TX_TAG, "Configuring transmitter");
     rmt_tx_int();
-    populate_rmt_items();
+    int number_of_items = sizeof(items) / sizeof(items[0]);
 
-    ESP_LOGI(RMT_TX_TAG, "Spinning out transmit task");
-    xTaskCreatePinnedToCore(&rmt_tx_task, "rmt_tx_task", 4 * 1024, NULL, 5, NULL, 0);
+    while (1) {
+        ESP_ERROR_CHECK(rmt_write_items(RMT_TX_CHANNEL, items, number_of_items, true));
+        ESP_LOGI(RMT_TX_TAG, "Transmission complete");
+        vTaskDelay(2000 / portTICK_PERIOD_MS);
+    }
+    vTaskDelete(NULL);
 }