Преглед изворни кода

Use 8-bit i2c address on LPC platform

Fix #9799 — hopefully not a unicorn
Scott Lahteine пре 5 година
родитељ
комит
a43e892fb5

+ 5
- 5
Marlin/src/HAL/shared/I2cEeprom.cpp Прегледај датотеку

@@ -87,7 +87,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
87 87
 
88 88
   eeprom_init();
89 89
 
90
-  Wire.beginTransmission(eeprom_device_address);
90
+  Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
91 91
   Wire.write((int)(eeprom_address >> 8));   // MSB
92 92
   Wire.write((int)(eeprom_address & 0xFF)); // LSB
93 93
   Wire.write(value);
@@ -103,7 +103,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
103 103
 void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
104 104
   eeprom_init();
105 105
 
106
-  Wire.beginTransmission(eeprom_device_address);
106
+  Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
107 107
   Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
108 108
   Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
109 109
   Wire.endTransmission();
@@ -115,7 +115,7 @@ void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
115 115
     flag |= Wire.read() ^ ptr[c];
116 116
 
117 117
   if (flag) {
118
-    Wire.beginTransmission(eeprom_device_address);
118
+    Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
119 119
     Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
120 120
     Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
121 121
     Wire.write((uint8_t*)pos, n);
@@ -133,7 +133,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
133 133
 
134 134
   eeprom_init();
135 135
 
136
-  Wire.beginTransmission(eeprom_device_address);
136
+  Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
137 137
   Wire.write((int)(eeprom_address >> 8));   // MSB
138 138
   Wire.write((int)(eeprom_address & 0xFF)); // LSB
139 139
   Wire.endTransmission();
@@ -145,7 +145,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
145 145
 void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
146 146
   eeprom_init();
147 147
 
148
-  Wire.beginTransmission(eeprom_device_address);
148
+  Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
149 149
   Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
150 150
   Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
151 151
   Wire.endTransmission();

+ 6
- 0
Marlin/src/core/macros.h Прегледај датотеку

@@ -229,3 +229,9 @@
229 229
 #define LROUND(x)   lroundf(x)
230 230
 #define FMOD(x, y)  fmodf(x, y)
231 231
 #define HYPOT(x,y)  SQRT(HYPOT2(x,y))
232
+
233
+#ifdef TARGET_LPC1768
234
+  #define I2C_ADDRESS(A) ((A) << 1)
235
+#else
236
+  #define I2C_ADDRESS(A) A
237
+#endif

+ 8
- 8
Marlin/src/feature/I2CPositionEncoder.cpp Прегледај датотеку

@@ -473,7 +473,7 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
473 473
 }
474 474
 
475 475
 void I2CPositionEncoder::reset() {
476
-  Wire.beginTransmission(i2cAddress);
476
+  Wire.beginTransmission(I2C_ADDRESS(i2cAddress));
477 477
   Wire.write(I2CPE_RESET_COUNT);
478 478
   Wire.endTransmission();
479 479
 
@@ -703,7 +703,7 @@ void I2CPositionEncodersMgr::report_position(const int8_t idx, const bool units,
703 703
 
704 704
 void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const uint8_t newaddr) {
705 705
   // First check 'new' address is not in use
706
-  Wire.beginTransmission(newaddr);
706
+  Wire.beginTransmission(I2C_ADDRESS(newaddr));
707 707
   if (!Wire.endTransmission()) {
708 708
     SERIAL_ECHOPAIR("?There is already a device with that address on the I2C bus! (", newaddr);
709 709
     SERIAL_ECHOLNPGM(")");
@@ -711,7 +711,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
711 711
   }
712 712
 
713 713
   // Now check that we can find the module on the oldaddr address
714
-  Wire.beginTransmission(oldaddr);
714
+  Wire.beginTransmission(I2C_ADDRESS(oldaddr));
715 715
   if (Wire.endTransmission()) {
716 716
     SERIAL_ECHOPAIR("?No module detected at this address! (", oldaddr);
717 717
     SERIAL_ECHOLNPGM(")");
@@ -722,7 +722,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
722 722
   SERIAL_ECHOLNPAIR(", changing address to ", newaddr);
723 723
 
724 724
   // Change the modules address
725
-  Wire.beginTransmission(oldaddr);
725
+  Wire.beginTransmission(I2C_ADDRESS(oldaddr));
726 726
   Wire.write(I2CPE_SET_ADDR);
727 727
   Wire.write(newaddr);
728 728
   Wire.endTransmission();
@@ -733,7 +733,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
733 733
   safe_delay(I2CPE_REBOOT_TIME);
734 734
 
735 735
   // Look for the module at the new address.
736
-  Wire.beginTransmission(newaddr);
736
+  Wire.beginTransmission(I2C_ADDRESS(newaddr));
737 737
   if (Wire.endTransmission()) {
738 738
     SERIAL_ECHOLNPGM("Address change failed! Check encoder module.");
739 739
     return;
@@ -753,7 +753,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
753 753
 
754 754
 void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
755 755
   // First check there is a module
756
-  Wire.beginTransmission(address);
756
+  Wire.beginTransmission(I2C_ADDRESS(address));
757 757
   if (Wire.endTransmission()) {
758 758
     SERIAL_ECHOPAIR("?No module detected at this address! (", address);
759 759
     SERIAL_ECHOLNPGM(")");
@@ -763,7 +763,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
763 763
   SERIAL_ECHOPAIR("Requesting version info from module at address ", address);
764 764
   SERIAL_ECHOLNPGM(":");
765 765
 
766
-  Wire.beginTransmission(address);
766
+  Wire.beginTransmission(I2C_ADDRESS(address));
767 767
   Wire.write(I2CPE_SET_REPORT_MODE);
768 768
   Wire.write(I2CPE_REPORT_VERSION);
769 769
   Wire.endTransmission();
@@ -777,7 +777,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
777 777
   }
778 778
 
779 779
   // Set module back to normal (distance) mode
780
-  Wire.beginTransmission(address);
780
+  Wire.beginTransmission(I2C_ADDRESS(address));
781 781
   Wire.write(I2CPE_SET_REPORT_MODE);
782 782
   Wire.write(I2CPE_REPORT_DISTANCE);
783 783
   Wire.endTransmission();

+ 5
- 5
Marlin/src/feature/dac/dac_mcp4728.cpp Прегледај датотеку

@@ -69,7 +69,7 @@ uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
69 69
  * This will also write current Vref, PowerDown, Gain settings to EEPROM
70 70
  */
71 71
 uint8_t mcp4728_eepromWrite() {
72
-  Wire.beginTransmission(DAC_DEV_ADDRESS);
72
+  Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
73 73
   Wire.write(SEQWRITE);
74 74
   LOOP_XYZE(i) {
75 75
     Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[i]));
@@ -82,7 +82,7 @@ uint8_t mcp4728_eepromWrite() {
82 82
  * Write Voltage reference setting to all input regiters
83 83
  */
84 84
 uint8_t mcp4728_setVref_all(uint8_t value) {
85
-  Wire.beginTransmission(DAC_DEV_ADDRESS);
85
+  Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
86 86
   Wire.write(VREFWRITE | (value ? 0x0F : 0x00));
87 87
   return Wire.endTransmission();
88 88
 }
@@ -90,7 +90,7 @@ uint8_t mcp4728_setVref_all(uint8_t value) {
90 90
  * Write Gain setting to all input regiters
91 91
  */
92 92
 uint8_t mcp4728_setGain_all(uint8_t value) {
93
-  Wire.beginTransmission(DAC_DEV_ADDRESS);
93
+  Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
94 94
   Wire.write(GAINWRITE | (value ? 0x0F : 0x00));
95 95
   return Wire.endTransmission();
96 96
 }
@@ -133,7 +133,7 @@ void mcp4728_setDrvPct(uint8_t pct[XYZE]) {
133 133
  * No EEPROM update
134 134
  */
135 135
 uint8_t mcp4728_fastWrite() {
136
-  Wire.beginTransmission(DAC_DEV_ADDRESS);
136
+  Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
137 137
   LOOP_XYZE(i) {
138 138
     Wire.write(highByte(mcp4728_values[i]));
139 139
     Wire.write(lowByte(mcp4728_values[i]));
@@ -145,7 +145,7 @@ uint8_t mcp4728_fastWrite() {
145 145
  * Common function for simple general commands
146 146
  */
147 147
 uint8_t mcp4728_simpleCommand(byte simpleCommand) {
148
-  Wire.beginTransmission(GENERALCALL);
148
+  Wire.beginTransmission(I2C_ADDRESS(GENERALCALL));
149 149
   Wire.write(simpleCommand);
150 150
   return Wire.endTransmission();
151 151
 }

+ 1
- 1
Marlin/src/feature/digipot/digipot_mcp4451.cpp Прегледај датотеку

@@ -50,7 +50,7 @@ static void i2c_send(const byte addr, const byte a, const byte b) {
50 50
     digipot_mcp4451_send_byte(a);
51 51
     digipot_mcp4451_send_byte(b);
52 52
   #else
53
-    Wire.beginTransmission(addr);
53
+    Wire.beginTransmission(I2C_ADDRESS(addr));
54 54
     Wire.write(a);
55 55
     Wire.write(b);
56 56
     Wire.endTransmission();

+ 1
- 1
Marlin/src/feature/leds/blinkm.cpp Прегледај датотеку

@@ -34,7 +34,7 @@
34 34
 
35 35
 void blinkm_set_led_color(const LEDColor &color) {
36 36
   Wire.begin();
37
-  Wire.beginTransmission(0x09);
37
+  Wire.beginTransmission(I2C_ADDRESS(0x09));
38 38
   Wire.write('o');                    //to disable ongoing script, only needs to be used once
39 39
   Wire.write('n');
40 40
   Wire.write(color.r);

+ 3
- 3
Marlin/src/feature/leds/pca9632.cpp Прегледај датотеку

@@ -74,14 +74,14 @@
74 74
 byte PCA_init = 0;
75 75
 
76 76
 static void PCA9632_WriteRegister(const byte addr, const byte regadd, const byte value) {
77
-  Wire.beginTransmission(addr);
77
+  Wire.beginTransmission(I2C_ADDRESS(addr));
78 78
   Wire.write(regadd);
79 79
   Wire.write(value);
80 80
   Wire.endTransmission();
81 81
 }
82 82
 
83 83
 static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const byte value1, const byte value2, const byte value3) {
84
-  Wire.beginTransmission(addr);
84
+  Wire.beginTransmission(I2C_ADDRESS(addr));
85 85
   Wire.write(PCA9632_AUTO_IND | regadd);
86 86
   Wire.write(value1);
87 87
   Wire.write(value2);
@@ -91,7 +91,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
91 91
 
92 92
 #if 0
93 93
   static byte PCA9632_ReadRegister(const byte addr, const byte regadd) {
94
-    Wire.beginTransmission(addr);
94
+    Wire.beginTransmission(I2C_ADDRESS(addr));
95 95
     Wire.write(regadd);
96 96
     const byte value = Wire.read();
97 97
     Wire.endTransmission();

+ 1
- 1
Marlin/src/feature/twibus.cpp Прегледај датотеку

@@ -81,7 +81,7 @@ void TWIBus::send() {
81 81
     debug(PSTR("send"), this->addr);
82 82
   #endif
83 83
 
84
-  Wire.beginTransmission(this->addr);
84
+  Wire.beginTransmission(I2C_ADDRESS(this->addr));
85 85
   Wire.write(this->buffer, this->buffer_s);
86 86
   Wire.endTransmission();
87 87
 

Loading…
Откажи
Сачувај