Exemplo n.º 1
0
/* Â˲¨ */
static int ads_filter(int* buf)
{
    int i, j, k, min;
    int temp;
    int tempXY[2][SAMP_CNT];

    for(i=0; i<SAMP_CNT; i++)
    {
        ads7843_readX(&buf[0]);
        ads7843_readY(&buf[1]);
        tempXY[0][i] = buf[0];
        tempXY[1][i] = buf[1];
    }

    for(k=0; k<2; k++)
    {
        for(i=0; i<SAMP_CNT-1; i++)
        {
            min=i;
            for (j=i+1; j<SAMP_CNT; j++)
            {
                if (tempXY[k][min] > tempXY[k][j]) min=j;
            }
            temp = tempXY[k][i];
            tempXY[k][i] = tempXY[k][min];
            tempXY[k][min] = temp;
        }
        if((tempXY[k][SAMP_CNT_DIV2]-tempXY[k][SAMP_CNT_DIV2-1]) > 9)
            return 1;
        buf[k] = (tempXY[k][SAMP_CNT_DIV2]+tempXY[k][SAMP_CNT_DIV2-1]) / 2;
    }

    return 0;
}
Exemplo n.º 2
0
static int DO_SPI_FLASH(int argc, char * const argv[])
{
    uint32_t i;
    int x,y;
    #define SPI_FLASH_TEST_LEN  (1024*512)
    volatile uint8_t* buf_test = SRAM_START_ADDRESS;
    uint32_t ret;
    static struct spi_bus bus;
    ret = kinetis_spi_bus_init(&bus, HW_SPI2);
    ret = ads7843_init(&bus, 0);
    ret = w25qxx_init(&bus, 1);
    
    
    for(i=0;i<100;i++)
    {
        ads7843_readX(&x);
        ads7843_readY(&y);
        printf("X:%04d Y:%04d\r", x, y);
        DelayMs(10);
    }
    /* probe w25qxx */
    if(w25qxx_probe())
    {
        printf("no w25qxx deived found\r\n");
        return 1;
    }
    printf("%s detected!\r\n", w25qxx_get_name());
    /*
    for(i=0;i<SPI_FLASH_TEST_LEN;i++)
    {
        buf_test[i] = i;
    }
    if(w25qxx_write(0, (uint8_t*)buf_test, SPI_FLASH_TEST_LEN))
    {
        printf("w25qxx write failed\r\n");
        return 1;
    }
    memset((uint8_t*)buf_test,0, SPI_FLASH_TEST_LEN);
    if(w25qxx_read(0, (uint8_t*)buf_test, SPI_FLASH_TEST_LEN))
    {
        printf("w25qxx read failed\r\n");
        return 1;
    }
    for(i=0;i<SPI_FLASH_TEST_LEN;i++)
    {
        if(buf_test[i] != i%256)
        {
           printf("error:[0x%X]:%d\r\n", i, buf_test[i]);
        }
    }
    */
    printf("spi flash test finish!\r\n");
    return 0;
}