Init
This commit is contained in:
parent
a2853dfda7
commit
fc93dbfc10
198
SensorSPI.c
198
SensorSPI.c
|
|
@ -58,87 +58,209 @@ static void setSensorTypeAdr(tSensorSPI *env, tConABC *connABC, uint8_t adr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DelayCn 1000
|
||||||
|
|
||||||
static void Delay(uint32_t count) {
|
static void Delay(uint32_t count) {
|
||||||
for (uint32_t i = 0; i < count; ++i) {
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
__asm__ volatile("nop");
|
__asm__ volatile("nop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool setSpiSensor(tSensorSPI *env, tSensorType sensorType, tSensorAdr sensorAdr, uint16_t data) {
|
bool setSpiSensor(tSensorSPI *env, tSensorType sensorType, tSensorAdr sensorAdr, uint16_t data) {
|
||||||
|
|
||||||
switch (sensorType) {
|
switch (sensorType) {
|
||||||
|
|
||||||
case SENSOR_TYPE_A: {
|
case SENSOR_TYPE_A: {
|
||||||
|
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
bool result = false;
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
|
||||||
Delay(1000);
|
|
||||||
|
|
||||||
if (sensorAdr >= SENSOR_ADR_9) {
|
if (sensorAdr >= SENSOR_ADR_9) {
|
||||||
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, sensorAdr - 8);
|
setSensorTypeAdr(env, &env->conns->COON_A.Con, sensorAdr - SENSOR_ADR_9);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
Delay(DelayCn);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, false);
|
|
||||||
|
GpioPinSet(&env->conns->COON_A.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_A.En2, false); // CS En2
|
||||||
} else {
|
} else {
|
||||||
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, sensorAdr);
|
setSensorTypeAdr(env, &env->conns->COON_A.Con, sensorAdr);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, false);
|
Delay(DelayCn);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
|
||||||
|
GpioPinSet(&env->conns->COON_A.En1, false); // CS En1
|
||||||
|
GpioPinSet(&env->conns->COON_A.En2, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Delay(1000);
|
Delay(DelayCn);
|
||||||
|
result = SpiPortTransmit(&env->spiPorts->Spi1_IO, &data, 1000);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
bool result = SpiPortTransmit(&env->spiPorts->Spi1_IO, &data, 1000);
|
GpioPinSet(&env->conns->COON_A.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_A.En2, true);
|
||||||
Delay(1000);
|
|
||||||
|
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
|
||||||
|
|
||||||
Delay(1000);
|
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case SENSOR_TYPE_B: {
|
case SENSOR_TYPE_B: {
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
if ((sensorAdr == SENSOR_ADR_8) || (sensorAdr == SENSOR_ADR_9)) {
|
// Эти управляются мультиплексором SENSOR_TYPE_A
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
if ((sensorAdr == SENSOR_ADR_9) || (sensorAdr == SENSOR_ADR_10)) {
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, false);
|
|
||||||
|
|
||||||
if (sensorAdr == SENSOR_ADR_8) {
|
|
||||||
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, SENSOR_ADR_8 - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sensorAdr == SENSOR_ADR_9) {
|
if (sensorAdr == SENSOR_ADR_9) {
|
||||||
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, SENSOR_ADR_9 - 1);
|
setSensorTypeAdr(env, &env->conns->COON_A.Con, SENSOR_ADR_7);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = SpiPortTransmit(&env->spiPorts->Spi1_IO, &data, 1000);
|
if (sensorAdr == SENSOR_ADR_10) {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_A.Con, SENSOR_ADR_8);
|
||||||
|
}
|
||||||
|
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
GpioPinSet(&env->conns->COON_A.En1, true);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
GpioPinSet(&env->conns->COON_A.En2, false); // CS En2
|
||||||
|
|
||||||
return result;
|
Delay(DelayCn);
|
||||||
|
// Только тут SPI2
|
||||||
|
result = SpiPortTransmit(&env->spiPorts->Spi2_IO, &data, 1000);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_A.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_A.En2, true);
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
} else {
|
} else {
|
||||||
GpioPinSet(&env->conns->COON_B.En1, false);
|
|
||||||
|
|
||||||
setSensorTypeAdr(env, &env->conns->COON_B.Con, sensorAdr);
|
setSensorTypeAdr(env, &env->conns->COON_B.Con, sensorAdr);
|
||||||
|
|
||||||
bool result = SpiPortTransmit(&env->spiPorts->Spi1_IO, &data, 1000);
|
Delay(DelayCn);
|
||||||
|
result = SpiPortTransmit(&env->spiPorts->Spi2_IO, &data, 1000);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
GpioPinSet(&env->conns->COON_B.En1, true);
|
GpioPinSet(&env->conns->COON_B.En1, true);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
Delay(DelayCn);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SENSOR_TYPE_C: {
|
|
||||||
break;
|
case SENSOR_TYPE_E: {
|
||||||
|
|
||||||
|
if (sensorAdr >= SENSOR_ADR_9) {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_E.Con, sensorAdr - SENSOR_ADR_9);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_E.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_E.En2, false); // CS En2
|
||||||
|
} else {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_E.Con, sensorAdr);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_E.En1, false); // CS En1
|
||||||
|
GpioPinSet(&env->conns->COON_E.En2, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
|
bool result = SpiPortTransmit(&env->spiPorts->Spi3_IO, &data, 1000);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_E.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_E.En2, true);
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case SENSOR_TYPE_D: {
|
case SENSOR_TYPE_D: {
|
||||||
break;
|
bool result = false;
|
||||||
|
|
||||||
|
// Эти управляются мультиплексором SENSOR_TYPE_E
|
||||||
|
if ((sensorAdr == SENSOR_ADR_9) || (sensorAdr == SENSOR_ADR_10)) {
|
||||||
|
|
||||||
|
if (sensorAdr == SENSOR_ADR_9) {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_E.Con, SENSOR_ADR_5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sensorAdr == SENSOR_ADR_10) {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_E.Con, SENSOR_ADR_6);
|
||||||
|
}
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_E.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_E.En2, false); // CS En2
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
|
result = SpiPortTransmit(&env->spiPorts->Spi3_IO, &data, 1000);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_E.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_E.En2, true);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_D.En1, false); // CS En1
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_D.Con, sensorAdr);
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
|
result = SpiPortTransmit(&env->spiPorts->Spi3_IO, &data, 1000);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_D.En1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
case SENSOR_TYPE_F: {
|
||||||
|
|
||||||
|
if (sensorAdr >= SENSOR_ADR_17) {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_F.Con, sensorAdr - SENSOR_ADR_17);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_F.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_F.En2, true);
|
||||||
|
GpioPinSet(&env->conns->COON_F.En3, false); // CS En3
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (sensorAdr >= SENSOR_ADR_9) {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_F.Con, sensorAdr - SENSOR_ADR_9);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_F.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_F.En2, false); // CS En2
|
||||||
|
GpioPinSet(&env->conns->COON_F.En3, true);
|
||||||
|
} else {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_F.Con, sensorAdr);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_F.En1, false); // CS En1
|
||||||
|
GpioPinSet(&env->conns->COON_F.En2, true);
|
||||||
|
GpioPinSet(&env->conns->COON_F.En3, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
|
bool result = SpiPortTransmit(&env->spiPorts->Spi4_IO, &data, 1000);
|
||||||
|
Delay(DelayCn);
|
||||||
|
|
||||||
|
GpioPinSet(&env->conns->COON_F.En1, true);
|
||||||
|
GpioPinSet(&env->conns->COON_F.En2, true);
|
||||||
|
GpioPinSet(&env->conns->COON_F.En3, true);
|
||||||
|
|
||||||
|
|
||||||
|
Delay(DelayCn);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
15
SensorSPI.h
15
SensorSPI.h
|
|
@ -18,11 +18,16 @@ typedef struct {
|
||||||
tConABC Con;
|
tConABC Con;
|
||||||
tGpioPin En1;
|
tGpioPin En1;
|
||||||
tGpioPin En2;
|
tGpioPin En2;
|
||||||
|
tGpioPin En3;
|
||||||
} tConn;
|
} tConn;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
tConn COON_A_B9_B10;
|
tConn COON_A;
|
||||||
tConn COON_B;
|
tConn COON_B;
|
||||||
|
tConn COON_C;
|
||||||
|
tConn COON_D;
|
||||||
|
tConn COON_E;
|
||||||
|
tConn COON_F;
|
||||||
} tConns;
|
} tConns;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -35,6 +40,8 @@ typedef enum {
|
||||||
SENSOR_TYPE_B,
|
SENSOR_TYPE_B,
|
||||||
SENSOR_TYPE_C,
|
SENSOR_TYPE_C,
|
||||||
SENSOR_TYPE_D,
|
SENSOR_TYPE_D,
|
||||||
|
SENSOR_TYPE_E,
|
||||||
|
SENSOR_TYPE_F
|
||||||
} tSensorType;
|
} tSensorType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
@ -53,7 +60,11 @@ typedef enum {
|
||||||
SENSOR_ADR_13 = 12,
|
SENSOR_ADR_13 = 12,
|
||||||
SENSOR_ADR_14 = 13,
|
SENSOR_ADR_14 = 13,
|
||||||
SENSOR_ADR_15 = 14,
|
SENSOR_ADR_15 = 14,
|
||||||
SENSOR_ADR_16 = 15
|
SENSOR_ADR_16 = 15,
|
||||||
|
SENSOR_ADR_17 = 16,
|
||||||
|
SENSOR_ADR_18 = 17,
|
||||||
|
SENSOR_ADR_19 = 18,
|
||||||
|
SENSOR_ADR_20 = 19
|
||||||
} tSensorAdr;
|
} tSensorAdr;
|
||||||
|
|
||||||
void SensorSpi_Init(tSensorSPI *env, tSpiPorts *spiPorts, tConns *conns);
|
void SensorSpi_Init(tSensorSPI *env, tSpiPorts *spiPorts, tConns *conns);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue