(baudrate)
return actual_baud, value, index
10,27 => divisor = 10000, rate = 300
    88,13 => divisor = 5000, rate = 600
    C4,09 => divisor = 2500, rate = 1200
    E2,04 => divisor = 1250, rate = 2,400
    71,02 => divisor = 625, rate = 4,800
    38,41 => divisor = 312.5, rate = 9,600
    D0,80 => divisor = 208.25, rate = 14406
    9C,80 => divisor = 156, rate = 19,230
    4E,C0 => divisor = 78, rate = 38,461
    34,00 => divisor = 52, rate = 57,692
    1A,00 => divisor = 26, rate = 115,384
    0D,00 => divisor = 13, rate = 230,769
10,27 => divisor = 10000, rate = 300
    88,13 => divisor = 5000, rate = 600
    C4,09 => divisor = 2500, rate = 1200
    E2,04 => divisor = 1250, rate = 2,400
    71,02 => divisor = 625, rate = 4,800
    38,41 => divisor = 312.5, rate = 9,600
    D0,80 => divisor = 208.25, rate = 14406
    9C,80 => divisor = 156, rate = 19,230
    4E,C0 => divisor = 78, rate = 38,461
    34,00 => divisor = 52, rate = 57,692
    1A,00 => divisor = 26, rate = 115,384
    0D,00 => divisor = 13, rate = 230,769
10 27 = > divisor = 10000 rate = 300 88 13 = > divisor = 5000 rate = 600 C4 09 = > divisor = 2500 rate = 1200 E2 04 = > divisor = 1250 rate = 2 400 71 02 = > divisor = 625 rate = 4 800 38 41 = > divisor = 312 . 5 rate = 9 600 D0 80 = > divisor = 208 . 25 rate = 14406 9C 80 = > divisor = 156 rate = 19 230 4E C0 = > divisor = 78 rate = 38 461 34 00 = > divisor = 52 rate = 57 692 1A 00 = > divisor = 26 rate = 115 384 0D 00 = > divisor = 13 rate = 230 769
def ftdi_to_clkbits(baudrate):  # from libftdi
    """
    10,27 => divisor = 10000, rate = 300
    88,13 => divisor = 5000, rate = 600
    C4,09 => divisor = 2500, rate = 1200
    E2,04 => divisor = 1250, rate = 2,400
    71,02 => divisor = 625, rate = 4,800
    38,41 => divisor = 312.5, rate = 9,600
    D0,80 => divisor = 208.25, rate = 14406
    9C,80 => divisor = 156, rate = 19,230
    4E,C0 => divisor = 78, rate = 38,461
    34,00 => divisor = 52, rate = 57,692
    1A,00 => divisor = 26, rate = 115,384
    0D,00 => divisor = 13, rate = 230,769
    """
    clk = 48000000
    clk_div = 16
    frac_code = [0, 3, 2, 4, 1, 5, 6, 7]
    actual_baud = 0
    if baudrate >= clk / clk_div:
        encoded_divisor = 0
        actual_baud = (clk // clk_div)
    elif baudrate >= clk / (clk_div + clk_div / 2):
        encoded_divisor = 1
        actual_baud = clk // (clk_div + clk_div // 2)
    elif baudrate >= clk / (2 * clk_div):
        encoded_divisor = 2
        actual_baud = clk // (2 * clk_div)
    else:
        # We divide by 16 to have 3 fractional bits and one bit for rounding
        divisor = clk * 16 // clk_div // baudrate
        best_divisor = (divisor + 1) // 2
        if best_divisor > 0x20000:
            best_divisor = 0x1ffff
        actual_baud = clk * 16 // clk_div // best_divisor
        actual_baud = (actual_baud + 1) // 2
        encoded_divisor = ((best_divisor >> 3) +
                           (frac_code[best_divisor & 0x7] << 14))

    value = encoded_divisor & 0xFFFF
    index = encoded_divisor >> 16
    return actual_baud, value, index
def ftdi_to_clkbits ( baudrate ) : # from libftdi clk = 48000000 clk_div = 16 frac_code = [ 0 , 3 , 2 , 4 , 1 , 5 , 6 , 7 ] actual_baud = 0 if baudrate >= clk / clk_div : encoded_divisor = 0 actual_baud = ( clk // clk_div ) elif baudrate >= clk / ( clk_div + clk_div / 2 ) : encoded_divisor = 1 actual_baud = clk // ( clk_div + clk_div // 2 ) elif baudrate >= clk / ( 2 * clk_div ) : encoded_divisor = 2 actual_baud = clk // ( 2 * clk_div ) else : # We divide by 16 to have 3 fractional bits and one bit for rounding divisor = clk * 16 // clk_div // baudrate best_divisor = ( divisor + 1 ) // 2 if best_divisor > 0x20000 : best_divisor = 0x1ffff actual_baud = clk * 16 // clk_div // best_divisor actual_baud = ( actual_baud + 1 ) // 2 encoded_divisor = ( ( best_divisor >> 3 ) + ( frac_code [ best_divisor & 0x7 ] << 14 ) ) value = encoded_divisor & 0xFFFF index = encoded_divisor >> 16 return actual_baud , value , index