Browse Source

Use 8-bit i2c address on LPC platform

Fix #9799 — hopefully not a unicorn
Scott Lahteine 5 years ago
parent
commit
a43e892fb5

+ 5
- 5
Marlin/src/HAL/shared/I2cEeprom.cpp View File

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

+ 6
- 0
Marlin/src/core/macros.h View File

229
 #define LROUND(x)   lroundf(x)
229
 #define LROUND(x)   lroundf(x)
230
 #define FMOD(x, y)  fmodf(x, y)
230
 #define FMOD(x, y)  fmodf(x, y)
231
 #define HYPOT(x,y)  SQRT(HYPOT2(x,y))
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 View File

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

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

69
  * This will also write current Vref, PowerDown, Gain settings to EEPROM
69
  * This will also write current Vref, PowerDown, Gain settings to EEPROM
70
  */
70
  */
71
 uint8_t mcp4728_eepromWrite() {
71
 uint8_t mcp4728_eepromWrite() {
72
-  Wire.beginTransmission(DAC_DEV_ADDRESS);
72
+  Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
73
   Wire.write(SEQWRITE);
73
   Wire.write(SEQWRITE);
74
   LOOP_XYZE(i) {
74
   LOOP_XYZE(i) {
75
     Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[i]));
75
     Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[i]));
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(uint8_t value) {
85
-  Wire.beginTransmission(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();
88
 }
88
 }
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(uint8_t value) {
93
-  Wire.beginTransmission(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();
96
 }
96
 }
133
  * No EEPROM update
133
  * No EEPROM update
134
  */
134
  */
135
 uint8_t mcp4728_fastWrite() {
135
 uint8_t mcp4728_fastWrite() {
136
-  Wire.beginTransmission(DAC_DEV_ADDRESS);
136
+  Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS));
137
   LOOP_XYZE(i) {
137
   LOOP_XYZE(i) {
138
     Wire.write(highByte(mcp4728_values[i]));
138
     Wire.write(highByte(mcp4728_values[i]));
139
     Wire.write(lowByte(mcp4728_values[i]));
139
     Wire.write(lowByte(mcp4728_values[i]));
145
  * Common function for simple general commands
145
  * Common function for simple general commands
146
  */
146
  */
147
 uint8_t mcp4728_simpleCommand(byte simpleCommand) {
147
 uint8_t mcp4728_simpleCommand(byte simpleCommand) {
148
-  Wire.beginTransmission(GENERALCALL);
148
+  Wire.beginTransmission(I2C_ADDRESS(GENERALCALL));
149
   Wire.write(simpleCommand);
149
   Wire.write(simpleCommand);
150
   return Wire.endTransmission();
150
   return Wire.endTransmission();
151
 }
151
 }

+ 1
- 1
Marlin/src/feature/digipot/digipot_mcp4451.cpp View File

50
     digipot_mcp4451_send_byte(a);
50
     digipot_mcp4451_send_byte(a);
51
     digipot_mcp4451_send_byte(b);
51
     digipot_mcp4451_send_byte(b);
52
   #else
52
   #else
53
-    Wire.beginTransmission(addr);
53
+    Wire.beginTransmission(I2C_ADDRESS(addr));
54
     Wire.write(a);
54
     Wire.write(a);
55
     Wire.write(b);
55
     Wire.write(b);
56
     Wire.endTransmission();
56
     Wire.endTransmission();

+ 1
- 1
Marlin/src/feature/leds/blinkm.cpp View File

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

+ 3
- 3
Marlin/src/feature/leds/pca9632.cpp View File

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

+ 1
- 1
Marlin/src/feature/twibus.cpp View File

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

Loading…
Cancel
Save