i2c no-ack fix (never actually worked properly, fixed now)
bumped config version, or else r198 crashed on update from recent version airplane mode config passed to drv_pwm git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@199 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
parent
e6cb4a0b1c
commit
10570a6579
4936
obj/baseflight.hex
4936
obj/baseflight.hex
File diff suppressed because it is too large
Load Diff
|
@ -13,7 +13,7 @@ config_t cfg;
|
|||
const char rcChannelLetters[] = "AERT1234";
|
||||
|
||||
static uint32_t enabledSensors = 0;
|
||||
uint8_t checkNewConf = 25;
|
||||
uint8_t checkNewConf = 26;
|
||||
|
||||
void parseRcChannels(const char *input)
|
||||
{
|
||||
|
|
|
@ -52,6 +52,7 @@ static void i2c_er_handler(void)
|
|||
/* Read the I2C1 status register */
|
||||
SR1Register = I2Cx->SR1;
|
||||
if (SR1Register & 0x0F00) { //an error
|
||||
error = true;
|
||||
// I2C1error.error = ((SR1Register & 0x0F00) >> 8); //save error
|
||||
// I2C1error.job = job; //the task
|
||||
}
|
||||
|
@ -89,7 +90,8 @@ bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data)
|
|||
read_p = my_data;
|
||||
bytes = len_;
|
||||
busy = 1;
|
||||
|
||||
error = false;
|
||||
|
||||
// too long
|
||||
if (len_ > 16)
|
||||
return false;
|
||||
|
@ -113,7 +115,7 @@ bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data)
|
|||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !error;
|
||||
}
|
||||
|
||||
bool i2cWrite(uint8_t addr_, uint8_t reg_, uint8_t data)
|
||||
|
@ -133,7 +135,8 @@ bool i2cRead(uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf)
|
|||
write_p = buf;
|
||||
bytes = len;
|
||||
busy = 1;
|
||||
|
||||
error = false;
|
||||
|
||||
if (!(I2Cx->CR2 & I2C_IT_EVT)) { //if we are restarting the driver
|
||||
if (!(I2Cx->CR1 & 0x0100)) { // ensure sending a start
|
||||
while (I2Cx->CR1 & 0x0200) { ; } //wait for any stop to finish sending
|
||||
|
@ -150,7 +153,7 @@ bool i2cRead(uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf)
|
|||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !error;
|
||||
}
|
||||
|
||||
void i2c_ev_handler(void)
|
||||
|
@ -158,7 +161,7 @@ void i2c_ev_handler(void)
|
|||
static uint8_t subaddress_sent, final_stop; //flag to indicate if subaddess sent, flag to indicate final bus condition
|
||||
static int8_t index; //index is signed -1==send the subaddress
|
||||
uint8_t SReg_1 = I2Cx->SR1; //read the status register here
|
||||
|
||||
|
||||
if (SReg_1 & 0x0001) { //we just sent a start - EV5 in ref manual
|
||||
I2Cx->CR1 &= ~0x0800; //reset the POS bit so ACK/NACK applied to the current byte
|
||||
I2C_AcknowledgeConfig(I2Cx, ENABLE); //make sure ACK is on
|
||||
|
@ -263,7 +266,7 @@ void i2cInit(I2C_TypeDef *I2C)
|
|||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
I2C_InitTypeDef I2C_InitStructure;
|
||||
|
||||
// Init pins
|
||||
// Init pins
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
|
@ -343,7 +346,7 @@ static void i2cUnstick(void)
|
|||
delayMicroseconds(10);
|
||||
GPIO_SetBits(GPIOB, GPIO_Pin_11); // Set bus sda high
|
||||
|
||||
// Init pins
|
||||
// Init pins
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
|
|
|
@ -23,7 +23,6 @@ int main(void)
|
|||
GPIOA->BRR = 0x8000; // set low 15
|
||||
GPIOC->CRH = 0x44434444; // PIN 12 Output 50MHz
|
||||
GPIOC->BRR = 0x1000; // set low 12
|
||||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
|
@ -52,7 +51,9 @@ int main(void)
|
|||
#endif
|
||||
|
||||
mixerInit(); // this will set useServo var depending on mixer type
|
||||
// pwmInit returns true if throttle calibration is requested. if so, do it here. throttleCalibration() does NOT return - for safety.
|
||||
// when using airplane/wing mixer, servo/motor outputs are remapped
|
||||
if (cfg.mixerConfiguration == MULTITYPE_AIRPLANE || cfg.mixerConfiguration == MULTITYPE_FLYING_WING)
|
||||
pwm_params.airplane = true;
|
||||
pwm_params.usePPM = feature(FEATURE_PPM);
|
||||
pwm_params.enableInput = !feature(FEATURE_SPEKTRUM); // disable inputs if using spektrum
|
||||
pwm_params.useServos = useServo;
|
||||
|
@ -92,8 +93,7 @@ int main(void)
|
|||
} else {
|
||||
// spektrum and GPS are mutually exclusive
|
||||
// Optional GPS - available only when using PPM, otherwise required pins won't be usable
|
||||
if (feature(FEATURE_PPM))
|
||||
{
|
||||
if (feature(FEATURE_PPM)) {
|
||||
if (feature(FEATURE_GPS))
|
||||
gpsInit(cfg.gps_baudrate);
|
||||
#ifdef SONAR
|
||||
|
|
22
src/mw.c
22
src/mw.c
|
@ -532,11 +532,11 @@ void loop(void)
|
|||
cycleTime = (int32_t)(currentTime - previousTime);
|
||||
previousTime = currentTime;
|
||||
|
||||
#ifdef MPU6050_DMP
|
||||
#ifdef MPU6050_DMP
|
||||
mpu6050DmpLoop();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MAG
|
||||
#ifdef MAG
|
||||
if (sensors(SENSOR_MAG)) {
|
||||
if (abs(rcCommand[YAW]) < 70 && f.MAG_MODE) {
|
||||
int16_t dif = heading - magHold;
|
||||
|
@ -549,9 +549,9 @@ void loop(void)
|
|||
} else
|
||||
magHold = heading;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BARO
|
||||
#endif
|
||||
|
||||
#ifdef BARO
|
||||
if (sensors(SENSOR_BARO)) {
|
||||
if (f.BARO_MODE) {
|
||||
if (abs(rcCommand[THROTTLE] - initialThrottleHold) > 20) {
|
||||
|
@ -560,8 +560,8 @@ void loop(void)
|
|||
rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if (sensors(SENSOR_GPS)) {
|
||||
// Check that we really need to navigate ?
|
||||
if ((!f.GPS_HOME_MODE && !f.GPS_HOLD_MODE) || (!f.GPS_FIX_HOME)) {
|
||||
|
@ -586,11 +586,11 @@ void loop(void)
|
|||
if (f.ACC_MODE && axis < 2) { // LEVEL MODE
|
||||
// 50 degrees max inclination
|
||||
errorAngle = constrain(2 * rcCommand[axis] - GPS_angle[axis], -500, +500) - angle[axis] + cfg.angleTrim[axis];
|
||||
#ifdef LEVEL_PDF
|
||||
#ifdef LEVEL_PDF
|
||||
PTerm = -(int32_t) angle[axis] * cfg.P8[PIDLEVEL] / 100;
|
||||
#else
|
||||
#else
|
||||
PTerm = (int32_t) errorAngle *cfg.P8[PIDLEVEL] / 100; //32 bits is needed for calculation: errorAngle*P8[PIDLEVEL] could exceed 32768 16 bits is ok for result
|
||||
#endif
|
||||
#endif
|
||||
PTerm = constrain(PTerm, -cfg.D8[PIDLEVEL] * 5, +cfg.D8[PIDLEVEL] * 5);
|
||||
|
||||
errorAngleI[axis] = constrain(errorAngleI[axis] + errorAngle, -10000, +10000); // WindUp // 16 bits is ok here
|
||||
|
|
Loading…
Reference in New Issue