Bladeren bron

Fix M261, i2c EEPROM, i2c Encoder for LPC (#17678)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
randellhodges 5 jaren geleden
bovenliggende
commit
b700b3cde6
No account linked to committer's email address

+ 6
- 6
Marlin/src/HAL/shared/eeprom_i2c.cpp Bestand weergeven

@@ -39,7 +39,7 @@
39 39
 // Private Variables
40 40
 // ------------------------
41 41
 
42
-static uint8_t eeprom_device_address = 0x50;
42
+static constexpr uint8_t eeprom_device_address = I2C_ADDRESS(0x50);
43 43
 
44 44
 // ------------------------
45 45
 // Public functions
@@ -54,7 +54,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
54 54
 
55 55
   eeprom_init();
56 56
 
57
-  Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
57
+  Wire.beginTransmission(eeprom_device_address);
58 58
   Wire.write((int)(eeprom_address >> 8));   // MSB
59 59
   Wire.write((int)(eeprom_address & 0xFF)); // LSB
60 60
   Wire.write(value);
@@ -70,7 +70,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
70 70
 void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
71 71
   eeprom_init();
72 72
 
73
-  Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
73
+  Wire.beginTransmission(eeprom_device_address);
74 74
   Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
75 75
   Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
76 76
   Wire.endTransmission();
@@ -82,7 +82,7 @@ void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
82 82
     flag |= Wire.read() ^ ptr[c];
83 83
 
84 84
   if (flag) {
85
-    Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
85
+    Wire.beginTransmission(eeprom_device_address);
86 86
     Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
87 87
     Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
88 88
     Wire.write((uint8_t*)pos, n);
@@ -99,7 +99,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
99 99
 
100 100
   eeprom_init();
101 101
 
102
-  Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
102
+  Wire.beginTransmission(eeprom_device_address);
103 103
   Wire.write((int)(eeprom_address >> 8));   // MSB
104 104
   Wire.write((int)(eeprom_address & 0xFF)); // LSB
105 105
   Wire.endTransmission();
@@ -111,7 +111,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
111 111
 void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
112 112
   eeprom_init();
113 113
 
114
-  Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
114
+  Wire.beginTransmission(eeprom_device_address);
115 115
   Wire.write((int)((unsigned)eeprom_address >> 8));   // MSB
116 116
   Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
117 117
   Wire.endTransmission();

+ 1
- 5
Marlin/src/core/macros.h Bestand weergeven

@@ -292,11 +292,7 @@
292 292
 #define FMOD(x, y)  fmodf(x, y)
293 293
 #define HYPOT(x,y)  SQRT(HYPOT2(x,y))
294 294
 
295
-#ifdef TARGET_LPC1768
296
-  #define I2C_ADDRESS(A) ((A) << 1)
297
-#else
298
-  #define I2C_ADDRESS(A) A
299
-#endif
295
+#define I2C_ADDRESS(A) (TERN(TARGET_LPC1768, (A) << 1, A))
300 296
 
301 297
 // Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
302 298
 #define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT

+ 2
- 2
Marlin/src/feature/encoder_i2c.cpp Bestand weergeven

@@ -305,7 +305,7 @@ int32_t I2CPositionEncoder::get_raw_count() {
305 305
 
306 306
   encoderCount.val = 0x00;
307 307
 
308
-  if (Wire.requestFrom((int)i2cAddress, 3) != 3) {
308
+  if (Wire.requestFrom(I2C_ADDRESS(i2cAddress), 3) != 3) {
309 309
     //houston, we have a problem...
310 310
     H = I2CPE_MAG_SIG_NF;
311 311
     return 0;
@@ -744,7 +744,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
744 744
   Wire.endTransmission();
745 745
 
746 746
   // Read value
747
-  if (Wire.requestFrom((int)address, 32)) {
747
+  if (Wire.requestFrom(I2C_ADDRESS(address), 32)) {
748 748
     char c;
749 749
     while (Wire.available() > 0 && (c = (char)Wire.read()) > 0)
750 750
       SERIAL_ECHO(c);

+ 2
- 2
Marlin/src/feature/twibus.cpp Bestand weergeven

@@ -104,8 +104,8 @@ bool TWIBus::request(const uint8_t bytes) {
104 104
   debug(PSTR("request"), bytes);
105 105
 
106 106
   // requestFrom() is a blocking function
107
-  if (Wire.requestFrom(addr, bytes) == 0) {
108
-    debug("request fail", addr);
107
+  if (Wire.requestFrom(I2C_ADDRESS(addr), bytes) == 0) {
108
+    debug("request fail", I2C_ADDRESS(addr));
109 109
     return false;
110 110
   }
111 111
 

Laden…
Annuleren
Opslaan