mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +01:00
implement Wire.end() for AVR core
This commit is contained in:
parent
d9bb8965eb
commit
d00a3ceba3
@ -75,6 +75,11 @@ void TwoWire::begin(int address)
|
||||
begin((uint8_t)address);
|
||||
}
|
||||
|
||||
void TwoWire::end(void)
|
||||
{
|
||||
twi_disable();
|
||||
}
|
||||
|
||||
void TwoWire::setClock(uint32_t frequency)
|
||||
{
|
||||
TWBR = ((F_CPU / frequency) - 16) / 2;
|
||||
|
@ -27,6 +27,9 @@
|
||||
|
||||
#define BUFFER_LENGTH 32
|
||||
|
||||
// WIRE_HAS_END means Wire has end()
|
||||
#define WIRE_HAS_END 1
|
||||
|
||||
class TwoWire : public Stream
|
||||
{
|
||||
private:
|
||||
@ -49,6 +52,7 @@ class TwoWire : public Stream
|
||||
void begin();
|
||||
void begin(uint8_t);
|
||||
void begin(int);
|
||||
void end();
|
||||
void setClock(uint32_t);
|
||||
void beginTransmission(uint8_t);
|
||||
void beginTransmission(int);
|
||||
|
@ -90,6 +90,22 @@ void twi_init(void)
|
||||
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function twi_disable
|
||||
* Desc disables twi pins
|
||||
* Input none
|
||||
* Output none
|
||||
*/
|
||||
void twi_disable(void)
|
||||
{
|
||||
// disable twi module, acks, and twi interrupt
|
||||
TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));
|
||||
|
||||
// deactivate internal pullups for twi.
|
||||
digitalWrite(SDA, 0);
|
||||
digitalWrite(SCL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function twi_slaveInit
|
||||
* Desc sets slave address and enables interrupt
|
||||
|
@ -39,6 +39,7 @@
|
||||
#define TWI_STX 4
|
||||
|
||||
void twi_init(void);
|
||||
void twi_disable(void);
|
||||
void twi_setAddress(uint8_t);
|
||||
uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t);
|
||||
uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t);
|
||||
|
Loading…
x
Reference in New Issue
Block a user