Exemple #1
0
/** Find the common SERCOM shared by two pins
 *
 * Finds the common SERCOM index of two input pins.
 * If swapping the input argument gives different result, it means, two SERCOMs share both pins
 * @param[in] pin1  First pin
 * @param[in] pin2  Second pin
 * @return          SERCOM index if found, else, NC
 */
uint32_t pinmap_merge_sercom(PinName pin1, PinName pin2)
{
    int i, j;
    uint32_t pin1_sercom[2];
    uint32_t pin2_sercom[2];
    uint32_t sercom_index[4];

    uint32_t pin_com = NC;
    uint32_t pin_alt = NC;
    uint32_t count_com = 0;
    uint32_t count_alt = 0;

    /* Adding a condition check just in case we need a different result when swapping arguments */
    if (pin1 >= pin2) {
        pin1_sercom[0] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PAD);
        pin1_sercom[1] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PADEx);
    } else {
        pin1_sercom[0] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PADEx);
        pin1_sercom[1] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PAD);
    }

    pin2_sercom[0] = pinmap_find_peripheral(pin2, PinMap_SERCOM_PAD);
    pin2_sercom[1] = pinmap_find_peripheral(pin2, PinMap_SERCOM_PADEx);

    for  (i=0; i<2; i++) {
        if (pin1_sercom[i] != NC) {
            pin1_sercom[i] &= 0x0F;
        }
        for  (j=0; j<2; j++) {
            if (pin2_sercom[i] != NC) {
                pin2_sercom[i] &= 0x0F;
            }
            sercom_index[(i*2) + j] = pinmap_merge_pins(pin1_sercom[i], pin2_sercom[j]);
        }
    }

    for (i=0; i<4; i++) {
        if (sercom_index[i] != NC) {
            if (pin_com == NC) {
                pin_com = sercom_index[i];
                count_com++;
            } else if (pin_com == sercom_index[i]) {
                count_com++;
            } else if (pin_alt == NC) {
                pin_alt = sercom_index[i];
                count_alt++;
            } else if (pin_alt == sercom_index[i]) {
                count_alt++;
            } else {}
        }
    }
    return ((count_com >= count_alt) ? pin_com : pin_alt);
}
/** Find the common SERCOM shared by two pins
 *
 * Finds the common SERCOM index of two input pins.
 * Currently uses default pad only
 * @param[in] pin1  First pin
 * @param[in] pin2  Second pin
 * @return          SERCOM index if found, else, NC
 */
uint32_t pinmap_merge_sercom(PinName pin1, PinName pin2)
{
    uint32_t pin1_sercom, pin2_sercom;

    /* Using default pads for now */
    pin1_sercom = pinmap_find_peripheral_from_pad(pin1, SERCOM_USE_DEFAULT_PAD);
    if (pin1_sercom != (uint32_t)NC) {
        pin1_sercom &= 0x0F;
    }
    pin2_sercom = pinmap_find_peripheral_from_pad(pin2, SERCOM_USE_DEFAULT_PAD);
    if (pin2_sercom != (uint32_t)NC) {
        pin2_sercom &= 0x0F;
    }

    return pinmap_merge_pins(pin1_sercom, pin2_sercom);
}