Browse Source

Apply const to mcp4728

Scott Lahteine 5 years ago
parent
commit
b315157053
2 changed files with 16 additions and 17 deletions
  1. 10
    11
      Marlin/src/feature/dac/dac_mcp4728.cpp
  2. 6
    6
      Marlin/src/feature/dac/dac_mcp4728.h

+ 10
- 11
Marlin/src/feature/dac/dac_mcp4728.cpp View File

58
  * Write input resister value to specified channel using fastwrite method.
58
  * Write input resister value to specified channel using fastwrite method.
59
  * Channel : 0-3, Values : 0-4095
59
  * Channel : 0-3, Values : 0-4095
60
  */
60
  */
61
-uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
61
+uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value) {
62
   mcp4728_values[channel] = value;
62
   mcp4728_values[channel] = value;
63
   return mcp4728_fastWrite();
63
   return mcp4728_fastWrite();
64
 }
64
 }
81
 /**
81
 /**
82
  * Write Voltage reference setting to all input regiters
82
  * Write Voltage reference setting to all input regiters
83
  */
83
  */
84
-uint8_t mcp4728_setVref_all(uint8_t value) {
84
+uint8_t mcp4728_setVref_all(const uint8_t value) {
85
   Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
85
   Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
86
   Wire.write(VREFWRITE | (value ? 0x0F : 0x00));
86
   Wire.write(VREFWRITE | (value ? 0x0F : 0x00));
87
   return Wire.endTransmission();
87
   return Wire.endTransmission();
89
 /**
89
 /**
90
  * Write Gain setting to all input regiters
90
  * Write Gain setting to all input regiters
91
  */
91
  */
92
-uint8_t mcp4728_setGain_all(uint8_t value) {
92
+uint8_t mcp4728_setGain_all(const uint8_t value) {
93
   Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
93
   Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
94
   Wire.write(GAINWRITE | (value ? 0x0F : 0x00));
94
   Wire.write(GAINWRITE | (value ? 0x0F : 0x00));
95
   return Wire.endTransmission();
95
   return Wire.endTransmission();
98
 /**
98
 /**
99
  * Return Input Register value
99
  * Return Input Register value
100
  */
100
  */
101
-uint16_t mcp4728_getValue(uint8_t channel) { return mcp4728_values[channel]; }
101
+uint16_t mcp4728_getValue(const uint8_t channel) { return mcp4728_values[channel]; }
102
 
102
 
103
 #if 0
103
 #if 0
104
 /**
104
 /**
105
  * Steph: Might be useful in the future
105
  * Steph: Might be useful in the future
106
  * Return Vout
106
  * Return Vout
107
  */
107
  */
108
-uint16_t mcp4728_getVout(uint8_t channel) {
109
-  uint32_t vref = 2048,
110
-           vOut = (vref * mcp4728_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096;
111
-  if (vOut > defaultVDD) vOut = defaultVDD;
112
-  return vOut;
108
+uint16_t mcp4728_getVout(const uint8_t channel) {
109
+  const uint32_t vref = 2048,
110
+                 vOut = (vref * mcp4728_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096;
111
+  return MIN(vOut, defaultVDD);
113
 }
112
 }
114
 #endif
113
 #endif
115
 
114
 
116
 /**
115
 /**
117
  * Returns DAC values as a 0-100 percentage of drive strength
116
  * Returns DAC values as a 0-100 percentage of drive strength
118
  */
117
  */
119
-uint8_t mcp4728_getDrvPct(uint8_t channel) { return uint8_t(100.0 * mcp4728_values[channel] / (DAC_STEPPER_MAX) + 0.5); }
118
+uint8_t mcp4728_getDrvPct(const uint8_t channel) { return uint8_t(100.0 * mcp4728_values[channel] / (DAC_STEPPER_MAX) + 0.5); }
120
 
119
 
121
 /**
120
 /**
122
  * Receives all Drive strengths as 0-100 percent values, updates
121
  * Receives all Drive strengths as 0-100 percent values, updates
144
 /**
143
 /**
145
  * Common function for simple general commands
144
  * Common function for simple general commands
146
  */
145
  */
147
-uint8_t mcp4728_simpleCommand(byte simpleCommand) {
146
+uint8_t mcp4728_simpleCommand(const byte simpleCommand) {
148
   Wire.beginTransmission(I2C_ADDRESS(GENERALCALL));
147
   Wire.beginTransmission(I2C_ADDRESS(GENERALCALL));
149
   Wire.write(simpleCommand);
148
   Wire.write(simpleCommand);
150
   return Wire.endTransmission();
149
   return Wire.endTransmission();

+ 6
- 6
Marlin/src/feature/dac/dac_mcp4728.h View File

46
 #define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS)
46
 #define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS)
47
 
47
 
48
 void mcp4728_init();
48
 void mcp4728_init();
49
-uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value);
49
+uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value);
50
 uint8_t mcp4728_eepromWrite();
50
 uint8_t mcp4728_eepromWrite();
51
-uint8_t mcp4728_setVref_all(uint8_t value);
52
-uint8_t mcp4728_setGain_all(uint8_t value);
53
-uint16_t mcp4728_getValue(uint8_t channel);
51
+uint8_t mcp4728_setVref_all(const uint8_t value);
52
+uint8_t mcp4728_setGain_all(const uint8_t value);
53
+uint16_t mcp4728_getValue(const uint8_t channel);
54
 uint8_t mcp4728_fastWrite();
54
 uint8_t mcp4728_fastWrite();
55
-uint8_t mcp4728_simpleCommand(byte simpleCommand);
56
-uint8_t mcp4728_getDrvPct(uint8_t channel);
55
+uint8_t mcp4728_simpleCommand(const byte simpleCommand);
56
+uint8_t mcp4728_getDrvPct(const uint8_t channel);
57
 void mcp4728_setDrvPct(uint8_t pct[XYZE]);
57
 void mcp4728_setDrvPct(uint8_t pct[XYZE]);

Loading…
Cancel
Save