Beispiel #1
0
static uint8_t getByte(const I2C_ABSTRACT_BUS* bus, boolean isLastByte){
	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)bus;
	int8_t i;
	uint8_t b = 0;

	sda_high(i2c);
	for(i=7; i>=0; i--){
		b <<= 1;
		scl_high(i2c);
		halfDelay();

		if(pin_is_high(i2c->sda)){
			b |= 1;
		}
		scl_low(i2c);
		halfDelay();
	}

	// Put the ACK
	if(isLastByte){
		sda_high(i2c);
	}else{
		sda_low(i2c);
	}
	scl_high(i2c);
	halfDelay(i2c);
	scl_low(i2c);
	sda_high(i2c);

	return b;						// return received byte
}
Beispiel #2
0
// Send the start and address
// return TRUE if acknowledged
static boolean start(const I2C_ABSTRACT_BUS* bus, uint8_t addr, boolean writeMode){
	boolean rtn = FALSE;

	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)bus;
	if(i2c){
		sda_high(i2c);
		halfDelay();
		scl_high(i2c);
		halfDelay();

		sda_low(i2c);
		halfDelay();
		scl_low(i2c);
		halfDelay();

		// Send the device addr and direction
//		uint8_t addr = device->addr & 0xfe;
		if(writeMode==FALSE){
			addr |= 1;
		}else{
			addr &= 0xfe;
		}
		rtn = putByte(bus, addr);
	}
	return rtn;
}
Beispiel #3
0
// Send the stop
static void stop(const I2C_ABSTRACT_BUS* bus){
	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)bus;
	sda_low(i2c);
	halfDelay();
	scl_high(i2c);
	halfDelay();
	sda_high(i2c);
	halfDelay();
}
Beispiel #4
0
// Return true if the slave acknowledges
static boolean getAck(const I2C_SOFTWARE_BUS* i2c){
	sda_high(i2c);	// allow slave to drive sda
	scl_high(i2c);
	halfDelay();
	boolean rtn = pin_is_low(i2c->sda);
	scl_low(i2c);

	return rtn;
}
Beispiel #5
0
// Send the start and address
// return TRUE if acknowledged
static boolean start(const I2C_DEVICE* device, boolean writeMode){
	boolean rtn = FALSE;

	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)(device->bus);
	if(i2c){
		sda_high(i2c);
		halfDelay();
		scl_high(i2c);
		halfDelay();

		sda_low(i2c);
		halfDelay();
		scl_low(i2c);
		halfDelay();

		// Send the device addr and direction
		uint8_t addr = device->addr & 0xfe;
		if(writeMode==FALSE){
			addr |= 1;
		}
		rtn = putByte(device->bus, addr);
	}
	return rtn;
}
Beispiel #6
0
void BobDeint::filter( QQueue< FrameBuffer > &framesQueue )
{
	int insertAt = addFramesToDeinterlace( framesQueue );
	while ( internalQueue.count() >= 2 )
	{
		FrameBuffer dequeued = internalQueue.dequeue();
		QByteArray videoFrameData2;

		VideoFrame *videoFrame1 = VideoFrame::fromData( dequeued.data );
		VideoFrame *videoFrame2 = VideoFrame::create( videoFrameData2, w, h );

		for ( int p = 0 ; p < 3 ; ++p )
		{
			const int linesize = videoFrame1->linesize[ p ];
			quint8 *src  = videoFrame1->data[ p ] + linesize;
			quint8 *dst1 = videoFrame1->data[ p ];
			quint8 *dst2 = videoFrame2->data[ p ];

			memcpy( dst2, src, linesize ); //Copy second line into new frame (duplicate first line in new frame, simple deshake)
			dst2 += linesize;

			const int H = p ? h >> 2 : h >> 1;
			for ( int i = 0 ; i < H ; ++i )
			{
				const bool notLast = i != H-1;

				memcpy( dst2, src, linesize );
				dst2 += linesize;
				if ( notLast )
				{
					VideoFilters::averageTwoLines( dst2, src, src + ( linesize << 1 ), linesize );
					dst2 += linesize;
				}

				dst1 += linesize;
				if ( notLast )
					VideoFilters::averageTwoLines( dst1, src - linesize, src + linesize, linesize );
				else
					memcpy( dst1, src - linesize, linesize );
				dst1 += linesize;

				src  += linesize << 1;
			}

			if ( h & 1 ) //Duplicate last line for odd height
				memcpy( dst2, dst2 - linesize, linesize );
		}

		const bool TFF = isTopFieldFirst( videoFrame1 );
		videoFrame1->setNoInterlaced();
		framesQueue.insert( insertAt++, FrameBuffer(  TFF ? dequeued.data : videoFrameData2, dequeued.ts ) );
		framesQueue.insert( insertAt++, FrameBuffer( !TFF ? dequeued.data : videoFrameData2, dequeued.ts + halfDelay( internalQueue.first(), dequeued ) ) );
	}
}