Add CJMCU revision detection. Use LEDs to indicate Spektrum binding
activity.
This commit is contained in:
parent
2641f6ada7
commit
53faaff63c
1
Makefile
1
Makefile
|
@ -355,6 +355,7 @@ CJMCU_SRC = startup_stm32f10x_md_gcc.S \
|
||||||
drivers/system_stm32f10x.c \
|
drivers/system_stm32f10x.c \
|
||||||
drivers/timer.c \
|
drivers/timer.c \
|
||||||
drivers/timer_stm32f10x.c \
|
drivers/timer_stm32f10x.c \
|
||||||
|
hardware_revision.c \
|
||||||
$(COMMON_SRC)
|
$(COMMON_SRC)
|
||||||
|
|
||||||
CC3D_SRC = startup_stm32f10x_md_gcc.S \
|
CC3D_SRC = startup_stm32f10x_md_gcc.S \
|
||||||
|
|
|
@ -74,8 +74,8 @@
|
||||||
#include "config/config_profile.h"
|
#include "config/config_profile.h"
|
||||||
#include "config/config_master.h"
|
#include "config/config_master.h"
|
||||||
|
|
||||||
#ifdef NAZE
|
#ifdef USE_HARDWARE_REVISION_DETECTION
|
||||||
#include "target/NAZE/hardware_revision.h"
|
#include "hardware_revision.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "build_config.h"
|
#include "build_config.h"
|
||||||
|
@ -146,12 +146,14 @@ void init(void)
|
||||||
SetSysClock(masterConfig.emf_avoidance);
|
SetSysClock(masterConfig.emf_avoidance);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NAZE
|
#ifdef USE_HARDWARE_REVISION_DETECTION
|
||||||
detectHardwareRevision();
|
detectHardwareRevision();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
systemInit();
|
systemInit();
|
||||||
|
|
||||||
|
ledInit();
|
||||||
|
|
||||||
#ifdef SPEKTRUM_BIND
|
#ifdef SPEKTRUM_BIND
|
||||||
if (feature(FEATURE_RX_SERIAL)) {
|
if (feature(FEATURE_RX_SERIAL)) {
|
||||||
switch (masterConfig.rxConfig.serialrx_provider) {
|
switch (masterConfig.rxConfig.serialrx_provider) {
|
||||||
|
@ -170,8 +172,6 @@ void init(void)
|
||||||
|
|
||||||
timerInit(); // timer must be initialized before any channel is allocated
|
timerInit(); // timer must be initialized before any channel is allocated
|
||||||
|
|
||||||
ledInit();
|
|
||||||
|
|
||||||
#ifdef BEEPER
|
#ifdef BEEPER
|
||||||
beeperConfig_t beeperConfig = {
|
beeperConfig_t beeperConfig = {
|
||||||
.gpioMode = Mode_Out_OD,
|
.gpioMode = Mode_Out_OD,
|
||||||
|
@ -201,7 +201,7 @@ void init(void)
|
||||||
spiInit(SPI2);
|
spiInit(SPI2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NAZE
|
#ifdef USE_HARDWARE_REVISION_DETECTION
|
||||||
updateHardwareRevision();
|
updateHardwareRevision();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "drivers/gpio.h"
|
#include "drivers/gpio.h"
|
||||||
#include "drivers/system.h"
|
#include "drivers/system.h"
|
||||||
|
|
||||||
|
#include "drivers/light_led.h"
|
||||||
|
|
||||||
#include "drivers/serial.h"
|
#include "drivers/serial.h"
|
||||||
#include "drivers/serial_uart.h"
|
#include "drivers/serial_uart.h"
|
||||||
#include "io/serial.h"
|
#include "io/serial.h"
|
||||||
|
@ -176,11 +178,12 @@ bool spekShouldBind(uint8_t spektrum_sat_bind)
|
||||||
void spektrumBind(rxConfig_t *rxConfig)
|
void spektrumBind(rxConfig_t *rxConfig)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!spekShouldBind(rxConfig->spektrum_sat_bind)) {
|
if (!spekShouldBind(rxConfig->spektrum_sat_bind)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LED1_ON;
|
||||||
|
|
||||||
gpio_config_t cfg = {
|
gpio_config_t cfg = {
|
||||||
BIND_PIN,
|
BIND_PIN,
|
||||||
Mode_Out_OD,
|
Mode_Out_OD,
|
||||||
|
@ -193,16 +196,22 @@ void spektrumBind(rxConfig_t *rxConfig)
|
||||||
|
|
||||||
// Bind window is around 20-140ms after powerup
|
// Bind window is around 20-140ms after powerup
|
||||||
delay(60);
|
delay(60);
|
||||||
|
LED1_OFF;
|
||||||
|
|
||||||
for (i = 0; i < rxConfig->spektrum_sat_bind; i++) {
|
for (i = 0; i < rxConfig->spektrum_sat_bind; i++) {
|
||||||
|
|
||||||
|
LED0_OFF;
|
||||||
|
LED2_OFF;
|
||||||
// RX line, drive low for 120us
|
// RX line, drive low for 120us
|
||||||
digitalLo(BIND_PORT, BIND_PIN);
|
digitalLo(BIND_PORT, BIND_PIN);
|
||||||
delayMicroseconds(120);
|
delayMicroseconds(120);
|
||||||
|
|
||||||
|
LED0_ON;
|
||||||
|
LED2_ON;
|
||||||
// RX line, drive high for 120us
|
// RX line, drive high for 120us
|
||||||
digitalHi(BIND_PORT, BIND_PIN);
|
digitalHi(BIND_PORT, BIND_PIN);
|
||||||
delayMicroseconds(120);
|
delayMicroseconds(120);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HARDWARE_BIND_PLUG
|
#ifndef HARDWARE_BIND_PLUG
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Cleanflight.
|
||||||
|
*
|
||||||
|
* Cleanflight is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#include "build_config.h"
|
||||||
|
|
||||||
|
#include "drivers/system.h"
|
||||||
|
#include "drivers/bus_spi.h"
|
||||||
|
#include "drivers/sensor.h"
|
||||||
|
#include "drivers/accgyro.h"
|
||||||
|
#include "drivers/accgyro_spi_mpu6500.h"
|
||||||
|
|
||||||
|
#include "hardware_revision.h"
|
||||||
|
|
||||||
|
static const char * const hardwareRevisionNames[] = {
|
||||||
|
"Unknown",
|
||||||
|
"R1",
|
||||||
|
"R2"
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t hardwareRevision = UNKNOWN;
|
||||||
|
|
||||||
|
void detectHardwareRevision(void)
|
||||||
|
{
|
||||||
|
if (GPIOC->IDR & GPIO_Pin_15) {
|
||||||
|
hardwareRevision = REV_2;
|
||||||
|
} else {
|
||||||
|
hardwareRevision = REV_1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateHardwareRevision(void)
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Cleanflight.
|
||||||
|
*
|
||||||
|
* Cleanflight is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef enum cjmcuHardwareRevision_t {
|
||||||
|
UNKNOWN = 0,
|
||||||
|
REV_1, // Blue LED3
|
||||||
|
REV_2 // Green LED3
|
||||||
|
} cjmcuHardwareRevision_e;
|
||||||
|
|
||||||
|
extern uint8_t hardwareRevision;
|
||||||
|
|
||||||
|
void updateHardwareRevision(void);
|
||||||
|
void detectHardwareRevision(void);
|
|
@ -18,6 +18,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define TARGET_BOARD_IDENTIFIER "CJM1" // CJMCU
|
#define TARGET_BOARD_IDENTIFIER "CJM1" // CJMCU
|
||||||
|
#define USE_HARDWARE_REVISION_DETECTION
|
||||||
|
|
||||||
#define FLASH_PAGE_COUNT 64
|
#define FLASH_PAGE_COUNT 64
|
||||||
#define FLASH_PAGE_SIZE ((uint16_t)0x400)
|
#define FLASH_PAGE_SIZE ((uint16_t)0x400)
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define TARGET_BOARD_IDENTIFIER "AFNA" // AFroNAze - NAZE might be considered misleading on Naze clones like the flip32.
|
#define TARGET_BOARD_IDENTIFIER "AFNA" // AFroNAze - NAZE might be considered misleading on Naze clones like the flip32.
|
||||||
|
#define USE_HARDWARE_REVISION_DETECTION
|
||||||
|
|
||||||
#define LED0_GPIO GPIOB
|
#define LED0_GPIO GPIOB
|
||||||
#define LED0_PIN Pin_3 // PB3 (LED)
|
#define LED0_PIN Pin_3 // PB3 (LED)
|
||||||
|
|
Loading…
Reference in New Issue