diff --git a/README.md b/README.md index 9f1e1a1..26fe7b6 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,7 @@ The downside is the effort required to develop firmware and flash by the end use The firmware radio decoding is inspired by 1) RF-Bridge-EFM8BB1 (Portisch) and 2) rc-switch projects. # Status -THIS IS A WORK IN PROGRESS and requires multiple flashing steps. -Decoding has only been tested with a single door sensor using standard 24 bit protocol. +THIS IS A WORK IN PROGRESS and requires multiple flashing steps. For many users it is probably easiest to flash the passthrough mode. Then perform any actual decoding/encoding on the ESP8265 using Tasmota/ESPHome. diff --git a/inc/portisch_command_format.h b/inc/portisch_command_format.h new file mode 100644 index 0000000..4737d61 --- /dev/null +++ b/inc/portisch_command_format.h @@ -0,0 +1,52 @@ +#ifndef PORTISCH_COMMAND_H +#define PORTISCH_COMMAND_H + +// common uart packet format for both rcswitch and portisch (despite the file name) + +// this is returned along with an ack in response to a request firmware version command +// which is a good demonstration that serial pins and state machine are working +#define FIRMWARE_VERSION 0x04 + + +// start and end of uart packet +#define RF_CODE_START 0xAA +#define RF_CODE_STOP 0x55 + +// uart packet format +typedef enum +{ + IDLE, + SYNC_INIT, + SYNC_FINISH, + RECEIVE_LENGTH, + RECEIVING, + TRANSMIT, + COMMAND +} uart_state_t; + + +// commands which should be supported partially by rcswitch and mostly by portisch are given here (learning are not supported as of writing): +// https://github.com/Portisch/RF-Bridge-EFM8BB1/wiki/Commands +typedef enum +{ + NONE = 0x00, + RF_CODE_ACK = 0xA0, + RF_CODE_LEARN = 0xA1, + RF_CODE_LEARN_KO = 0xA2, + RF_CODE_LEARN_OK = 0xA3, + RF_CODE_RFIN = 0xA4, + RF_CODE_RFOUT = 0xA5, + RF_CODE_SNIFFING_ON = 0xA6, + RF_CODE_SNIFFING_OFF = 0xA7, + RF_CODE_RFOUT_NEW = 0xA8, + RF_CODE_LEARN_NEW = 0xA9, + RF_CODE_LEARN_KO_NEW = 0xAA, + RF_CODE_LEARN_OK_NEW = 0xAB, + RF_CODE_RFOUT_BUCKET = 0xB0, + RF_CODE_SNIFFING_ON_BUCKET = 0xB1, + RF_DO_BEEP = 0xC0, + RF_ALTERNATIVE_FIRMWARE = 0xFF +} uart_command_t; + + +#endif \ No newline at end of file diff --git a/inc/portisch_macros.h b/inc/portisch_macros.h index bebfe45..d45afa7 100644 --- a/inc/portisch_macros.h +++ b/inc/portisch_macros.h @@ -10,14 +10,6 @@ #include #include - -//#include - -// used in timer functions -//#define SYSCLK 24500000 - -// -#define FIRMWARE_VERSION 0x03 // macros #define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0])) diff --git a/inc/portisch_serial.h b/inc/portisch_serial.h index 1bb7585..e5bb1ca 100644 --- a/inc/portisch_serial.h +++ b/inc/portisch_serial.h @@ -2,52 +2,12 @@ #define INC_SERIAL_H #include - -// tasmota protocol -#define RF_CODE_START 0xAA -#define RF_CODE_STOP 0x55 - -//----------------------------------------------------------------------------- -// Global Enums -//----------------------------------------------------------------------------- -typedef enum -{ - IDLE, - SYNC_INIT, - SYNC_FINISH, - RECEIVE_LEN, - RECEIVING, - TRANSMIT, - COMMAND -} uart_state_t; - -typedef enum -{ - NONE = 0x00, - RF_CODE_ACK = 0xA0, - RF_CODE_LEARN = 0xA1, - RF_CODE_LEARN_KO = 0xA2, - RF_CODE_LEARN_OK = 0xA3, - RF_CODE_RFIN = 0xA4, - RF_CODE_RFOUT = 0xA5, - RF_CODE_SNIFFING_ON = 0xA6, - RF_CODE_SNIFFING_OFF = 0xA7, - RF_CODE_RFOUT_NEW = 0xA8, - RF_CODE_LEARN_NEW = 0xA9, - RF_CODE_LEARN_KO_NEW = 0xAA, - RF_CODE_LEARN_OK_NEW = 0xAB, - RF_CODE_RFOUT_BUCKET = 0xB0, - RF_CODE_SNIFFING_ON_BUCKET = 0xB1, - RF_DO_BEEP = 0xC0, - RF_ALTERNATIVE_FIRMWARE = 0xFF -} uart_command_t; - //----------------------------------------------------------------------------- // Global Variables //----------------------------------------------------------------------------- -extern __xdata uart_state_t uart_state; -extern __xdata uart_command_t uart_command; +//extern __xdata uart_state_t uart_state; +//extern __xdata uart_command_t uart_command; //extern void uart_put_command(uint8_t command); diff --git a/inc/state_machine.h b/inc/state_machine.h index 00b2d0e..838a202 100644 --- a/inc/state_machine.h +++ b/inc/state_machine.h @@ -6,47 +6,6 @@ #ifndef STATE_MACHINE_H #define STATE_MACHINE_H -// this is returned along with an ack in response to a request firmware version command -// which is a good demonstration that serial pins and state machine are working -#define FIRMWARE_VERSION 0x03 - - -// FIXME: add comment -typedef enum -{ - IDLE, - SYNC_INIT, - SYNC_FINISH, - RECEIVE_LENGTH, - RECEIVING, - TRANSMIT, - COMMAND -} UART_STATE_T; - - -// commands which should be supported (eventually) are given here: -// https://github.com/Portisch/RF-Bridge-EFM8BB1/wiki/Commands -typedef enum -{ - NONE = 0x00, - RF_CODE_ACK = 0xA0, - RF_CODE_LEARN = 0xA1, - RF_CODE_LEARN_KO = 0xA2, - RF_CODE_LEARN_OK = 0xA3, - RF_CODE_RFIN = 0xA4, - RF_CODE_RFOUT = 0xA5, - RF_CODE_SNIFFING_ON = 0xA6, - RF_CODE_SNIFFING_OFF = 0xA7, - RF_CODE_RFOUT_NEW = 0xA8, - RF_CODE_LEARN_NEW = 0xA9, - RF_CODE_LEARN_KO_NEW = 0xAA, - RF_CODE_LEARN_OK_NEW = 0xAB, - RF_CODE_RFOUT_BUCKET = 0xB0, - RF_CODE_SNIFFING_ON_BUCKET = 0xB1, - RF_DO_BEEP = 0xC0, - RF_ALTERNATIVE_FIRMWARE = 0xFF -} UART_COMMAND_T; - typedef enum { RF_IDLE = 0x00, diff --git a/src/main_portisch.c b/src/main_portisch.c index 726846b..a6d5302 100644 --- a/src/main_portisch.c +++ b/src/main_portisch.c @@ -22,6 +22,7 @@ #include "delay.h" #include "hal.h" #include "portisch.h" +#include "portisch_command_format.h" #include "portisch_protocols.h" #include "portisch_serial.h" #include "timer_interrupts.h" @@ -203,10 +204,10 @@ void uart_state_machine(const unsigned int rxdata) break; case RF_CODE_RFOUT_NEW: tr_repeats = RF_TRANSMIT_REPEATS; - uart_state = RECEIVE_LEN; + uart_state = RECEIVE_LENGTH; break; case RF_CODE_RFOUT_BUCKET: - uart_state = RECEIVE_LEN; + uart_state = RECEIVE_LENGTH; break; case RF_CODE_SNIFFING_ON_BUCKET: PCA0_DoSniffing(); @@ -233,7 +234,7 @@ void uart_state_machine(const unsigned int rxdata) break; // Receiving UART data length - case RECEIVE_LEN: + case RECEIVE_LENGTH: position = 0; packetLength = rxdata & 0xFF; if (packetLength > 0) diff --git a/src/main_rcswitch.c b/src/main_rcswitch.c index fe804fe..812ea08 100644 --- a/src/main_rcswitch.c +++ b/src/main_rcswitch.c @@ -181,7 +181,7 @@ int main (void) unsigned int rxdataWithFlags = UART_NO_DATA; // allows communication between uart state machine and radio state machine - RF_COMMAND_T rfCommand = NONE; + RF_COMMAND_T rfCommand; // hardware initialization @@ -203,7 +203,7 @@ int main (void) // DEBUG: // on some boards, "debug pin" is actually buzzer so we do not want to use it for debugging unless buzzer has been removed - debug_pin01_off(); + //debug_pin01_off(); // startup_blink(); diff --git a/src/portisch_serial.c b/src/portisch_serial.c index 693e85d..39c45b4 100644 --- a/src/portisch_serial.c +++ b/src/portisch_serial.c @@ -3,12 +3,6 @@ #include "portisch_serial.h" #include "uart.h" -//void uart_put_command(uint8_t command) -//{ -// uart_putc(RF_CODE_START); -// uart_putc(command); -// uart_putc(RF_CODE_STOP); -//} void uart_put_RF_Data_Standard(uint8_t command) { diff --git a/src/rcswitch.c b/src/rcswitch.c index 4aa87e6..f04ceff 100644 --- a/src/rcswitch.c +++ b/src/rcswitch.c @@ -290,7 +290,7 @@ void transmit(const bool invertedSignal, uint16_t delayHigh, uint16_t delayLow) set_tdata(firstLogicLevel); // DEBUG: - set_debug_pin01(firstLogicLevel); + //set_debug_pin01(firstLogicLevel); init_delay_timer_us(1, delayHigh); wait_delay_timer_finished(); @@ -300,7 +300,7 @@ void transmit(const bool invertedSignal, uint16_t delayHigh, uint16_t delayLow) set_tdata(secondLogicLevel); // DEBUG: - set_debug_pin01(secondLogicLevel); + //set_debug_pin01(secondLogicLevel); init_delay_timer_us(1, delayLow); diff --git a/src/state_machine.c b/src/state_machine.c index abafe2d..d65567d 100644 --- a/src/state_machine.c +++ b/src/state_machine.c @@ -1,5 +1,9 @@ #include "delay.h" #include "hal.h" + +// we use the same format as portisch so okay to include +#include "portisch_command_format.h" + #include "rcswitch.h" #include "state_machine.h" #include "uart.h" @@ -36,8 +40,8 @@ RF_COMMAND_T uart_state_machine(const unsigned int rxdataWithFlags) { // FIXME: eventually an appropriate initialization value might be RF_RFIN for decoding by default // but right now we decode outside of state machine - __xdata static UART_STATE_T state = IDLE; - __xdata static UART_COMMAND_T command = NONE; + __xdata static uart_state_t state = IDLE; + __xdata static uart_command_t command = NONE; // FIXME: need to know what initialization value is appropriate __xdata static uint8_t position = 0;