Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msp430: i2c, allow choosing which USCI_Bx module to use #590

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion hardware/msp430/cores/msp430/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ uint8_t TwoWire::txBufferLength = 0;
uint8_t TwoWire::transmitting = 0;
void (*TwoWire::user_onRequest)(void);
void (*TwoWire::user_onReceive)(int);
uint8_t TwoWire::i2cModule = 0;

// Constructors ////////////////////////////////////////////////////////////////

Expand All @@ -68,7 +69,7 @@ void TwoWire::begin(void)
txBufferIndex = 0;
txBufferLength = 0;

twi_init();
twi_init(i2cModule);
}

void TwoWire::begin(uint8_t address)
Expand Down Expand Up @@ -301,6 +302,11 @@ void TwoWire::onRequest( void (*function)(void) )
user_onRequest = function;
}

void TwoWire::setModule(uint8_t _i2cModule)
{
i2cModule = _i2cModule;
}

// Preinstantiate Objects //////////////////////////////////////////////////////

TwoWire Wire = TwoWire();
Expand Down
4 changes: 4 additions & 0 deletions hardware/msp430/cores/msp430/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class TwoWire : public Stream
static void (*user_onReceive)(int);
static void onRequestService(void);
static void onReceiveService(uint8_t*, int);

static uint8_t i2cModule;
public:
TwoWire();
void begin();
Expand Down Expand Up @@ -86,6 +88,8 @@ class TwoWire : public Stream
inline size_t write(unsigned int n) { return write((uint8_t)n); }
inline size_t write(int n) { return write((uint8_t)n); }
using Print::write;

void setModule(uint8_t module);
};

extern TwoWire Wire;
Expand Down
Loading