Beispiel #1
0
uint8_t twi_sync_mt(uint8_t address, uint8_t *req_data, uint8_t req_len) {
	// write start condition
	write_start();
	WAIT_FOR_BUS();

	// write SLA+W
	write_slave_address(address, TW_WRITE);
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_MT_SLA_ACK) {
		write_stop();
		return TWI_ERROR;
	}

	// write request data
	while (req_len--) {
		write_data_byte(*req_data++);
		WAIT_FOR_BUS();

		if (TW_STATUS != TW_MT_DATA_ACK) {
			write_stop();
			return TWI_ERROR;
		}
	}

	// write stop condition
	write_stop();

	while (!(TWCR & (1 << TWSTO)));

	return TWI_OK;
}
Beispiel #2
0
uint8_t twi_sync_mtmr(uint8_t address, uint8_t *req_data, uint8_t req_len, uint8_t *res_data, uint8_t res_len) {

	// Master Transmitter

	// write start condition
	write_start();
	WAIT_FOR_BUS();

	// write SLA+W
	write_slave_address(address, TW_WRITE);
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_MT_SLA_ACK) {
		write_stop();
		return TWI_ERROR;
	}

	// write request data
	while (req_len--) {
		write_data_byte(*req_data++);
		WAIT_FOR_BUS();

		if (TW_STATUS != TW_MT_DATA_ACK) {
			write_stop();
			return TWI_ERROR;
		}
	}

	// Master Receiver

	// write repeated start
	write_start();
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_REP_START) {
		write_stop();
		return TWI_ERROR;
	}

	// write SLA+R
	write_slave_address(address, TW_READ);
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_MR_SLA_ACK) {
		write_stop();
		return TWI_ERROR;
	}

	// read data
	while (res_len > 1) {
		read_data_byte(res_data++, 1);
		WAIT_FOR_BUS();

		if (TW_STATUS != TW_MR_DATA_ACK) {
			write_stop();
			return TWI_ERROR;
		}

		res_len--;
	}

	read_data_byte(res_data++, 0);
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_MR_DATA_NACK) {
		write_stop();
		return TWI_ERROR;
	}

	// write stop condition
	write_stop();

	while (!(TWCR & (1 << TWSTO)));

	return TWI_OK;
}
Beispiel #3
0
static void _setup(void) {
	write_command(0xC0);	//Power control
	write_data_byte(0x23);	//VRH[5:0]

	write_command(0xC1);	//Power control
	write_data_byte(0x10);	//SAP[2:0];BT[3:0]

	write_command(0xC5);	//VCM control
	write_data_byte(0x3e);
	write_data_byte(0x28);

	write_command(0xC7);	//VCM control2
	write_data_byte(0x86);

	write_command(0x36);	// Memory Access Control
	write_data_byte(0x48);

	write_command(0x3A);
	write_data_byte(0x55);

	write_command(0xB1);
	write_data_byte(0x00);
	write_data_byte(0x18);

	write_command(0xB6);	// Display Function Control
	write_data_byte(0x08);
	write_data_byte(0xA2);
	write_data_byte(0x27);

	write_command(0xF2);	// 3Gamma Function Disable
	write_data_byte(0x00);

	write_command(0x26);	//Gamma curve selected
	write_data_byte(0x01);

	write_command(0xE0);    //Set Gamma
	write_data_byte(0x0F);
	write_data_byte(0x31);
	write_data_byte(0x2B);
	write_data_byte(0x0C);
	write_data_byte(0x0E);
	write_data_byte(0x08);
	write_data_byte(0x4E);
	write_data_byte(0xF1);
	write_data_byte(0x37);
	write_data_byte(0x07);
	write_data_byte(0x10);
	write_data_byte(0x03);
	write_data_byte(0x0E);
	write_data_byte(0x09);
	write_data_byte(0x00);

	write_command(0XE1);    //Set Gamma
	write_data_byte(0x00);
	write_data_byte(0x0E);
	write_data_byte(0x14);
	write_data_byte(0x03);
	write_data_byte(0x11);
	write_data_byte(0x07);
	write_data_byte(0x31);
	write_data_byte(0xC1);
	write_data_byte(0x48);
	write_data_byte(0x08);
	write_data_byte(0x0F);
	write_data_byte(0x0C);
	write_data_byte(0x31);
	write_data_byte(0x36);
	write_data_byte(0x0F);

	write_command(0x11);    //Exit Sleep
	bcm2835_delay(120);
	write_command(0x29);
}