Init
This commit is contained in:
parent
22646c56f5
commit
a4217a5668
35
SensorSPI.c
35
SensorSPI.c
|
|
@ -58,47 +58,42 @@ static void setSensorTypeAdr(tSensorSPI *env, tConABC *connABC, uint8_t adr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Delay(uint32_t count) {
|
||||||
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
|
__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);
|
||||||
|
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
||||||
|
Delay(100);
|
||||||
|
|
||||||
if (sensorAdr >= SENSOR_ADR_9) {
|
if (sensorAdr >= SENSOR_ADR_9) {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, sensorAdr - 8);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, false);
|
GpioPinSet(&env->conns->COON_A_B9_B10.En2, false);
|
||||||
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, sensorAdr - 8);
|
|
||||||
} else {
|
} else {
|
||||||
|
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, sensorAdr);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, false);
|
GpioPinSet(&env->conns->COON_A_B9_B10.En1, false);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
||||||
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, sensorAdr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__asm__ volatile("nop");
|
Delay(100);
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
// SystemDelayMs(1);
|
|
||||||
|
|
||||||
bool result = SpiPortTransmit(&env->spiPorts->Spi1_IO, &data, 1000);
|
bool result = SpiPortTransmit(&env->spiPorts->Spi1_IO, &data, 1000);
|
||||||
|
|
||||||
__asm__ volatile("nop");
|
Delay(100);
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
// SystemDelayMs(1);
|
|
||||||
|
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
||||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
||||||
|
|
||||||
__asm__ volatile("nop");
|
Delay(100);
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
__asm__ volatile("nop");
|
|
||||||
// SystemDelayMs(1);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue