Beispiel #1
0
/**
 * \brief Read one byte of data from QT1070 Register.
 *
 * \param pTwid   Pointer to twi driver structure.
 * \param regAddr Register address to read.
 * \return value in the given register.
 */
static uint8_t QT1070_ReadReg(Twid *pTwid, uint8_t regAddr)
{
    uint8_t data;
    TWID_Write(pTwid, QT1070_SLAVE_ADDRESS, 0, 0, &regAddr, 1, 0);
    TWID_Read(pTwid, QT1070_SLAVE_ADDRESS, 0, 0, &data, 1, 0);
    return data;
}
/**
 * \brief  Write a value to a register in an OV sensor device.
 * \param pTwid TWI interface
 * \param reg Register to be writen
 * \param pData Data written
 * \return 0 if no error; otherwize TWID_ERROR_BUSY
 */
uint8_t ov_write_reg16(Twid *pTwid, uint16_t reg,  uint8_t val)
{
    uint8_t status;
    status = TWID_Write(pTwid, twiSlaveAddr, reg, 2, &val, 1, 0);
    if( status != 0 ) {
        TRACE_ERROR("ov_write_reg pb\n\r");
    }

    return status;
}
/**
 * \brief  Write data to WM8904 Register.
 *
 * \param pTwid   Pointer to twi driver structure
 * \param device  Twi slave address.
 * \param regAddr Register address to read.
 * \param data    Data to write
 */
void WM8904_Write(Twid *pTwid,
                  uint32_t device,
                  uint32_t regAddr,
                  uint16_t data)
{
    uint8_t tmpData[2];

    tmpData[0] = (data & 0xff00) >> 8;
    tmpData[1] = data & 0xff;
    TWID_Write(pTwid, device, regAddr, 1, tmpData, 2, 0);
}
/**
 * \brief  Read a value from a register in an OV sensor device.
 * \param pTwid TWI interface
 * \param reg Register to be read
 * \param isize Internal address size in bytes.
 * \param pData Data read
 * \return 0 if no error; otherwize TWID_ERROR_BUSY
 */
uint8_t ov_read_reg8(Twid *pTwid, uint8_t reg, uint8_t *pData)
{
    uint8_t status;

    status = TWID_Write( pTwid, twiSlaveAddr, 0, 0, &reg, 1, 0);
    status |= TWID_Read( pTwid, twiSlaveAddr, 0, 0, pData, 1, 0);
    if( status != 0 ) {
        TRACE_ERROR("ov_read_reg pb\n\r");
    }
    return status;
}
Beispiel #5
0
void bmo_write_registers(const uint8_t reg, const uint8_t *data, const uint8_t length) {
	mutex_take(mutex_twi_bricklet, MUTEX_BLOCKING);
    TWID_Write(&twid,
    		   BMO055_ADDRESS_HIGH,
    		   reg,
               1,
               (uint8_t *)data,
               length,
               NULL);
	mutex_give(mutex_twi_bricklet);
}
Beispiel #6
0
void bmo_write_register(const uint8_t reg, uint8_t const value) {
	mutex_take(mutex_twi_bricklet, MUTEX_BLOCKING);
    TWID_Write(&twid,
    		   BMO055_ADDRESS_HIGH,
    		   reg,
               1,
               (uint8_t *)&value,
               1,
               NULL);
	mutex_give(mutex_twi_bricklet);
}
int e4k_reg_write(struct e4k_state *e4k, uint8_t reg, uint8_t val)
{
	unsigned char rc;

	rc = TWID_Write(e4k->i2c_dev, e4k->i2c_addr, reg, 1, &val, 1, NULL);
	if (rc != 0) {
		LOGP(DTUN, LOGL_ERROR, "Error %u in TWID_Write\n", rc);
		return -EIO;
	}

	return 0;
}
Beispiel #8
0
/**
 * \brief  Read a value from a register in an OV sensor device.
 * \param pTwid TWI interface
 * \param reg Register to be read
 * \param pData Data read
 * \return 0 if no error; otherwise TWID_ERROR_BUSY
 */
uint8_t ov_read_reg16(Twid *pTwid, uint16_t reg, uint8_t *pData)
{
	uint8_t status;
	uint8_t reg8[2];
	reg8[0] = reg>>8;
	reg8[1] = reg & 0xff;

	status = TWID_Write( pTwid, twiSlaveAddr, 0, 0, reg8,  2, 0);
	status |= TWID_Read( pTwid, twiSlaveAddr, 0, 0, pData, 1, 0);
	if( status != 0 ) {
		TRACE_ERROR("ov_read_reg pb\n\r");
	}
	return status;
}
Beispiel #9
0
extern int main( void )
{
    volatile uint32_t delay;
    uint8_t i;
    uint8_t SNo[16];
    Async async;
    /* Disable watchdog */
    WDT_Disable( WDT ) ;

    /* Enable I and D cache */
    SCB_EnableICache();
    SCB_EnableDCache();
    
    CallBackFired = 0;
    
    /* Output example information */
    printf("-- TWI EEPROM Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
    
    TimeTick_Configure();
    
    /* Configure TWI pins. */
    PIO_Configure(pins, PIO_LISTSIZE(pins));
    PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM);
    /* Configure TWI */
    
    twi_dma.pTwid = malloc(sizeof(Twid));
    twi_dma.pTwiDma = malloc(sizeof(sXdmad));
    
    TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK);
    TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM);
    TWID_DmaInitialize(&twi_dma, BOARD_BASE_TWI_EEPROM, 0);

    TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x80, 1, SNo, PAGE_SIZE, 0);

    /* Erase all page */
    memset(pData, 0, PAGE_SIZE);
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Filling page #%d with zeroes ...\r\n", i);
        TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");

    _fillBuffer(pData);

    /* Synchronous operation */
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("\n\r-I- Filling page #%d with checkerboard pattern ...\r", i);
        TWID_DmaWrite(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");


    /* Read back data */
    memset(pData, 0, PAGE_SIZE);
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Reading page #%d... ", i);
        TWID_DmaRead(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
        _checkReadBuffer(pData);
    }
     printf("\r\n");

    /* Configure TWI interrupts */
    NVIC_ClearPendingIRQ(TWIHS0_IRQn);
    NVIC_EnableIRQ(TWIHS0_IRQn);

    /* Asynchronous operation */
    printf("-I- Read/write on page #0 (IRQ mode)\n\r");

    /* Write checkerboard pattern in first page */
    _fillBuffer(pData);
    memset(&async, 0, sizeof(async));
    async.callback = (void *) TestCallback;

    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Filling page #%d with checkerboard pattern ...\r", i);
        TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async);
        while (!ASYNC_IsFinished(&async));
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");


    /* Read back data */
    memset(pData, 0, PAGE_SIZE);
    memset(&async, 0, sizeof(async));
    async.callback = (void *) TestCallback;
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Reading page # %d...\r", i);
        TWID_Read(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async);
        while ( !ASYNC_IsFinished( &async ) ) ;
        /* Wait at least 10 ms */
        Wait(10);
        _checkReadBuffer(pData);
    }
    printf("\r\n Callback Fired %d times", CallBackFired);

    return 0 ;
}
Beispiel #10
0
/**
 * \brief  Write one byte of data to QT1070 Register.
 *
 * \param pTwid   Pointer to twi driver structure.
 * \param regAddr Register address to write.
 * \param data    Data to write.
 */
static void QT1070_WriteReg(Twid *pTwid, uint32_t regAddr, uint8_t data)
{
    TWID_Write(pTwid, QT1070_SLAVE_ADDRESS, regAddr, 1, &data, 1, 0);
}