/**
 * GY-271 header file
 * 
 * HARDWARE CONNECTIONS
 *  - GPIO 6 ---> GY-271 SDA
 *  - GPIO 7 ---> GY-271 SCL
 *  - 3.3v ---> GY-271 VCC
 *  - RP2040 GND ---> GY-271 GND
 */


#define GY271_I2C_CHAN i2c1
#define GY271_SDA_PIN  6
#define GY271_SCL_PIN  7
#define GY271_I2C_BAUD_RATE 400000

// QMC5883L: 0x0D
// HMC5883L: 0x1E
#define QMC5883L_ADDRESS 0x0D
#define HMC5883L_ADDRESS 0x1E

#define MAG_ADDRESS QMC5883L_ADDRESS

// Fixed point data type
typedef signed int fix15 ;
#define multfix15(a,b) ((fix15)(((( signed long long)(a))*(( signed long long)(b)))>>16)) 
#define float2fix15(a) ((fix15)((a)*65536.0f)) // 2^16
#define fix2float15(a) ((float)(a)/65536.0f) 
#define int2fix15(a) ((a)<<16)
#define fix2int15(a) ((a)>>16)
#define divfix(a,b) ((fix15)(((( signed long long)(a) << 16 / (b)))))

// Parameter values
#define oneeightyoverpi 3754936
#define zeropt001 65
#define zeropt999 65470
#define zeropt01 655
#define zeropt99 64880
#define zeropt1 6553
#define zeropt9 58982

void gy271_reset(void);
void gy271_read_raw(fix15 mag[3]);
int gy271_detect_chip(void);

