Skip to content

Instantly share code, notes, and snippets.

@ataffanel
Created December 22, 2014 12:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ataffanel/33965c74119d3d2d33f2 to your computer and use it in GitHub Desktop.
Save ataffanel/33965c74119d3d2d33f2 to your computer and use it in GitHub Desktop.
Crazyflie 2.0 Expansion board driver prototype
#include <stdbool.h>
#include <gpio.h>
#include <exp.h>
#define RED EXP_IO1
#define ORANGE EXP_IO2
#define GREEN EXP_IO3
static bool isInit = false;
static void traficLightInit()
{
gpioInit(RED, GPIO_OUTPUT, GPIO_SLOW);
gpioInit(ORANGE, GPIO_OUTPUT, GPIO_SLOW);
gpioInit(GREEN, GPIO_OUTPUT, GPIO_SLOW);
isInit = true;
}
static struct expDefine_s {
.init = traficLightInit,
.type = "cftlh", //Type written in the OW memory
.uses = [RED, ORANGE, GREEN, NULL], //List of pins or peripheral used
} traficlightExp;
EXP_REGISTER(traficlightExp);
static int state;
static void traficlightVariableUpdated(void* variable)
{
if (state > 3) {
return;
}
if (state == 0) {
gpioSet(RED, 0);
gpioSet(ORANGE, 0);
gpioSet(GREEN, 0);
} else if (state == 1) {
gpioSet(RED, 1);
gpioSet(ORANGE, 0);
gpioSet(GREEN, 0);
} else if (state == 2) {
gpioSet(RED, 0);
gpioSet(ORANGE, 1);
gpioSet(GREEN, 0);
} else if (state == 3) {
gpioSet(RED, 0);
gpioSet(ORANGE, 0);
gpioSet(GREEN, 1);
}
}
PARAM_GROUP_START_EN(E_traficlight, isInit) //The callbacks are enabled by isInit
PARAM_ADD(PARAM_UINT8 | PARAM_RO, present, &isInit)
PARAM_ADD_CB(PARAM_UINT8, state, &state, traficlightVariableUpdated) //Callback when the value is written
PARAM_GROUP_END(E_traficlight)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment