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) {
|
||||
|
||||
switch (sensorType) {
|
||||
|
||||
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) {
|
||||
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.En2, false);
|
||||
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, sensorAdr - 8);
|
||||
} 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.En2, true);
|
||||
setSensorTypeAdr(env, &env->conns->COON_A_B9_B10.Con, sensorAdr);
|
||||
}
|
||||
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
// SystemDelayMs(1);
|
||||
Delay(100);
|
||||
|
||||
bool result = SpiPortTransmit(&env->spiPorts->Spi1_IO, &data, 1000);
|
||||
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
// SystemDelayMs(1);
|
||||
Delay(100);
|
||||
|
||||
GpioPinSet(&env->conns->COON_A_B9_B10.En1, true);
|
||||
GpioPinSet(&env->conns->COON_A_B9_B10.En2, true);
|
||||
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
// SystemDelayMs(1);
|
||||
Delay(100);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue