1
0
forked from me/IronOS

Starting hall effect support

This commit is contained in:
Ben V. Brown
2020-10-13 18:46:37 +11:00
parent 2c626d7203
commit 58c4ecaea6
8 changed files with 103 additions and 2 deletions

View File

@@ -0,0 +1,35 @@
/*
* Si7210.cpp
*
* Created on: 5 Oct. 2020
* Author: Ralim
*/
#include <Si7210.h>
#include "Si7210_defines.h"
#include "I2C_Wrapper.hpp"
bool Si7210::detect() {
return FRToSI2C::probe(SI7210_ADDRESS);
}
bool Si7210::init() {
//Turn on auto increment and sanity check ID
uint8_t temp;
if (FRToSI2C::Mem_Read(SI7210_ADDRESS, SI7210_REG_ID, &temp, 1)) {
// We don't really care what model it is etc, just probing to check its probably this iC
if (temp != 0x00 && temp != 0xFF) {
temp = 0x01; //turn on auto increment
if (FRToSI2C::Mem_Write(SI7210_ADDRESS, SI7210_REG_INCR, &temp, 1)) {
return true;
}
}
}
return false;
}
int16_t Si7210::read() {
//Read the two regs
int16_t temp = 0;
FRToSI2C::Mem_Read(SI7210_ADDRESS, SI7210_REG_DATAH,(uint8_t*) &temp, 2);
return __builtin_bswap16(temp);
}

View File

@@ -0,0 +1,21 @@
/*
* Si7210.h
*
* Created on: 5 Oct. 2020
* Author: Ralim
*/
#ifndef CORE_DRIVERS_SI7210_H_
#define CORE_DRIVERS_SI7210_H_
#include <stdint.h>
class Si7210 {
public:
//Return true if present
static bool detect();
static bool init();
static int16_t read();
private:
};
#endif /* CORE_DRIVERS_SI7210_H_ */

View File

@@ -0,0 +1,19 @@
/*
* Si7210_defines.h
*
* Created on: 5 Oct. 2020
* Author: Ralim
*/
#ifndef CORE_DRIVERS_SI7210_DEFINES_H_
#define CORE_DRIVERS_SI7210_DEFINES_H_
#define SI7210_ADDRESS (0x30<<1)
#define SI7210_REG_ID 0xC0
#define SI7210_REG_DATAH 0xC1
#define SI7210_REG_DATAL 0xC2
#define SI7210_REG_INCR 0xC5
#endif /* CORE_DRIVERS_SI7210_DEFINES_H_ */