Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
marlin-anet-a8
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Leder
marlin-anet-a8
Commits
b3151570
Commit
b3151570
authored
May 26, 2019
by
Scott Lahteine
Browse files
Options
Downloads
Patches
Plain Diff
Apply const to mcp4728
parent
3c179bbd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Marlin/src/feature/dac/dac_mcp4728.cpp
+10
-11
10 additions, 11 deletions
Marlin/src/feature/dac/dac_mcp4728.cpp
Marlin/src/feature/dac/dac_mcp4728.h
+6
-6
6 additions, 6 deletions
Marlin/src/feature/dac/dac_mcp4728.h
with
16 additions
and
17 deletions
Marlin/src/feature/dac/dac_mcp4728.cpp
+
10
−
11
View file @
b3151570
...
@@ -58,7 +58,7 @@ void mcp4728_init() {
...
@@ -58,7 +58,7 @@ void mcp4728_init() {
* Write input resister value to specified channel using fastwrite method.
* Write input resister value to specified channel using fastwrite method.
* Channel : 0-3, Values : 0-4095
* Channel : 0-3, Values : 0-4095
*/
*/
uint8_t
mcp4728_analogWrite
(
uint8_t
channel
,
uint16_t
value
)
{
uint8_t
mcp4728_analogWrite
(
const
uint8_t
channel
,
const
uint16_t
value
)
{
mcp4728_values
[
channel
]
=
value
;
mcp4728_values
[
channel
]
=
value
;
return
mcp4728_fastWrite
();
return
mcp4728_fastWrite
();
}
}
...
@@ -81,7 +81,7 @@ uint8_t mcp4728_eepromWrite() {
...
@@ -81,7 +81,7 @@ uint8_t mcp4728_eepromWrite() {
/**
/**
* Write Voltage reference setting to all input regiters
* Write Voltage reference setting to all input regiters
*/
*/
uint8_t
mcp4728_setVref_all
(
uint8_t
value
)
{
uint8_t
mcp4728_setVref_all
(
const
uint8_t
value
)
{
Wire
.
beginTransmission
(
I2C_ADDRESS
(
DAC_DEV_ADDRESS
));
Wire
.
beginTransmission
(
I2C_ADDRESS
(
DAC_DEV_ADDRESS
));
Wire
.
write
(
VREFWRITE
|
(
value
?
0x0F
:
0x00
));
Wire
.
write
(
VREFWRITE
|
(
value
?
0x0F
:
0x00
));
return
Wire
.
endTransmission
();
return
Wire
.
endTransmission
();
...
@@ -89,7 +89,7 @@ uint8_t mcp4728_setVref_all(uint8_t value) {
...
@@ -89,7 +89,7 @@ uint8_t mcp4728_setVref_all(uint8_t value) {
/**
/**
* Write Gain setting to all input regiters
* Write Gain setting to all input regiters
*/
*/
uint8_t
mcp4728_setGain_all
(
uint8_t
value
)
{
uint8_t
mcp4728_setGain_all
(
const
uint8_t
value
)
{
Wire
.
beginTransmission
(
I2C_ADDRESS
(
DAC_DEV_ADDRESS
));
Wire
.
beginTransmission
(
I2C_ADDRESS
(
DAC_DEV_ADDRESS
));
Wire
.
write
(
GAINWRITE
|
(
value
?
0x0F
:
0x00
));
Wire
.
write
(
GAINWRITE
|
(
value
?
0x0F
:
0x00
));
return
Wire
.
endTransmission
();
return
Wire
.
endTransmission
();
...
@@ -98,25 +98,24 @@ uint8_t mcp4728_setGain_all(uint8_t value) {
...
@@ -98,25 +98,24 @@ uint8_t mcp4728_setGain_all(uint8_t value) {
/**
/**
* Return Input Register value
* Return Input Register value
*/
*/
uint16_t
mcp4728_getValue
(
uint8_t
channel
)
{
return
mcp4728_values
[
channel
];
}
uint16_t
mcp4728_getValue
(
const
uint8_t
channel
)
{
return
mcp4728_values
[
channel
];
}
#if 0
#if 0
/**
/**
* Steph: Might be useful in the future
* Steph: Might be useful in the future
* Return Vout
* Return Vout
*/
*/
uint16_t mcp4728_getVout(uint8_t channel) {
uint16_t mcp4728_getVout(
const
uint8_t channel) {
uint32_t vref = 2048,
const
uint32_t vref = 2048,
vOut = (vref * mcp4728_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096;
vOut = (vref * mcp4728_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096;
if (vOut > defaultVDD) vOut = defaultVDD;
return MIN(vOut, defaultVDD);
return vOut;
}
}
#endif
#endif
/**
/**
* Returns DAC values as a 0-100 percentage of drive strength
* Returns DAC values as a 0-100 percentage of drive strength
*/
*/
uint8_t
mcp4728_getDrvPct
(
uint8_t
channel
)
{
return
uint8_t
(
100.0
*
mcp4728_values
[
channel
]
/
(
DAC_STEPPER_MAX
)
+
0.5
);
}
uint8_t
mcp4728_getDrvPct
(
const
uint8_t
channel
)
{
return
uint8_t
(
100.0
*
mcp4728_values
[
channel
]
/
(
DAC_STEPPER_MAX
)
+
0.5
);
}
/**
/**
* Receives all Drive strengths as 0-100 percent values, updates
* Receives all Drive strengths as 0-100 percent values, updates
...
@@ -144,7 +143,7 @@ uint8_t mcp4728_fastWrite() {
...
@@ -144,7 +143,7 @@ uint8_t mcp4728_fastWrite() {
/**
/**
* Common function for simple general commands
* Common function for simple general commands
*/
*/
uint8_t
mcp4728_simpleCommand
(
byte
simpleCommand
)
{
uint8_t
mcp4728_simpleCommand
(
const
byte
simpleCommand
)
{
Wire
.
beginTransmission
(
I2C_ADDRESS
(
GENERALCALL
));
Wire
.
beginTransmission
(
I2C_ADDRESS
(
GENERALCALL
));
Wire
.
write
(
simpleCommand
);
Wire
.
write
(
simpleCommand
);
return
Wire
.
endTransmission
();
return
Wire
.
endTransmission
();
...
...
This diff is collapsed.
Click to expand it.
Marlin/src/feature/dac/dac_mcp4728.h
+
6
−
6
View file @
b3151570
...
@@ -46,12 +46,12 @@
...
@@ -46,12 +46,12 @@
#define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS)
#define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS)
void
mcp4728_init
();
void
mcp4728_init
();
uint8_t
mcp4728_analogWrite
(
uint8_t
channel
,
uint16_t
value
);
uint8_t
mcp4728_analogWrite
(
const
uint8_t
channel
,
const
uint16_t
value
);
uint8_t
mcp4728_eepromWrite
();
uint8_t
mcp4728_eepromWrite
();
uint8_t
mcp4728_setVref_all
(
uint8_t
value
);
uint8_t
mcp4728_setVref_all
(
const
uint8_t
value
);
uint8_t
mcp4728_setGain_all
(
uint8_t
value
);
uint8_t
mcp4728_setGain_all
(
const
uint8_t
value
);
uint16_t
mcp4728_getValue
(
uint8_t
channel
);
uint16_t
mcp4728_getValue
(
const
uint8_t
channel
);
uint8_t
mcp4728_fastWrite
();
uint8_t
mcp4728_fastWrite
();
uint8_t
mcp4728_simpleCommand
(
byte
simpleCommand
);
uint8_t
mcp4728_simpleCommand
(
const
byte
simpleCommand
);
uint8_t
mcp4728_getDrvPct
(
uint8_t
channel
);
uint8_t
mcp4728_getDrvPct
(
const
uint8_t
channel
);
void
mcp4728_setDrvPct
(
uint8_t
pct
[
XYZE
]);
void
mcp4728_setDrvPct
(
uint8_t
pct
[
XYZE
]);
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