Przeglądaj źródła

Apply const to mcp4728

Scott Lahteine 5 lat temu
rodzic
commit
b315157053

+ 10
- 11
Marlin/src/feature/dac/dac_mcp4728.cpp Wyświetl plik

@@ -58,7 +58,7 @@ void mcp4728_init() {
58 58
  * Write input resister value to specified channel using fastwrite method.
59 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 62
   mcp4728_values[channel] = value;
63 63
   return mcp4728_fastWrite();
64 64
 }
@@ -81,7 +81,7 @@ uint8_t mcp4728_eepromWrite() {
81 81
 /**
82 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 85
   Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
86 86
   Wire.write(VREFWRITE | (value ? 0x0F : 0x00));
87 87
   return Wire.endTransmission();
@@ -89,7 +89,7 @@ uint8_t mcp4728_setVref_all(uint8_t value) {
89 89
 /**
90 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 93
   Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
94 94
   Wire.write(GAINWRITE | (value ? 0x0F : 0x00));
95 95
   return Wire.endTransmission();
@@ -98,25 +98,24 @@ uint8_t mcp4728_setGain_all(uint8_t value) {
98 98
 /**
99 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 103
 #if 0
104 104
 /**
105 105
  * Steph: Might be useful in the future
106 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 113
 #endif
115 114
 
116 115
 /**
117 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 121
  * Receives all Drive strengths as 0-100 percent values, updates
@@ -144,7 +143,7 @@ uint8_t mcp4728_fastWrite() {
144 143
 /**
145 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 147
   Wire.beginTransmission(I2C_ADDRESS(GENERALCALL));
149 148
   Wire.write(simpleCommand);
150 149
   return Wire.endTransmission();

+ 6
- 6
Marlin/src/feature/dac/dac_mcp4728.h Wyświetl plik

@@ -46,12 +46,12 @@
46 46
 #define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS)
47 47
 
48 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 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 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 57
 void mcp4728_setDrvPct(uint8_t pct[XYZE]);

Ładowanie…
Anuluj
Zapisz