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
03ef25d2
Commit
03ef25d2
authored
10 years ago
by
Jonathan BAUDIN
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring UART functions
parent
b6658c1b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cores/arduino/SERCOM.cpp
+14
-36
14 additions, 36 deletions
cores/arduino/SERCOM.cpp
cores/arduino/SERCOM.h
+1
-1
1 addition, 1 deletion
cores/arduino/SERCOM.h
with
15 additions
and
37 deletions
cores/arduino/SERCOM.cpp
+
14
−
36
View file @
03ef25d2
...
...
@@ -20,8 +20,7 @@ SERCOM::SERCOM(Sercom* s)
void
SERCOM
::
initUART
(
SercomUartMode
mode
,
SercomUartSampleRate
sampleRate
,
uint32_t
baudrate
)
{
resetUART
();
initClock
();
initNVIC
();
initClockNvic
();
//Setting the CTRLA register
sercom
->
USART
.
CTRLA
.
reg
=
SERCOM_USART_CTRLA_MODE
(
mode
)
|
...
...
@@ -154,6 +153,7 @@ int SERCOM::writeDataUART(uint8_t data)
void
SERCOM
::
initSPI
(
SercomSpiTXPad
mosi
,
SercomRXPad
miso
,
SercomSpiCharSize
charSize
,
SercomDataOrder
dataOrder
)
{
resetSPI
();
initClockNvic
();
//Setting the CTRLA register
sercom
->
SPI
.
CTRLA
.
reg
=
SERCOM_SPI_CTRLA_MODE
(
SPI_MASTER_OPERATION
)
|
...
...
@@ -493,35 +493,46 @@ uint8_t SERCOM::readDataWIRE()
}
void
SERCOM
::
initClock
()
void
SERCOM
::
initClock
Nvic
()
{
uint8_t
clockId
=
0
;
IRQn_Type
Id
;
if
(
sercom
==
SERCOM0
)
{
clockId
=
GENERIC_CLOCK_SERCOM0
;
Id
=
SERCOM0_IRQn
;
}
else
if
(
sercom
==
SERCOM1
)
{
clockId
=
GENERIC_CLOCK_SERCOM1
;
Id
=
SERCOM1_IRQn
;
}
else
if
(
sercom
==
SERCOM2
)
{
clockId
=
GENERIC_CLOCK_SERCOM2
;
Id
=
SERCOM2_IRQn
;
}
else
if
(
sercom
==
SERCOM3
)
{
clockId
=
GENERIC_CLOCK_SERCOM3
;
Id
=
SERCOM3_IRQn
;
}
else
if
(
sercom
==
SERCOM4
)
{
clockId
=
GENERIC_CLOCK_SERCOM4
;
Id
=
SERCOM4_IRQn
;
}
else
if
(
sercom
==
SERCOM5
)
{
clockId
=
GENERIC_CLOCK_SERCOM5
;
Id
=
SERCOM5_IRQn
;
}
//Setting NVIC
NVIC_EnableIRQ
(
Id
);
NVIC_SetPriority
(
Id
,
(
1
<<
__NVIC_PRIO_BITS
)
-
1
);
/* set Priority */
//Setting clock
GCLK
->
CLKCTRL
.
reg
=
GCLK_CLKCTRL_ID
(
clockId
)
|
// Generic Clock 0 (SERCOMx)
GCLK_CLKCTRL_GEN_GCLK0
|
// Generic Clock Generator 0 is source
...
...
@@ -534,39 +545,6 @@ void SERCOM::initClock()
}
}
void
SERCOM
::
initNVIC
()
{
IRQn_Type
Id
;
if
(
sercom
==
SERCOM0
)
{
Id
=
SERCOM0_IRQn
;
}
else
if
(
sercom
==
SERCOM1
)
{
Id
=
SERCOM1_IRQn
;
}
else
if
(
sercom
==
SERCOM2
)
{
Id
=
SERCOM2_IRQn
;
}
else
if
(
sercom
==
SERCOM3
)
{
Id
=
SERCOM3_IRQn
;
}
else
if
(
sercom
==
SERCOM4
)
{
Id
=
SERCOM4_IRQn
;
}
else
if
(
sercom
==
SERCOM5
)
{
Id
=
SERCOM5_IRQn
;
}
NVIC_EnableIRQ
(
Id
);
NVIC_SetPriority
(
Id
,
(
1
<<
__NVIC_PRIO_BITS
)
-
1
);
/* set Priority */
}
/* =========================
* ===== SERCOM DEFINITION
* =========================
...
...
This diff is collapsed.
Click to expand it.
cores/arduino/SERCOM.h
+
1
−
1
View file @
03ef25d2
...
...
@@ -198,7 +198,7 @@ class SERCOM
Sercom
*
sercom
;
uint8_t
calculateBaudrateSynchronous
(
uint32_t
baudrate
);
uint32_t
division
(
uint32_t
dividend
,
uint32_t
divisor
);
void
initClock
();
void
initClock
Nvic
();
void
initNVIC
();
};
...
...
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