Example #1
0
static uint8_t __spiReadMISO(const SPI_SW* spi, uint8_t data){
	if(spi->_bus_.order == SPI_DATA_ORDER_MSB){
		// MSB is sent first
		data<<=1;
		if(pin_is_high(spi->MISO)){
			data |= 1;
		}
	}else{
		// LSB is sent first
		data>>=1;
		if(pin_is_high(spi->MISO)){
			data |= 0x80;
		}
	}
	return data;
}
Example #2
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
}
Example #3
0
static uint8_t readNibble(const HD44780* device, uint8_t pos){
	uint8_t rtn = 0;
	uint8_t mask = 1;
	for(uint8_t i=0; i<4; i++){
		if(pin_is_high(device->data[pos++])){
			// Pin is high
			rtn |= mask;
		}
		mask <<= 1;
	}
	return rtn;
}
Example #4
0
/*
 * triggered when the clock signal goes high
 */
pin2_interrupt()
{
	if (pin_is_high(PIN_DATA))
		value |= 1 << (7 - clk);

	clk++;
	timer1_clock_reset();
	timer1_count_set(0);
	second = 0;
	if (clk == 8) {
		if (cnt < 255) {
			data[cnt] = value;
			cnt++;
			events |= EV_DATA;
		}
		clk = 0;
		value = 0;
	}
}
Example #5
0
static uint8_t
ow_read(void)
{
    return !!pin_is_high(OW_PIN);
}