need help on understanding RMT item
Posted: Mon Apr 22, 2019 6:48 pm
by manoj15
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.
Re: need help on understanding RMT item
Posted: Tue Apr 23, 2019 12:57 am
by ESP_Angus
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.