Merge branch 'master' into feature/cmake_update

This commit is contained in:
Angus Gratton
2018-05-30 17:41:35 +10:00
committed by Angus Gratton
1102 changed files with 77140 additions and 96159 deletions
+37 -1
View File
@@ -15,6 +15,7 @@ static const char *RMT_TX_TAG = "RMT Tx";
#define RMT_TX_CHANNEL RMT_CHANNEL_0
#define RMT_TX_GPIO 18
#define SAMPLE_CNT (10)
/*
* Prepare a raw table with a message in the Morse code
@@ -48,6 +49,37 @@ rmt_item32_t items[] = {
{{{ 0, 1, 0, 0 }}}
};
//Convert uint8_t type of data to rmt format data.
static void IRAM_ATTR u8_to_rmt(const void* src, rmt_item32_t* dest, size_t src_size,
size_t wanted_num, size_t* translated_size, size_t* item_num)
{
if(src == NULL || dest == NULL) {
*translated_size = 0;
*item_num = 0;
return;
}
const rmt_item32_t bit0 = {{{ 32767, 1, 15000, 0 }}}; //Logical 0
const rmt_item32_t bit1 = {{{ 32767, 1, 32767, 0 }}}; //Logical 1
size_t size = 0;
size_t num = 0;
uint8_t *psrc = (uint8_t *)src;
rmt_item32_t* pdest = dest;
while (size < src_size && num < wanted_num) {
for(int i = 0; i < 8; i++) {
if(*psrc & (0x1 << i)) {
pdest->val = bit1.val;
} else {
pdest->val = bit0.val;
}
num++;
pdest++;
}
size++;
psrc++;
}
*translated_size = size;
*item_num = num;
}
/*
* Initialize the RMT Tx channel
@@ -77,18 +109,22 @@ static void rmt_tx_int()
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
ESP_ERROR_CHECK(rmt_translator_init(config.channel, u8_to_rmt));
}
void app_main(void *ignore)
{
ESP_LOGI(RMT_TX_TAG, "Configuring transmitter");
rmt_tx_int();
int number_of_items = sizeof(items) / sizeof(items[0]);
const uint8_t sample[SAMPLE_CNT] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
while (1) {
ESP_ERROR_CHECK(rmt_write_items(RMT_TX_CHANNEL, items, number_of_items, true));
ESP_LOGI(RMT_TX_TAG, "Transmission complete");
vTaskDelay(1000 / portTICK_PERIOD_MS);
ESP_ERROR_CHECK(rmt_write_sample(RMT_TX_CHANNEL, sample, SAMPLE_CNT, true));
ESP_LOGI(RMT_TX_TAG, "Sample transmission complete");
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
vTaskDelete(NULL);