Isolate more pat9125 code
Remove probing from Marlin_main and move it into pat9125_probe so that it can support the various variants.
This commit is contained in:
parent
008d3b0e65
commit
502bc8c72d
@ -88,18 +88,13 @@
|
|||||||
#include "la10compat.h"
|
#include "la10compat.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SWSPI
|
|
||||||
#include "swspi.h"
|
|
||||||
#endif //SWSPI
|
|
||||||
|
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
||||||
#ifdef SWI2C
|
|
||||||
#include "swi2c.h"
|
|
||||||
#endif //SWI2C
|
|
||||||
|
|
||||||
#ifdef FILAMENT_SENSOR
|
#ifdef FILAMENT_SENSOR
|
||||||
#include "fsensor.h"
|
#include "fsensor.h"
|
||||||
|
#ifdef IR_SENSOR
|
||||||
|
#include "pat9125.h" // for pat9125_probe
|
||||||
|
#endif
|
||||||
#endif //FILAMENT_SENSOR
|
#endif //FILAMENT_SENSOR
|
||||||
|
|
||||||
#ifdef TMC2130
|
#ifdef TMC2130
|
||||||
@ -864,9 +859,7 @@ static void check_if_fw_is_on_right_printer(){
|
|||||||
#ifdef FILAMENT_SENSOR
|
#ifdef FILAMENT_SENSOR
|
||||||
if((PRINTER_TYPE == PRINTER_MK3) || (PRINTER_TYPE == PRINTER_MK3S)){
|
if((PRINTER_TYPE == PRINTER_MK3) || (PRINTER_TYPE == PRINTER_MK3S)){
|
||||||
#ifdef IR_SENSOR
|
#ifdef IR_SENSOR
|
||||||
swi2c_init();
|
if (pat9125_probe()){
|
||||||
const uint8_t pat9125_detected = swi2c_readByte_A8(PAT9125_I2C_ADDR,0x00,NULL);
|
|
||||||
if (pat9125_detected){
|
|
||||||
lcd_show_fullscreen_message_and_wait_P(_i("MK3S firmware detected on MK3 printer"));}////c=20 r=3
|
lcd_show_fullscreen_message_and_wait_P(_i("MK3S firmware detected on MK3 printer"));}////c=20 r=3
|
||||||
#endif //IR_SENSOR
|
#endif //IR_SENSOR
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#define ADC_CALLBACK adc_ready //callback function ()
|
#define ADC_CALLBACK adc_ready //callback function ()
|
||||||
|
|
||||||
//SWI2C configuration
|
//SWI2C configuration
|
||||||
#define SWI2C
|
|
||||||
//#define SWI2C_SDA 20 //SDA on P3
|
//#define SWI2C_SDA 20 //SDA on P3
|
||||||
//#define SWI2C_SCL 21 //SCL on P3
|
//#define SWI2C_SCL 21 //SCL on P3
|
||||||
#define SWI2C_A8
|
#define SWI2C_A8
|
||||||
@ -31,7 +30,10 @@
|
|||||||
#define SWI2C_TMO 2048 //2048 cycles timeout
|
#define SWI2C_TMO 2048 //2048 cycles timeout
|
||||||
|
|
||||||
//PAT9125 configuration
|
//PAT9125 configuration
|
||||||
|
//#define PAT9125_SWSPI
|
||||||
#define PAT9125_SWI2C
|
#define PAT9125_SWI2C
|
||||||
|
//#define PAT9125_I2C
|
||||||
|
|
||||||
#define PAT9125_I2C_ADDR 0x75 //ID=LO
|
#define PAT9125_I2C_ADDR 0x75 //ID=LO
|
||||||
//#define PAT9125_I2C_ADDR 0x79 //ID=HI
|
//#define PAT9125_I2C_ADDR 0x79 //ID=HI
|
||||||
//#define PAT9125_I2C_ADDR 0x73 //ID=NC
|
//#define PAT9125_I2C_ADDR 0x73 //ID=NC
|
||||||
|
@ -26,12 +26,15 @@
|
|||||||
#define PAT9125_BANK_SELECTION 0x7f
|
#define PAT9125_BANK_SELECTION 0x7f
|
||||||
|
|
||||||
|
|
||||||
#ifdef PAT9125_SWSPI
|
#if defined(PAT9125_SWSPI)
|
||||||
#include "swspi.h"
|
#include "swspi.h"
|
||||||
#endif //PAT9125_SWSPI
|
#elif defined(PAT9125_SWI2C)
|
||||||
#ifdef PAT9125_SWI2C
|
|
||||||
#include "swi2c.h"
|
#include "swi2c.h"
|
||||||
#endif //PAT9125_SWI2C
|
#elif defined(PAT9125_I2C)
|
||||||
|
#error not implemented
|
||||||
|
#else
|
||||||
|
#error unknown PAT9125 communication method
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
uint8_t pat9125_PID1 = 0;
|
uint8_t pat9125_PID1 = 0;
|
||||||
@ -103,14 +106,30 @@ extern FILE _uartout;
|
|||||||
#define uartout (&_uartout)
|
#define uartout (&_uartout)
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t pat9125_probe()
|
||||||
|
{
|
||||||
|
#if defined(PAT9125_SWSPI)
|
||||||
|
swspi_init();
|
||||||
|
//#error not implemented
|
||||||
|
#elif defined(PAT9125_SWI2C)
|
||||||
|
swi2c_init();
|
||||||
|
return swi2c_readByte_A8(PAT9125_I2C_ADDR,0x00,NULL);
|
||||||
|
#elif defined(PAT9125_I2C)
|
||||||
|
twi_init();
|
||||||
|
#ifdef IR_SENSOR
|
||||||
|
// NOTE: this is called from the MK3S variant, so it should be kept minimal
|
||||||
|
#error not implemented
|
||||||
|
#else
|
||||||
|
return pat9125_rd_reg(PAT9125_PID1) != 0;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t pat9125_init(void)
|
uint8_t pat9125_init(void)
|
||||||
{
|
{
|
||||||
#ifdef PAT9125_SWSPI
|
if (!pat9125_probe())
|
||||||
swspi_init();
|
return 0;
|
||||||
#endif //PAT9125_SWSPI
|
|
||||||
#ifdef PAT9125_SWI2C
|
|
||||||
swi2c_init();
|
|
||||||
#endif //PAT9125_SWI2C
|
|
||||||
// Verify that the sensor responds with its correct product ID.
|
// Verify that the sensor responds with its correct product ID.
|
||||||
pat9125_PID1 = pat9125_rd_reg(PAT9125_PID1);
|
pat9125_PID1 = pat9125_rd_reg(PAT9125_PID1);
|
||||||
pat9125_PID2 = pat9125_rd_reg(PAT9125_PID2);
|
pat9125_PID2 = pat9125_rd_reg(PAT9125_PID2);
|
||||||
|
@ -18,6 +18,7 @@ extern int16_t pat9125_y;
|
|||||||
extern uint8_t pat9125_b;
|
extern uint8_t pat9125_b;
|
||||||
extern uint8_t pat9125_s;
|
extern uint8_t pat9125_s;
|
||||||
|
|
||||||
|
extern uint8_t pat9125_probe(void); // Return non-zero if PAT9125 can be trivially detected
|
||||||
extern uint8_t pat9125_init(void);
|
extern uint8_t pat9125_init(void);
|
||||||
extern uint8_t pat9125_update(void); // update all sensor data
|
extern uint8_t pat9125_update(void); // update all sensor data
|
||||||
extern uint8_t pat9125_update_y(void); // update _y only
|
extern uint8_t pat9125_update_y(void); // update _y only
|
||||||
|
Loading…
Reference in New Issue
Block a user