need help on understanding RMT item

manoj15
Posts: 8
Joined: Mon Apr 22, 2019 6:40 pm

need help on understanding RMT item

Postby manoj15 » Mon Apr 22, 2019 6:48 pm

Code: Select all


typedef struct rmt_item32_s {
    union {
        struct {
            uint32_t duration0 :15;
            uint32_t level0 :1;
            uint32_t duration1 :15;
            uint32_t level1 :1;
        };
        uint32_t val;
    };
} rmt_item32_t;

I want to understand why the structure was packed over union ?
and how is the packing happening ? based on the datasheet I understand that each item is only 32 bit only consist of level and pulse length while the struct member each @ 32bit length.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: need help on understanding RMT item

Postby ESP_Angus » Tue Apr 23, 2019 12:57 am

That's right, each item register is only 32 bits wide.

The union is between "val", which gives thar raw 32-bit value of the item register and the anoymous struct, which uses a C feature called "bitfields" to have integers which are only X bits wide. The width of each field is given after the ":" on the line. This means the total width of the struct is also 32 bits (15+1+15+1).

This provides an easy way to access the level and duration of each item via struct fields, without needing to manually mask and shift each field.

Who is online

Users browsing this forum: Google [Bot] and 62 guests