示例#1
0
void nxgl_yuv2rgb(uint8_t y, uint8_t u, uint8_t v,
                  uint8_t *r, uint8_t *g, uint8_t *b)
{
  b16_t vm128 = itob16(v) - b16_128P0;
  b16_t um128 = itob16(u) - b16_128P0;

  /* Per the JFIF specification:
   *
   * R = Y                         + 1.40200 * (V - 128.0)
   * G = Y - 0.34414 * (U - 128.0) - 0.71414 * (V - 128.0)
   * B = Y + 1.77200 * (U - 128.0)
   */

  *r = (uint8_t)b16toi(itob16(y) +                             b16muli(b16_1P402, vm128));
  *g = (uint8_t)b16toi(itob16(y) - b16muli(b16_P3441, um128) - b16muli(b16_P7141, vm128));
  *b = (uint8_t)b16toi(itob16(y) + b16muli(b16_1P772, um128));
}
示例#2
0
static b16_t trv_joystick_slope(int16_t value, int32_t full_range)
{
  return itob16(full_range) / (int32_t)value;
}
示例#3
0
void nxgl_circletraps(FAR const struct nxgl_point_s *center, nxgl_coord_t radius,
                      FAR struct nxgl_trapezoid_s *circle)
{
  nxgl_coord_t xoffs;
  nxgl_coord_t yoffs;

  circle[0].top.x1      = itob16(center->x);
  circle[0].top.x2      = circle[0].top.x1;
  circle[0].top.y       = center->y - radius;

  circle[7].bot.x1      = circle[0].top.x1;
  circle[7].bot.x2      = circle[0].top.x1;
  circle[7].bot.y       = center->y + radius;

  circle[3].bot.x1      = itob16(center->x - radius);
  circle[3].bot.x2      = itob16(center->x + radius);
  circle[3].bot.y       = center->y;

  circle[4].top.x1      = circle[3].bot.x1;
  circle[4].top.x2      = circle[3].bot.x2;
  circle[4].top.y       = circle[3].bot.y;

  /* Now 22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, and 337.5 */

  xoffs = b16toi(b16muli(COS_22p5, radius) + b16HALF);
  yoffs = b16toi(b16muli(SIN_22p5, radius) + b16HALF);

  circle[2].bot.x1      = itob16(center->x - xoffs);
  circle[2].bot.x2      = itob16(center->x + xoffs);
  circle[2].bot.y       = center->y - yoffs;

  circle[3].top.x1      = circle[2].bot.x1;
  circle[3].top.x2      = circle[2].bot.x2;
  circle[3].top.y       = circle[2].bot.y;

  circle[4].bot.x1      = circle[2].bot.x1;
  circle[4].bot.x2      = circle[2].bot.x2;
  circle[4].bot.y       = center->y + yoffs;

  circle[5].top.x1      = circle[4].bot.x1;
  circle[5].top.x2      = circle[4].bot.x2;
  circle[5].top.y       = circle[4].bot.y;

  circle[0].bot.x1      = itob16(center->x - yoffs);
  circle[0].bot.x2      = itob16(center->x + yoffs);
  circle[0].bot.y       = center->y - xoffs;

  circle[1].top.x1      = circle[0].bot.x1;
  circle[1].top.x2      = circle[0].bot.x2;
  circle[1].top.y       = circle[0].bot.y;

  circle[6].bot.x1      = circle[1].top.x1;
  circle[6].bot.x2      = circle[1].top.x2;
  circle[6].bot.y       = center->y + xoffs;

  circle[7].top.x1      = circle[6].bot.x1;
  circle[7].top.x2      = circle[6].bot.x2;
  circle[7].top.y       = circle[6].bot.y;

  /* Finally, 45.0, 135.0, 225.0, 315.0 */

  xoffs = b16toi(b16muli(COS_45p0, radius) + b16HALF);

  circle[1].bot.x1      = itob16(center->x - xoffs);
  circle[1].bot.x2      = itob16(center->x + xoffs);
  circle[1].bot.y       = center->y - xoffs;

  circle[2].top.x1      = circle[1].bot.x1;
  circle[2].top.x2      = circle[1].bot.x2;
  circle[2].top.y       = circle[1].bot.y;
  
  circle[5].bot.x1      = circle[1].bot.x1;
  circle[5].bot.x2      = circle[1].bot.x2;
  circle[5].bot.y       = center->y + xoffs;

  circle[6].top.x1      = circle[5].bot.x1;
  circle[6].top.x2      = circle[5].bot.x2;
  circle[6].top.y       = circle[5].bot.y;
}
示例#4
0
文件: imx_serial.c 项目: a1ien/nuttx
static int up_setup(struct uart_dev_s *dev)
{
#ifndef CONFIG_SUPPRESS_UART_CONFIG
    struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
    uint64_t tmp;
    uint32_t regval;
    uint32_t ucr2;
    uint32_t refclk;
    uint32_t div;
    uint32_t num;
    uint32_t den;
    b16_t ratio;

    /* Disable the UART */

    up_serialout(priv, UART_UCR1, 0);
    up_serialout(priv, UART_UCR2, 0);
    up_serialout(priv, UART_UCR3, 0);
    up_serialout(priv, UART_UCR4, 0);

    /* Set up UCR2 */

    ucr2  = up_serialin(priv, UART_UCR2);
    ucr2 |= (UART_UCR2_SRST | UART_UCR2_IRTS)

            /* Select the number of data bits */

            DEBUGASSERT(priv->bits == 7 || priv->bits == 8);
    if (priv->bits == 8)
    {
        ucr2 |= UART_UCR2_WS;
    }

    /* Select the number of stop bits */

    if (priv->stopbits2)
    {
        ucr2 |= UART_UCR2_STPB;
    }

    /* Select even/odd parity */

    if (priv->parity)
    {
        DEBUGASSERT(priv->parity == 1 || priv->parity == 2);
        ucr2 |= UART_UCR2_PREN;
        if (priv->parity == 1)
        {
            ucr2 |= UART_UCR2_PROE;
        }
    }

    /* Setup hardware flow control */

    regval = 0;

#if 0
    if (priv->hwfc)
    {
        /* Don't ignore RTS */

        ucr2 &= ~UART_UCR2_IRTS;

        /* CTS controled by Rx FIFO */

        ucr2 |= UART_UCR2_CTSC;

        /* Set CTS trigger level */

        regval |= 30 << UART_UCR4_CTSTL_SHIFT;
    }
#endif

    /* i.MX reference clock (PERCLK1) is configured for 16MHz */

    up_serialout(priv, UART_UCR4, regval | UART_UCR4_REF16);

    /* Setup the new UART configuration */

    up_serialout(priv, UART_UCR2, ucr2);

    /* Select a reference clock divider.
     * REVISIT:  For now we just use a divider of 3.  That might not be
     * optimal for very high or very low baud settings.
     */

    div    = 3;
    refclk = (IMX_PERCLK1_FREQ / 3);

    /* Set the baud.
     *
     *   baud    = REFFREQ / (16 * NUM/DEN)
     *   baud    = REFFREQ / 16 / RATIO
     *   RATIO   = REFREQ / 16 / baud;
     *
     *   NUM     = SCALE * RATIO
     *   DEN     = SCALE
     *
     *   UMBR    = NUM-1
     *   UBIR    = DEN-1;
     */

    tmp   = ((uint64_t)refclk << (16 - 4)) / config->baud;
    DEBUGASSERT(tmp < 0x0000000100000000LL);
    ratio = (b16_t)tmp;

    /* Pick a scale factor that gives us about 14 bits of accuracy.
     * REVISIT:  Why not go all the way to 16-bits?
     */

    if (ratio < b16HALF)
    {
        den = (1 << 15);
        num = b16toi(ratio << 15);
        DEBUGASSERT(num > 0);
    }
    else if (ratio < b16ONE)
    {
        den = (1 << 14);
        num = b16toi(ratio << 14);
    }
    else if (ratio < itob16(2))
    {
        den = (1 << 13);
        num = b16toi(ratio << 13);
    }
    else if (ratio < itob16(4))
    {
        den = (1 << 12);
        num = b16toi(ratio << 12);
    }
    else if (ratio < itob16(8))
    {
        den = (1 << 11);
        num = b16toi(ratio << 11);
    }
    else if (ratio < itob16(16))
    {
        den = (1 << 10);
        num = b16toi(ratio << 10);
    }
    else if (ratio < itob16(32))
    {
        den = (1 << 9);
        num = b16toi(ratio << 9);
    }
    else if (ratio < itob16(64))
    {
        den = (1 << 8);
        num = b16toi(ratio << 8);
    }
    else if (ratio < itob16(128))
    {
        den = (1 << 7);
        num = b16toi(ratio << 7);
    }
    else if (ratio < itob16(256))
    {
        den = (1 << 6);
        num = b16toi(ratio << 6);
    }
    else if (ratio < itob16(512))
    {
        den = (1 << 5);
        num = b16toi(ratio << 5);
    }
    else if (ratio < itob16(1024))
    {
        den = (1 << 4);
        num = b16toi(ratio << 4);
    }
    else if (ratio < itob16(2048))
    {
        den = (1 << 3);
        num = b16toi(ratio << 3);
    }
    else if (ratio < itob16(4096))
    {
        den = (1 << 2);
        num = b16toi(ratio << 2);
    }
    else if (ratio < itob16(8192))
    {
        den = (1 << 1);
        num = b16toi(ratio << 1);
    }
    else /* if (ratio < itob16(16384)) */
    {
        DEBUGASSERT(ratio < itob16(16384));
        den = (1 << 0);
        num = b16toi(ratio);
    }

    /* Reduce if possible without losing accuracy. */

    while ((num & 1) == 0 && (den & 1) == 0)
    {
        num >>= 1;
        den >>= 1;
    }

    /* The actual values are we write to the registers need to be
     * decremented by 1.  NOTE that the UBIR must be set before
     * the UBMR.
     */

    up_serialout(priv, UART_UBIR, den - 1);
    up_serialout(priv, UART_UBMR, num - 1);

    /* Fixup the divisor, the value in the UFCR regiser is
     *
     *   000 = Divide input clock by 6
     *   001 = Divide input clock by 5
     *   010 = Divide input clock by 4
     *   011 = Divide input clock by 3
     *   100 = Divide input clock by 2
     *   101 = Divide input clock by 1
     *   110 = Divide input clock by 7
     */

    if (div == 7)
    {
        div = 6;
    }
    else
    {
        div = 6 - div;
    }
    regval = div << UART_UFCR_RFDIV_SHIFT;

    /* Set the TX trigger level to interrupt when the TxFIFO has 2 or fewer characters.
     * Set the RX trigger level to interrupt when the RxFIFO has 1 character.
     */

    regval |= ((2 << UART_UFCR_TXTL_SHIFT) | (1 << UART_UFCR_RXTL_SHIFT));
    up_serialout(priv, UART_UFCR, regval);

    /* Initialize the UCR1 shadow register */

    priv->ucr1 = up_serialin(priv, UART_UCR1);

    /* Enable the UART
     *
     *  UART_UCR1_UARTCLEN = Enable UART clocking
     */

    ucr2 |= (UART_UCR2_TXEN | UART_UCR2_RXEN);
    up_serialout(priv, UART_UCR1, ucr2);

    priv->ucr1 |= UART_UCR1_UARTCLEN;
    up_serialout(priv, UART_UCR1, priv->ucr1);
#endif
    return OK;
}