moved flame code into core

- flames now hav an API
- default flame code handles both types simultaneously
- l0dables may claim a flame to manipulate as they wish
This commit is contained in:
bsx 2011-12-22 14:33:48 +01:00
parent 6e93dd4002
commit fda93e381f
7 changed files with 293 additions and 315 deletions

View File

@ -23,6 +23,7 @@ LIBS += filesystem/libfat.a
LIBS += usb/libusb.a LIBS += usb/libusb.a
LIBS += funk/libfunk.a LIBS += funk/libfunk.a
LIBS += usbcdc/libusbcdc.a LIBS += usbcdc/libusbcdc.a
LIBS += flame/libflame.a
########################################################################## ##########################################################################
# GNU GCC compiler flags # GNU GCC compiler flags
@ -49,6 +50,7 @@ LDLIBS += -Lcore -lcore
LDLIBS += -Lusb -lusb LDLIBS += -Lusb -lusb
LDLIBS += -lbasic LDLIBS += -lbasic
LDLIBS += -lfunk LDLIBS += -lfunk
LDLIBS += -Lflame -lflame
OCFLAGS = --strip-unneeded OCFLAGS = --strip-unneeded
SUBDIRS?= $(foreach lib,$(LIBS),$(dir $(lib))) SUBDIRS?= $(foreach lib,$(LIBS),$(dir $(lib)))

View File

@ -1,176 +1,131 @@
/* /*
flame m0dul - https://github.com/kiu/flame original flame m0dul - https://github.com/kiu/flame
flame m0dul with RGB (rev c) - https://github.com/schneider42/flame
*/ */
#include "basic/basic.h" #include "basic/basic.h"
#include "core/i2c/i2c.h"
#include "basic/config.h" #include "basic/config.h"
#include "basic/xxtea.h"
#include "flame/flame.h"
#define FLAME_I2C_WRITE 0xC4 #include "filesystem/util.h"
#define FLAME_I2C_READ 0xC5
#define FLAME_I2C_CR_INPUT 0x00 #define nick GLOBAL(nickname)
#define FLAME_I2C_CR_PSC0 0x01
#define FLAME_I2C_CR_PWM0 0x02
#define FLAME_I2C_CR_PSC1 0x03
#define FLAME_I2C_CR_PWM1 0x04
#define FLAME_I2C_CR_LS0 0x05
#define FLAME_I2C_LS0_OFF 0x00 static uint8_t flamesEnabled = 0;
#define FLAME_I2C_LS0_ON 0x01 static uint8_t flameMode = FLAME_STATE_OFF;
#define FLAME_I2C_LS0_PWM0 0x02 static uint8_t flameBrightness = 0;
#define FLAME_I2C_LS0_PWM1 0x03 static uint8_t flameTicks = 0;
static uint8_t flamesOwned = 0;
#define FLAME_I2C_LS0_LED0 0x00 static uint8_t rgbData[24];
#define FLAME_I2C_LS0_LED1 0x02 static uint8_t rgbDataSize = 0;
#define FLAME_I2C_LS0_LED2 0x04 static uint8_t rgbDataOffset = 0;
#define FLAME_I2C_LS0_LED3 0x06
#define FLAME_OFF 0x00 static void changeColor() {
#define FLAME_UP 0x01 if (rgbDataSize > 2) {
#define FLAME_UP_WAIT 0x02 flameSetColor(flamesOwned, rgbData[rgbDataOffset],
#define FLAME_DOWN 0x03 rgbData[rgbDataOffset + 1], rgbData[rgbDataOffset + 2]);
#define FLAME_DOWN_WAIT 0x04 if (rgbDataSize >= rgbDataOffset + 5) {
rgbDataOffset += 3;
} else {
rgbDataOffset = 0;
}
} else {
// generate a hash from the nickname
uint32_t hash[4];
uint32_t const key[4] = {0, 0, 0, 0};
xxtea_cbcmac(hash, (uint32_t *)nick, 4, key);
/**************************************************************************/ flameSetColor(flamesOwned, hash[0] & 0xFF, hash[1] & 0xFF, hash[2] & 0xFF);
}
#define flameBrightnessMax GLOBAL(flamemax)
#define flameBrightnessMin GLOBAL(flamemin)
#define flameSpeedUp GLOBAL(flamespeed)
#define flameSpeedDown GLOBAL(flamespeed)
#define flameWaitUp GLOBAL(flamemaxw)
#define flameWaitDown GLOBAL(flameminw)
uint8_t flameEnabled = 0;
uint8_t flameMode = FLAME_OFF;
uint8_t flameI2Cpwm = 0;
uint8_t flameTicks = 0;
uint32_t flameSetI2C(uint8_t cr, uint8_t value) {
I2CMasterBuffer[0] = FLAME_I2C_WRITE;
I2CMasterBuffer[1] = cr;
I2CMasterBuffer[2] = value;
I2CWriteLength = 3;
I2CReadLength = 0;
return i2cEngine();
}
void setFlamePWM() {
flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm
} }
void tick_flame(void) { // every 10ms void tick_flame(void) { // every 10ms
static char night=0; static char night=0;
flamesOwned = flamesEnabled & ~flamesClaimed;
if (!flameEnabled) { if (!flamesOwned) {
return; return;
} }
if (night != isNight()) { if (night != isNight()) {
night = isNight(); night = isNight();
if (!night) { if (!night) {
flameMode = FLAME_OFF; flameMode = FLAME_STATE_OFF;
flameI2Cpwm = 0; flameBrightness = 0;
push_queue(&setFlamePWM); flameSetBrightness(flamesOwned, flameBrightness);
}; };
}; };
flameTicks++; flameTicks++;
if (flameI2Cpwm > flameBrightnessMax) { if (flameBrightness > flameBrightnessMax) {
flameI2Cpwm = flameBrightnessMax; flameBrightness = flameBrightnessMax;
} }
if (flameI2Cpwm < flameBrightnessMin) { if (flameBrightness < flameBrightnessMin) {
flameI2Cpwm = flameBrightnessMin; flameBrightness = flameBrightnessMin;
} }
if (flameMode == FLAME_OFF) { if (flameMode == FLAME_STATE_OFF) {
if (isNight()) { if (isNight()) {
flameTicks = 0; flameTicks = 0;
flameMode = FLAME_UP; flameMode = FLAME_STATE_UP;
changeColor(flamesOwned, flameBrightness);
} }
} }
if (flameMode == FLAME_UP) { if (flameMode == FLAME_STATE_UP) {
if (0xFF - flameI2Cpwm >= flameSpeedUp ) { if (0xFF - flameBrightness >= flameSpeedUp ) {
flameI2Cpwm += flameSpeedUp; flameBrightness += flameSpeedUp;
} else { } else {
flameI2Cpwm = 0xFF; flameBrightness = 0xFF;
} }
push_queue(&setFlamePWM); flameSetBrightness(flamesOwned, flameBrightness);
if (flameI2Cpwm >= flameBrightnessMax) { if (flameBrightness >= flameBrightnessMax) {
flameMode = FLAME_UP_WAIT; flameMode = FLAME_STATE_UP_WAIT;
flameTicks = 0; flameTicks = 0;
} }
} }
if (flameMode == FLAME_UP_WAIT) { if (flameMode == FLAME_STATE_UP_WAIT) {
if (flameTicks >= flameWaitUp) { if (flameTicks >= flameWaitUp) {
flameMode = FLAME_DOWN; flameMode = FLAME_STATE_DOWN;
} }
} }
if (flameMode == FLAME_DOWN) { if (flameMode == FLAME_STATE_DOWN) {
if (flameSpeedDown <= flameI2Cpwm) { if (flameSpeedDown <= flameBrightness) {
flameI2Cpwm -= flameSpeedDown; flameBrightness -= flameSpeedDown;
} else { } else {
flameI2Cpwm = 0x00; flameBrightness = 0x00;
} }
push_queue(&setFlamePWM); flameSetBrightness(flamesOwned, flameBrightness);
if (flameI2Cpwm <= flameBrightnessMin) { if (flameBrightness <= flameBrightnessMin) {
flameMode = FLAME_DOWN_WAIT; flameMode = FLAME_STATE_DOWN_WAIT;
flameTicks = 0; flameTicks = 0;
} }
} }
if (flameMode == FLAME_DOWN_WAIT) { if (flameMode == FLAME_STATE_DOWN_WAIT) {
if (flameTicks >= flameWaitDown) { if (flameTicks >= flameWaitDown) {
flameMode = FLAME_OFF; flameMode = FLAME_STATE_OFF;
} }
} }
} }
void init_flame(void) { void init_flame(void) {
i2cInit(I2CMASTER); // Init I2C flamesEnabled = flameDetect();
flameEnabled = (flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0) == I2CSTATE_ACK); // probe i2c if (!flamesEnabled)
if (!flameEnabled)
return; return;
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0); // set led0 off flameInit(flamesEnabled);
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED1); // set led1 off
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED2); // set led2 off
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED3); // set led3 off
flameSetI2C(FLAME_I2C_CR_PSC0, 0x00); // set prescaler rgbDataSize = readTextFile("FLAME.RGB", rgbData, 24);
flameSetI2C(FLAME_I2C_CR_PWM0, 0x00); // set pwm
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_PWM0 << FLAME_I2C_LS0_LED0); // set led0 to pwm
enableConfig(CFG_TYPE_FLAME,1); enableConfig(CFG_TYPE_FLAME,1);
} }
#include "lcd/print.h"
// //# MENU flame
void ChkFlame(void) {
do{
lcdClear();
lcdPrint("Enabled:");
lcdPrintln(IntToStr(flameEnabled,1,0));
lcdPrint("State:");
lcdPrintln(IntToStr(flameMode,1,0));
lcdPrint("PWMtarg:");
lcdPrintln(IntToStr(flameI2Cpwm,3,0));
lcdPrint("FTicks:");
lcdPrintln(IntToStr(flameTicks,3,0));
lcdRefresh();
delayms_queue(10);
} while ((getInputRaw())==BTN_NONE);
}

View File

@ -1,196 +0,0 @@
/*
flame m0dul with RGB (rev c) - https://github.com/schneider42/flame
LED driver is a PCA9633
*/
#include "basic/basic.h"
#include "core/i2c/i2c.h"
#include "basic/config.h"
#include "basic/xxtea.h"
#include "filesystem/util.h"
#define FLAME_I2C_WRITE 0xC6
#define FLAME_I2C_READ 0xC7
#define FLAME_I2C_CR_MODE1 0x00
#define FLAME_I2C_CR_MODE2 0x01
#define FLAME_I2C_CR_PWM0 0x02
#define FLAME_I2C_CR_PWM1 0x03
#define FLAME_I2C_CR_PWM2 0x04
#define FLAME_I2C_CR_PWM3 0x05
#define FLAME_I2C_CR_GRPPWM 0x06
#define FLAME_I2C_CR_GRPFREQ 0x07
#define FLAME_I2C_CR_LEDOUT 0x08
#define FLAME_I2C_LED0_OFF 0x00
#define FLAME_I2C_LED0_FULL 0x01
#define FLAME_I2C_LED0_INDY 0x02
#define FLAME_I2C_LED0_GRP 0x03
#define FLAME_I2C_LED1_OFF 0x00
#define FLAME_I2C_LED1_FULL 0x04
#define FLAME_I2C_LED1_INDY 0x08
#define FLAME_I2C_LED1_GRP 0x0c
#define FLAME_I2C_LED2_OFF 0x00
#define FLAME_I2C_LED2_FULL 0x10
#define FLAME_I2C_LED2_INDY 0x20
#define FLAME_I2C_LED2_GRP 0x30
#define FLAME_I2C_LED3_OFF 0x00
#define FLAME_I2C_LED3_FULL 0x40
#define FLAME_I2C_LED3_INDY 0x80
#define FLAME_I2C_LED3_GRP 0xC0
#define FLAME_OFF 0x00
#define FLAME_UP 0x01
#define FLAME_UP_WAIT 0x02
#define FLAME_DOWN 0x03
#define FLAME_DOWN_WAIT 0x04
/**************************************************************************/
#define flameBrightnessMax GLOBAL(flamemax)
#define flameBrightnessMin GLOBAL(flamemin)
#define flameSpeedUp GLOBAL(flamespeed)
#define flameSpeedDown GLOBAL(flamespeed)
#define flameWaitUp GLOBAL(flamemaxw)
#define flameWaitDown GLOBAL(flameminw)
#define nick GLOBAL(nickname)
static uint32_t flameRGBSetI2C(uint8_t cr, uint8_t value) {
I2CMasterBuffer[0] = FLAME_I2C_WRITE;
I2CMasterBuffer[1] = cr;
I2CMasterBuffer[2] = value;
I2CWriteLength = 3;
I2CReadLength = 0;
return i2cEngine();
}
uint8_t flameRGBEnabled = 0;
uint8_t flameRGBMode = FLAME_OFF;
uint8_t flameRGBI2Cpwm = 0;
uint8_t flameRGBTicks = 0;
uint8_t rgbData[24];
uint8_t rgbDataSize = 0;
uint8_t rgbDataOffset = 0;
void setFlameRGBPWM() {
flameRGBSetI2C(FLAME_I2C_CR_GRPPWM, flameRGBI2Cpwm); // set pwm
}
void setFlameRGBColor() {
if (rgbDataSize > 2) {
flameRGBSetI2C(FLAME_I2C_CR_PWM0, rgbData[rgbDataOffset]);
flameRGBSetI2C(FLAME_I2C_CR_PWM3, rgbData[rgbDataOffset + 1]);
flameRGBSetI2C(FLAME_I2C_CR_PWM2, rgbData[rgbDataOffset + 2]);
if (rgbDataSize >= rgbDataOffset + 5) {
rgbDataOffset += 3;
} else {
rgbDataOffset = 0;
}
} else {
// generate a hash from the nickname
uint32_t hash[4];
uint32_t const key[4] = {0, 0, 0, 0};
xxtea_cbcmac(hash, (uint32_t *)nick, 4, key);
// set color, LED0 = red, LED1 = unused, LED2 = blue, LED3 = green
int i;
uint8_t regs[] = {FLAME_I2C_CR_PWM0, FLAME_I2C_CR_PWM1,
FLAME_I2C_CR_PWM2, FLAME_I2C_CR_PWM3 };
for(i=0; i<4; i++)
flameRGBSetI2C(regs[i], hash[i] & 0xFF);
}
}
void tick_flame_rgb(void) { // every 10ms
static char night=0;
if (!flameRGBEnabled) {
return;
}
if (night != isNight()) {
night = isNight();
if (!night) {
flameRGBMode = FLAME_OFF;
flameRGBI2Cpwm = 0;
push_queue(&setFlameRGBPWM);
};
};
flameRGBTicks++;
if (flameRGBI2Cpwm > flameBrightnessMax) {
flameRGBI2Cpwm = flameBrightnessMax;
}
if (flameRGBI2Cpwm < flameBrightnessMin) {
flameRGBI2Cpwm = flameBrightnessMin;
}
if (flameRGBMode == FLAME_OFF) {
if (isNight()) {
flameRGBTicks = 0;
flameRGBMode = FLAME_UP;
push_queue(&setFlameRGBColor);
}
}
if (flameRGBMode == FLAME_UP) {
if (0xFF - flameRGBI2Cpwm >= flameSpeedUp ) {
flameRGBI2Cpwm += flameSpeedUp;
} else {
flameRGBI2Cpwm = 0xFF;
}
push_queue(&setFlameRGBPWM);
if (flameRGBI2Cpwm >= flameBrightnessMax) {
flameRGBMode = FLAME_UP_WAIT;
flameRGBTicks = 0;
}
}
if (flameRGBMode == FLAME_UP_WAIT) {
if (flameRGBTicks >= flameWaitUp) {
flameRGBMode = FLAME_DOWN;
}
}
if (flameRGBMode == FLAME_DOWN) {
if (flameSpeedDown <= flameRGBI2Cpwm) {
flameRGBI2Cpwm -= flameSpeedDown;
} else {
flameRGBI2Cpwm = 0x00;
}
push_queue(&setFlameRGBPWM);
if (flameRGBI2Cpwm <= flameBrightnessMin) {
flameRGBMode = FLAME_DOWN_WAIT;
flameRGBTicks = 0;
}
}
if (flameRGBMode == FLAME_DOWN_WAIT) {
if (flameRGBTicks >= flameWaitDown) {
flameRGBMode = FLAME_OFF;
}
}
}
void init_flame_rgb(void) {
i2cInit(I2CMASTER); // Init I2C
flameRGBEnabled = (flameRGBSetI2C(FLAME_I2C_CR_MODE1, 0x00) == I2CSTATE_ACK); // probe i2c and enable flame if present
if (!flameRGBEnabled)
return;
// enable individual PWN and group PWN for LED0, LED3 and LED2 and disable LED1
flameRGBSetI2C(FLAME_I2C_CR_LEDOUT, FLAME_I2C_LED0_GRP | FLAME_I2C_LED1_OFF | FLAME_I2C_LED2_GRP | FLAME_I2C_LED3_GRP);
flameRGBSetI2C(FLAME_I2C_CR_GRPPWM, 0x00); // overall dimming
rgbDataSize = readTextFile("FLAME.RGB", rgbData, 24);
enableConfig(CFG_TYPE_FLAME,1);
}

23
firmware/flame/Makefile Normal file
View File

@ -0,0 +1,23 @@
##########################################################################
# User configuration and firmware specific object files
##########################################################################
OBJS =
OBJS += flame.o
LIBNAME=flame
##########################################################################
# GNU GCC compiler flags
##########################################################################
ROOT_PATH?= ..
INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I.
include $(ROOT_PATH)/Makefile.inc
##########################################################################
# Actual work
##########################################################################
include $(ROOT_PATH)/Makefile.util

92
firmware/flame/flame.c Normal file
View File

@ -0,0 +1,92 @@
#include "flame/flame.h"
#include "basic/basic.h"
#include "core/i2c/i2c.h"
uint8_t flamesClaimed = FLAME_TYPE_NONE;
uint8_t flameBrigthnessRGB = 0;
uint8_t flameBrigthnessM0n0 = 0;
uint8_t rgb[3];
uint32_t flameSetI2C(uint8_t addr, uint8_t cr, uint8_t value) {
I2CMasterBuffer[0] = addr;
I2CMasterBuffer[1] = cr;
I2CMasterBuffer[2] = value;
I2CWriteLength = 3;
I2CReadLength = 0;
return i2cEngine();
}
uint8_t flameDetect() {
i2cInit(I2CMASTER); // Init I2C
uint8_t found = FLAME_TYPE_NONE;
if (flameSetI2C(FLAME_RGB_I2C_WRITE, FLAME_RGB_I2C_CR_MODE1, 0x00) == I2CSTATE_ACK) {
found |= FLAME_TYPE_RGB;
}
if (flameSetI2C(FLAME_M0N0_I2C_WRITE, FLAME_M0N0_I2C_CR_LS0, FLAME_M0N0_I2C_LS0_OFF << FLAME_M0N0_I2C_LS0_LED0) == I2CSTATE_ACK) {
found |= FLAME_TYPE_M0N0;
}
return found;
}
void flameInit(uint8_t type) {
if (type & FLAME_TYPE_M0N0) {
flameSetI2Cm0n0(FLAME_M0N0_I2C_CR_LS0, FLAME_M0N0_I2C_LS0_OFF << FLAME_M0N0_I2C_LS0_LED0); // set led0 off
flameSetI2Cm0n0(FLAME_M0N0_I2C_CR_LS0, FLAME_M0N0_I2C_LS0_OFF << FLAME_M0N0_I2C_LS0_LED1); // set led1 off
flameSetI2Cm0n0(FLAME_M0N0_I2C_CR_LS0, FLAME_M0N0_I2C_LS0_OFF << FLAME_M0N0_I2C_LS0_LED2); // set led2 off
flameSetI2Cm0n0(FLAME_M0N0_I2C_CR_LS0, FLAME_M0N0_I2C_LS0_OFF << FLAME_M0N0_I2C_LS0_LED3); // set led3 off
flameSetI2Cm0n0(FLAME_M0N0_I2C_CR_PSC0, 0x00); // set prescaler
flameSetI2Cm0n0(FLAME_M0N0_I2C_CR_PWM0, 0x00); // set pwm
flameSetI2Cm0n0(FLAME_M0N0_I2C_CR_LS0, FLAME_M0N0_I2C_LS0_PWM0 << FLAME_M0N0_I2C_LS0_LED0); // set led0 to pwm
}
if (type & FLAME_TYPE_RGB) {
// enable individual PWN and group PWN for LED0, LED3 and LED2 and disable LED1
flameSetI2Crgb(FLAME_RGB_I2C_CR_LEDOUT, FLAME_RGB_I2C_LED0_GRP | FLAME_RGB_I2C_LED1_OFF | FLAME_RGB_I2C_LED2_GRP | FLAME_RGB_I2C_LED3_GRP);
flameSetI2Crgb(FLAME_RGB_I2C_CR_GRPPWM, 0x00); // overall dimming
}
}
void _setFlamePWMrgb() {
flameSetI2Crgb(FLAME_RGB_I2C_CR_GRPPWM, flameBrigthnessRGB);
}
void _setFlamePWMm0n0() {
flameSetI2Cm0n0(FLAME_M0N0_I2C_CR_PWM0, flameBrigthnessM0n0);
}
void flameSetBrightness(uint8_t type, uint8_t bright) {
if (type & FLAME_TYPE_M0N0) {
flameBrigthnessM0n0 = bright;
push_queue(&_setFlamePWMm0n0);
}
if (type & FLAME_TYPE_RGB) {
flameBrigthnessRGB = bright;
push_queue(&_setFlamePWMrgb);
}
}
void _setFlameColor() {
flameSetI2Crgb(FLAME_RGB_I2C_CR_PWM0, rgb[0]);
flameSetI2Crgb(FLAME_RGB_I2C_CR_PWM3, rgb[1]);
flameSetI2Crgb(FLAME_RGB_I2C_CR_PWM2, rgb[2]);
}
void flameSetColor(uint8_t type, uint8_t red, uint8_t green, uint8_t blue) {
if (type & FLAME_TYPE_RGB) {
rgb[0] = red;
rgb[1] = green;
rgb[2] = blue;
push_queue(&_setFlameColor);
}
}
void flameClaim(uint8_t type) {
flamesClaimed |= type;
}
void flameFree(uint8_t type) {
flamesClaimed &= ~type;
}

95
firmware/flame/flame.h Normal file
View File

@ -0,0 +1,95 @@
#ifndef _FLAME_H
#define _FLAME_H 1
#include <sysdefs.h>
#include "basic/config.h"
/* available types of flames */
#define FLAME_TYPE_NONE 0
#define FLAME_TYPE_M0N0 1
#define FLAME_TYPE_RGB 2
/* I2C protocol for m0n0 flame (PCA9533) */
#define FLAME_M0N0_I2C_WRITE 0xC4
#define FLAME_M0N0_I2C_READ 0xC5
#define FLAME_M0N0_I2C_CR_INPUT 0x00
#define FLAME_M0N0_I2C_CR_PSC0 0x01
#define FLAME_M0N0_I2C_CR_PWM0 0x02
#define FLAME_M0N0_I2C_CR_PSC1 0x03
#define FLAME_M0N0_I2C_CR_PWM1 0x04
#define FLAME_M0N0_I2C_CR_LS0 0x05
#define FLAME_M0N0_I2C_LS0_OFF 0x00
#define FLAME_M0N0_I2C_LS0_ON 0x01
#define FLAME_M0N0_I2C_LS0_PWM0 0x02
#define FLAME_M0N0_I2C_LS0_PWM1 0x03
#define FLAME_M0N0_I2C_LS0_LED0 0x00
#define FLAME_M0N0_I2C_LS0_LED1 0x02
#define FLAME_M0N0_I2C_LS0_LED2 0x04
#define FLAME_M0N0_I2C_LS0_LED3 0x06
/* I2C protocol for rgb flame (PC9633) */
#define FLAME_RGB_I2C_WRITE 0xC6
#define FLAME_RGB_I2C_READ 0xC7
#define FLAME_RGB_I2C_CR_MODE1 0x00
#define FLAME_RGB_I2C_CR_MODE2 0x01
#define FLAME_RGB_I2C_CR_PWM0 0x02
#define FLAME_RGB_I2C_CR_PWM1 0x03
#define FLAME_RGB_I2C_CR_PWM2 0x04
#define FLAME_RGB_I2C_CR_PWM3 0x05
#define FLAME_RGB_I2C_CR_GRPPWM 0x06
#define FLAME_RGB_I2C_CR_GRPFREQ 0x07
#define FLAME_RGB_I2C_CR_LEDOUT 0x08
#define FLAME_RGB_I2C_LED0_OFF 0x00
#define FLAME_RGB_I2C_LED0_FULL 0x01
#define FLAME_RGB_I2C_LED0_INDY 0x02
#define FLAME_RGB_I2C_LED0_GRP 0x03
#define FLAME_RGB_I2C_LED1_OFF 0x00
#define FLAME_RGB_I2C_LED1_FULL 0x04
#define FLAME_RGB_I2C_LED1_INDY 0x08
#define FLAME_RGB_I2C_LED1_GRP 0x0c
#define FLAME_RGB_I2C_LED2_OFF 0x00
#define FLAME_RGB_I2C_LED2_FULL 0x10
#define FLAME_RGB_I2C_LED2_INDY 0x20
#define FLAME_RGB_I2C_LED2_GRP 0x30
#define FLAME_RGB_I2C_LED3_OFF 0x00
#define FLAME_RGB_I2C_LED3_FULL 0x40
#define FLAME_RGB_I2C_LED3_INDY 0x80
#define FLAME_RGB_I2C_LED3_GRP 0xC0
/* state machine constants for default blinking */
#define FLAME_STATE_OFF 0x00
#define FLAME_STATE_UP 0x01
#define FLAME_STATE_UP_WAIT 0x02
#define FLAME_STATE_DOWN 0x03
#define FLAME_STATE_DOWN_WAIT 0x04
/* config options */
#define flameBrightnessMax GLOBAL(flamemax)
#define flameBrightnessMin GLOBAL(flamemin)
#define flameSpeedUp GLOBAL(flamespeed)
#define flameSpeedDown GLOBAL(flamespeed)
#define flameWaitUp GLOBAL(flamemaxw)
#define flameWaitDown GLOBAL(flameminw)
/* flame "API" */
uint32_t flameSetI2C(uint8_t addr, uint8_t cr, uint8_t value);
uint8_t flameDetect();
void flameInit(uint8_t type);
void flameSetBrightness(uint8_t type, uint8_t bright);
void flameSetColor(uint8_t type, uint8_t red, uint8_t green, uint8_t blue);
void flameClaim(uint8_t type);
void flameFree(uint8_t type);
extern uint8_t flamesClaimed;
#define flameSetI2Cm0n0(a, b) flameSetI2C(FLAME_M0N0_I2C_WRITE, a, b)
#define flameSetI2Crgb(a, b) flameSetI2C(FLAME_RGB_I2C_WRITE, a, b)
#endif /* _FLAME_H */

View File

@ -130,3 +130,10 @@ lcdSetCrsr
lcdSetCrsrX lcdSetCrsrX
getInputWaitRepeat getInputWaitRepeat
applyConfig applyConfig
# flame API
flameDetect
flameSetBrightness
flameSetColor
flameClaim
flameFree