Esempio n. 1
0
void TwoWire::begin(uint8_t address)
{
  twi_setAddress(address);
  twi_attachSlaveTxEvent(onRequestService);
  twi_attachSlaveRxEvent(onReceiveService);
  begin();
}
Esempio n. 2
0
void twi_init_slave(uint8_t address)
{
  twi_setAddress(address);
  twi_attachSlaveTxEvent(onRequestService);
  twi_attachSlaveRxEvent(onReceiveService);
  twi_init_master();
}
Esempio n. 3
0
void i2c_begin_address(uint8_t address)
{
	twi_setAddress(address);
	/*
	 * TODO: NEED TO RESEARCH INTERRUPTS
	twi_attachSlaveTxEvent(onRequestService);
	twi_attachSlaveRxEvent(onReceiveService);
	*/
	i2c_begin();
}
Esempio n. 4
0
void TwoWire::begin(uint8_t address)
{
    begin();
    // Likewise, in the other begin function, this will prevent
    // the attach events being called more than once.
    if (beginCount == 1) { // First init
        twi_setAddress(address);
        twi_attachSlaveTxEvent(onRequestService);
        twi_attachSlaveRxEvent(onReceiveService);
    }
}
Esempio n. 5
0
void TwoWire::begin(uint32_t speed, uint8_t address)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init(speed);
  twi_setAddress(address);
  twi_attachSlaveTxEvent(onRequestService);
  twi_attachSlaveRxEvent(onReceiveService);
}
Esempio n. 6
0
// main
// ===============================================================
// ===============================================================
// ===============================================================
// ===============================================================
int main(void)
{
	uint8_t i1, i2, i3, i4;
	
	uint8_t bus_address;
	uint8_t rx_type;
	uint8_t k_row;

	k_row = 0;
	refresh_row = 0;
	scan_keypad = 0;
	key_read = key_write = 0;
	rx_read = rx_write = 0;
	
	intensity_index = 15;

	reply_type = _REPLY_KEYPAD;

	DDRB = 0xfe;	// input pin 1, outputs else
	DDRC = 0xff;	// output
	DDRD = 0xff;	// output

	bus_address = ADDR;	// initialized value, default 100 or from makefile
						// we will overwrite this with the value stored in eeprom

	// led refresh interrupt
	TCCR0A = 0;
	TCCR0B = (1<<CS02);// | (1<<CS00);	// prescale io/256
	TIMSK0 = (1 << OCIE0A) | (1 << OCIE0B);// | (1 << TOIE0);
	OCR0A = LED_REFRESH_RATE;
	OCR0B = ints[intensity_index];
	
	TCCR2A = 0;
	TCCR2B = (1<<CS22) | (1<<CS21);		// prescale io/256
	TIMSK2 = (1 << OCIE2A) | (1 << OCIE2B);// | (1 << OCIE0B);// | (1 << TOIE0);
	OCR2A = d1ints[intensity_index];
	OCR2B = d2ints[intensity_index];
	
	// keypad interrupt
	TCCR1A = 0;
	TCCR1B = (1<<CS12) | (1<<CS10);
	TIMSK1 = (1<<OCIE1A);
	OCR1A = KEYPAD_REFRESH_RATE;

	buttonInit();

	sei();

	twi_init();
	twi_setAddress(bus_address);
	twi_attachSlaveRxEvent(processRx);
	twi_attachSlaveTxEvent(processTx);


	// loop
	// ===============================================================
	// ===============================================================
	while(1) {
		if(scan_keypad) {
			//for(k_row=0;k_row<8;k_row++) {
				button_last[k_row] = button_current[k_row];
				//_delay_us(5);
				PORTB |= B2_KCOL_SH;
				_delay_us(5);

				for(i1=0;i1<8;i1++) {
					i2 = !(PINB & B0_KCOL_Q);
					PORTB |= B1_KCOL_CLK;
					//_delay_us(2);
					PORTB &= ~B1_KCOL_CLK;
					if (i2)
			            button_current[k_row] |= (1 << i1);
			        else
			            button_current[k_row] &= ~(1 << i1);
					buttonCheck(k_row,i1);
					if(button_event[k_row] & (1<<i1)) {
						button_event[k_row] &= ~(1<<i1);
						key_changes[key_write]= ((!i2)<<7) + ((7-i1)*8) + (k_row);
						key_write++;
						key_write %= 128;
					}
				}

			PORTB &= ~B2_KCOL_SH;
			
			k_row++;
			k_row %= 8;
			PORTC = k_row;//(PINC | 0x07) | k_row;

			scan_keypad = 0;
		}

		if(rx_read != rx_write) {
			rx_type = rx[rx_read];

			if(rx_type == _QUERY) {
				i1 = 0;
			} else if(rx_type == _SLEEP) {
				TIMSK0 = 0;
				TIMSK1 = 0;
				TIMSK2 = 0;
				PORTD = 0;
			} else if(rx_type == _WAKE) {
				TIMSK0 = (1 << OCIE0A) | (1 << OCIE0B);
				TIMSK1 = (1<<OCIE1A);
			} else if(rx_type == _KEYPAD_REQUEST) {
				reply_type = _REPLY_KEYPAD;
			} else if(rx_type == _LED_SET0) {
				// _LED_SET0 //////////////////////////////////////////////
				i3 = rx[(rx_read + 1)%128];
				i1 = i3 & 0x0f;
				i2 = i3 >> 4;
				lights[i1] &= ~(1<<i2);
			} else if(rx_type == _LED_SET1) {
Esempio n. 7
0
void NabaztagInjector::disableRFID() {
  if(rfidPort > 0) {
    twi_setAddress(CRX14_ADR);
    digitalWrite(rfidPort, LOW);
  }
}
Esempio n. 8
0
void NabaztagInjector::enableRFID() {
  if(rfidPort > 0) {
    twi_setAddress(DUMMY_ADR);
    digitalWrite(rfidPort, HIGH);
  }
}