1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <sys/time.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_sleep.h"
- #include "esp_log.h"
- #include "driver/uart.h"
- #include "driver/rtc_io.h"
- #include "esp_intr_alloc.h"
- #include "esp_attr.h"
- #include "driver/timer.h"
- #include <stddef.h>
- #include "esp_intr_alloc.h"
- #include "transceiver.h"
- #include "rxTimer.h"
- #include "config.h"
- bool disableRx = true; // Controls if trcv is in RX or TX-mode
- #ifdef TRANCEIVER_ENABLED
- void trcvSendHighLowPulse(uint32_t high, uint32_t low) {
- if( disableRx == false ) return;
-
- gpio_set_level(GPIO_TX_DATA, 1);
- delayMicroseconds( high );
- gpio_set_level(GPIO_TX_DATA, 0);
- delayMicroseconds( low );
- }
- void initTransceiver() {
- gpio_set_level(GPIO_ENABLE, 0);
- gpio_set_level(GPIO_TX_ENABLE, 0);
- gpio_set_level(GPIO_TX_DATA, 0);
- gpio_pad_select_gpio(GPIO_ENABLE);
- gpio_pad_select_gpio(GPIO_TX_ENABLE);
- gpio_pad_select_gpio(GPIO_TX_DATA);
- gpio_pad_select_gpio(GPIO_RX_DATA);
- gpio_set_direction(GPIO_ENABLE, GPIO_MODE_OUTPUT);
- gpio_set_direction(GPIO_TX_ENABLE, GPIO_MODE_OUTPUT);
- gpio_set_direction(GPIO_TX_DATA, GPIO_MODE_OUTPUT);
- gpio_set_direction(GPIO_RX_DATA, GPIO_MODE_INPUT);
- // ------------------ INIT THE TRANCEIVER -------------------------
- // From powerdown mode (pin 4-5-6 low),
- // 1. Drive high pin 6 (ENABLE)
- // 2. After 20us drive high pin 5 (RX/TX)200us, hold on 40us
- // 3. Drive down 20us pin 6 (ENABLE).
- gpio_set_level(GPIO_ENABLE, 1); delayMicroseconds( 20 );
- gpio_set_level(GPIO_TX_ENABLE, 1); delayMicroseconds( 200 ); gpio_set_level(GPIO_TX_ENABLE, 0);
- delayMicroseconds( 40 );
- gpio_set_level(GPIO_ENABLE, 0); delayMicroseconds( 20 ); gpio_set_level(GPIO_ENABLE, 1);
- delayMicroseconds( 200 );
- // ------------------ INIT THE TRANCEIVER -------------------------
-
- ESP_LOGI("TRCV", "Transceiver has been initialized.");
- }
- void trcvSwitch2transmit() {
- disableRx = true;
- // ------------------ GO TO TRANSMIT STATE -------------------------
- gpio_set_level(GPIO_TX_ENABLE, 1);
- delayMicroseconds( 400 );
- // ------------------ GO TO TRANSMIT STATE -------------------------
- }
- void trcvSwitch2receive() {
- // ------------------ GO TO RECEIVE STATE -------------------------
- // From Transmission Mode to Receiver Mode follow the procedure:
- // Drive down pin 5 (RX/TX), after 40us drive down pin 6 (ENABLE) 20us long.
- //After 200 us the device is ready for reception.
- gpio_set_level(GPIO_TX_ENABLE, 0);
- delayMicroseconds( 40 );
- gpio_set_level(GPIO_ENABLE, 0);
- delayMicroseconds( 20 );
- gpio_set_level(GPIO_ENABLE, 1);
- delayMicroseconds( 200 );
- // ------------------ GO TO RECEIVE STATE -------------------------
- disableRx = false;
- }
- #endif
|