actual project
This commit is contained in:
37
src/i2c.h
Normal file
37
src/i2c.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Bunch of i2c helper functions and defs mostly */
|
||||
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#define I2C_DEVICE_ADDR 0x2b
|
||||
|
||||
#define I2C_REG_WHOAMI 0x00
|
||||
#define I2C_REG_CURRENT_RPM 0x02
|
||||
#define I2C_REG_TARGET_RPM 0x04
|
||||
#define I2C_REG_CURRENT_DUTY 0x06
|
||||
#define I2C_REG_MAX_DUTY 0x08
|
||||
#define I2C_REG_STATE 0x0a
|
||||
#define I2C_REG_MODE 0x0b
|
||||
|
||||
static void i2c_set_register_word(volatile uint8_t* reg, const uint8_t addr, const uint16_t value) {
|
||||
if (addr % 2) return;
|
||||
reg[addr] = value >> 8;
|
||||
reg[addr + 1] = value & 0xff;
|
||||
}
|
||||
|
||||
static uint16_t i2c_get_register_word(volatile uint8_t* reg, const uint8_t addr) {
|
||||
if (addr % 2) return 0;
|
||||
return (reg[addr] << 8) + reg[addr + 1];
|
||||
}
|
||||
|
||||
static void i2c_registers_reinit(volatile uint8_t* reg) {
|
||||
i2c_set_register_word(reg, I2C_REG_WHOAMI, 26923); // magic value ;)
|
||||
i2c_set_register_word(reg, I2C_REG_MAX_DUTY, fan_driver_pwm_get_max_duty());
|
||||
}
|
||||
|
||||
static void i2c_registers_set_defaults(volatile uint8_t* reg) {
|
||||
i2c_set_register_word(reg, I2C_REG_TARGET_RPM, 750);
|
||||
reg[I2C_REG_MODE] = 0x01; // target rpm mode, power enabled
|
||||
}
|
||||
|
||||
#endif //I2C_H
|
||||
Reference in New Issue
Block a user