Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
b81bc464
Commit
b81bc464
authored
9 years ago
by
Thibaut VIARD
Browse files
Options
Downloads
Patches
Plain Diff
[zero] Bring more customization to Wire class
parent
7fbd6652
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libraries/Wire/Wire.cpp
+8
-77
8 additions, 77 deletions
libraries/Wire/Wire.cpp
libraries/Wire/Wire.h
+4
-1
4 additions, 1 deletion
libraries/Wire/Wire.h
with
12 additions
and
78 deletions
libraries/Wire/Wire.cpp
+
8
−
77
View file @
b81bc464
...
...
@@ -26,9 +26,11 @@ extern "C" {
#include
"Wire.h"
TwoWire
::
TwoWire
(
SERCOM
*
s
)
TwoWire
::
TwoWire
(
SERCOM
*
s
,
uint8_t
pinSDA
,
uint8_t
pinSCL
)
{
this
->
sercom
=
s
;
this
->
_uc_pinSDA
=
pinSDA
;
this
->
_uc_pinSCL
=
pinSCL
;
transmissionBegun
=
false
;
}
...
...
@@ -37,8 +39,8 @@ void TwoWire::begin(void) {
sercom
->
initMasterWIRE
(
TWI_CLOCK
);
sercom
->
enableWIRE
();
pinPeripheral
(
PIN_WIRE_
SDA
,
g_APinDescription
[
PIN_WIRE_
SDA
].
ulPinType
);
pinPeripheral
(
PIN_WIRE_
SCL
,
g_APinDescription
[
PIN_WIRE_
SCL
].
ulPinType
);
pinPeripheral
(
_uc_pin
SDA
,
g_APinDescription
[
_uc_pin
SDA
].
ulPinType
);
pinPeripheral
(
_uc_pin
SCL
,
g_APinDescription
[
_uc_pin
SCL
].
ulPinType
);
}
void
TwoWire
::
begin
(
uint8_t
address
)
{
...
...
@@ -254,77 +256,6 @@ void TwoWire::onService(void)
}
}
/*
void TwoWire::onService(void)
{
// Retrieve interrupt status
uint32_t sr = TWI_GetStatus(twi);
if (status == SLAVE_IDLE && TWI_STATUS_SVACC(sr)) {
TWI_DisableIt(twi, TWI_IDR_SVACC);
TWI_EnableIt(twi, TWI_IER_RXRDY | TWI_IER_GACC | TWI_IER_NACK
| TWI_IER_EOSACC | TWI_IER_SCL_WS | TWI_IER_TXCOMP);
srvBufferLength = 0;
srvBufferIndex = 0;
// Detect if we should go into RECV or SEND status
// SVREAD==1 means *master* reading -> SLAVE_SEND
if (!TWI_STATUS_SVREAD(sr)) {
status = SLAVE_RECV;
} else {
status = SLAVE_SEND;
// Alert calling program to generate a response ASAP
if (onRequestCallback)
onRequestCallback();
else
// create a default 1-byte response
write((uint8_t) 0);
}
}
if (status != SLAVE_IDLE) {
if (TWI_STATUS_TXCOMP(sr) && TWI_STATUS_EOSACC(sr)) {
if (status == SLAVE_RECV && onReceiveCallback) {
// Copy data into rxBuffer
// (allows to receive another packet while the
// user program reads actual data)
for (uint8_t i = 0; i < srvBufferLength; ++i)
rxBuffer[i] = srvBuffer[i];
rxBufferIndex = 0;
rxBufferLength = srvBufferLength;
// Alert calling program
onReceiveCallback( rxBufferLength);
}
// Transfer completed
TWI_EnableIt(twi, TWI_SR_SVACC);
TWI_DisableIt(twi, TWI_IDR_RXRDY | TWI_IDR_GACC | TWI_IDR_NACK
| TWI_IDR_EOSACC | TWI_IDR_SCL_WS | TWI_IER_TXCOMP);
status = SLAVE_IDLE;
}
}
if (status == SLAVE_RECV) {
if (TWI_STATUS_RXRDY(sr)) {
if (srvBufferLength < BUFFER_LENGTH)
srvBuffer[srvBufferLength++] = TWI_ReadByte(twi);
}
}
if (status == SLAVE_SEND) {
if (TWI_STATUS_TXRDY(sr) && !TWI_STATUS_NACK(sr)) {
uint8_t c = 'x';
if (srvBufferIndex < srvBufferLength)
c = srvBuffer[srvBufferIndex++];
TWI_WriteByte(twi, c);
}
}
}
*/
#if WIRE_INTERFACES_COUNT > 0
/*static void Wire_Init(void) {
pmc_enable_periph_clk(WIRE_INTERFACE_ID);
...
...
@@ -346,10 +277,10 @@ void TwoWire::onService(void)
}*/
TwoWire
Wire
(
&
sercom3
);
TwoWire
Wire
(
&
PERIPH_WIRE
,
PIN_WIRE_SDA
,
PIN_WIRE_SCL
);
void
SERCOM3_Handler
(
void
)
{
void
WIRE_IT_HANDLER
(
void
)
{
Wire
.
onService
();
}
#endif
#endif
// WIRE_INTERFACES_COUNT > 0
This diff is collapsed.
Click to expand it.
libraries/Wire/Wire.h
+
4
−
1
View file @
b81bc464
...
...
@@ -31,7 +31,7 @@
class
TwoWire
:
public
Stream
{
public:
TwoWire
(
SERCOM
*
s
);
TwoWire
(
SERCOM
*
s
,
uint8_t
pinSDA
,
uint8_t
pinSCL
);
void
begin
();
void
begin
(
uint8_t
);
void
setClock
(
uint32_t
);
// dummy function
...
...
@@ -59,6 +59,9 @@ class TwoWire : public Stream
private:
SERCOM
*
sercom
;
uint8_t
_uc_pinSDA
;
uint8_t
_uc_pinSCL
;
bool
transmissionBegun
;
// RX Buffer
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment