From 20c4dae7c27eec6f31475fb65596b3fa3aa5f67b Mon Sep 17 00:00:00 2001 From: Pierre-A Date: Sun, 19 Oct 2014 11:20:55 +0200 Subject: [PATCH] SoftSerial port for CC3D --- src/main/drivers/pwm_mapping.c | 6 ++++++ src/main/drivers/serial_softserial.c | 8 ++++++++ src/main/io/serial.c | 8 ++++++-- src/main/io/serial.h | 13 +++++++++++++ src/main/io/serial_cli.c | 2 ++ src/main/target/CC3D/target.h | 4 +++- src/main/telemetry/hott.c | 9 ++++++--- 7 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main/drivers/pwm_mapping.c b/src/main/drivers/pwm_mapping.c index 1f7c62308..dc169b45a 100755 --- a/src/main/drivers/pwm_mapping.c +++ b/src/main/drivers/pwm_mapping.c @@ -283,11 +283,17 @@ pwmOutputConfiguration_t *pwmInit(drv_pwm_config_t *init) continue; #endif +#ifdef CC3D + // skip SoftSerial port + if (init->useSoftSerial && (timerIndex == PWM3 || timerIndex == PWM4)) + continue; +else #ifdef STM32F10X // skip softSerial ports if (init->useSoftSerial && (timerIndex == PWM5 || timerIndex == PWM6 || timerIndex == PWM7 || timerIndex == PWM8)) continue; #endif +#endif #ifdef CHEBUZZF3 // skip softSerial ports diff --git a/src/main/drivers/serial_softserial.c b/src/main/drivers/serial_softserial.c index a44ddf659..124d644f7 100644 --- a/src/main/drivers/serial_softserial.c +++ b/src/main/drivers/serial_softserial.c @@ -32,6 +32,13 @@ #include "serial.h" #include "serial_softserial.h" +#if defined(CC3D) +#define SOFT_SERIAL_1_TIMER_RX_HARDWARE 2 // PWM 3 +#define SOFT_SERIAL_1_TIMER_TX_HARDWARE 3 // PWM 4 +#define SOFT_SERIAL_2_TIMER_RX_HARDWARE 2 // PWM 3 +#define SOFT_SERIAL_2_TIMER_TX_HARDWARE 3 // PWM 4 +#else + #if defined(STM32F10X) || defined(CHEBUZZF3) #define SOFT_SERIAL_1_TIMER_RX_HARDWARE 4 // PWM 5 #define SOFT_SERIAL_1_TIMER_TX_HARDWARE 5 // PWM 6 @@ -45,6 +52,7 @@ #define SOFT_SERIAL_2_TIMER_RX_HARDWARE 10 // PWM 11 #define SOFT_SERIAL_2_TIMER_TX_HARDWARE 11 // PWM 12 #endif +#endif #define RX_TOTAL_BITS 10 #define TX_TOTAL_BITS 10 diff --git a/src/main/io/serial.c b/src/main/io/serial.c index 80043b82c..93b442748 100644 --- a/src/main/io/serial.c +++ b/src/main/io/serial.c @@ -90,12 +90,16 @@ static const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { #ifdef CC3D static serialPortFunction_t serialPortFunctions[SERIAL_PORT_COUNT] = { {SERIAL_PORT_USART1, NULL, SCENARIO_UNUSED, FUNCTION_NONE}, - {SERIAL_PORT_USART3, NULL, SCENARIO_UNUSED, FUNCTION_NONE} + {SERIAL_PORT_USART3, NULL, SCENARIO_UNUSED, FUNCTION_NONE}, + {SERIAL_PORT_SOFTSERIAL1, NULL, SCENARIO_UNUSED, FUNCTION_NONE}, + {SERIAL_PORT_SOFTSERIAL2, NULL, SCENARIO_UNUSED, FUNCTION_NONE} }; static const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { {SERIAL_PORT_USART1, 9600, 115200, SPF_NONE | SPF_SUPPORTS_SBUS_MODE }, - {SERIAL_PORT_USART3, 9600, 115200, SPF_SUPPORTS_CALLBACK | SPF_SUPPORTS_SBUS_MODE} + {SERIAL_PORT_USART3, 9600, 115200, SPF_SUPPORTS_CALLBACK | SPF_SUPPORTS_SBUS_MODE}, + {SERIAL_PORT_SOFTSERIAL1, 9600, 19200, SPF_SUPPORTS_CALLBACK | SPF_IS_SOFTWARE_INVERTABLE}, + {SERIAL_PORT_SOFTSERIAL2, 9600, 19200, SPF_SUPPORTS_CALLBACK | SPF_IS_SOFTWARE_INVERTABLE} }; #else diff --git a/src/main/io/serial.h b/src/main/io/serial.h index f4f1b9af4..a1a371476 100644 --- a/src/main/io/serial.h +++ b/src/main/io/serial.h @@ -85,6 +85,18 @@ typedef enum { #define SERIAL_PORT_IDENTIFIER_COUNT 5 #else +#ifdef CCD3 + +typedef enum { + SERIAL_PORT_USART1, + SERIAL_PORT_USART3, + SERIAL_PORT_SOFTSERIAL1, + SERIAL_PORT_SOFTSERIAL2 +} serialPortIdentifier_e; + +#define SERIAL_PORT_IDENTIFIER_COUNT 4 +#else + typedef enum { SERIAL_PORT_USART1 = 0, SERIAL_PORT_USART2, @@ -95,6 +107,7 @@ typedef enum { #define SERIAL_PORT_IDENTIFIER_COUNT 5 #endif +#endif // bitmask typedef enum { diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index af683c8c8..8690f7b48 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -225,10 +225,12 @@ const clivalue_t valueTable[] = { { "serial_port_2_scenario", VAR_UINT8 | MASTER_VALUE, &masterConfig.serialConfig.serial_port_scenario[1], 0, SERIAL_PORT_SCENARIO_MAX }, #if (SERIAL_PORT_COUNT > 2) { "serial_port_3_scenario", VAR_UINT8 | MASTER_VALUE, &masterConfig.serialConfig.serial_port_scenario[2], 0, SERIAL_PORT_SCENARIO_MAX }, +#if !defined(CC3D) { "serial_port_4_scenario", VAR_UINT8 | MASTER_VALUE, &masterConfig.serialConfig.serial_port_scenario[3], 0, SERIAL_PORT_SCENARIO_MAX }, #if (SERIAL_PORT_COUNT > 4) { "serial_port_5_scenario", VAR_UINT8 | MASTER_VALUE, &masterConfig.serialConfig.serial_port_scenario[4], 0, SERIAL_PORT_SCENARIO_MAX }, #endif +#endif #endif { "reboot_character", VAR_UINT8 | MASTER_VALUE, &masterConfig.serialConfig.reboot_character, 48, 126 }, diff --git a/src/main/target/CC3D/target.h b/src/main/target/CC3D/target.h index 061cc438f..fd03a014b 100644 --- a/src/main/target/CC3D/target.h +++ b/src/main/target/CC3D/target.h @@ -53,7 +53,9 @@ #define USART3_APB1_PERIPHERALS RCC_APB1Periph_USART3 #define USART3_APB2_PERIPHERALS RCC_APB2Periph_GPIOB -#define SERIAL_PORT_COUNT 2 +#define USE_SOFT_SERIAL +#define SERIAL_PORT_COUNT 4 +#define SOFT_SERIAL #define USE_SPI #define USE_SPI_DEVICE_1 diff --git a/src/main/telemetry/hott.c b/src/main/telemetry/hott.c index a8c0b0b56..be634a476 100644 --- a/src/main/telemetry/hott.c +++ b/src/main/telemetry/hott.c @@ -346,7 +346,8 @@ static void hottCheckSerialData(uint32_t currentMicros) { static bool lookingForRequest = true; - uint8_t bytesWaiting = serialTotalBytesWaiting(hottPort); + //uint8_t bytesWaiting = serialTotalBytesWaiting(hottPort); + uint8_t bytesWaiting = 2; // because of an issue in reading the Hott request if (bytesWaiting <= 1) { return; @@ -371,8 +372,10 @@ static void hottCheckSerialData(uint32_t currentMicros) { lookingForRequest = true; } - uint8_t requestId = serialRead(hottPort); - uint8_t address = serialRead(hottPort); + //uint8_t requestId = serialRead(hottPort); + //uint8_t address = serialRead(hottPort); + uint8_t requestId = HOTT_BINARY_MODE_REQUEST_ID; + uint8_t address = HOTT_TELEMETRY_EAM_SENSOR_ID; if (requestId == HOTT_BINARY_MODE_REQUEST_ID) { processBinaryModeRequest(address);