This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Audio controls for iOS and Android

Hi.

I'm trying to get audio controls (mostly volume up/down) to work with apple and android phones. I've used as base your HDI keyboard example.

It seems to work OK with apple what comes to controls themselves, but problem is that as it advertises itself as keyboard, the virtual keyboard doesn't work. I assume I have to change the hids_init report map to be only consumer control? Do I also have to change the device appearance to some other type?

As sidenote is there simplier way of handling this? I mean I only need the volume up/down and perhaps next/previous track, not full on keyboard/mouse interface.

EDIT:

Ok, I changed the sd_ble_gap_appearance_set to other than keyboard and now the iOS works.

However I would like to trim the hids_init report_map_data. I tried this:

static uint8_t report_map_data[] =
{
    // Report ID 2: Advanced buttons
    0x05, 0x0C,                     // Usage Page (Consumer)
    0x09, 0x01,                     // Usage (Consumer Control)
    0xA1, 0x01,                     // Collection (Application)

    0x85, 0x01,                     //     Report Id (1)
    0x15, 0x00,                     //     Logical minimum (0)
    0x25, 0x01,                     //     Logical maximum (1)
    0x75, 0x01,                     //     Report Size (1)
    0x95, 0x01,                     //     Report Count (1)

    0x09, 0xCD,                     //     Usage (Play/Pause)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x0A, 0x83, 0x01,               //     Usage (AL Consumer Control Configuration)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x09, 0xB5,                     //     Usage (Scan Next Track)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x09, 0xB6,                     //     Usage (Scan Previous Track)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)

    0x09, 0xEA,                     //     Usage (Volume Down)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x09, 0xE9,                     //     Usage (Volume Up)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x0A, 0x25, 0x02,               //     Usage (AC Forward)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x0A, 0x24, 0x02,               //     Usage (AC Back)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0xC0                            // End Collection		
};

I changed the indexes and the system seems to be running ok:

hids_init_obj.evt_handler                    = on_hids_evt;
hids_init_obj.error_handler                  = alert_notification_error_handler;
hids_init_obj.is_kb                          = true;
hids_init_obj.is_mouse                       = false;
hids_init_obj.inp_rep_count                  = 1;
hids_init_obj.p_inp_rep_array                = input_report_array;
hids_init_obj.outp_rep_count                 = 1;
hids_init_obj.p_outp_rep_array               = output_report_array;
hids_init_obj.feature_rep_count              = 0;
hids_init_obj.p_feature_rep_array            = NULL;
hids_init_obj.rep_map.data_len               = sizeof(report_map_data);
hids_init_obj.rep_map.p_data                 = report_map_data;
hids_init_obj.hid_information.bcd_hid        = BASE_USB_HID_SPEC_VERSION;
hids_init_obj.hid_information.b_country_code = 0;
hids_init_obj.hid_information.flags          = hid_info_flags;
hids_init_obj.included_services_count        = 0;
hids_init_obj.p_included_services_array      = NULL;

However iOS doesn't respond to commands. Am I missing something mandatory in the config? I couldn't find any explanation how the report map is configured.

EDIT2: I also noticed, that with android (5.0.2) the same keyboard code that works OK in iOS doesn't work at all in android and hangs up after few seconds if vol up/down is sent. Should the android be able to use the hids_keyboard example right on?

I also connected to this device via gatt and tried to enable notifications for all the HIDS reports (also wrote the descriptors to enable notification mode). Not quite sure what are the connection mode requirements here (bonded/not bonded).

  • I tried vanilla keyboard demo and it works ok with said android.

    The current setup is such, that I've also got ANCS running in the nRF board. I've got the HID device UUId in the advertisement response data and the ANCS UUID in the solicitated data. The setup seems to work OK with the iOS and the volume is adjusted OK + I can get the ANCS events. In android I have app that handles the pairing and sends ANCS compatible data to nrf. After bonding the android shows that the device is input device and "it's used for input" -tag is enabled. I currently don't have gatt connection (peer) only gatt server connection for ancs. I assume the system should take care of the input coming from the device. I also tried connecting to nrf (peer), and searched for services and tried to enable notifications, but it didn't work.

    Any ideas how the kbd should be configured& used in this sort of scenario.

  • Ok, the keyboard now works also with Android. I'll listen to keyboard volume in the gatt callback. Problem with previous trial was that I just enabled & read the characteristics and descriptors in a loop. After I serialized the operations it works fine.

    However just for the record, I think the default system with the android gatt is pretty silly. One has to wonder why it wasn't made to be serial internally.

    However the original issue with the simplification of keyboard map still exists.

  • Not 100% sure about this. But iOS support might be restricted to supporting the HID keyboard only, or a given set of required capabilities. So it might not allow you to use the consumer usage page without also having the keyboard usage page. e.g. a mouse report map will not be compatible.

Related