-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth: Host: Add conversion macros from ms to various units #81068
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure where to put these. We already have various conversion functions like BT_GAP_PER_ADV_INTERVAL_TO_MS
and BT_CONN_INTERVAL_TO_MS
, but they are placed here and there.
include/zephyr/bluetooth/gap.h
Outdated
* @note If @p _int is not a multiple of the unit, it will round down to nearest. For example | ||
* BT_GAP_MS_TO_PER_ADV_INT(23) will become 22.5 milliseconds | ||
*/ | ||
#define BT_GAP_MS_TO_PER_ADV_INT(_int) ((uint16_t)((_int) / 1.25)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure whether to use INT
or INTERVAL
. We seem to be using both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I'd prefer INTERVAL
, it is more consistent with the previous macro BT_GAP_PER_ADV_INTERVAL_TO_MS
. Not going to block this because at the end of the day INT
also works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer "interval".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to INTERVAL
502fad3
to
4788ec6
Compare
4788ec6
to
70fa597
Compare
What do the reviewers think of the prefix and location of these macros? Should they be in gap and prefixed with BT_GAP like they are today, or should they be moved to the individual parts (e.g. adv => |
714e26b
to
32a0db2
Compare
4bd2837
to
fff387f
Compare
Added unit tests |
fff387f
to
491436e
Compare
zassert_equal(BT_GAP_MS_TO_ADV_INTERVAL(20U), 0x0020U); | ||
/* Round down expected from 33.60 */ | ||
zassert_equal(BT_GAP_MS_TO_ADV_INTERVAL(21U), 0x0021U); | ||
/* Round down expected from 35.20 */ | ||
zassert_equal(BT_GAP_MS_TO_ADV_INTERVAL(22U), 0x0023U); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure whether to use hex as expected (typical use is hex), or decimal. Let me know what you prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hex is nice
I don't think we have too many conversion functions like this yet; anyways it is nice to have these grouped together, so I'd say keep them in gap |
491436e
to
625a276
Compare
Added microsecond versions of the macros as well, as well as added the value ranges. Since we don't have the value ranges defined in MS/US, I opted to just add them as literal values instead of values that could be |
625a276
to
6a4da5d
Compare
Add conversion macros from milliseconds to various units. The purpose of these macros is to make it more clear/easier for users to set and read values using milliseconds rather than the various BT units which may be in 0.625, 1.25 or 10ms units. This is especially useful when comparing related values using different units, such as advertising interval (0.625ms units) and periodic advertising interval units (1.25ms units). Users will have to be aware that these macros can provide slightly different values than what is provided, if the provided values do not match the units. Signed-off-by: Emil Gydesen <[email protected]>
6a4da5d
to
01d1884
Compare
Add conversion macros from milliseconds to various units. The purpose of these macros is to make it more clear/easier for users to set and read values using milliseconds rather than the various BT units which may be in 0.625, 1.25 or 10ms units.
This is especially useful when comparing related values using different units, such as advertising interval (0.625ms units) and periodic advertising interval units (1.25ms units).
Users will have to be aware that these macros can provide slightly different values than what is provided, if the provided values do not match the units.
A followup PR for audio can be found here #81093 which uses more of these macros.