--- src/modules/flow/i2c.c.orig 2015-08-22 08:54:18 +0300
+++ src/modules/flow/i2c.c 2015-08-27 19:48:53 +0300
@@ -51,9 +51,13 @@
#include "gyro.h"
#include "sonar.h"
#include "main.h"
-
+#include "settings.h"
+#include "usart.h"
+#include "dcmi.h"
+#include "mt9v034.h"
#include "mavlink_bridge_header.h"
#include <mavlink.h>
+#include "communication.h"
/* prototypes */
void I2C1_EV_IRQHandler(void);
@@ -71,6 +75,8 @@
uint8_t readout_done_frame1 = 1;
uint8_t readout_done_frame2 = 1;
uint8_t stop_accumulation = 0;
+uint8_t regNum;
+float tmpParam;
void i2c_init() {
@@ -158,6 +164,7 @@
//receive address offset
dataRX = I2C_ReceiveData(I2C1 );
rxDataIndex++;
+ if (rxDataIndex == 1 && (dataRX < 0x20)) {
//set Index
txDataIndex1 = dataRX;
if (dataRX > I2C_FRAME_SIZE) {
@@ -169,10 +176,82 @@
//indicate sending
readout_done_frame1 = 0;
readout_done_frame2 = 0;
+ } else {
+ // receiving parameter value (0x80+setting number)
+ switch (rxDataIndex) {
+ case 1:
+ // Just register number or specific element from integral frame
+ if (dataRX < 0x80) {
+ regNum = dataRX - 0x20;
+ readout_done_frame2 = 0;
+ readout_done_frame1 = 0;
+ } else {
+ regNum = dataRX - 0x80;
+ txDataIndex1 = 0;
+ }
+ break;
+ case 2:
+ // lower byte
+ *((uint8_t *) &tmpParam) = dataRX;
+ break;
+ case 3:
+ *((uint8_t *) &tmpParam + 1) = dataRX;
+ break;
+ case 4:
+ *((uint8_t *) &tmpParam + 2) = dataRX;
+ break;
+ case 5:
+ *((uint8_t *) &tmpParam + 3) = dataRX;
+ // higher byte, saving parameter
+ rxDataIndex = 0;
+ if (global_data.param_access[regNum] == READ_ONLY)
+ break;
+ global_data.param[regNum] = tmpParam;
+ // copied from communication.c - do stuff for some parameters
+ switch (regNum) {
+ case PARAM_SENSOR_POSITION:
+ set_sensor_position_settings((uint8_t) tmpParam);
+ mt9v034_context_configuration();
+ dma_reconfigure();
+ buffer_reset();
+ break;
+ case PARAM_IMAGE_LOW_LIGHT:
+ case PARAM_IMAGE_ROW_NOISE_CORR:
+ mt9v034_context_configuration();
+ dma_reconfigure();
+ buffer_reset();
+ break;
+ case PARAM_GYRO_SENSITIVITY_DPS:
+ l3gd20_config();
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
break;
}
case I2C_EVENT_SLAVE_BYTE_TRANSMITTING :
case I2C_EVENT_SLAVE_BYTE_TRANSMITTED : {
+ // Check if host is asking for parameters, not frames
+ if (dataRX > 0x80) {
+ I2C_SendData(I2C1,
+ *(((uint8_t *) &global_data.param[regNum]) + txDataIndex1));
+ txDataIndex1++;
+ break;
+ }
+ // Check if host wants specific byte from integral array (+0x20)
+ if (dataRX > 0x20) {
+ I2C_SendData(I2C1,
+ txDataFrame2[publishedIndexFrame2][regNum]);
+ // If last byte from integral array read - reset accumulation
+ if (regNum >= (I2C_INTEGRAL_FRAME_SIZE-1)) {
+ readout_done_frame2 = 1;
+ stop_accumulation = 1;
+ }
+ break;
+ }
if (txDataIndex1 < (I2C_FRAME_SIZE)) {
I2C_SendData(I2C1,