Browse Source

added i2cWriteBuffer() for ledring stuff

fixed ledring stuff
fixed mag orientation (thanks GrootWitBaas)

git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@111 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
master
timecop 13 years ago
parent
commit
204d25d491
  1. 44
      baseflight.uvopt
  2. 20
      src/drv_i2c.c
  3. 1
      src/drv_i2c.h
  4. 10
      src/drv_ledring.c
  5. 9
      src/sensors.c

44
baseflight.uvopt

@ -502,10 +502,10 @@
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<ColumnNumber>0</ColumnNumber>
<ColumnNumber>30</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>1</TopLine>
<CurrentLine>1</CurrentLine>
<TopLine>55</TopLine>
<CurrentLine>68</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>.\src\config.c</PathWithFileName>
<FilenameWithoutPath>config.c</FilenameWithoutPath>
@ -572,10 +572,10 @@
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<ColumnNumber>1</ColumnNumber>
<ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>264</TopLine>
<CurrentLine>264</CurrentLine>
<TopLine>216</TopLine>
<CurrentLine>229</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>.\src\sensors.c</PathWithFileName>
<FilenameWithoutPath>sensors.c</FilenameWithoutPath>
@ -602,8 +602,8 @@
<Focus>0</Focus>
<ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>0</TopLine>
<CurrentLine>0</CurrentLine>
<TopLine>35</TopLine>
<CurrentLine>72</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>.\src\board.h</PathWithFileName>
<FilenameWithoutPath>board.h</FilenameWithoutPath>
@ -614,10 +614,10 @@
<FileType>5</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<ColumnNumber>20</ColumnNumber>
<ColumnNumber>14</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>151</TopLine>
<CurrentLine>167</CurrentLine>
<TopLine>241</TopLine>
<CurrentLine>249</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>.\src\mw.h</PathWithFileName>
<FilenameWithoutPath>mw.h</FilenameWithoutPath>
@ -679,8 +679,8 @@
<Focus>0</Focus>
<ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>0</TopLine>
<CurrentLine>0</CurrentLine>
<TopLine>28</TopLine>
<CurrentLine>51</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>.\src\drv_hmc5883l.c</PathWithFileName>
<FilenameWithoutPath>drv_hmc5883l.c</FilenameWithoutPath>
@ -689,12 +689,12 @@
<GroupNumber>2</GroupNumber>
<FileNumber>15</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<Focus>0</Focus>
<ColumnNumber>11</ColumnNumber>
<ColumnNumber>81</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>121</TopLine>
<CurrentLine>121</CurrentLine>
<TopLine>106</TopLine>
<CurrentLine>140</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>.\src\drv_i2c.c</PathWithFileName>
<FilenameWithoutPath>drv_i2c.c</FilenameWithoutPath>
@ -719,10 +719,10 @@
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<ColumnNumber>0</ColumnNumber>
<ColumnNumber>5</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>0</TopLine>
<CurrentLine>0</CurrentLine>
<TopLine>71</TopLine>
<CurrentLine>87</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>.\src\drv_pwm.c</PathWithFileName>
<FilenameWithoutPath>drv_pwm.c</FilenameWithoutPath>
@ -761,10 +761,10 @@
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<ColumnNumber>7</ColumnNumber>
<ColumnNumber>17</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg>
<TopLine>17</TopLine>
<CurrentLine>52</CurrentLine>
<CurrentLine>35</CurrentLine>
<bDave2>0</bDave2>
<PathWithFileName>.\src\drv_ledring.c</PathWithFileName>
<FilenameWithoutPath>drv_ledring.c</FilenameWithoutPath>

20
src/drv_i2c.c

@ -73,21 +73,28 @@ static void i2c_er_handler(void)
busy = 0;
}
bool i2cWrite(uint8_t addr_, uint8_t reg_, uint8_t data)
bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data)
{
uint8_t my_data[1];
uint8_t i;
uint8_t my_data[8];
uint32_t timeout = I2C_DEFAULT_TIMEOUT;
addr = addr_ << 1;
reg = reg_;
writing = 1;
reading = 0;
my_data[0] = data;
write_p = my_data;
read_p = my_data;
bytes = 1;
bytes = len_;
busy = 1;
// too long
if (len_ > 7)
return false;
for (i = 0; i < len_; i++)
my_data[i] = data[i];
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
@ -107,6 +114,11 @@ bool i2cWrite(uint8_t addr_, uint8_t reg_, uint8_t data)
return true;
}
bool i2cWrite(uint8_t addr_, uint8_t reg_, uint8_t data)
{
return i2cWriteBuffer(addr_, reg_, 1, &data);
}
bool i2cRead(uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf)
{
uint32_t timeout = I2C_DEFAULT_TIMEOUT;

1
src/drv_i2c.h

@ -1,6 +1,7 @@
#pragma once
void i2cInit(I2C_TypeDef *I2Cx);
bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data);
bool i2cWrite(uint8_t addr_, uint8_t reg, uint8_t data);
bool i2cRead(uint8_t addr_, uint8_t reg, uint8_t len, uint8_t* buf);
uint16_t i2cGetErrorCounter(void);

10
src/drv_ledring.c

@ -9,7 +9,7 @@ bool ledringDetect(void)
bool ack = false;
uint8_t sig = 'e';
ack = 0; // i2cWrite(LED_RING_ADDRESS, 0xFF, 1, &sig);
ack = i2cWrite(LED_RING_ADDRESS, 0xFF, sig);
if (!ack)
return false;
return true;
@ -23,13 +23,13 @@ void ledringState(void)
if (state == 0) {
b[0] = 'z';
b[1] = (180 - heading) / 2; // 1 unit = 2 degrees;
// i2cWrite(LED_RING_ADDRESS, 0xFF, 2, b);
i2cWriteBuffer(LED_RING_ADDRESS, 0xFF, 2, b);
state = 1;
} else if (state == 1) {
b[0] = 'y';
b[1] = constrain(angle[ROLL] / 10 + 90, 0, 180);
b[2] = constrain(angle[PITCH] / 10 + 90, 0, 180);
// i2cWrite(LED_RING_ADDRESS, 0xFF, 3, b);
i2cWriteBuffer(LED_RING_ADDRESS, 0xFF, 3, b);
state = 2;
} else if (state == 2) {
b[0] = 'd'; // all unicolor GREEN
@ -38,7 +38,7 @@ void ledringState(void)
b[2] = 1;
else
b[2] = 0;
// i2cWrite(LED_RING_ADDRESS, 0xFF, 3, b);
i2cWriteBuffer(LED_RING_ADDRESS, 0xFF, 3, b);
state = 0;
}
}
@ -49,5 +49,5 @@ void ledringBlink(void)
b[0] = 'k';
b[1] = 10;
b[2] = 10;
// i2cWrite(LED_RING_ADDRESS, 0xFF, 3, b);
i2cWriteBuffer(LED_RING_ADDRESS, 0xFF, 3, b);
}

9
src/sensors.c

@ -228,10 +228,17 @@ static void Mag_getRawADC(void)
static int16_t rawADC[3];
hmc5883lRead(rawADC);
// no way? is this finally the proper orientation??
#if 0
// no way? is this finally the proper orientation?? (seems -180 swapped)
magADC[ROLL] = -rawADC[2]; // X
magADC[PITCH] = rawADC[0]; // Y
magADC[YAW] = rawADC[1]; // Z
#else
// no way? is THIS finally the proper orientation?? (by GrootWitBaas)
magADC[ROLL] = rawADC[2]; // X
magADC[PITCH] = -rawADC[0]; // Y
magADC[YAW] = -rawADC[1]; // Z
#endif
}
void Mag_init(void)

Loading…
Cancel
Save