コード例 #1
0
ファイル: rmt_simple.c プロジェクト: EdWeller/esp32-snippets
void runRmtTest() {
	ESP_LOGD(tag, ">> runRmtTest");

	rmt_config_t config;
	config.rmt_mode = RMT_MODE_TX;
	config.channel = RMT_CHANNEL_0;
	config.gpio_num = 21;
	config.mem_block_num = 1;
	config.tx_config.loop_en = 0;
	config.tx_config.carrier_en = 0;
	config.tx_config.idle_output_en = 1;
	config.tx_config.idle_level = 0;
	config.tx_config.carrier_duty_percent = 50;
	config.tx_config.carrier_freq_hz = 10000;
	config.tx_config.carrier_level = 1;
	config.clk_div = 80;

	ESP_ERROR_CHECK(rmt_config(&config));
	ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
	dumpStatus(config.channel);

	rmt_item32_t items[3];
	items[0].duration0 = 10000;
	items[0].level0 = 1;
	items[0].duration1 = 10000;
	items[0].level1 = 0;

	items[1].duration0 = 10000;
	items[1].level0 = 1;
	items[1].duration1 = 5000;
	items[1].level1 = 0;

	items[2].duration0 = 0;
	items[2].level0 = 1;
	items[2].duration1 = 0;
	items[2].level1 = 0;

	while(1) {
	ESP_ERROR_CHECK(rmt_write_items(config.channel, items,
			3, /* Number of items */
			1 /* wait till done */));
		vTaskDelay(1000/portTICK_PERIOD_MS);
	}
	ESP_LOGD(tag, "<< runRmtTest");
}
コード例 #2
0
ファイル: RMT.cpp プロジェクト: pilate/esp32-snippets
/**
 * @brief Create a class instance.
 *
 * @param [in] pin The GPIO pin on which the signal is sent/received.
 * @param [in] channel The RMT channel to work with.
 */
RMT::RMT(gpio_num_t pin, rmt_channel_t channel) {
	this->channel = channel;

	rmt_config_t config;
	config.rmt_mode                  = RMT_MODE_TX;
	config.channel                   = channel;
	config.gpio_num                  = pin;
	config.mem_block_num             = 8 - this->channel;
	config.clk_div                   = 8;
	config.tx_config.loop_en         = 0;
	config.tx_config.carrier_en      = 0;
	config.tx_config.idle_output_en  = 1;
	config.tx_config.idle_level      = (rmt_idle_level_t)0;
	config.tx_config.carrier_freq_hz = 10000;
	config.tx_config.carrier_level   = (rmt_carrier_level_t)1;
	config.tx_config.carrier_duty_percent = 50;

	ESP_ERROR_CHECK(rmt_config(&config));
	ESP_ERROR_CHECK(rmt_driver_install(this->channel, 0, 0));
}
コード例 #3
0
ファイル: WS2812.cpp プロジェクト: seco/esp32-snippets
WS2812::WS2812(rmt_channel_t channel, gpio_num_t gpioNum, uint16_t pixelCount) {
	this->pixelCount = pixelCount;
	this->channel = channel;
	this->items = (rmt_item32_t *)malloc(sizeof(rmt_item32_t) * (pixelCount * 24));
	this->pixels = (pixel_t *)malloc(sizeof(pixel_t) * pixelCount);

	rmt_config_t config;
	config.rmt_mode = RMT_MODE_TX;
	config.channel = channel;
	config.gpio_num = gpioNum;
	config.mem_block_num = 1;
	config.tx_config.loop_en = 0;
	config.tx_config.carrier_en = 0;
	config.tx_config.idle_output_en = 1;
	config.tx_config.idle_level = (rmt_idle_level_t)0;
	config.tx_config.carrier_duty_percent = 50;
	config.tx_config.carrier_freq_hz = 10000;
	config.tx_config.carrier_level = (rmt_carrier_level_t)1;
	config.clk_div = 8;

	ESP_ERROR_CHECK(rmt_config(&config));
	ESP_ERROR_CHECK(rmt_driver_install(this->channel, 0, 19));
} // WS2812