Bluetooth: has: Introduce BT_HAS_PRESET_SUPPORT helper symbol

Introduce invisible helper symbol that could simplify and make more
readable condiitional code checks.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2022-05-12 10:45:18 +02:00 committed by Carles Cufí
commit e5aad57fc5
2 changed files with 11 additions and 8 deletions

View file

@ -66,7 +66,10 @@ config BT_HAS_PRESET_COUNT
This option sets the number of Hearing Access Service Presets This option sets the number of Hearing Access Service Presets
that can be registered. Setting this value to 0 disables Presets support. that can be registered. Setting this value to 0 disables Presets support.
if BT_HAS_PRESET_COUNT > 0 config BT_HAS_PRESET_SUPPORT
def_bool BT_HAS_PRESET_COUNT > 0
if BT_HAS_PRESET_SUPPORT
if BT_HAS_HEARING_AID_BINAURAL if BT_HAS_HEARING_AID_BINAURAL
@ -91,7 +94,7 @@ config BT_HAS_PRESET_NAME_DYNAMIC
help help
Enabling this option allows for runtime configuration of preset name. Enabling this option allows for runtime configuration of preset name.
endif # BT_HAS_PRESET_COUNT > 0 endif # BT_HAS_PRESET_SUPPORT
config BT_DEBUG_HAS config BT_DEBUG_HAS
bool "Hearing Access Service debug" bool "Hearing Access Service debug"

View file

@ -30,7 +30,7 @@
static struct bt_has has; static struct bt_has has;
#if CONFIG_BT_HAS_PRESET_COUNT > 0 #if defined(CONFIG_BT_HAS_PRESET_SUPPORT)
static ssize_t write_control_point(struct bt_conn *conn, const struct bt_gatt_attr *attr, static ssize_t write_control_point(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const void *data, uint16_t len, uint16_t offset, uint8_t flags); const void *data, uint16_t len, uint16_t offset, uint8_t flags);
@ -46,7 +46,7 @@ static ssize_t read_active_preset_index(struct bt_conn *conn, const struct bt_ga
return bt_gatt_attr_read(conn, attr, buf, len, offset, &has.active_index, return bt_gatt_attr_read(conn, attr, buf, len, offset, &has.active_index,
sizeof(has.active_index)); sizeof(has.active_index));
} }
#endif /* CONFIG_BT_HAS_PRESET_COUNT > 0 */ #endif /* CONFIG_BT_HAS_PRESET_SUPPORT */
static ssize_t read_features(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, static ssize_t read_features(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset) uint16_t len, uint16_t offset)
@ -71,7 +71,7 @@ BT_GATT_SERVICE_DEFINE(has_svc,
BT_GATT_PRIMARY_SERVICE(BT_UUID_HAS), BT_GATT_PRIMARY_SERVICE(BT_UUID_HAS),
BT_GATT_CHARACTERISTIC(BT_UUID_HAS_HEARING_AID_FEATURES, BT_GATT_CHRC_READ, BT_GATT_CHARACTERISTIC(BT_UUID_HAS_HEARING_AID_FEATURES, BT_GATT_CHRC_READ,
BT_GATT_PERM_READ_ENCRYPT, read_features, NULL, NULL), BT_GATT_PERM_READ_ENCRYPT, read_features, NULL, NULL),
#if CONFIG_BT_HAS_PRESET_COUNT > 0 #if defined(CONFIG_BT_HAS_PRESET_SUPPORT)
BT_GATT_CHARACTERISTIC(BT_UUID_HAS_PRESET_CONTROL_POINT, BT_GATT_CHARACTERISTIC(BT_UUID_HAS_PRESET_CONTROL_POINT,
#if defined(CONFIG_BT_EATT) #if defined(CONFIG_BT_EATT)
BT_GATT_CHRC_WRITE | BT_GATT_CHRC_INDICATE | BT_GATT_CHRC_NOTIFY, BT_GATT_CHRC_WRITE | BT_GATT_CHRC_INDICATE | BT_GATT_CHRC_NOTIFY,
@ -84,10 +84,10 @@ BT_GATT_SERVICE_DEFINE(has_svc,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ_ENCRYPT, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ_ENCRYPT,
read_active_preset_index, NULL, NULL), read_active_preset_index, NULL, NULL),
BT_GATT_CCC(ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT), BT_GATT_CCC(ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT),
#endif /* CONFIG_BT_HAS_PRESET_COUNT > 0 */ #endif /* CONFIG_BT_HAS_PRESET_SUPPORT */
); );
#if CONFIG_BT_HAS_PRESET_COUNT > 0 #if defined(CONFIG_BT_HAS_PRESET_SUPPORT)
#define PRESET_CONTROL_POINT_ATTR &has_svc.attrs[4] #define PRESET_CONTROL_POINT_ATTR &has_svc.attrs[4]
static struct has_client { static struct has_client {
@ -706,7 +706,7 @@ void bt_has_preset_foreach(uint8_t index, bt_has_preset_func_t func, void *user_
preset_foreach(start_index, end_index, bt_has_preset_foreach_func, &data); preset_foreach(start_index, end_index, bt_has_preset_foreach_func, &data);
} }
#endif /* CONFIG_BT_HAS_PRESET_COUNT > 0 */ #endif /* CONFIG_BT_HAS_PRESET_SUPPORT */
static int has_init(const struct device *dev) static int has_init(const struct device *dev)
{ {