Преглед на файлове

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

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
randellhodges преди 5 години
родител
ревизия
b700b3cde6
No account linked to committer's email address
променени са 4 файла, в които са добавени 11 реда и са изтрити 15 реда
  1. 6
    6
      Marlin/src/HAL/shared/eeprom_i2c.cpp
  2. 1
    5
      Marlin/src/core/macros.h
  3. 2
    2
      Marlin/src/feature/encoder_i2c.cpp
  4. 2
    2
      Marlin/src/feature/twibus.cpp

+ 6
- 6
Marlin/src/HAL/shared/eeprom_i2c.cpp Целия файл

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

+ 1
- 5
Marlin/src/core/macros.h Целия файл

292
 #define FMOD(x, y)  fmodf(x, y)
292
 #define FMOD(x, y)  fmodf(x, y)
293
 #define HYPOT(x,y)  SQRT(HYPOT2(x,y))
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
 // Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
297
 // Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
302
 #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
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 Целия файл

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

+ 2
- 2
Marlin/src/feature/twibus.cpp Целия файл

104
   debug(PSTR("request"), bytes);
104
   debug(PSTR("request"), bytes);
105
 
105
 
106
   // requestFrom() is a blocking function
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
     return false;
109
     return false;
110
   }
110
   }
111
 
111
 

Loading…
Отказ
Запис