Обновлена библиотека для датчиков с py32 модуля

This commit is contained in:
2025-03-05 11:45:32 +03:00
parent d86a7899a3
commit 0689046c85
12 changed files with 524 additions and 513 deletions

View File

@@ -16,6 +16,7 @@ void OneWire_WriteBit(OneWire_t* OW, uint8_t bit)
if(OW == NULL)
return;
#ifndef ONEWIRE_UART_H
__disable_irq();
if(bit)
{
/* Set line low */
@@ -23,13 +24,13 @@ void OneWire_WriteBit(OneWire_t* OW, uint8_t bit)
OneWire_Pin_Mode(OW, Output);
/* Forming pulse */
OneWireDelay_uw(ONEWIRE_WRITE_1_US);
OneWire_Delay_uw(ONEWIRE_WRITE_1_US);
/* Release line (pull up line) */
OneWire_Pin_Mode(OW, Input);
/* Wait for 55 us and release the line */
OneWireDelay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_1_US);
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_1_US);
OneWire_Pin_Mode(OW, Input);
}else{
/* Set line low */
@@ -37,15 +38,16 @@ void OneWire_WriteBit(OneWire_t* OW, uint8_t bit)
OneWire_Pin_Mode(OW, Output);
/* Forming pulse */
OneWireDelay_uw(ONEWIRE_WRITE_0_US);
OneWire_Delay_uw(ONEWIRE_WRITE_0_US);
/* Release line (pull up line) */
OneWire_Pin_Mode(OW, Input);
/* Wait for 5 us and release the line */
OneWireDelay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_0_US);
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_0_US);
OneWire_Pin_Mode(OW, Input);
}
__enable_irq();
#else
OneWireUART_ProcessBit(onewire_uart, bit);
#endif
@@ -61,22 +63,24 @@ uint8_t OneWire_ReadBit(OneWire_t* OW)
if(OW == NULL)
return 0;
__disable_irq();
uint8_t bit = 0;
#ifndef ONEWIRE_UART_H
/* Line low */
OneWire_Pin_Level(OW, 0);
OneWire_Pin_Mode(OW, Output);
OneWireDelay_uw(ONEWIRE_READ_CMD_US);
OneWire_Delay_uw(ONEWIRE_READ_CMD_US);
/* Release line */
OneWire_Pin_Mode(OW, Input);
OneWireDelay_uw(ONEWIRE_READ_DELAY_US);
OneWire_Delay_uw(ONEWIRE_READ_DELAY_US);
/* Read line value */
bit = OneWire_Pin_Read(OW);
/* Wait 50us to complete 60us period */
OneWireDelay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_READ_CMD_US - ONEWIRE_READ_DELAY_US);
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_READ_CMD_US - ONEWIRE_READ_DELAY_US);
__enable_irq();
#else
bit = OneWireUART_ProcessBit(onewire_uart, 1);
#endif
@@ -145,17 +149,17 @@ uint8_t OneWire_Reset(OneWire_t* OW)
/* Line low, and wait 480us */
OneWire_Pin_Level(OW, 0);
OneWire_Pin_Mode(OW, Output);
OneWireDelay_uw(ONEWIRE_RESET_PULSE_US);
OneWire_Delay_uw(ONEWIRE_RESET_PULSE_US);
/* Release line and wait for 70us */
OneWire_Pin_Mode(OW, Input);
OneWireDelay_uw(ONEWIRE_PRESENCE_WAIT_US);
OneWire_Delay_uw(ONEWIRE_PRESENCE_WAIT_US);
/* Check bit value */
uint8_t rslt = OneWire_Pin_Read(OW);
/* Delay for 410 us */
OneWireDelay_uw(ONEWIRE_PRESENCE_DURATION_US);
OneWire_Delay_uw(ONEWIRE_PRESENCE_DURATION_US);
#else
uint8_t rslt = 0;
@@ -312,11 +316,11 @@ void OneWire_Init(OneWire_t* OW)
{
OneWire_Pin_Mode(OW, Output);
OneWire_Pin_Level(OW, 1);
OneWireDelay_uw(1000);
OneWire_Delay_uw(1000);
OneWire_Pin_Level(OW, 0);
OneWireDelay_uw(1000);
OneWire_Delay_uw(1000);
OneWire_Pin_Level(OW, 1);
OneWireDelay_uw(2000);
OneWire_Delay_uw(2000);
/* Reset the search state */
OW->LastDiscrepancy = 0;