TM16xx icon indicating copy to clipboard operation
TM16xx copied to clipboard

Add pinMode() to sendData() and getButtons()

Open gary7530 opened this issue 1 year ago • 1 comments

TM16XX and DS1302 their pin definitions are very similar, so I connect their pins together to do use. The DS1302 also uses pinMode() to change the GPIO settings, so I recommend adding pinMode() to sendData() to make sure it doesn't cause any problems in use.

void TM16xx::sendData(byte address, byte data)
{
  // Pull-up off
  pinMode(dataPin, OUTPUT);
  digitalWrite(dataPin, LOW);
  
  sendCommand(TM16XX_CMD_DATA_FIXED);							// use fixed addressing for data
  start();
  send(TM16XX_CMD_ADDRESS | address);						// address command + address
  send(data);
  stop();
}
uint32_t TM1620B::getButtons(void)
{
	// Pull-up off
	pinMode(dataPin, OUTPUT);
	digitalWrite(dataPin, LOW);

	word keys_K2 = 0;
	byte received;

	start();
	send(TM16XX_CMD_DATA_READ); // send read buttons command
	for (int i = 0; i < 3; i++)
	{
		received = receive();
		keys_K2 |= ((((received & _BV(1)) >> 1) | ((received & _BV(4)) >> 3)) << (2 * i));
	}
	stop();
	return (uint32_t)keys_K2;
}

gary7530 avatar Feb 27 '23 13:02 gary7530