10000 2016-11-26 · Smeedy/esp32-snippets@5ecdbdc · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ecdbdc

Browse files
author
kolban
committed
2016-11-26
1 parent 5dcef5f commit 5ecdbdc

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

rmt/fragments/rmt_simple.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <freertos/FreeRTOS.h>
2+
#include <freertos/task.h>
3+
#include <esp_log.h>
4+
#include <driver/rmt.h>
5+
#include "sdkconfig.h"
6+
7+
static char tag[] = "rmt_tests";
8+
static void dumpStatus(rmt_channel_t channel) {
9+
bool loop_en;
10+
uint8_t div_cnt;
11+
uint8_t memNum;
12+
bool lowPowerMode;
13+
rmt_mem_owner_t owner;
14+
uint16_t idleThreshold;
15+
uint32_t status;
16+
rmt_source_clk_t srcClk;
17+
18+
rmt_get_tx_loop_mode(channel, &loop_en);
19+
rmt_get_clk_div(channel, &div_cnt);
20+
rmt_get_mem_block_num(channel, &memNum);
21+
rmt_get_mem_pd(channel, &lowPowerMode);
22+
rmt_get_memory_owner(channel, &owner);
23+
rmt_get_rx_idle_thresh(channel, &idleThreshold);
24+
rmt_get_status(channel, &status);
25+
rmt_get_source_clk(channel, &srcClk);
26+
27+
ESP_LOGD(tag, "Status for RMT channel %d", channel);
28+
ESP_LOGD(tag, "- Loop enabled: %d", loop_en);
29+
ESP_LOGD(tag, "- Clock divisor: %d", div_cnt);
30+
ESP_LOGD(tag, "- Number of memory blocks: %d", memNum);
31+
ESP_LOGD(tag, "- Low power mode: %d", lowPowerMode);
32+
ESP_LOGD(tag, "- Memory owner: %s", owner==RMT_MEM_OWNER_TX?"TX":"RX");
33+
ESP_LOGD(tag, "- Idle threshold: %d", idleThreshold);
34+
ESP_LOGD(tag, "- Status: %d", status);
35+
ESP_LOGD(tag, "- Source clock: %s", srcClk==RMT_BASECLK_APB?"APB (80MHz)":"1MHz");
36+
}
37+
38+
void runRmtTest() {
39+
ESP_LOGD(tag, ">> runRmtTest");
40+
41+
rmt_config_t config;
42+
config.rmt_mode = RMT_MODE_TX;
43+
config.channel = RMT_CHANNEL_0;
44+
config.gpio_num = 21;
45+
config.mem_block_num = 1;
46+
config.tx_config.loop_en = 0;
47+
config.tx_config.carrier_en = 0;
48+
config.tx_config.idle_output_en = 1;
49+
config.tx_config.idle_level = 0;
50+
config.tx_config.carrier_duty_percent = 50;
51+
config.tx_config.carrier_freq_hz = 10000;
52+
config.tx_config.carrier_level = 1;
53+
config.clk_div = 80;
54+
55+
ESP_ERROR_CHECK(rmt_config(&config));
56+
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 19));
57+
dumpStatus(config.channel);
58+
59+
rmt_item32_t items[3];
60+
items[0].duration0 = 10000;
61+
items[0].level0 = 1;
62+
items[0].duration1 = 10000;
63+
items[0].level1 = 0;
64+
65+
items[1].duration0 = 10000;
66+
items[1].level0 = 1;
67+
items[1].duration1 = 5000;
68+
items[1].level1 = 0;
69+
70+
items[2].duration0 = 0;
71+
items[2].level0 = 1;
72+
items[2].duration1 = 0;
73+
items[2].level1 = 0;
74+
75+
while(1) {
76+
ESP_ERROR_CHECK(rmt_write_items(config.channel, items,
77+
3, /* Number of items */
78+
1 /* wait till done */));
79+
vTaskDelay(1000/portTICK_PERIOD_MS);
80+
}
81+
ESP_LOGD(tag, "<< runRmtTest");
82+
}

0 commit comments

Comments
 (0)
0